omowright 0.2.0 → 0.3.1

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.
Files changed (174) hide show
  1. package/README.md +43 -29
  2. package/TOOLS.md +9 -8
  3. package/dist/agent-tabs.d.ts +56 -0
  4. package/dist/aria-hidden.d.ts +1 -0
  5. package/dist/aside/cli-binary.d.ts +7 -0
  6. package/dist/aside/cli-contract.d.ts +9 -0
  7. package/dist/aside/errors.d.ts +8 -0
  8. package/dist/aside/line-transport.d.ts +11 -0
  9. package/dist/aside/mcp-transport.d.ts +11 -0
  10. package/dist/aside/onboard.d.ts +76 -0
  11. package/dist/aside/session-types.d.ts +68 -0
  12. package/dist/aside/session.d.ts +20 -0
  13. package/{bin/omowright-cloak.mjs → dist/bin/omowright-cloak.js} +28 -31
  14. package/dist/bridge-schemas.d.ts +326 -0
  15. package/dist/bridge-transport.d.ts +144 -0
  16. package/dist/browser-context.d.ts +4024 -0
  17. package/dist/browser-process.d.ts +10 -0
  18. package/dist/bsk/browser-signals.d.ts +23 -0
  19. package/dist/bsk/browsers.d.ts +46 -0
  20. package/dist/bsk/connect.d.ts +23 -0
  21. package/dist/bsk/daemon-info.d.ts +16 -0
  22. package/dist/bsk/external-extension.d.ts +74 -0
  23. package/dist/bsk/identify-browser.d.ts +48 -0
  24. package/dist/bsk/install-cli.d.ts +37 -0
  25. package/dist/bsk/ipc-client.d.ts +45 -0
  26. package/dist/bsk/onboard.d.ts +96 -0
  27. package/dist/bsk/reply-fields.d.ts +3 -0
  28. package/dist/bsk/screenshot.d.ts +24 -0
  29. package/dist/bsk/session.d.ts +142 -0
  30. package/dist/bsk/snapshot.d.ts +16 -0
  31. package/dist/bsk/targets.d.ts +20 -0
  32. package/dist/captcha-wait.d.ts +17 -0
  33. package/dist/captcha.d.ts +46 -0
  34. package/dist/cdp-errors.d.ts +38 -0
  35. package/dist/cdp-methods.d.ts +10 -0
  36. package/dist/cdp-protocol.d.ts +459 -0
  37. package/dist/chrome-profile.d.ts +77 -0
  38. package/dist/chrome.d.ts +130 -0
  39. package/dist/cloak-profile.d.ts +43 -0
  40. package/dist/connection.d.ts +4024 -0
  41. package/dist/console-events.d.ts +22 -0
  42. package/dist/cookies.d.ts +42 -0
  43. package/dist/core.d.ts +10810 -0
  44. package/dist/cua.d.ts +56 -0
  45. package/dist/dialog-policy.d.ts +43 -0
  46. package/dist/ego/bindings.d.ts +68 -0
  47. package/dist/ego/cdp-client.d.ts +28 -0
  48. package/dist/ego/client.d.ts +8 -0
  49. package/dist/ego/errors.d.ts +7 -0
  50. package/dist/emulate.d.ts +62 -0
  51. package/dist/engines.d.ts +59 -0
  52. package/dist/events.d.ts +93 -0
  53. package/dist/frames-snapshot.d.ts +58 -0
  54. package/dist/har.d.ts +88 -0
  55. package/dist/human-handoff.d.ts +30 -0
  56. package/{src/index.js → dist/index.d.ts} +12 -55
  57. package/dist/index.js +39478 -0
  58. package/dist/injected.d.ts +1 -0
  59. package/dist/instance-lock.d.ts +5 -0
  60. package/dist/instances.d.ts +45 -0
  61. package/dist/internal-capability.d.ts +1 -0
  62. package/dist/launch-endpoint.d.ts +34 -0
  63. package/dist/layers.d.ts +31 -0
  64. package/dist/llm.d.ts +1349 -0
  65. package/dist/lock-backend-win32-xbcm60vz.js +57 -0
  66. package/dist/lock-backend-win32.d.ts +3 -0
  67. package/dist/lock-backend.d.ts +6 -0
  68. package/dist/native-host-win32.d.ts +38 -0
  69. package/dist/network-events.d.ts +66 -0
  70. package/dist/network-snoop.d.ts +56 -0
  71. package/dist/nul-frames.d.ts +4 -0
  72. package/dist/open-shadow-query.d.ts +1 -0
  73. package/dist/owner-only.d.ts +15 -0
  74. package/dist/page-bundle.js +1597 -0
  75. package/dist/page-events.d.ts +25 -0
  76. package/dist/page-routes.d.ts +30 -0
  77. package/dist/page-setup.d.ts +55 -0
  78. package/dist/pipe.d.ts +71 -0
  79. package/dist/process-start-time.d.ts +2 -0
  80. package/dist/read-property.d.ts +2 -0
  81. package/dist/routes.d.ts +60 -0
  82. package/dist/running-browser.d.ts +39 -0
  83. package/dist/scroll-collect.d.ts +36 -0
  84. package/dist/serial-emitter.d.ts +5 -0
  85. package/dist/shared-connections.d.ts +11 -0
  86. package/dist/snapshot-diff.d.ts +57 -0
  87. package/dist/text-matching.d.ts +21 -0
  88. package/dist/trace.d.ts +59 -0
  89. package/dist/url-match.d.ts +7 -0
  90. package/dist/viewport.d.ts +26 -0
  91. package/dist/ws.d.ts +62 -0
  92. package/package.json +47 -26
  93. package/presets/agent-events/SKILL.md +1 -1
  94. package/presets/captcha/SKILL.md +1 -3
  95. package/presets/chrome/SKILL.md +2 -2
  96. package/presets/cloak-bridge/SKILL.md +11 -11
  97. package/presets/network/SKILL.md +15 -13
  98. package/presets/visual-browse/SKILL.md +14 -10
  99. package/skills/omowright/SKILL.md +83 -49
  100. package/skills/omowright/references/aside.md +50 -0
  101. package/skills/omowright/references/browserskill.md +29 -32
  102. package/skills/omowright/references/ego.md +24 -0
  103. package/skills/omowright/references/eval-kernel.md +44 -23
  104. package/skills/omowright/references/frames-layers-human.md +16 -7
  105. package/skills/omowright/references/quickstart.md +7 -4
  106. package/skills/omowright/references/stealth.md +11 -8
  107. package/src/agent-tabs.js +0 -179
  108. package/src/aria-hidden.js +0 -47
  109. package/src/bridge-schemas.js +0 -44
  110. package/src/bridge-transport.js +0 -83
  111. package/src/browser-context.js +0 -105
  112. package/src/browser-process.js +0 -127
  113. package/src/bsk/browser-signals.js +0 -90
  114. package/src/bsk/browsers.js +0 -114
  115. package/src/bsk/connect.js +0 -75
  116. package/src/bsk/daemon-info.js +0 -100
  117. package/src/bsk/external-extension.js +0 -110
  118. package/src/bsk/identify-browser.js +0 -88
  119. package/src/bsk/install-cli.js +0 -81
  120. package/src/bsk/ipc-client.js +0 -236
  121. package/src/bsk/onboard.js +0 -140
  122. package/src/bsk/screenshot.js +0 -49
  123. package/src/bsk/session.js +0 -131
  124. package/src/bsk/snapshot.js +0 -56
  125. package/src/bsk/targets.js +0 -25
  126. package/src/captcha-wait.js +0 -79
  127. package/src/captcha.js +0 -142
  128. package/src/cdp-errors.js +0 -23
  129. package/src/cdp-methods.js +0 -69
  130. package/src/chrome-profile.js +0 -176
  131. package/src/chrome.js +0 -194
  132. package/src/cloak-profile.js +0 -266
  133. package/src/connection.js +0 -234
  134. package/src/console-events.js +0 -12
  135. package/src/cookies.js +0 -39
  136. package/src/core.js +0 -1702
  137. package/src/cua.js +0 -74
  138. package/src/dialog-policy.js +0 -80
  139. package/src/emulate.js +0 -127
  140. package/src/events.js +0 -111
  141. package/src/frames-snapshot.js +0 -138
  142. package/src/har.js +0 -103
  143. package/src/human-handoff.js +0 -124
  144. package/src/injected.js +0 -3
  145. package/src/instance-lock.js +0 -74
  146. package/src/instances.js +0 -490
  147. package/src/internal-capability.js +0 -1
  148. package/src/launch-endpoint.js +0 -185
  149. package/src/layers.js +0 -138
  150. package/src/llm.js +0 -201
  151. package/src/lock-backend-win32.js +0 -54
  152. package/src/lock-backend.js +0 -81
  153. package/src/native-host-win32.js +0 -201
  154. package/src/network-events.js +0 -223
  155. package/src/network-snoop.js +0 -229
  156. package/src/nul-frames.js +0 -28
  157. package/src/open-shadow-query.js +0 -101
  158. package/src/owner-only.js +0 -196
  159. package/src/page-bundle.js +0 -1478
  160. package/src/page-events.js +0 -45
  161. package/src/page-routes.js +0 -94
  162. package/src/page-setup.js +0 -239
  163. package/src/pipe.js +0 -418
  164. package/src/process-start-time.js +0 -64
  165. package/src/routes.js +0 -256
  166. package/src/running-browser.js +0 -85
  167. package/src/scroll-collect.js +0 -73
  168. package/src/serial-emitter.js +0 -17
  169. package/src/shared-connections.js +0 -285
  170. package/src/snapshot-diff.js +0 -75
  171. package/src/text-matching.js +0 -101
  172. package/src/trace.js +0 -183
  173. package/src/url-match.js +0 -148
  174. package/src/viewport.js +0 -12
