CodeSampleX

サンプル

playwright 1.63.0: devices

検証済みサンプル — npm playwright 1.63.0: devices. node 22 · linux debian/x64 · docker で contract を実行し、成功しました: playwright.devices exports a non-empty registry of…

sha256:1469cf2d732ed4e422f221cd4f4d2367ff1dfa05da13d054413b514a97613333

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 MIT-0

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
1
ビルドした署名鍵
1
宣言された環境 linux 24 · ubuntu · glibc 2.39 x64 npm

検証実行環境

環境 コントラクト ステージ 実行日
node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2…
2026-09-10

ケース

HOW
ゴール
verify playwright.devices in pkg:npm/playwright@1.63.0
パッケージ
シンボル
  • playwright.devices
作成日
2026-09-10T20:26:05Z

コントラクト

  1. playwright.devices exports a non-empty registry of device emulation descriptors
  2. playwright.devices contains standard Desktop Chrome descriptor configured for non-mobile chromium
  3. playwright.devices contains standard iPhone 13 descriptor configured for mobile webkit with touch
  4. playwright.devices contains standard Pixel 5 descriptor configured for mobile chromium with touch
  5. all device descriptors in playwright.devices conform to standard descriptor schema
  6. getDevicesByBrowser filters device descriptors by matching defaultBrowserType
  7. getDevicesByMobile separates mobile device profiles from desktop profiles
  8. getDevice returns undefined when requested device name does not exist

ファイル

  • 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 playwright.devices in pkg:npm/playwright@1.63.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/playwright@1.63.0
Demonstrate these symbols/APIs:
  - playwright.devices

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:4b269e863b296eaa2f7f8540e7064908f86a209297c1eaa17c65ea8ae31536f7","contract":["playwright.devices exports a non-empty registry of device emulation descriptors","playwright.devices contains standard Desktop Chrome descriptor configured for non-mobile chromium","playwright.devices contains standard iPhone 13 descriptor configured for mobile webkit with touch","playwright.devices contains standard Pixel 5 descriptor configured for mobile chromium with touch","all device descriptors in playwright.devices conform to standard descriptor schema","getDevicesByBrowser filters device descriptors by matching defaultBrowserType","getDevicesByMobile separates mobile device profiles from desktop profiles","getDevice returns undefined when requested device name does not exist"],"goal":"verify playwright.devices in pkg:npm/playwright@1.63.0","kind":"HOW","packages":["pkg:npm/playwright@1.63.0"],"schemaVersion":1,"symbols":["playwright.devices"]},"contractCommand":["node","test/contract.mjs"],"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/playwright@1.63.0"],"schemaVersion":1,"subject":"pkg:npm/playwright@1.63.0","symbols":["playwright.devices"],"verifierAdapter":"node-typescript@1"}
index.js
import { devices } from 'playwright';

/**
 * Returns the full dictionary of device descriptors.
 * @returns {Record<string, object>}
 */
export function getAllDevices() {
  return devices;
}

/**
 * Retrieves a device descriptor by name.
 * @param {string} deviceName
 * @returns {object | undefined}
 */
export function getDevice(deviceName) {
  return devices[deviceName];
}

/**
 * Filters device descriptors by defaultBrowserType ('chromium' | 'firefox' | 'webkit').
 * @param {string} browserType
 * @returns {Record<string, object>}
 */
export function getDevicesByBrowser(browserType) {
  const result = {};
  for (const [name, descriptor] of Object.entries(devices)) {
    if (descriptor.defaultBrowserType === browserType) {
      result[name] = descriptor;
    }
  }
  return result;
}

/**
 * Filters device descriptors by mobile capability.
 * @param {boolean} isMobile
 * @returns {Record<string, object>}
 */
export function getDevicesByMobile(isMobile) {
  const result = {};
  for (const [name, descriptor] of Object.entries(devices)) {
    if (descriptor.isMobile === isMobile) {
      result[name] = descriptor;
    }
  }
  return result;
}

/**
 * Validates the schema of a device descriptor.
 * @param {object} descriptor
 * @returns {boolean}
 */
export function isValidDeviceDescriptor(descriptor) {
  if (!descriptor || typeof descriptor !== 'object') {
    return false;
  }
  return (
    typeof descriptor.userAgent === 'string' &&
    typeof descriptor.viewport === 'object' &&
    descriptor.viewport !== null &&
    typeof descriptor.viewport.width === 'number' &&
    typeof descriptor.viewport.height === 'number' &&
    typeof descriptor.deviceScaleFactor === 'number' &&
    typeof descriptor.isMobile === 'boolean' &&
    typeof descriptor.hasTouch === 'boolean' &&
    typeof descriptor.defaultBrowserType === 'string'
  );
}

