@hy-sde-org/dsh-browser 0.2.2-rc.3 → 0.2.2-rc.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
@@ -1,12 +1,12 @@
1
1
  # @hy-sde-org/dsh-browser
2
2
 
3
- The host `ctx.browser` service for the agentic browser tool (ported from omp / oh-my-pi): it owns real browser connections over Chrome DevTools Protocol through [playwright-core CDP](https://playwright.dev/docs/api/class-browsertype#browser-type-connect-over-cdp), with four backends — **launch** (stealth-patched browser binary), **patch** (the CloakBrowser Chromium, source-level C++ fingerprint patches, via the optional `cloakbrowser` peer), **attach** (existing CDP endpoint via `cdp_url`), and **relay** (the user's own Chrome tabs through an in-process relay server + companion MV3 extension). Intended to be consumed by [`@hy-sde-org/dsh-tool-browser`](../tool-browser/README.md), never by the model directly. A standalone plugin — no upstream harness changes required; installs on official DeepSeek Harness releases (`0.2.0-rc.2` and later).
3
+ The host `ctx.browser` service for the agentic browser tool (ported from omp / oh-my-pi): it owns real browser connections over Chrome DevTools Protocol through [playwright-core CDP](https://playwright.dev/docs/api/class-browsertype#browser-type-connect-over-cdp), with four backends — **launch** (stealth-patched browser binary), **patch** (a patchright-driven Chromium — a Playwright fork closing Playwright's own automation leaks — via the optional `patchright` peer), **attach** (existing CDP endpoint via `cdp_url`), and **relay** (the user's own Chrome tabs through an in-process relay server + companion MV3 extension). Intended to be consumed by [`@hy-sde-org/dsh-tool-browser`](../tool-browser/README.md), never by the model directly. A standalone plugin — no upstream harness changes required; installs on official DeepSeek Harness releases (`0.2.0-rc.2` and later).
4
4
 
5
5
  ## What it does
6
6
 
7
7
  Registers one host service on the composition (`ctx.browser`). The surface:
8
8
 
9
- - **Backends** — `resolveKind` maps a tool request to `launch` / `patch` / `attach` / `relay`, mirroring omp's kind resolution (`app.path` → spawn, `app.patch` / `usePatch` → CloakBrowser, `app.cdp_url` → attach, `app.relay` / `DSH_BROWSER_RELAY` → relay); `ensureRelay` starts the in-process relay server (default `http://127.0.0.1:9224`, ephemeral port fallback).
9
+ - **Backends** — `resolveKind` maps a tool request to `launch` / `patch` / `attach` / `relay`, mirroring omp's kind resolution (`app.path` → spawn, `app.patch` / `usePatch` → patchright, `app.cdp_url` → attach, `app.relay` / `DSH_BROWSER_RELAY` → relay); `ensureRelay` starts the in-process relay server (default `http://127.0.0.1:9224`, ephemeral port fallback).
10
10
  - **Tabs** — `open` navigates a named tab (one tab per name, one browser connection per cwd+kind); `run` evaluates JS in a tab; `observe` returns title/url/size + an ARIA snapshot with `[ref=eN]` ids; `click`/`type` address elements by ARIA ref or CSS selector; `screenshot` writes a PNG; `close` closes tabs and, with `kill`, spawned browsers.
11
11
  - **Stealth** — the 14 omp-puppeteer init scripts run in every launched page (`src/stealth-scripts.ts`, generated), the machine-tell launch flags are suppressed, and a spoofed user-agent + client-hints override is applied on the browser CDP session.
12
12
 
@@ -17,19 +17,19 @@ The ARIA snapshot is produced by the bundled Playwright ARIA-snapshot sources (A
17
17
  | kind | resolution | browser |
18
18
  | --- | --- | --- |
19
19
  | `launch` | `app.path` (or `browserPath` config) | `chromium.launch({ executablePath, headless, args: STEALTH_LAUNCH_ARGS, ignoreDefaultArgs })` |
20
- | `patch` | `app.patch` / `usePatch` config | `cloakbrowser.launch(...)` — the CloakBrowser Chromium (71 source-level C++ fingerprint patches, per-session randomization) |
20
+ | `patch` | `app.patch` / `usePatch` config | `patchright chromium.launch(...)` — a patchright-driven Chromium (Playwright fork closing Playwright's own automation leaks) |
21
21
  | `attach` | `app.cdp_url` | `chromium.connectOverCDP(cdpUrl)` — any real Chrome family endpoint |
22
22
  | `relay` | `app.relay` / `DSH_BROWSER_RELAY=1` | `chromium.connectOverCDP(relay)` — the relay impersonates Chrome's CDP discovery |
23
23
 
24
- The `patch` backend is powered by the **optional** `cloakbrowser` peer (`npm i cloakbrowser`): a drop-in Playwright replacement whose Chromium is patched at the C++ level (canvas, WebGL, audio, fonts, GPU, screen, WebRTC, network timing, automation signals). The first launch auto-downloads its patched Chromium (~200 MB, cached under `~/.cloakbrowser/`). Because CloakBrowser randomizes fingerprints per session at the browser layer, the dsh-browser UA override and JS init scripts are **deliberately not applied** on this backend. Useful extra flags via `patchOptions`: `proxy`, `geoip` (match timezone+locale to the proxy IP), `humanize` (human-like input). Nothing is guaranteed per site — anti-detection raises the bar, it does not make a site accessible.
24
+ The `patch` backend is powered by the **optional** `patchright` peer (`npm i patchright`, browser binary via `npx patchright install chromium`, cached under `~/Library/Caches/ms-playwright/`): a drop-in Playwright replacement that closes Playwright's own automation leaks at the CDP client layer (Runtime.enable, console/stack-trace leaks, automation default args). Patchright does not randomize fingerprints, so the dsh-browser UA/client-hints override and JS init scripts **are applied** on this backend — the same hardening as `launch`, on a leak-patched driver. Useful extra flags via `patchOptions`: `proxy` (URL) and `channel` (e.g. `chrome` to drive installed Google Chrome). Nothing is guaranteed per site — anti-detection raises the bar, it does not make a site accessible.
25
25
 
26
26
  The relay (`src/relay/server.ts`, `bridge.ts`, a port of omp's) binds loopback, serves `GET /json/version` (503 until the extension connects; both the 200 and the 503 body carry the `dshRelayProtocol` build marker, so a stale relay of another build is diagnosable before blaming the extension — a mismatch never fails a connection), `GET /json`, `WS /cdp` (downstream CDP clients), `WS /ext` (the extension, token-gated when configured), and `GET /ext-assets/*` so the extension can be sideloaded from `chrome://extensions` → Load unpacked. The relay path waits (bounded budget, silent expiry) for `/json/version` to answer 200 before `connectOverCDP`, so the first connect does not race a cold extension service-worker dial. The bridge multiplexes every downstream CDP connection over the extension's one `chrome.debugger` attachment per tab with minted session ids. Chrome-discarded tabs (memory saver) are never announced or attached — a discard retires held sessions and retracts the target, a revival (activation refetch) reannounces and re-attaches, and an attach waits out a tracked in-flight detach instead of being silently undone by it — the same design as `omp browser-relay` (MIT).
27
27
 
28
28
  ## Configuration
29
29
 
30
30
  - `browserPath` — default executable for `launch` (optional; Playwright resolves one).
31
- - `usePatch` — prefer the CloakBrowser backend when no path/cdp_url/relay is requested (optional; needs the `cloakbrowser` peer).
32
- - `patchOptions` — CloakBrowser launch flags: `proxy` (URL), `geoip` (bool), `humanize` (bool).
31
+ - `usePatch` — prefer the patchright backend when no path/cdp_url/relay is requested (optional; needs the `patchright` peer).
32
+ - `patchOptions` — patchright launch flags: `proxy` (URL), `channel` (e.g. `chrome`).
33
33
  - `headless` — default headless (true).
34
34
  - `viewport` — launch viewport (default 1365×768 @ 1.25).
35
35
  - `relayUrl` / `relayToken` — relay endpoint and optional extension token.
@@ -12,6 +12,78 @@ async function ownedDebuggerTabs(targets, probe) {
12
12
  }));
13
13
  return owned.filter((tabId) => tabId !== undefined);
14
14
  }
15
+ // extension/foreign-frames.ts
16
+ // While any frame of a tab, cross-site ones included, shows another extension's page, Chrome
17
+ // refuses this extension's debugger there: `attach` and every `sendCommand` fail with
18
+ // "Cannot access a chrome-extension:// URL of different extension". Password managers draw their
19
+ // inline autofill menus as such frames on a focused field. Chrome checks before running the
20
+ // request, so a refused one is retried once every such frame is pointed at an empty document
21
+ // (`srcdoc` outranks `src`, so a vendor that re-points the same frame later loads nothing). The
22
+ // relay asks for this only in a tab it drives, so the user's other tabs keep their menus.
23
+ var FOREIGN_FRAME_REFUSAL = /chrome-extension:\/\/ URL of different extension/i;
24
+ var FOREIGN_FRAME_RETRY_DELAYS_MS = [50, 100, 200, 400];
25
+ var foreignFrameSweeps = new Map();
26
+ async function pastForeignFrames(tabId, request) {
27
+ for (let attempt = 0; ; attempt++) {
28
+ try {
29
+ return await request();
30
+ } catch (error) {
31
+ // A vendor may re-show its menu meanwhile, so every refusal sweeps again.
32
+ if (attempt === FOREIGN_FRAME_RETRY_DELAYS_MS.length || !FOREIGN_FRAME_REFUSAL.test(String(error)) || (await sweepForeignFrames(tabId)) === 0)
33
+ throw error;
34
+ }
35
+ await new Promise((resolve) => setTimeout(resolve, FOREIGN_FRAME_RETRY_DELAYS_MS[attempt]));
36
+ }
37
+ }
38
+ function sweepForeignFrames(tabId) {
39
+ let pending = foreignFrameSweeps.get(tabId);
40
+ if (!pending) {
41
+ pending = neutralizeForeignFrames(tabId).finally(() => foreignFrameSweeps.delete(tabId));
42
+ foreignFrameSweeps.set(tabId, pending);
43
+ }
44
+ return pending;
45
+ }
46
+ async function neutralizeForeignFrames(tabId) {
47
+ try {
48
+ const results = await chrome.scripting.executeScript({
49
+ target: { tabId, allFrames: true },
50
+ injectImmediately: true,
51
+ args: [chrome.runtime.id],
52
+ func: (self) => {
53
+ let changed = 0;
54
+ const visit = (root) => {
55
+ const walker = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT);
56
+ for (let element = walker.nextNode(); element; element = walker.nextNode()) {
57
+ const tag = element.tagName.toUpperCase();
58
+ if (tag === "IFRAME" || tag === "FRAME") {
59
+ const src = element.getAttribute("src") ?? "";
60
+ if (src.startsWith("chrome-extension://") && !src.startsWith(`chrome-extension://${self}/`)) {
61
+ // `srcdoc` outranks `src`; a `<frame>` has no `srcdoc`. Hiding the emptied frame
62
+ // keeps its layout gap from flashing.
63
+ if (tag === "IFRAME") {
64
+ element.setAttribute("srcdoc", "");
65
+ } else {
66
+ element.setAttribute("src", "about:blank");
67
+ }
68
+ element.style.setProperty("display", "none", "important");
69
+ changed++;
70
+ }
71
+ }
72
+ const shadow = chrome.dom.openOrClosedShadowRoot(element);
73
+ if (shadow)
74
+ visit(shadow);
75
+ }
76
+ };
77
+ visit(document);
78
+ return changed;
79
+ }
80
+ });
81
+ return results.reduce((total, frame) => total + (frame.result ?? 0), 0);
82
+ } catch {
83
+ // A page no extension may script (the Web Store, another extension's page).
84
+ return 0;
85
+ }
86
+ }
15
87
  // extension/background.ts
16
88
  var DEFAULT_PORT = 9224;
17
89
  var PING_INTERVAL_MS = 20000;
@@ -154,14 +226,18 @@ async function buildHello() {
154
226
  }
155
227
  async function runRpc(msg, originSocket) {
156
228
  switch (msg.op) {
157
- case "attach":
158
- await chrome.debugger.attach({ tabId: msg.tabId }, "1.3");
229
+ case "attach": {
230
+ const attach = () => chrome.debugger.attach({ tabId: msg.tabId }, "1.3");
231
+ await (msg.clearForeignFrames ? pastForeignFrames(msg.tabId, attach) : attach());
159
232
  return {};
233
+ }
160
234
  case "detach":
161
235
  await chrome.debugger.detach({ tabId: msg.tabId });
162
236
  return {};
163
- case "send":
164
- return await chrome.debugger.sendCommand(msg.sessionId ? { tabId: msg.tabId, sessionId: msg.sessionId } : { tabId: msg.tabId }, msg.method, msg.params);
237
+ case "send": {
238
+ const send = () => chrome.debugger.sendCommand(msg.sessionId ? { tabId: msg.tabId, sessionId: msg.sessionId } : { tabId: msg.tabId }, msg.method, msg.params);
239
+ return await (msg.clearForeignFrames ? pastForeignFrames(msg.tabId, send) : send());
240
+ }
165
241
  case "createTab": {
166
242
  const tab = await chrome.tabs.create({ url: msg.url, active: msg.active ?? true });
167
243
  const snap = snapshot(tab);
@@ -3,7 +3,8 @@
3
3
  "name": "DSH Browser Relay",
4
4
  "version": "0.2.1",
5
5
  "description": "Lets the DeepSeek Harness agent drive your existing tabs through a local CDP relay.",
6
- "permissions": ["debugger", "tabs", "tabGroups", "storage", "alarms"],
6
+ "permissions": ["debugger", "tabs", "tabGroups", "storage", "alarms", "scripting"],
7
+ "host_permissions": ["<all_urls>"],
7
8
  "background": {
8
9
  "service_worker": "background.js"
9
10
  },
package/dist/index.d.ts CHANGED
@@ -17,7 +17,7 @@ import type { BrowserConfig } from './types.ts';
17
17
  export * from './types.ts';
18
18
  export * from './aria.ts';
19
19
  export * from './stealth.ts';
20
- export * from './cloak.ts';
20
+ export * from './patchright.ts';
21
21
  export * from './service.ts';
22
22
  export * from './relay/kind.ts';
23
23
  export * from './relay/protocol.ts';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,KAAK,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AG,EAAE,OAAO,EAAE,MAAM,GAAE,aAAkB,GAAG,IAAI,CAEpE;AAED,iDAAiD;AACjD,eAAO,MAAM,IAAI,YAAY,CAAA;;;;;AAE7B,wBAA8B"}
package/dist/index.js CHANGED
@@ -15,7 +15,7 @@ import { BrowserService } from "./service.js";
15
15
  export * from "./types.js";
16
16
  export * from "./aria.js";
17
17
  export * from "./stealth.js";
18
- export * from "./cloak.js";
18
+ export * from "./patchright.js";
19
19
  export * from "./service.js";
20
20
  export * from "./relay/kind.js";
21
21
  export * from "./relay/protocol.js";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAG7C,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA;AACzB,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA;AAC5B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,qBAAqB,CAAA;AACnC,cAAc,kBAAkB,CAAA;AAShC,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAE7C;;;;;;GAMG;AACH,MAAM,UAAU,KAAK,CAAC,GAAY,EAAE,SAAwB,EAAE;IAC5D,KAAK,IAAI,cAAc,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;AACtC,CAAC;AAED,iDAAiD;AACjD,MAAM,CAAC,MAAM,IAAI,GAAG,SAAS,CAAA;AAE7B,eAAe,EAAE,IAAI,EAAE,KAAK,EAAE,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAG7C,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA;AACzB,cAAc,cAAc,CAAA;AAC5B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,cAAc,CAAA;AAC5B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,qBAAqB,CAAA;AACnC,cAAc,kBAAkB,CAAA;AAShC,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAE7C;;;;;;GAMG;AACH,MAAM,UAAU,KAAK,CAAC,GAAY,EAAE,SAAwB,EAAE;IAC5D,KAAK,IAAI,cAAc,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;AACtC,CAAC;AAED,iDAAiD;AACjD,MAAM,CAAC,MAAM,IAAI,GAAG,SAAS,CAAA;AAE7B,eAAe,EAAE,IAAI,EAAE,KAAK,EAAE,CAAA"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Patchright backend (`app.patch`): launch Chromium through
3
+ * [patchright](https://github.com/Kaliiiiiiiiii-Vinyzu/patchright) — a
4
+ * Playwright fork that closes Playwright's own automation leaks at the CDP
5
+ * client layer (Runtime.enable, console/stack-trace/URL leaks, the
6
+ * `--enable-automation`-style default args) while staying a drop-in
7
+ * Playwright replacement: its `chromium.launch()` returns a standard
8
+ * `Browser` object.
9
+ *
10
+ * `patchright` is an OPTIONAL peer: it is dynamically imported here with a
11
+ * computed specifier (same technique as @hy-sde-org/dsh-tool-library-search's
12
+ * optional transformers embedder) so the package keeps zero hard dependency on
13
+ * it. The browser binary is fetched once with `npx patchright install
14
+ * chromium` (cached under `~/Library/Caches/ms-playwright/`). Patchright only
15
+ * fixes automation-leak channels — it does NOT randomize fingerprints — so the
16
+ * dsh-browser JS stealth layer (launch args, UA/client-hints override, init
17
+ * scripts) IS applied on this backend, same as the launch backend.
18
+ * @module @hy-sde-org/dsh-browser/patchright
19
+ */
20
+ /** Raised when the Patchright backend is requested but not usable. */
21
+ export declare class PatchrightUnavailableError extends Error {
22
+ constructor(message: string);
23
+ }
24
+ /** Launch options passed through to `patchright.chromium.launch()`. */
25
+ export interface PatchrightLaunchOptions {
26
+ /** Headless mode (default: the service's `headless` config, usually true). */
27
+ headless?: boolean;
28
+ /** Proxy URL passed to the browser (e.g. a residential proxy). */
29
+ proxy?: string;
30
+ /** Browser distribution channel, e.g. `chrome` to drive installed Google Chrome. */
31
+ channel?: string;
32
+ /** Explicit browser executable path (overrides the channel). */
33
+ executablePath?: string;
34
+ /** Extra Chromium launch args. */
35
+ args?: string[];
36
+ /** Chromium default args to strip. */
37
+ ignoreDefaultArgs?: string[];
38
+ }
39
+ /**
40
+ * Launch a patchright-driven Chromium.
41
+ * @param options - launch options (headless/proxy/channel/executable passthrough).
42
+ * @returns the Playwright-compatible `Browser` (cast by the caller).
43
+ * @throws {PatchrightUnavailableError} when `patchright` is not installed or has
44
+ * no `chromium.launch` export (too old / wrong package).
45
+ */
46
+ export declare function launchPatchrightBrowser(options: PatchrightLaunchOptions): Promise<unknown>;
47
+ /**
48
+ * OS pid of a launched patchright Chromium, when the peer exposes its
49
+ * process. patchright's `chromium.launch()` returns a standard `Browser`
50
+ * with no launchServer handle, so a crashed host's patch browser is only
51
+ * reapable if the peer surfaces the pid (duck-typed — a peer without the
52
+ * accessor records nothing, same as before this existed).
53
+ * @param browser - the value returned by {@link launchPatchrightBrowser}.
54
+ * @returns the browser's OS pid, or undefined when not exposed.
55
+ */
56
+ export declare function patchrightBrowserPid(browser: unknown): number | undefined;
57
+ //# sourceMappingURL=patchright.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"patchright.d.ts","sourceRoot":"","sources":["../src/patchright.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,sEAAsE;AACtE,qBAAa,0BAA2B,SAAQ,KAAK;gBACvC,OAAO,EAAE,MAAM;CAI5B;AAED,uEAAuE;AACvE,MAAM,WAAW,uBAAuB;IACtC,8EAA8E;IAC9E,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,kEAAkE;IAClE,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,oFAAoF;IACpF,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,gEAAgE;IAChE,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,kCAAkC;IAClC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;IACf,sCAAsC;IACtC,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAA;CAC7B;AAED;;;;;;GAMG;AACH,wBAAsB,uBAAuB,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,OAAO,CAAC,CA4BhG;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAKzE"}
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Patchright backend (`app.patch`): launch Chromium through
3
+ * [patchright](https://github.com/Kaliiiiiiiiii-Vinyzu/patchright) — a
4
+ * Playwright fork that closes Playwright's own automation leaks at the CDP
5
+ * client layer (Runtime.enable, console/stack-trace/URL leaks, the
6
+ * `--enable-automation`-style default args) while staying a drop-in
7
+ * Playwright replacement: its `chromium.launch()` returns a standard
8
+ * `Browser` object.
9
+ *
10
+ * `patchright` is an OPTIONAL peer: it is dynamically imported here with a
11
+ * computed specifier (same technique as @hy-sde-org/dsh-tool-library-search's
12
+ * optional transformers embedder) so the package keeps zero hard dependency on
13
+ * it. The browser binary is fetched once with `npx patchright install
14
+ * chromium` (cached under `~/Library/Caches/ms-playwright/`). Patchright only
15
+ * fixes automation-leak channels — it does NOT randomize fingerprints — so the
16
+ * dsh-browser JS stealth layer (launch args, UA/client-hints override, init
17
+ * scripts) IS applied on this backend, same as the launch backend.
18
+ * @module @hy-sde-org/dsh-browser/patchright
19
+ */
20
+ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
21
+ if (typeof path === "string" && /^\.\.?\//.test(path)) {
22
+ return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
23
+ return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
24
+ });
25
+ }
26
+ return path;
27
+ };
28
+ /** Raised when the Patchright backend is requested but not usable. */
29
+ export class PatchrightUnavailableError extends Error {
30
+ constructor(message) {
31
+ super(message);
32
+ this.name = 'PatchrightUnavailableError';
33
+ }
34
+ }
35
+ /**
36
+ * Launch a patchright-driven Chromium.
37
+ * @param options - launch options (headless/proxy/channel/executable passthrough).
38
+ * @returns the Playwright-compatible `Browser` (cast by the caller).
39
+ * @throws {PatchrightUnavailableError} when `patchright` is not installed or has
40
+ * no `chromium.launch` export (too old / wrong package).
41
+ */
42
+ export async function launchPatchrightBrowser(options) {
43
+ // Computed specifier: keeps the OPTIONAL peer out of static type resolution
44
+ // (it is not installed in base deployments) while still allowing a runtime
45
+ // `npm i patchright` to be picked up lazily. Typed as `string` so tsc
46
+ // never tries to resolve it.
47
+ const moduleName = 'patchright';
48
+ let mod;
49
+ try {
50
+ mod = await import(__rewriteRelativeImportExtension(moduleName));
51
+ }
52
+ catch {
53
+ throw new PatchrightUnavailableError('browser app.patch: install the optional peer `patchright` (npm i patchright) and download its browser '
54
+ + '(npx patchright install chromium) to use this backend.');
55
+ }
56
+ const chromium = mod.chromium;
57
+ if (!chromium || typeof chromium.launch !== 'function') {
58
+ throw new PatchrightUnavailableError('browser app.patch: the installed `patchright` has no `chromium.launch` export — install a current version (>=1.49).');
59
+ }
60
+ const launchOptions = { headless: options.headless ?? true };
61
+ if (options.channel !== undefined)
62
+ launchOptions.channel = options.channel;
63
+ if (options.executablePath !== undefined)
64
+ launchOptions.executablePath = options.executablePath;
65
+ if (options.proxy !== undefined)
66
+ launchOptions.proxy = { server: options.proxy };
67
+ if (options.args !== undefined)
68
+ launchOptions.args = options.args;
69
+ if (options.ignoreDefaultArgs !== undefined)
70
+ launchOptions.ignoreDefaultArgs = options.ignoreDefaultArgs;
71
+ return chromium.launch(launchOptions);
72
+ }
73
+ /**
74
+ * OS pid of a launched patchright Chromium, when the peer exposes its
75
+ * process. patchright's `chromium.launch()` returns a standard `Browser`
76
+ * with no launchServer handle, so a crashed host's patch browser is only
77
+ * reapable if the peer surfaces the pid (duck-typed — a peer without the
78
+ * accessor records nothing, same as before this existed).
79
+ * @param browser - the value returned by {@link launchPatchrightBrowser}.
80
+ * @returns the browser's OS pid, or undefined when not exposed.
81
+ */
82
+ export function patchrightBrowserPid(browser) {
83
+ const processFn = browser.process;
84
+ if (typeof processFn !== 'function')
85
+ return undefined;
86
+ const pid = processFn.call(browser)?.pid;
87
+ return typeof pid === 'number' && Number.isInteger(pid) ? pid : undefined;
88
+ }
89
+ //# sourceMappingURL=patchright.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"patchright.js","sourceRoot":"","sources":["../src/patchright.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;;;;;;;;;AAEH,sEAAsE;AACtE,MAAM,OAAO,0BAA2B,SAAQ,KAAK;IACnD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAA;IAC1C,CAAC;CACF;AAkBD;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAAC,OAAgC;IAC5E,4EAA4E;IAC5E,2EAA2E;IAC3E,sEAAsE;IACtE,6BAA6B;IAC7B,MAAM,UAAU,GAAW,YAAY,CAAA;IACvC,IAAI,GAAwF,CAAA;IAC5F,IAAI,CAAC;QACH,GAAG,GAAG,MAAM,MAAM,kCAAC,UAAU,EAAwF,CAAA;IACvH,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,0BAA0B,CAClC,wGAAwG;cACtG,wDAAwD,CAC3D,CAAA;IACH,CAAC;IACD,MAAM,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAA;IAC7B,IAAI,CAAC,QAAQ,IAAI,OAAO,QAAQ,CAAC,MAAM,KAAK,UAAU,EAAE,CAAC;QACvD,MAAM,IAAI,0BAA0B,CAClC,qHAAqH,CACtH,CAAA;IACH,CAAC;IACD,MAAM,aAAa,GAA4B,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,IAAI,EAAE,CAAA;IACrF,IAAI,OAAO,CAAC,OAAO,KAAK,SAAS;QAAE,aAAa,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAA;IAC1E,IAAI,OAAO,CAAC,cAAc,KAAK,SAAS;QAAE,aAAa,CAAC,cAAc,GAAG,OAAO,CAAC,cAAc,CAAA;IAC/F,IAAI,OAAO,CAAC,KAAK,KAAK,SAAS;QAAE,aAAa,CAAC,KAAK,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,KAAK,EAAE,CAAA;IAChF,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS;QAAE,aAAa,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAA;IACjE,IAAI,OAAO,CAAC,iBAAiB,KAAK,SAAS;QAAE,aAAa,CAAC,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAA;IACxG,OAAO,QAAQ,CAAC,MAAM,CAAC,aAAa,CAAC,CAAA;AACvC,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,oBAAoB,CAAC,OAAgB;IACnD,MAAM,SAAS,GAAI,OAA4D,CAAC,OAAO,CAAA;IACvF,IAAI,OAAO,SAAS,KAAK,UAAU;QAAE,OAAO,SAAS,CAAA;IACrD,MAAM,GAAG,GAAG,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,GAAG,CAAA;IACxC,OAAO,OAAO,GAAG,KAAK,QAAQ,IAAI,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAA;AAC3E,CAAC"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Create an empty Chromium profile directory under the OS temp dir and seed
3
+ * its automation-safe preferences. The seed is best-effort (a failure is
4
+ * contained here); the caller owns removing the directory after the browser
5
+ * closes.
6
+ * @returns the absolute path of the created profile directory.
7
+ */
8
+ export declare function openSeededProfileDir(): Promise<string>;
9
+ /**
10
+ * Pin automation-safe preferences in a Chromium profile this host owns.
11
+ * Password leak detection answers a password form submit with a tab-modal
12
+ * "Change your password" dialog; while it is open Chromium drops
13
+ * `Input.dispatchMouseEvent` input for the tab, and a hidden browser offers
14
+ * no way to close it. A page's `window.print()` opens Chrome's print preview,
15
+ * which holds the page's script until someone closes it, so input, navigation
16
+ * and most evaluations stall; with printing off, `print()` returns at once
17
+ * and `Page.printToPDF` still works (oh-my-pi ffbd1976f7). Chromium reads
18
+ * `Preferences` only at startup and rewrites it from memory, so call this
19
+ * before a Chromium process starts on the profile. Best-effort: the
20
+ * preferences only suppress dialogs, so a failure never blocks the launch.
21
+ * @param userDataDir - profile directory to seed (created when missing).
22
+ */
23
+ export declare function seedProfilePreferences(userDataDir: string): Promise<void>;
24
+ //# sourceMappingURL=profile-seed.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"profile-seed.d.ts","sourceRoot":"","sources":["../src/profile-seed.ts"],"names":[],"mappings":"AAQA;;;;;;GAMG;AACH,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,MAAM,CAAC,CAI5D;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,sBAAsB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAwB/E"}
@@ -0,0 +1,68 @@
1
+ import { promises as fs } from 'node:fs';
2
+ import { mkdtemp } from 'node:fs/promises';
3
+ import * as os from 'node:os';
4
+ import * as path from 'node:path';
5
+ /** Chromium profile subdirectory holding the JSON `Preferences` store. */
6
+ const PREFERENCES_FILE = path.join('Default', 'Preferences');
7
+ /**
8
+ * Create an empty Chromium profile directory under the OS temp dir and seed
9
+ * its automation-safe preferences. The seed is best-effort (a failure is
10
+ * contained here); the caller owns removing the directory after the browser
11
+ * closes.
12
+ * @returns the absolute path of the created profile directory.
13
+ */
14
+ export async function openSeededProfileDir() {
15
+ const dir = await mkdtemp(path.join(os.tmpdir(), 'dsh-chromium-'));
16
+ await seedProfilePreferences(dir);
17
+ return dir;
18
+ }
19
+ /**
20
+ * Pin automation-safe preferences in a Chromium profile this host owns.
21
+ * Password leak detection answers a password form submit with a tab-modal
22
+ * "Change your password" dialog; while it is open Chromium drops
23
+ * `Input.dispatchMouseEvent` input for the tab, and a hidden browser offers
24
+ * no way to close it. A page's `window.print()` opens Chrome's print preview,
25
+ * which holds the page's script until someone closes it, so input, navigation
26
+ * and most evaluations stall; with printing off, `print()` returns at once
27
+ * and `Page.printToPDF` still works (oh-my-pi ffbd1976f7). Chromium reads
28
+ * `Preferences` only at startup and rewrites it from memory, so call this
29
+ * before a Chromium process starts on the profile. Best-effort: the
30
+ * preferences only suppress dialogs, so a failure never blocks the launch.
31
+ * @param userDataDir - profile directory to seed (created when missing).
32
+ */
33
+ export async function seedProfilePreferences(userDataDir) {
34
+ try {
35
+ const file = path.join(userDataDir, PREFERENCES_FILE);
36
+ let prefs = {};
37
+ try {
38
+ prefs = JSON.parse(await fs.readFile(file, 'utf8'));
39
+ }
40
+ catch (error) {
41
+ if (!isMissingOrInvalid(error))
42
+ throw error;
43
+ }
44
+ const profile = isRecord(prefs.profile) ? prefs.profile : {};
45
+ const printing = isRecord(prefs.printing) ? prefs.printing : {};
46
+ if (profile.password_manager_leak_detection === false && printing.enabled === false)
47
+ return;
48
+ profile.password_manager_leak_detection = false;
49
+ printing.enabled = false;
50
+ prefs.profile = profile;
51
+ prefs.printing = printing;
52
+ await fs.mkdir(path.dirname(file), { recursive: true });
53
+ const staged = `${file}.dsh-${process.pid}`;
54
+ await fs.writeFile(staged, JSON.stringify(prefs));
55
+ await fs.rename(staged, file);
56
+ }
57
+ catch {
58
+ // Best effort: the preferences only suppress dialogs a person could close
59
+ // by hand, so a lost seed must never fail the launch it precedes.
60
+ }
61
+ }
62
+ function isMissingOrInvalid(error) {
63
+ return error.code === 'ENOENT' || error instanceof SyntaxError;
64
+ }
65
+ function isRecord(value) {
66
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
67
+ }
68
+ //# sourceMappingURL=profile-seed.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"profile-seed.js","sourceRoot":"","sources":["../src/profile-seed.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAA;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAC1C,OAAO,KAAK,EAAE,MAAM,SAAS,CAAA;AAC7B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AAEjC,0EAA0E;AAC1E,MAAM,gBAAgB,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,aAAa,CAAC,CAAA;AAE5D;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB;IACxC,MAAM,GAAG,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,eAAe,CAAC,CAAC,CAAA;IAClE,MAAM,sBAAsB,CAAC,GAAG,CAAC,CAAA;IACjC,OAAO,GAAG,CAAA;AACZ,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAC,WAAmB;IAC9D,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,gBAAgB,CAAC,CAAA;QACrD,IAAI,KAAK,GAA4B,EAAE,CAAA;QACvC,IAAI,CAAC;YACH,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAA4B,CAAA;QAChF,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC;gBAAE,MAAM,KAAK,CAAA;QAC7C,C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