@@ -1,12 +1,9 @@
1
1
  # Attached engine: the user's own browser through BrowserSkill
2
2
 
3
- OmOWright has two engines. The **owned** engine (`connectPipe`,
4
- `connectCloakProfile`) launches a browser you control. The **attached** engine
5
- drives the browser the user is already signed into, through Tencent
6
- BrowserSkill (stock `bsk` daemon + Web Store extension, no fork). Pick the
7
- attached engine when the task needs the user's sessions, cookies, or their
8
- open tabs; pick the owned engine for scraping, WAF targets, headless runs, and
9
- anything that should not touch the user's profile.
3
+ BrowserSkill is third in `connectBrowser()`'s order, after Aside and Ego Lite.
4
+ It drives the browser the user is already signed into (Chrome, Edge, Brave)
5
+ through Tencent BrowserSkill (stock `bsk` daemon + Web Store extension, no
6
+ fork), so it serves tasks that need the user's sessions, cookies, or open tabs.
10
7
 
11
8
  ## Core loop
12
9
 
@@ -19,11 +16,11 @@ const sync = () => session.cooperate("sync").then((r) => r.context_id);
19
16
  const { tree, refs, css } = await bskSnapshot(session, { interactive: true, context: await sync() });
20
17
  // tree and refs look exactly like page.snapshot(); css[ref] is a light-DOM
21
18
  // selector for the same element (null inside shadow roots)
22
- await session.click({ selector: css.e3 }, { context: await sync() }); // or "@e3" after session.observe()
19
+ await session.click({ selector: css.e3 }, { context: await sync() }); // or "@e3" after session.observe()
23
20
  await session.fill(css.e5, "hello", { clearBefore: true, context: await sync() });
24
21
  await session.press("Enter", { context: await sync() });
25
22
  await session.waitForNavigation({ waitUntil: "load" });
