CodeSampleX

샘플

chromium-bidi 2.1.2: Exception

검증된 샘플 — npm chromium-bidi 2.1.2: Exception. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: Exception constructor sets error code, message and…

sha256:4abb250bc42aa0a94a8a0b773f8a1398c6b344e57da61eccf3398fc26301351d

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 linux 24 · ubuntu · glibc 2.39 x64 npm

검증 실행 환경

환경 컨트랙트 단계 실행일
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5…
2026-08-27

케이스

HOW
목표
verify chromium-bidi.Exception in pkg:npm/chromium-bidi@2.1.2
패키지
심벌
  • chromium-bidi.Exception
생성일
2026-08-27T10:54:45Z

컨트랙트

  1. Exception constructor sets error code, message and optional stacktrace
  2. Exception subclasses inherit from Exception with predefined error names
  3. Exception.toErrorResponse formats standard BiDi error payload with stacktrace field
  4. NoSuchElementException.toErrorResponse formats error response with no such element code
  5. NoSuchScriptException.toErrorResponse formats error response with undefined stacktrace
  6. Protocol parser throws InvalidArgumentException inheriting from Exception on invalid input

파일

  • PROMPT.md
  • csx.json
  • index.js
  • package-lock.json
  • package.json
  • spec.json
  • test/contract.js

소스 아티팩트 내려받기 (tar.gz)

소스

PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify chromium-bidi.Exception in pkg:npm/chromium-bidi@2.1.2
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/chromium-bidi@2.1.2
Demonstrate these symbols/APIs:
  - chromium-bidi.Exception

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:a1309acd2f58a903cf72325887d6b6c78e70ca95a2a6fc53a0ebb80ddf2ca539","contract":["Exception constructor sets error code, message and optional stacktrace","Exception subclasses inherit from Exception with predefined error names","Exception.toErrorResponse formats standard BiDi error payload with stacktrace field","NoSuchElementException.toErrorResponse formats error response with no such element code","NoSuchScriptException.toErrorResponse formats error response with undefined stacktrace","Protocol parser throws InvalidArgumentException inheriting from Exception on invalid input"],"goal":"verify chromium-bidi.Exception in pkg:npm/chromium-bidi@2.1.2","kind":"HOW","packages":["pkg:npm/chromium-bidi@2.1.2"],"schemaVersion":1,"symbols":["chromium-bidi.Exception"]},"contractCommand":["node","test/contract.js"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/chromium-bidi@2.1.2"],"schemaVersion":1,"subject":"pkg:npm/chromium-bidi@2.1.2","symbols":["chromium-bidi.Exception"],"verifierAdapter":"node-typescript@1"}
index.js
'use strict';

const {
  Exception,
  InvalidArgumentException,
  NoSuchElementException,
  NoSuchScriptException,
  NoSuchFrameException,
  InvalidSelectorException,
  UnknownErrorException,
  UnsupportedOperationException,
} = require('chromium-bidi/lib/cjs/protocol/protocol.js');

const {
  Script,
  BrowsingContext,
} = require('chromium-bidi/lib/cjs/protocol-parser/protocol-parser.js');

function createException(error, message, stacktrace) {
  return new Exception(error, message, stacktrace);
}

function createNoSuchElementException(message, stacktrace) {
  return new NoSuchElementException(message, stacktrace);
}

function createNoSuchScriptException(message, stacktrace) {
  return new NoSuchScriptException(message, stacktrace);
}

function formatErrorResponse(exception, commandId) {
  return exception.toErrorResponse(commandId);
}

function parseEvaluateScript(params) {
  return Script.parseEvaluateParams(params);
}

