CodeSampleX

示例

chromium-bidi 2.1.2: BrowsingContext

已验证示例 — npm chromium-bidi 2.1.2: BrowsingContext. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: BrowsingContext.parseCreateParams parses valid…

sha256:474d4237a5d90548cf00333f67273d3cffcf7265e4e672c0f135a706f987db23

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 MIT-0

执行证据

声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。

证据依据
签名契约通过
验证回执
1
构建过它的签名密钥
1
声明的环境 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

验证运行环境

环境 契约 阶段 运行日期
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.BrowsingContext in pkg:npm/chromium-bidi@2.1.2
包
符号
  • chromium-bidi.BrowsingContext
环境
node 22.23.2
创建时间
2026-08-27T10:49:46Z

契约

  1. BrowsingContext.parseCreateParams parses valid create parameters for tab and window
  2. BrowsingContext.parseCreateParams throws InvalidArgumentException on invalid type
  3. BrowsingContext.parseNavigateParams parses valid navigation parameters with url and wait state
  4. BrowsingContext.parseCloseParams parses close parameters with promptUnload flag
  5. BrowsingContext.parseSetViewportParams parses viewport dimensions and devicePixelRatio
  6. BrowsingContext.parseCaptureScreenshotParams parses screenshot format and clipping options
  7. BrowsingContext.parseLocateNodesParams parses locator strategy and selector
  8. BrowsingContext.parseTraverseHistoryParams parses history delta navigation

文件

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