26
- await session.stop(); // ALWAYS: returns borrowed tabs, closes the Agent Window
23
+ await session.stop(); // ALWAYS: returns borrowed tabs, closes the Agent Window
27
24
  ```
28
25
 
29
26
  ### Shared control (BrowserSkill 0.4+)
@@ -70,16 +67,16 @@ Targets are a ref (`"e3"` / `"@e3"` from `session.observe()` or
70
67
  `session.snapshot()`), a CSS selector, or `{ captureId, x, y }` from a
71
68
  screenshot.
72
69
 
73
- | Need | Call |
74
- | --- | --- |
75
- | Navigate / history | `navigate(url, {waitUntil, timeoutMs})`, `back()`, `forward()`, `reload({hard})`, `waitForNavigation()` |
76
- | Read the page | `observe({maxTokens, cursor, probeHover})` (VOM text with `@eN` refs), `snapshot()`, `getHtml({ref, maxBytes})`, `bskSnapshot(session)` (OmOWright tree + css) |
77
- | Act | `click(target, {button, clickCount, modifiers})`, `hover`, `fill(target, value)`, `press(key, {target, holdMs})`, `select(target, values)`, `focus`, `blur`, `scrollTo`, `wheel({deltaY})` |
78
- | Script | `evaluate(expression, {awaitPromise, timeoutMs})` → `{ok, value, error}`; Agent Window tabs only |
79
- | Pixels | `screenshot({ref})` → `{buffer, width, height, captureId}`; `screenshot({fullPage: true})` streams the capture back in chunks |
80
- | Tabs | `tabList({scope: "user"})`, `tabCreate({url})`, `tabSelect(id)`, `tabClose(id)`, `tabBorrow(id)` (the user confirms), `tabReturn(id)` |
81
- | Humans | `requestHelp({prompt, targets, completionCriteria, timeoutMs})` for login, CAPTCHA, OTP, payment — the extension shows an overlay and waits |
82
- | Diagnostics | `console({since})`, `network({since})` (metadata only), `emulate({overrides})`, `resize(w, h)` |
70
+ | Need | Call |
71
+ | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
72
+ | Navigate / history | `navigate(url, {waitUntil, timeoutMs})`, `back()`, `forward()`, `reload({hard})`, `waitForNavigation()` |
73
+ | Read the page | `observe({maxTokens, cursor, probeHover})` (VOM text with `@eN` refs), `snapshot()`, `getHtml({ref, maxBytes})`, `bskSnapshot(session)` (OmOWright tree + css) |
74
+ | Act | `click(target, {button, clickCount, modifiers})`, `hover`, `fill(target, value)`, `press(key, {target, holdMs})`, `select(target, values)`, `focus`, `blur`, `scrollTo`, `wheel({deltaY})` |
75
+ | Script | `evaluate(expression, {awaitPromise, timeoutMs})` → `{ok, value, error}`; Agent Window tabs only |
76
+ | Pixels | `screenshot({ref})` → `{buffer, width, height, captureId}`; `screenshot({fullPage: true})` streams the capture back in chunks |
77
+ | Tabs | `tabList({scope: "user"})`, `tabCreate({url})`, `tabSelect(id)`, `tabClose(id)`, `tabBorrow(id)` (the user confirms), `tabReturn(id)` |
78
+ | Humans | `requestHelp({prompt, targets, completionCriteria, timeoutMs})` for login, CAPTCHA, OTP, payment — the extension shows an overlay and waits |
79
+ | Diagnostics | `console({since})`, `network({since})` (metadata only), `emulate({overrides})`, `resize(w, h)` |
83
80
 
84
81
  Anything the daemon refuses comes back as a `BskRpcError` with the daemon's
85
82
  `code` (`not_found`, `invalid_params`, `permission_denied`, `timeout`,
@@ -106,7 +103,7 @@ bot detection; for WAF-heavy targets use the owned engine with CloakBrowser
106
103
 
107
104
  ```js
108
105
  const { bskDoctor, bskOnboard } = await import("omowright");
109
- const report = await bskDoctor(); // {cli, daemon, browsers, primary, identification, browsersConnected, ready, nextStep}
106
+ const report = await bskDoctor(); // {cli, daemon, browsers, primary, identification, browsersConnected, ready, nextStep}
110
107
  if (!report.ready) {
111
108
  const result = await bskOnboard({ browser: knownBrowserOrUndefined, onHumanStep: (s) => console.log(s.step) });
112
109
  // result.needsChoice === true: nothing was registered; ask the user which
@@ -136,11 +133,11 @@ proves nothing — Chrome leaves one behind after a single launch — so
136
133
  Brave, Chromium, Arc, Dia, Vivaldi, Opera, Comet, Aside, Naver Whale) by
137
134
  usage signals from `probeBrowserSignals`:
138
135
 
139
- | Signal | macOS | Linux | Windows |
140
- | --- | --- | --- | --- |
141
- | Default browser | LaunchServices `https` handler | `xdg-settings get default-web-browser` | `UserChoice` ProgId |
142
- | Running now | the app bundle in `/Applications` or `~/Applications` (automation builds elsewhere do not count) | process name | `tasklist` image |
143
- | Recent use | `Local State` / `Default/History` mtime within 7 days | same | same |
136
+ | Signal | macOS | Linux | Windows |
137
+ | --------------- | ------------------------------------------------------------------------------------------------ | -------------------------------------- | ------------------- |
138
+ | Default browser | LaunchServices `https` handler | `xdg-settings get default-web-browser` | `UserChoice` ProgId |
139
+ | Running now | the app bundle in `/Applications` or `~/Applications` (automation builds elsewhere do not count) | process name | `tasklist` image |
140
+ | Recent use | `Local State` / `Default/History` mtime within 7 days | same | same |
144
141
 
145
142
  The decision, in order, with the `confidence` each step reports: an explicit
146
143
  `browser` option or `OMOWRIGHT_BROWSER` (`explicit`); the one browser whose
@@ -168,13 +165,13 @@ reverted — the library calls the binary by absolute path); `bsk status` to
168
165
  start the daemon; then, for the identified browser only, Chrome's
