ohos-playwright 0.2.3 → 0.2.5

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/README.md CHANGED
@@ -42,10 +42,19 @@ export default defineConfig(withOpenHarmony({ /* your config */ }))
42
42
  | Variable | Default |
43
43
  |---|---|
44
44
  | `OHOS_PW_BUNDLE` | `com.huawei.hmos.browser` |
45
- | `OHOS_PW_LAUNCH_URL` | `http://localhost:5173` |
45
+ | `OHOS_PW_LAUNCH_URL` | `about:blank` (set to your dev server URL, e.g. `http://localhost:5173`) |
46
46
  | `OHOS_PW_HDC` | `/data/service/hnp/bin/hdc` |
47
47
  | `OHOS_PW_AUTO_CONNECT` | auto (set `0` to skip device auto-connect) |
48
48
  | `OHOS_PW_INFO_PATH` | `<tmpdir>/ohos-playwright-cdp.json` |
49
+ | `OHOS_PW_UI_HOST` | `0.0.0.0` — used when `--ui` is passed without `--ui-host` on an OHOS device |
50
+ | `OHOS_PW_UI_PORT` | `8765` — used when `--ui` is passed without `--ui-port` on an OHOS device |
51
+
52
+ ### `--ui` and `--debug` on an OHOS device
53
+
54
+ Playwright's bundled Chromium cannot exec inside the OHOS app sandbox, which breaks the local windows that `--ui` and `--debug` normally open.
55
+
56
+ - **`--ui`** auto-injects `--ui-host=0.0.0.0 --ui-port=8765` when run on OHOS, so the UI server starts as HTTP-only. Open `http://<device-ip>:8765` in any browser on your LAN.
57
+ - **`--debug`** has no equivalent escape hatch; running it on OHOS exits with guidance. Use `await page.pause()` inside a test, or run `--debug` from a host (Linux/macOS/Windows) connected to the device via hdc.
49
58
 
50
59
  ## Compatibility
51
60
 
package/dist/cli.mjs CHANGED
@@ -35,7 +35,33 @@ if (!existsSync(resolve(pkgRoot, 'package.json'))) {
35
35
  const playwrightCli = resolve(pkgRoot, 'cli.js');
36
36
  // Node 24 has native TypeScript support; register.mts is resolved directly.
37
37
  const register = resolve(import.meta.dirname, 'register.mjs');
38
- const child = spawn(process.execPath, ['--import', register, playwrightCli, ...process.argv.slice(2)], { stdio: 'inherit' });
38
+ const argv = process.argv.slice(2);
39
+ // On OpenHarmony, Playwright's bundled Chromium cannot exec inside the app
40
+ // sandbox (unsigned ELF). Two of Playwright's CLI modes try to launch it:
41
+ // --ui : opens a Chromium window to host the UI app
42
+ // --debug : opens a Chromium window for the Inspector (via PWDEBUG=1)
43
+ // For --ui, Playwright skips the local Chromium when --ui-host or --ui-port
44
+ // is provided (runner/index.js: runUIMode). Inject defaults so users don't
45
+ // need to remember the flags. For --debug, no such escape hatch exists —
46
+ // fail fast with guidance.
47
+ if (process.platform === 'openharmony') {
48
+ const hasFlag = (name) => argv.some((a) => a === name || a.startsWith(name + '='));
49
+ if (hasFlag('--debug')) {
50
+ console.error('[ohos-playwright] --debug is not supported on OpenHarmony.\n' +
51
+ ' Playwright Inspector launches a bundled Chromium that the OHOS app sandbox cannot exec.\n' +
52
+ ' Alternatives:\n' +
53
+ ' 1) Use `await page.pause()` inside a test for step-through inspection.\n' +
54
+ ' 2) Run `ohos-playwright test --debug` from a host (Linux/macOS/Windows) connected to the device via hdc.');
55
+ process.exit(2);
56
+ }
57
+ if (hasFlag('--ui') && !hasFlag('--ui-host') && !hasFlag('--ui-port')) {
58
+ const host = process.env.OHOS_PW_UI_HOST ?? '0.0.0.0';
59
+ const port = process.env.OHOS_PW_UI_PORT ?? '8765';
60
+ argv.push(`--ui-host=${host}`, `--ui-port=${port}`);
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
+ }
63
+ }
64
+ const child = spawn(process.execPath, ['--import', register, playwrightCli, ...argv], { stdio: 'inherit' });
39
65
  child.on('exit', (code, signal) => {
40
66
  if (signal)
41
67
  process.kill(process.pid, signal);
package/dist/setup.mjs CHANGED
@@ -7,7 +7,7 @@ import http from 'node:http';
7
7
  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
- const LAUNCH_URL = process.env.OHOS_PW_LAUNCH_URL ?? 'http://localhost:5173';
10
+ const LAUNCH_URL = process.env.OHOS_PW_LAUNCH_URL ?? 'about:blank';
11
11
  const HDC_OPTS = { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] };
12
12
  function hdc(args, opts) {
13
13
  return String(execFileSync(HDC, args, { ...HDC_OPTS, ...opts })).trim();
@@ -39,6 +39,10 @@ function fetchDeviceState() {
39
39
  }
40
40
  export function findBrowserPid() {
41
41
  const { ps } = fetchDeviceState();
42
+ // Match the main process only: its cmdline equals BUNDLE exactly.
43
+ // Child processes like "com.huawei.hmos.browser:render" / ":gpu" must be
44
+ // excluded — the DevTools abstract socket only exists on the main process,
45
+ // so picking a child PID leads to socket-not-found errors downstream.
42
46
  for (const line of ps.split('\n')) {
43
47
  const t = line.trim();
44
48
  if (!t)
@@ -46,7 +50,7 @@ export function findBrowserPid() {
46
50
  const s = t.indexOf(' ');
47
51
  if (s === -1)
48
52
  continue;
49
- if (t.slice(s + 1).includes(BUNDLE)) {
53
+ if (t.slice(s + 1).trim() === BUNDLE) {
50
54
  const pid = parseInt(t.slice(0, s), 10);
51
55
  if (!Number.isNaN(pid))
52
56
  return pid;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ohos-playwright",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "description": "Playwright adapter for OpenHarmony / ArkWeb via hdc + CDP",
5
5
  "license": "MIT",
6
6
  "author": "social4hyq",