下载源代码构件 (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.BrowsingContext 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.BrowsingContext
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: esm
  - packageManager: npm@10.9.8
  - runtime: node@22.23.2

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:2b9fce6a3a98b6701eef072eca8a9b5bc8f243c58db81c48d77bf6c88a2f9a16","constraints":{"executionContext":"node"},"contract":["BrowsingContext.parseCreateParams parses valid create parameters for tab and window","BrowsingContext.parseCreateParams throws InvalidArgumentException on invalid type","BrowsingContext.parseNavigateParams parses valid navigation parameters with url and wait state","BrowsingContext.parseCloseParams parses close parameters with promptUnload flag","BrowsingContext.parseSetViewportParams parses viewport dimensions and devicePixelRatio","BrowsingContext.parseCaptureScreenshotParams parses screenshot format and clipping options","BrowsingContext.parseLocateNodesParams parses locator strategy and selector","BrowsingContext.parseTraverseHistoryParams parses history delta navigation"],"goal":"verify chromium-bidi.BrowsingContext in pkg:npm/chromium-bidi@2.1.2","kind":"HOW","packages":["pkg:npm/chromium-bidi@2.1.2"],"schemaVersion":1,"symbols":["chromium-bidi.BrowsingContext"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"esm","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","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.BrowsingContext"],"verifierAdapter":"node-typescript@1"}
index.js
import { BrowsingContext } from 'chromium-bidi/lib/esm/protocol-parser/protocol-parser.js';
import { InvalidArgumentException } from 'chromium-bidi/lib/esm/protocol/protocol.js';

export function parseCreateParams(params) {
  return BrowsingContext.parseCreateParams(params);
}

export function parseNavigateParams(params) {
  return BrowsingContext.parseNavigateParams(params);
}

export function parseCloseParams(params) {
  return BrowsingContext.parseCloseParams(params);
}

export function parseSetViewportParams(params) {
  return BrowsingContext.parseSetViewportParams(params);
}

export function parseCaptureScreenshotParams(params) {
  return BrowsingContext.parseCaptureScreenshotParams(params);
}

export function parseLocateNodesParams(params) {
  return BrowsingContext.parseLocateNodesParams(params);
}

export function parseTraverseHistoryParams(params) {
  return BrowsingContext.parseTraverseHistoryParams(params);
}

export { BrowsingContext, InvalidArgumentException };
package-lock.json
{
  "name": "sample-180421414",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-180421414",
      "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-180421414",
  "version": "1.0.0",
  "description": "Minimal sample verifying chromium-bidi.BrowsingContext in pkg:npm/chromium-bidi@2.1.2",
  "type": "module",
  "main": "index.js",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "keywords": [],
  "author": "",
  "license": "MIT-0",
  "dependencies": {
    "chromium-bidi": "2.1.2"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify chromium-bidi.BrowsingContext in pkg:npm/chromium-bidi@2.1.2",
  "kind": "HOW",
  "packages": [
    "pkg:npm/chromium-bidi@2.1.2"
  ],
  "symbols": [
    "chromium-bidi.BrowsingContext"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "esm",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.mjs
import assert from 'node:assert';
import {
  InvalidArgumentException,
  parseCreateParams,
  parseNavigateParams,
  parseCloseParams,
  parseSetViewportParams,
  parseCaptureScreenshotParams,
  parseLocateNodesParams,
  parseTraverseHistoryParams,
} from '../index.js';

async function runContract() {
  // 1. BrowsingContext.parseCreateParams parses valid create parameters for tab and window
  const createTab = parseCreateParams({ type: 'tab' });
  assert.strictEqual(createTab.type, 'tab');
  const createWindow = parseCreateParams({ type: 'window', referenceContext: 'ctx-0' });
  assert.strictEqual(createWindow.type, 'window');
  assert.strictEqual(createWindow.referenceContext, 'ctx-0');

  // 2. BrowsingContext.parseCreateParams throws InvalidArgumentException on invalid type
  assert.throws(
    () => parseCreateParams({ type: 'invalid' }),
    (err) => {
      assert(err instanceof InvalidArgumentException, 'Error must be InvalidArgumentException');
      assert.strictEqual(err.error, 'invalid argument');
      return true;
    }
  );

  // 3. BrowsingContext.parseNavigateParams parses valid navigation parameters with url and wait state
  const nav = parseNavigateParams({
    context: 'ctx-1',
    url: 'https://example.com',
    wait: 'complete',
  });
  assert.strictEqual(nav.context, 'ctx-1');
  assert.strictEqual(nav.url, 'https://example.com');
  assert.strictEqual(nav.wait, 'complete');

  // 4. BrowsingContext.parseCloseParams parses close parameters with promptUnload flag
  const close = parseCloseParams({ context: 'ctx-1', promptUnload: true });
  assert.strictEqual(close.context, 'ctx-1');
  assert.strictEqual(close.promptUnload, true);

  // 5. BrowsingContext.parseSetViewportParams parses viewport dimensions and devicePixelRatio
  const viewport = parseSetViewportParams({
    context: 'ctx-1',
    viewport: { width: 1280, height: 720 },
    devicePixelRatio: 1.5,
  });
  assert.strictEqual(viewport.context, 'ctx-1');
  assert.strictEqual(viewport.viewport.width, 1280);
  assert.strictEqual(viewport.viewport.height, 720);
  assert.strictEqual(viewport.devicePixelRatio, 1.5);

  // 6. BrowsingContext.parseCaptureScreenshotParams parses screenshot format and clipping options
  const screenshot = parseCaptureScreenshotParams({
    context: 'ctx-1',
    format: { type: 'image/png' },
  });
  assert.strictEqual(screenshot.context, 'ctx-1');
  assert.strictEqual(screenshot.format.type, 'image/png');

  // 7. BrowsingContext.parseLocateNodesParams parses locator strategy and selector
  const locate = parseLocateNodesParams({
    context: 'ctx-1',
    locator: { type: 'css', value: '#main' },
  });
  assert.strictEqual(locate.context, 'ctx-1');
  assert.strictEqual(locate.locator.type, 'css');
  assert.strictEqual(locate.locator.value, '#main');

  // 8. BrowsingContext.parseTraverseHistoryParams parses history delta navigation
  const history = parseTraverseHistoryParams({
    context: 'ctx-1',
    delta: -2,
  });
  assert.strictEqual(history.context, 'ctx-1');
  assert.strictEqual(history.delta, -2);

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

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

原始种子者

匿名