169
166
  external-extension registration for the Web Store listing:
170
167
 
171
- | Platform | Where the entry goes | What the user does |
172
- | --- | --- | --- |
173
- | macOS | `<user data dir>/External Extensions/<id>.json` | relaunch the browser, click **Enable** once |
174
- | Windows | `HKCU\Software\<vendor>\<browser>\Extensions\<id>` (`reg add`, no admin) | click **Enable** on the toolbar badge; no restart |
175
- | Linux (Chromium) | `<user data dir>/External Extensions/<id>.json` | relaunch; installs silently |
176
- | Linux (Chrome/Edge/Brave) | `/opt/google/chrome/extensions/<id>.json` etc. — needs root | otherwise: open the store link and click Add |
177
- | Opera, and Vivaldi/Whale off macOS | no external-extension path | open the store link in that browser and click Add |
168
+ | Platform | Where the entry goes | What the user does |
169
+ | ---------------------------------- | ------------------------------------------------------------------------ | ------------------------------------------------- |
170
+ | macOS | `<user data dir>/External Extensions/<id>.json` | relaunch the browser, click **Enable** once |
171
+ | Windows | `HKCU\Software\<vendor>\<browser>\Extensions\<id>` (`reg add`, no admin) | click **Enable** on the toolbar badge; no restart |
172
+ | Linux (Chromium) | `<user data dir>/External Extensions/<id>.json` | relaunch; installs silently |
173
+ | Linux (Chrome/Edge/Brave) | `/opt/google/chrome/extensions/<id>.json` etc. — needs root | otherwise: open the store link and click Add |
174
+ | Opera, and Vivaldi/Whale off macOS | no external-extension path | open the store link in that browser and click Add |
178
175
 
179
176
  Then it waits on `system.status{wait_for_browser_ms}` until the extension
180
177
  connects. Tell the user exactly `result.humanStep`, nothing more. If the user
@@ -0,0 +1,24 @@
1
+ # Ego Lite engine: an agent task space in the user's Ego browser
2
+
3
+ Ego Lite is second in `connectBrowser()`'s order. Its CDP bindings
4
+ (`globalThis.ego`) exist only inside a script run by `ego-browser nodejs`, so
5
+ load omowright there by absolute path:
6
+
7
+ ```bash
8
+ ego-browser nodejs -e "const { connectBrowser } = await import('file:///<abs>/omowright/src/index.ts'); const { handle: browser } = await connectBrowser({ allow: ['ego'] }); const page = await browser.newTab('https://example.com'); console.log(await page.title()); await browser.close();"
9
+ ```
10
+
11
+ The script runs as ESM with top-level await, outside your shell's working
12
+ directory and environment: use absolute paths and write inputs into the script.
13
+
14
+ `connectEgo({ taskName, profileId, taskSpace })` (or `connectBrowser({ ego: {...} })`)
15
+ creates an agent task space and selects it, because Ego sends raw CDP only for
16
+ the selected, agent-owned space. `taskSpace: <numeric id>` reuses one the agent
17
+ already claimed. The handle is a `BrowserConnection`: the full Page API,
18
+ `compactSnapshot` and CUA apply. `handle.taskSpace` names the space.
19
+
20
+ One client at a time owns Ego's callbacks in a runtime: a second connect
21
+ rejects with `ego_busy` and changes nothing, so close the first.
22
+ `close()` releases the callbacks and leaves the user's browser running.
23
+ Sends Ego refuses (the user took the space over, no space selected) reject at
24
+ once with Ego's `error_code`, such as `EGO_TASK_SPACE_USER_IN_CONTROL`.
@@ -21,17 +21,25 @@ rejects every call. Two patterns hold up:
21
21
  the setup cell below):
22
22
 
23
23
  ```js
24
- await tool.monitor({ description: "omowright browser", command: `${shell} --headless --no-first-run --remote-debugging-port=9333 --user-data-dir=${profile} about:blank` });
25
- globalThis.omw = await omwTools.connect("http://127.0.0.1:9333"); // the port is loopback-only; close the monitor with kill_bash when done
24
+ await tool.monitor({
25
+ description: "omowright browser",
26
+ command: `${shell} --headless --no-first-run --remote-debugging-port=9333 --user-data-dir=${profile} about:blank`,
27
+ });
28
+ globalThis.omw = await omwTools.connect("http://127.0.0.1:9333"); // the port is loopback-only; close the monitor with kill_bash when done
26
29
  ```
27
30
 
28
- If you'd rather keep `connectPipe`, treat the browser as disposable: start
29
- every cell with a probe and relaunch on failure.
31
+ If you'd rather keep `connectPipe`, treat the browser as disposable: start
32
+ every cell with a probe and relaunch on failure.
30
33
 
31
34
  ```js
32
- try { await globalThis.omw.listTargets(); }
33
- catch {
34
- globalThis.omw = await omwTools.connectPipe({ browserPath: shell, browserArgs: ["--headless", "--no-first-run", `--user-data-dir=${profile}`], storageRoot: profile });
35
+ try {
36
+ await globalThis.omw.listTargets();
37
+ } catch {
38
+ globalThis.omw = await omwTools.connectPipe({
39
+ browserPath: shell,
40
+ browserArgs: ["--headless", "--no-first-run", `--user-data-dir=${profile}`],
41
+ storageRoot: profile,
42
+ });
35
43
  globalThis.omwPage = await omw.newTab("about:blank");
36
44
  }
37
45
  ```
@@ -47,7 +55,12 @@ const m = await import("omowright");
47
55
  const fs = await import("node:fs");
48
56
  const os = await import("node:os");
49
57
  const path = await import("node:path");
50
- const shell = fs.globSync(`${env("HOME")}/Library/Caches/ms-playwright/chromium_headless_shell-*/chrome-headless-shell-mac-arm64/chrome-headless-shell`).sort().at(-1);
58
+ const shell = fs
59
+ .globSync(
60
+ `${env("HOME")}/Library/Caches/ms-playwright/chromium_headless_shell-*/chrome-headless-shell-mac-arm64/chrome-headless-shell`,
61
+ )
62
+ .sort()
63
+ .at(-1);
51
64
  const profile = fs.mkdtempSync(path.join(os.tmpdir(), "omowright-eval-"));