module.exports = {
  Exception,
  InvalidArgumentException,
  NoSuchElementException,
  NoSuchScriptException,
  NoSuchFrameException,
  InvalidSelectorException,
  UnknownErrorException,
  UnsupportedOperationException,
  createException,
  createNoSuchElementException,
  createNoSuchScriptException,
  formatErrorResponse,
  parseEvaluateScript,
};
package-lock.json
{
  "name": "sample-4170787998",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-4170787998",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "chromium-bidi": "2.1.2"
      }
    },
    "node_modules/chromium-bidi": {
      "version": "2.1.2",
      "resolved": "https://registry.npmjs.org/chromium-bidi/-/chromium-bidi-2.1.2.tgz",
      "integrity": "sha512-vtRWBK2uImo5/W2oG6/cDkkHSm+2t6VHgnj+Rcwhb0pP74OoUb4GipyRX/T/y39gYQPhioP0DPShn+A7P6CHNw==",
      "license": "Apache-2.0",
      "dependencies": {
        "mitt": "^3.0.1",
        "zod": "^3.24.1"
      },
      "peerDependencies": {
        "devtools-protocol": "*"
      }
    },
    "node_modules/devtools-protocol": {
      "version": "0.0.1686980",
      "resolved": "https://registry.npmjs.org/devtools-protocol/-/devtools-protocol-0.0.1686980.tgz",
      "integrity": "sha512-NnnxGO1/cRffXL29DqGysbfgCcsYoIxprtmXgh+UDXFvhTwhRBewcRdGlEXvc3cmROi04JRmd2PqCURsijW25A==",
      "license": "BSD-3-Clause",
      "peer": true
    },
    "node_modules/mitt": {
      "version": "3.0.1",
      "resolved": "https://registry.npmjs.org/mitt/-/mitt-3.0.1.tgz",
      "integrity": "sha512-vKivATfr97l2/QBCYAkXYDbrIWPM2IIKEl7YPhjCvKlG3kE2gm+uBo6nEXK3M5/Ffh/FLpKExzOQ3JJoJGFKBw==",
      "license": "MIT"
    },
    "node_modules/zod": {
      "version": "3.25.76",
      "resolved": "https://registry.npmjs.org/zod/-/zod-3.25.76.tgz",
      "integrity": "sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ==",
      "license": "MIT",
      "funding": {
        "url": "https://github.com/sponsors/colinhacks"
      }
    }
  }
}
package.json
{
  "name": "sample-4170787998",
  "version": "1.0.0",
  "description": "verify chromium-bidi.Exception in pkg:npm/chromium-bidi@2.1.2",
  "main": "index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "keywords": [],
  "author": "",
  "license": "MIT-0",
  "dependencies": {
    "chromium-bidi": "2.1.2"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify chromium-bidi.Exception in pkg:npm/chromium-bidi@2.1.2",
  "kind": "HOW",
  "packages": [
    "pkg:npm/chromium-bidi@2.1.2"
  ],
  "symbols": [
    "chromium-bidi.Exception"
  ]
}
test/contract.js
'use strict';

const assert = require('assert');
const {
  Exception,
  InvalidArgumentException,
  NoSuchElementException,
  NoSuchScriptException,
  NoSuchFrameException,
  InvalidSelectorException,
  UnknownErrorException,
  UnsupportedOperationException,
  createException,
  createNoSuchElementException,
  createNoSuchScriptException,
  formatErrorResponse,
  parseEvaluateScript,
} = require('../index.js');

async function runContract() {
  // 1. Exception constructor sets error code, message and optional stacktrace
  const baseEx = createException('unknown error', 'A protocol error occurred', 'mock-stack-trace');
  assert(baseEx instanceof Error, 'Exception must be an instance of Error');
  assert(baseEx instanceof Exception, 'Exception must be an instance of Exception');
  assert.strictEqual(baseEx.error, 'unknown error');
  assert.strictEqual(baseEx.message, 'A protocol error occurred');
  assert.strictEqual(baseEx.stacktrace, 'mock-stack-trace');

  // 2. Exception subclasses inherit from Exception with predefined error names
  const elementEx = createNoSuchElementException('Element #header not found', 'stack-line-1');
  assert(elementEx instanceof Error, 'NoSuchElementException must be an instance of Error');
  assert(elementEx instanceof Exception, 'NoSuchElementException must be an instance of Exception');
  assert(elementEx instanceof NoSuchElementException, 'NoSuchElementException must be an instance of NoSuchElementException');
  assert.strictEqual(elementEx.error, 'no such element');
  assert.strictEqual(elementEx.message, 'Element #header not found');
  assert.strictEqual(elementEx.stacktrace, 'stack-line-1');

  const scriptEx = createNoSuchScriptException('Script execution timed out');
  assert(scriptEx instanceof Exception, 'NoSuchScriptException must be an instance of Exception');
  assert.strictEqual(scriptEx.error, 'no such script');
  assert.strictEqual(scriptEx.stacktrace, undefined);

  const frameEx = new NoSuchFrameException('Frame not found');
  assert(frameEx instanceof Exception, 'NoSuchFrameException must be an instance of Exception');
  assert.strictEqual(frameEx.error, 'no such frame');

  const selectorEx = new InvalidSelectorException('Invalid CSS selector');
  assert(selectorEx instanceof Exception, 'InvalidSelectorException must be an instance of Exception');
  assert.strictEqual(selectorEx.error, 'invalid selector');

  const unknownEx = new UnknownErrorException('Internal server error');
  assert(unknownEx instanceof Exception, 'UnknownErrorException must be an instance of Exception');
  assert.strictEqual(unknownEx.error, 'unknown error');

  const unsupportedEx = new UnsupportedOperationException('Feature disabled');
  assert(unsupportedEx instanceof Exception, 'UnsupportedOperationException must be an instance of Exception');
  assert.strictEqual(unsupportedEx.error, 'unsupported operation');

  // 3. Exception.toErrorResponse formats standard BiDi error payload with stacktrace field
  const basePayload = formatErrorResponse(baseEx, 10);
  assert.deepStrictEqual(basePayload, {
    type: 'error',
    id: 10,
    error: 'unknown error',
    message: 'A protocol error occurred',
    stacktrace: 'mock-stack-trace',
  });

  // 4. NoSuchElementException.toErrorResponse formats error response with no such element code
  const elementPayload = formatErrorResponse(elementEx, 20);
  assert.deepStrictEqual(elementPayload, {
    type: 'error',
    id: 20,
    error: 'no such element',
    message: 'Element #header not found',
    stacktrace: 'stack-line-1',
  });

  // 5. NoSuchScriptException.toErrorResponse formats error response with undefined stacktrace
  const scriptPayload = formatErrorResponse(scriptEx, 30);
  assert.deepStrictEqual(scriptPayload, {
    type: 'error',
    id: 30,
    error: 'no such script',
    message: 'Script execution timed out',
    stacktrace: undefined,
  });

  // 6. Protocol parser throws InvalidArgumentException inheriting from Exception on invalid input
  assert.throws(
    () => {
      parseEvaluateScript({ expression: 12345 });
    },
    (err) => {
      assert(err instanceof Exception, 'Parser error must be an instance of Exception');
      assert(err instanceof InvalidArgumentException, 'Parser error must be InvalidArgumentException');
      assert.strictEqual(err.error, 'invalid argument');
      assert(err.message.includes('expression'), 'Error message should indicate invalid expression parameter');
      return true;
    }
  );

  console.log('Contract tests passed successfully.');
}

runContract().catch((err) => {
  console.error('Contract test failed:', err);
  process.exit(1);
});

오리진 시더

익명