ohos-playwright 0.2.5 → 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.mjs CHANGED
@@ -61,7 +61,12 @@ if (process.platform === 'openharmony') {
61
61
  console.error(`[ohos-playwright] UI server bound to ${host}:${port} — open http://<device-ip>:${port} in any browser. Override with OHOS_PW_UI_HOST / OHOS_PW_UI_PORT.`);
62
62
  }
63
63
  }
64
- const child = spawn(process.execPath, ['--import', register, playwrightCli, ...argv], { stdio: 'inherit' });
64
+ const child = spawn(process.execPath, ['--import', register, playwrightCli, ...argv], { stdio: ['inherit', 'pipe', 'pipe'] });
65
+ // Playwright prints its own binary name in report hints (e.g. "playwright show-report").
66
+ // Rewrite them so users see the ohos-playwright counterpart.
67
+ const RE_WRITE = /\bplaywright\s+(show-report|test|open)\b/g;
68
+ child.stdout.on('data', (d) => process.stdout.write(d.toString().replace(RE_WRITE, 'ohos-playwright $1')));
69
+ child.stderr.on('data', (d) => process.stderr.write(d.toString().replace(RE_WRITE, 'ohos-playwright $1')));
65
70
  child.on('exit', (code, signal) => {
66
71
  if (signal)
67
72
  process.kill(process.pid, signal);
package/dist/setup.mjs CHANGED
@@ -8,6 +8,16 @@ import { INFO_PATH } from "./info-path.mjs";
8
8
  const HDC = process.env.OHOS_PW_HDC ?? '/data/service/hnp/bin/hdc';
9
9
  const BUNDLE = process.env.OHOS_PW_BUNDLE ?? 'com.huawei.hmos.browser';
10
10
  const LAUNCH_URL = process.env.OHOS_PW_LAUNCH_URL ?? 'about:blank';
11
+ // 校验环境变量,防止通过 hdc shell 注入恶意命令。
12
+ // BUNDLE 必须是点分隔的 Android 风格包名;LAUNCH_URL 必须是合法 URL。
13
+ const SAFE_BUNDLE_RE = /^[a-zA-Z][a-zA-Z0-9.]*$/;
14
+ const SAFE_URL_RE = /^[a-z][a-z0-9+.-]*:(?:\/\/)?\S+$/i;
15
+ if (!SAFE_BUNDLE_RE.test(BUNDLE) || BUNDLE.length > 256) {
16
+ throw new Error(`[ohos-playwright] OHOS_PW_BUNDLE "${BUNDLE}" 不是合法的包名(期望: com.example.app)`);
17
+ }
18
+ if (!SAFE_URL_RE.test(LAUNCH_URL) || LAUNCH_URL.length > 2048) {
19
+ throw new Error(`[ohos-playwright] OHOS_PW_LAUNCH_URL "${LAUNCH_URL}" 不是合法的 URL`);
20
+ }
11
21
  const HDC_OPTS = { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] };
12
22
  function hdc(args, opts) {
13
23
  return String(execFileSync(HDC, args, { ...HDC_OPTS, ...opts })).trim();
@@ -208,7 +218,13 @@ export default async function globalSetup() {
208
218
  const probe = await probeCdp(port);
209
219
  if (!probe.ok)
210
220
  throw new Error(`CDP probe failed: ${probe.err || probe.body}`);
211
- const info = JSON.parse(probe.body);
221
+ let info;
222
+ try {
223
+ info = JSON.parse(probe.body);
224
+ }
225
+ catch {
226
+ throw new Error(`CDP response is not valid JSON (body preview: ${probe.body?.slice(0, 300) ?? '(empty)'})`);
227
+ }
212
228
  console.log(`[ohos-playwright] CDP ready: ${info.Browser}`);
213
229
  mkdirSync(dirname(INFO_PATH), { recursive: true });
214
230
  writeFileSync(INFO_PATH, JSON.stringify({ port, pid, socket, endpoint: `http://127.0.0.1:${port}` }, null, 2));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ohos-playwright",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
4
4
  "description": "Playwright adapter for OpenHarmony / ArkWeb via hdc + CDP",
5
5
  "license": "MIT",
6
6
  "author": "social4hyq",