52
65
  globalThis.omw = await m.connectPipe({
53
66
  browserPath: shell,
@@ -61,11 +74,11 @@ globalThis.omwTools = m;
61
74
  ## Later cells
62
75
 
63
76
  ```js
64
- await omw.listTargets(); // throws if the kernel reaped the browser: rerun setup
77
+ await omw.listTargets(); // throws if the kernel reaped the browser: rerun setup
65
78
  await omwPage.goto("https://example.com");
66
79
  console.log(omwTools.compactSnapshot(await omwPage.snapshot()));
67
80
  await omwPage.locator("e1").click();
68
- display(await omwPage.screenshot({ type: "png" })); // display() renders images inline
81
+ display(await omwPage.screenshot({ type: "png" })); // display() renders images inline
69
82
  ```
70
83
 
71
84
  ## Parallel lanes (research fan-out)
@@ -75,25 +88,33 @@ transport has no ports to collide on. Every lane connects, acts, and closes
75
88
  inside the cell, so the reaping rule never bites.
76
89
 
77
90
  ```js
78
- const results = await parallel([1, 2, 3].map(i => async () => {
79
- const prof = fs.mkdtempSync(path.join(os.tmpdir(), `omw-lane${i}-`));
80
- const br = await omwTools.connectPipe({ browserPath: shell, browserArgs: ["--headless", `--user-data-dir=${prof}`], storageRoot: prof });
81
- try {
82
- const p = await br.newTab(urls[i]);
83
- return omwTools.compactSnapshot(await p.snapshot());
84
- } finally {
85
- await br.close();
86
- fs.rmSync(prof, { recursive: true, force: true });
87
- }
88
- }));
91
+ const results = await parallel(
92
+ [1, 2, 3].map((i) => async () => {
93
+ const prof = fs.mkdtempSync(path.join(os.tmpdir(), `omw-lane${i}-`));
94
+ const br = await omwTools.connectPipe({
95
+ browserPath: shell,
96
+ browserArgs: ["--headless", `--user-data-dir=${prof}`],
97
+ storageRoot: prof,
98
+ });
99
+ try {
100
+ const p = await br.newTab(urls[i]);
101
+ return omwTools.compactSnapshot(await p.snapshot());
102
+ } finally {
103
+ await br.close();
104
+ fs.rmSync(prof, { recursive: true, force: true });
105
+ }
106
+ }),
107
+ );
89
108
  ```
90
109
 
91
110
  ## Cleanup cell
92
111
 
93
112
  ```js
94
- await omw.close().catch(() => {}); // no-op if the process is already gone
113
+ await omw.close().catch(() => {}); // no-op if the process is already gone
95
114
  fs.rmSync(profile, { recursive: true, force: true });
96
- delete globalThis.omw; delete globalThis.omwPage; delete globalThis.omwTools;
115
+ delete globalThis.omw;
116
+ delete globalThis.omwPage;
117
+ delete globalThis.omwTools;
97
118
  ```
98
119
 
99
120
  For the monitor-launched form, stop the monitor after `close()` so the profile
@@ -4,8 +4,17 @@ Four modules for the moments when the plain snapshot-and-click loop stalls.
4
4
  All come from the package entrypoint:
5
5
 
6
6
  ```js
7
- const { reconcileFrames, snapshotWithFrames, describeLayers, layersHeader, snapshotWithLayers,
8
- requestHuman, DEVICE_PRESETS, emulate, compactSnapshot } = await import("omowright");
7
+ const {
8
+ reconcileFrames,
9
+ snapshotWithFrames,
10
+ describeLayers,
11
+ layersHeader,
12
+ snapshotWithLayers,
13
+ requestHuman,
14
+ DEVICE_PRESETS,
15
+ emulate,
16
+ compactSnapshot,
17
+ } = await import("omowright");
9
18
  ```
10
19
 
11
20
  ## Out-of-process iframes and shadow DOM
@@ -58,7 +67,7 @@ console.log(layersHeader(layers));
58
67
  if (layers.blocking) {
59
68
  // Dismiss through a fresh ref: snapshot the overlay by its hint, click its button.
60
69
  const tree = compactSnapshot(await page.snapshot({ selector: layers.blocking.selectorHint, interactive: true }));
61
- await page.locator(/\[ref=(e\d+)\]/.exec(tree)[1]).click(); // first interactive ref inside the overlay
70
+ await page.locator(/\[ref=(e\d+)\]/.exec(tree)[1]).click(); // first interactive ref inside the overlay
62
71
  }
63
72
  ```
64
73
 
@@ -85,7 +94,7 @@ captcha preset can't clear, hand the tab to the person and wait for a signal:
85
94
  ```js
86
95
  const result = await requestHuman(page, {
87
96
  prompt: "Sign in with your account, then click Done.",
88
- until: { url: /\/dashboard/ }, // or { selector: "nav.account" } or async page => boolean
97
+ until: { url: /\/dashboard/ }, // or { selector: "nav.account" } or async page => boolean
89
98
  timeoutMs: 300000,
90
99
  });
91
100
  // { outcome: "continued" | "timed_out" | "cancelled", elapsedMs, reason: "until" | "done-button" | "timed_out" | "signal" }
@@ -107,11 +116,11 @@ browser and continue from that session.
107
116
  `emulate` sets viewport metrics, touch, and user agent in one call:
108
117
 
109
118
  ```js
110
- await emulate(page, "iphone-14"); // 390x844 @3x, touch, iOS Safari UA
119
+ await emulate(page, "iphone-14"); // 390x844 @3x, touch, iOS Safari UA
111
120
  await page.goto("https://example.com");
112
121
  await page.screenshot({ path: "/tmp/home-iphone.png" });
113
- await emulate(page, "desktop-1440"); // 1440x900, mouse
114
- await emulate(page, null); // clear the override, restore the original UA
122
+ await emulate(page, "desktop-1440"); // 1440x900, mouse
123
+ await emulate(page, null); // clear the override, restore the original UA
115
124
  ```
116
125
 
117
126
  Presets in `DEVICE_PRESETS`: `iphone-14` (390x844), `pixel-7` (412x915),
@@ -46,7 +46,10 @@ await userBrowser.close();
46
46
  ```
47
47
 
48
48
  Always launch with a dedicated `--user-data-dir` (a `mkdtemp` dir) and delete it
49
- after `browser.close()`. Under Node, `node:sqlite` loads lazily with a
49
+ after `browser.close()`. On Windows a second launch on Chrome's shared default
50
+ profile exits with code 21. Also on Windows, write `browserPath` with forward
51
+ slashes or `String.raw`: backslashes in a plain string literal are escapes
52
+ (usually ENOENT, a SyntaxError for segments such as `\u`). Under Node, `node:sqlite` loads lazily with a
50
53
  `bun:sqlite` fallback under Bun (see Runtime above).
51
54
 
52
55
  ## Page essentials
@@ -68,9 +71,9 @@ await page.close();
68
71
  ## Snapshot discipline
69
72
 
70
73
  ```js
71
- const snap = await page.snapshot(); // { tree, refs } or JSON string
72
- const tree = compactSnapshot(snap); // raw tree, ~57% smaller
73
- await page.snapshot({ interactive: true }); // controls, headings, landmarks and state feedback
74
+ const snap = await page.snapshot(); // { tree, refs } or JSON string
75
+ const tree = compactSnapshot(snap); // raw tree without the refs map: 7%-64% smaller on pages measured 2026-11-09
76
+ await page.snapshot({ interactive: true }); // controls, headings, landmarks and state feedback
74
77
  await page.snapshot({ maxDepth: 20, maxChars: 4000, selector: "main" });
75
78
  ```
76
79
 
@@ -12,7 +12,10 @@ python3 -c "import cloakbrowser, json; print(cloakbrowser.binary_info()['binary_
12
12
  ```
13
13
 
14
14
  Not installed: `uv pip install "cloakbrowser==0.5.7"` in a venv, then
15
- `python -c "import cloakbrowser; cloakbrowser.ensure_binary()"`.
15
+ `python -c "import cloakbrowser; cloakbrowser.ensure_binary()"`. The pin is
16
+ deliberate: these docs are written against 0.5.7, and current releases (0.7.1
17
+ on 2026-11-07) ask for a license key on every launch. Moving it is a separate,
18
+ tested change.
16
19
 
17
20
  ## Single-instance rule
18
21
 
@@ -43,10 +46,10 @@ on a machine you trust and only when the instance is meant to be shared.
43
46
  ```js
44
47
  const { connectNamed, listInstances } = await import("omowright");
45
48
  const browser = await connectNamed("cloak-main", {
46
- browserPath, // required only when a launch is needed (connectCloakProfile resolves it)
49
+ browserPath, // required only when a launch is needed (connectCloakProfile resolves it)
47
50
  browserArgs,
48
- profileDir, // recorded with the instance; used for endpoint discovery
49
- registryRoot, // defaults to ~/.local/share/omowright/instances
51
+ profileDir, // recorded with the instance; used for endpoint discovery
52
+ registryRoot, // defaults to ~/.local/share/omowright/instances
50
53
  });
51
54
  const page = await browser.newTab("https://target.com");
52
55
  await listInstances();
@@ -75,7 +78,7 @@ curl -s -m 2 http://127.0.0.1:9242/json/version # Browser info -> an instance
75
78
  const browser = await connect("http://127.0.0.1:9242");
76
79
  const page = await browser.newTab("https://target.com");
77
80
  // ... work ...
78
- await page.close(); // close only YOUR tab
81
+ await page.close(); // close only YOUR tab
79
82
  ```
80
83
 
81
84
  ## Launch
@@ -84,7 +87,7 @@ await page.close(); // close only YOUR tab
84
87
  const { connectCloakProfile } = await import("omowright");
85
88
  const browser = await connectCloakProfile({
86
89
  profileDir: `${process.env.HOME}/.local/share/omowright-cloak`,
87
- fingerprintSeed: 63498, // first use pins it; later runs reuse it and reject a mismatch
90
+ fingerprintSeed: 63498, // first use pins it; later runs reuse it and reject a mismatch
88
91
  });
89
92
  ```
90
93
 
@@ -116,8 +119,8 @@ extract them to JSON and inject with the package helper:
116
119
  ```js
117
120
  import { injectCookies } from "omowright";
118
121
  const cookies = JSON.parse(await fs.promises.readFile(cookieFile, "utf8"));
119
- await injectCookies(page, cookies); // sanitize + Network.setCookies
120
- await page.goto(url); // cookies apply on navigation
122
+ await injectCookies(page, cookies); // sanitize + Network.setCookies
123
+ await page.goto(url); // cookies apply on navigation
121
124
  ```
122
125
 
123
126
  `injectCookies` drops `expires <= 0`, forces `secure` + root path + url-scoping
package/src/agent-tabs.js DELETED
@@ -1,179 +0,0 @@
1
- import { DEFAULT_AGENT_VIEWPORT, repinViewport } from "./viewport.js";
2
- import { targetCreationCapability } from "./internal-capability.js";
3
-
4
- const managers = new WeakMap();
5
- const CAPABILITY = targetCreationCapability;
6
-
7
- function optionsKey(options = {}) {
8
- return JSON.stringify({
9
- viewport: { ...DEFAULT_AGENT_VIEWPORT, ...(options.viewport ?? {}) },
10
- closeTimeoutMs: options.closeTimeoutMs ?? 5_000,
11
- });
12
- }
13
-
14
- export class AgentTabManager {
15
- #connection;
16
- #owned = new Map();
17
- #unsubscribers = [];
18
- #disposed = false;
19
- #closing = new Map();
20
- viewport;
21
- closeTimeoutMs;
22
- ready;
23
-
24
- constructor(connection, options = {}) {
25
- if (!connection?.cdp) throw new TypeError("createAgentTabs requires a browser connection");
26
- this.#connection = connection;
27
- this.viewport = Object.freeze({ ...DEFAULT_AGENT_VIEWPORT, ...(options.viewport ?? {}) });
28
- this.closeTimeoutMs = options.closeTimeoutMs ?? 5_000;
29
- this.#unsubscribers.push(connection.cdp.on("Target.targetDestroyed", info => this.#destroyed(info?.targetId)));
30
- this.#unsubscribers.push(connection.cdp.on("Target.targetCrashed", info => this.#destroyed(info?.targetId)));
31
- this.#unsubscribers.push(connection.cdp.transportEvents?.on?.("disconnected", () => {
32
- for (const id of [...this.#owned.keys()]) this.#destroyed(id, Error("Browser transport disconnected"));
33
- }));
34
- this.ready = Promise.resolve(connection.cdp.ensureConnected?.());
35
- }
36
-
37
- async create(url = "about:blank", options = {}) {
38
- if (this.#disposed) throw Error("Agent tab manager is disposed");
39
- await this.ready;
40
- const viewport = { ...this.viewport, ...(options.viewport ?? {}) };
41
- // A headed browser keeps a background tab in a shared window hidden: it never
42
- // paints (Page.captureScreenshot hangs) and requestAnimationFrame never fires.
43
- // Its own window doesn't take focus from the user's tab, and the tab renders
44
- // (verified headed on Linux and macOS).
45
- const result = await this.#connection.cdp.send("Target.createTarget", {
46
- url: "about:blank", background: true, newWindow: true,
47
- ...(options.browserContextId ? { browserContextId: options.browserContextId } : {}),
48
- }, undefined, { capability: CAPABILITY });
49
- const targetId = result.targetId;
50
- // CloakBrowser headless defers renderer startup for background targets until
51
- // activation; activating before attach avoids Page.enable timing out.
52
- if (await this.#isHeadless()) await this.#connection.cdp.send("Target.activateTarget", { targetId });
53
- // Finish session/domain setup on a stable document before starting a
54
- // navigation that can replace the renderer or its execution contexts.
55
- const tab = await this.adopt(targetId, { viewport });
56
- if (url !== "about:blank") await tab.page.goto(url);
57
- return tab;
58
- }
59
-
60
- async adopt(targetId, options = {}) {
61
- if (this.#disposed) throw Error("Agent tab manager is disposed");
62
- const existing = this.#owned.get(targetId);
63
- if (existing) return this.#public(existing);
64
- const viewport = { ...this.viewport, ...(options.viewport ?? {}) };
65
- const record = { targetId, page: null, viewport: Object.freeze({ ...viewport }), repinQueue: Promise.resolve() };
66
- this.#owned.set(targetId, record);
67
- try {
68
- record.page = await this.#connection.attachPage(targetId);
69
- await repinViewport(record.page, record.viewport);
70
- record.navigationOff = record.page.on?.("framenavigated", event => {
71
- if (!event.parentFrameId) this.#repin(record);
72
- });
73
- return this.#public(record);
74
- } catch (error) {
75
- await this.#connection.cdp.send("Target.closeTarget", { targetId }).catch(() => {});
76
- throw error;
77
- }
78
- }
79
-
80
- #public(record) {
81
- return Object.freeze({ targetId: record.targetId, page: record.page, viewport: { ...record.viewport }, close: options => this.close(record.targetId, options) });
82
- }
83
- get(targetId) { const record = this.#owned.get(targetId); return record ? this.#public(record) : null; }
84
- list() { return [...this.#owned.values()].map(record => this.#public(record)); }
85
- async #isHeadless() {
86
- if (typeof this.#connection.cdp.isHeadless === "boolean") return this.#connection.cdp.isHeadless;
87
- const version = await this.#connection.cdp.send("Browser.getVersion").catch(() => null);
88
- return /Headless/i.test(version?.product ?? "");
89
- }
90
- #queueRepin(record, viewport, reportErrors = false) {
91
- const size = { ...viewport };
92
- const operation = record.repinQueue.then(async () => {
93
- try { await repinViewport(record.page, size); }
94
- catch (error) { if (reportErrors) console.warn(`[agent-tabs] viewport repin failed for ${record.targetId}`, error); else throw error; }
95
- record.viewport = Object.freeze(size);
96
- return { ...size };
97
- });
98
- record.repinQueue = operation.catch(() => {});
99
- return operation;
100
- }
101
- async #repin(record) { await this.#queueRepin(record, record.viewport, true); }
102
- async repin(tabOrTargetId, viewport = this.viewport) {
103
- const id = typeof tabOrTargetId === "string" ? tabOrTargetId : tabOrTargetId?.targetId;
104
- const record = this.#owned.get(id);
105
- if (!record) throw Error(`Target ${id} is not owned by this manager`);
106
- return this.#queueRepin(record, viewport);
107
- }
108
-
109
- async close(tabOrTargetId, options = {}) {
110
- const id = typeof tabOrTargetId === "string" ? tabOrTargetId : tabOrTargetId?.targetId;
111
- const record = this.#owned.get(id);
112
- if (!record) throw Error(`Target ${id} is not owned by this manager`);
113
- const existing = this.#closing.get(id);
114
- if (existing) return existing.promise;
115
- let resolveOperation, rejectOperation;
116
- const promise = new Promise((resolve, reject) => { resolveOperation = resolve; rejectOperation = reject; });
117
- const entry = { promise, reject: rejectOperation };
118
- this.#closing.set(id, entry);
119
- this.#close(record, options).then(resolveOperation, rejectOperation).finally(() => {
120
- if (this.#closing.get(id) === entry) this.#closing.delete(id);
121
- });
122
- return promise;
123
- }
124
-
125
- async #close(record, options) {
126
- let resolveDestroy, rejectDestroy;
127
- const destroyed = new Promise((resolve, reject) => { resolveDestroy = resolve; rejectDestroy = reject; });
128
- const timeout = setTimeout(() => rejectDestroy(Error(`Timed out waiting for target ${record.targetId} to close`)), options.timeoutMs ?? this.closeTimeoutMs);
129
- const off = this.#connection.cdp.on("Target.targetDestroyed", info => { if (info?.targetId === record.targetId) resolveDestroy(); });
130
- const offDisconnect = this.#connection.cdp.transportEvents?.on?.("disconnected", () => rejectDestroy(Error("Browser transport disconnected")));
131
- try {
132
- if (options.runBeforeUnload && record.page) await record.page.cdp.send("Page.close", undefined, await record.page.resolveSessionId()).catch(() => this.#connection.cdp.send("Target.closeTarget", { targetId: record.targetId }));
133
- else await this.#connection.cdp.send("Target.closeTarget", { targetId: record.targetId });
134
- if (this.#owned.has(record.targetId)) await destroyed;
135
- } finally {
136
- clearTimeout(timeout); off(); offDisconnect?.();
137
- // Ownership is removed only by Target.targetDestroyed (or transport loss).
138
- if (!this.#owned.has(record.targetId)) record.navigationOff?.();
139
- }
140
- }
141
-
142
- #destroyed(id, error) {
143
- const record = this.#owned.get(id);
144
- if (!record) return;
145
- record.navigationOff?.();
146
- this.#owned.delete(id);
147
- if (error) this.#closing.get(id)?.reject(error);
148
- }
149
- async closeAll(options = {}) {
150
- const results = await Promise.allSettled([...this.#owned.keys()].map(id => this.close(id, options)));
151
- const failures = results.filter(result => result.status === "rejected").map(result => result.reason);
152
- if (failures.length) throw new AggregateError(failures, "Failed to close one or more agent tabs");
153
- }
154
- async dispose(options = { closeOwned: true }) {
155
- if (this.#disposed) return;
156
- let failure;
157
- if (options.closeOwned !== false) try { await this.closeAll(options); } catch (error) { failure = error; }
158
- this.#disposed = true;
159
- for (const off of this.#unsubscribers) off();
160
- this.#unsubscribers = [];
161
- if (failure) throw failure;
162
- }
163
- }
164
-
165
- export function getAgentTabs(connection) {
166
- return managers.get(connection);
167
- }
168
-
169
- export function createAgentTabs(connection, options = {}) {
170
- const current = managers.get(connection);
171
- if (current) {
172
- if (current._optionsKey !== optionsKey(options)) throw new TypeError("Conflicting AgentTabManager options");
173
- return current;
174
- }
175
- const manager = new AgentTabManager(connection, options);
176
- Object.defineProperty(manager, "_optionsKey", { value: optionsKey(options) });
177
- managers.set(connection, manager);
178
- return manager;
179
- }
@@ -1,47 +0,0 @@
1
- // Self-contained because role locator queries serialize this into the frame's isolated world.
2
- // Port of Playwright's isElementHiddenForAria (packages/injected/src/roleUtils.ts): getByRole skips the elements it
3
- // reports unless includeHidden is set. `cache` memoizes the ancestor walk for one query.
4
- export function isElementHiddenForAria(element, cache) {
5
- const getStyle = node => node.ownerDocument?.defaultView?.getComputedStyle(node);
6
- const isVisibleTextNode = text => {
7
- const range = text.ownerDocument.createRange();
8
- range.selectNode(text);
9
- const rect = range.getBoundingClientRect();
10
- return rect.width > 0 && rect.height > 0;
11
- };
12
- const belongsToDisplayNoneOrAriaHiddenOrNonSlotted = node => {
13
- let hidden = cache.get(node);
14
- if (hidden === undefined) {
15
- // Light-DOM children of a shadow host render only when a slot takes them.
16
- hidden = !!(node.parentElement && node.parentElement.shadowRoot && !node.assignedSlot);
17
- if (!hidden) {
18
- const style = getStyle(node);
19
- hidden = !style || style.display === "none" || node.getAttribute("aria-hidden")?.toLowerCase() === "true";
20
- }
21
- if (!hidden) {
22
- const parent = node.parentElement ?? (node.parentNode?.nodeType === 11 ? node.parentNode.host : null);
23
- if (parent) hidden = belongsToDisplayNoneOrAriaHiddenOrNonSlotted(parent);
24
- }
25
- cache.set(node, hidden);
26
- }
27
- return hidden;
28
- };
29
- // A form's named controls can shadow its tagName.
30
- const tagName = typeof element.tagName === "string" ? element.tagName.toUpperCase() : "FORM";
31
- if (["STYLE", "SCRIPT", "NOSCRIPT", "TEMPLATE"].includes(tagName)) return true;
32
- const style = getStyle(element);
33
- const isSlot = element.nodeName === "SLOT";
34
- if (style?.display === "contents" && !isSlot) {
35
- // display:contents is not rendered itself, but its child nodes are.
36
- for (let child = element.firstChild; child; child = child.nextSibling) {
37
- if (child.nodeType === 1 && !isElementHiddenForAria(child, cache)) return false;
38
- if (child.nodeType === 3 && isVisibleTextNode(child)) return false;
39
- }
40
- return true;
41
- }
42
- // <option> inside <select> and <slot> ignore visibility and content-visibility; checkVisibility() covers
43
- // content-visibility and closed <details> up the flat tree.
44
- const isOptionInsideSelect = element.nodeName === "OPTION" && !!element.closest("select");
45
- if (!isOptionInsideSelect && !isSlot && style && (!element.checkVisibility() || style.visibility !== "visible")) return true;
46
- return belongsToDisplayNoneOrAriaHiddenOrNonSlotted(element);
47
- }