export default devices;
package-lock.json
{
  "name": "sample-playwright-devices",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-playwright-devices",
      "version": "1.0.0",
      "dependencies": {
        "playwright": "1.63.0"
      }
    },
    "node_modules/playwright": {
      "version": "1.63.0",
      "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.63.0.tgz",
      "integrity": "sha512-+7ziBLidS4NaNCdt57SUDT+wYmmd5fmiQejUic/kb+YsYSCPyOOE9sebzMjNmQrsnNpDJqd4WHvV/8lfKfUDUg==",
      "license": "Apache-2.0",
      "dependencies": {
        "playwright-core": "1.63.0"
      },
      "bin": {
        "playwright": "cli.js"
      },
      "engines": {
        "node": ">=20"
      }
    },
    "node_modules/playwright-core": {
      "version": "1.63.0",
      "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.63.0.tgz",
      "integrity": "sha512-rYCsBF/M5HjUch52bbtVONEFjv6Xu8sm8h72dNlR5bzIE1fvC/bxgspzkjSfU+MweEMmPM8KJebG6nnyxo5mCg==",
      "license": "Apache-2.0",
      "bin": {
        "playwright-core": "cli.js"
      },
      "engines": {
        "node": ">=20"
      }
    }
  }
}
package.json
{
  "name": "sample-playwright-devices",
  "version": "1.0.0",
  "description": "verify playwright.devices in pkg:npm/playwright@1.63.0",
  "main": "index.js",
  "type": "module",
  "license": "MIT-0",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "playwright": "1.63.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify playwright.devices in pkg:npm/playwright@1.63.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/playwright@1.63.0"
  ],
  "symbols": [
    "playwright.devices"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import devices, {
  getAllDevices,
  getDevice,
  getDevicesByBrowser,
  getDevicesByMobile,
  isValidDeviceDescriptor
} from '../index.js';

// 1. playwright.devices exports a non-empty registry of device emulation descriptors
{
  assert(devices && typeof devices === 'object', 'devices must be an object');
  const all = getAllDevices();
  const keys = Object.keys(all);
  assert(keys.length > 50, `expected at least 50 device descriptors, found ${keys.length}`);
}

// 2. playwright.devices contains standard Desktop Chrome descriptor configured for non-mobile chromium
{
  const desktopChrome = getDevice('Desktop Chrome');
  assert(desktopChrome, 'Desktop Chrome device descriptor must exist');
  assert.strictEqual(desktopChrome.defaultBrowserType, 'chromium');
  assert.strictEqual(desktopChrome.isMobile, false);
  assert.strictEqual(desktopChrome.hasTouch, false);
  assert(desktopChrome.viewport.width > 0 && desktopChrome.viewport.height > 0);
  assert(typeof desktopChrome.userAgent === 'string' && desktopChrome.userAgent.length > 0);
}

// 3. playwright.devices contains standard iPhone 13 descriptor configured for mobile webkit with touch
{
  const iphone = getDevice('iPhone 13');
  assert(iphone, 'iPhone 13 device descriptor must exist');
  assert.strictEqual(iphone.defaultBrowserType, 'webkit');
  assert.strictEqual(iphone.isMobile, true);
  assert.strictEqual(iphone.hasTouch, true);
  assert.strictEqual(iphone.deviceScaleFactor, 3);
  assert.strictEqual(iphone.viewport.width, 390);
  assert.strictEqual(iphone.viewport.height, 664);
  assert(iphone.userAgent.includes('iPhone'));
}

// 4. playwright.devices contains standard Pixel 5 descriptor configured for mobile chromium with touch
{
  const pixel = getDevice('Pixel 5');
  assert(pixel, 'Pixel 5 device descriptor must exist');
  assert.strictEqual(pixel.defaultBrowserType, 'chromium');
  assert.strictEqual(pixel.isMobile, true);
  assert.strictEqual(pixel.hasTouch, true);
  assert.strictEqual(pixel.deviceScaleFactor, 2.75);
  assert.strictEqual(pixel.viewport.width, 393);
  assert.strictEqual(pixel.viewport.height, 727);
  assert(pixel.userAgent.includes('Pixel 5'));
}

// 5. all device descriptors in playwright.devices conform to standard descriptor schema
{
  for (const [name, descriptor] of Object.entries(devices)) {
    assert(isValidDeviceDescriptor(descriptor), `Device descriptor for "${name}" does not match schema`);
  }
}

// 6. getDevicesByBrowser filters device descriptors by matching defaultBrowserType
{
  const chromiumDevices = getDevicesByBrowser('chromium');
  const webkitDevices = getDevicesByBrowser('webkit');
  const firefoxDevices = getDevicesByBrowser('firefox');

  assert(Object.keys(chromiumDevices).length > 0, 'Must have chromium devices');
  assert(Object.keys(webkitDevices).length > 0, 'Must have webkit devices');
  for (const desc of Object.values(chromiumDevices)) {
    assert.strictEqual(desc.defaultBrowserType, 'chromium');
  }
  for (const desc of Object.values(webkitDevices)) {
    assert.strictEqual(desc.defaultBrowserType, 'webkit');
  }
  for (const desc of Object.values(firefoxDevices)) {
    assert.strictEqual(desc.defaultBrowserType, 'firefox');
  }
}

// 7. getDevicesByMobile separates mobile device profiles from desktop profiles
{
  const mobileDevices = getDevicesByMobile(true);
  const desktopDevices = getDevicesByMobile(false);

  assert(Object.keys(mobileDevices).length > 0, 'Must have mobile devices');
  assert(Object.keys(desktopDevices).length > 0, 'Must have desktop devices');
  for (const desc of Object.values(mobileDevices)) {
    assert.strictEqual(desc.isMobile, true);
  }
  for (const desc of Object.values(desktopDevices)) {
    assert.strictEqual(desc.isMobile, false);
  }
}

// 8. getDevice returns undefined when requested device name does not exist
{
  const nonexistent = getDevice('__nonexistent_device_model_12345__');
  assert.strictEqual(nonexistent, undefined);
}

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

オリジンシーダー

匿名