@parcha/pi-browser 0.1.0-beta.35 → 0.1.0-beta.37

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 (46) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +20 -25
  3. package/dist/core/driving-guard.d.ts +1 -1
  4. package/dist/core/driving-guard.js +1 -1
  5. package/dist/core/host.d.ts +1 -12
  6. package/dist/core/images.d.ts +32 -4
  7. package/dist/core/images.js +81 -16
  8. package/dist/core/page-scan.d.ts +69 -0
  9. package/dist/core/page-scan.js +467 -10
  10. package/dist/core/public-fetch.js +3 -0
  11. package/dist/core/read-page.js +20 -4
  12. package/dist/core/tools.js +4 -1
  13. package/dist/core/vault.d.ts +0 -10
  14. package/dist/core/vault.js +0 -13
  15. package/dist/driver/cdp.js +3 -3
  16. package/dist/driver/page-driver.js +7 -3
  17. package/dist/durable/store.d.ts +1 -1
  18. package/dist/durable.d.ts +6 -1
  19. package/dist/durable.js +24 -5
  20. package/dist/index.d.ts +1 -0
  21. package/dist/index.js +3 -0
  22. package/dist/live-view/index.d.ts +2 -0
  23. package/dist/live-view/index.js +4 -0
  24. package/dist/live-view/server.d.ts +11 -0
  25. package/dist/live-view/server.js +13 -2
  26. package/dist/providers/cdp.js +2 -2
  27. package/dist/providers/profiles.d.ts +1 -15
  28. package/dist/providers/profiles.js +1 -64
  29. package/dist/providers/shared.d.ts +1 -47
  30. package/dist/providers/shared.js +1 -82
  31. package/dist/providers/worker-extension.js +1 -1
  32. package/dist/testing/backend.d.ts +4 -3
  33. package/dist/testing/backend.js +6 -5
  34. package/dist/vault-session.d.ts +4 -7
  35. package/dist/vault-session.js +26 -81
  36. package/dist/vendor/browser-use-pi/page.d.ts +3 -12
  37. package/dist/vendor/browser-use-pi/page.js +6 -19
  38. package/package.json +7 -20
  39. package/dist/providers/browserbase-net.d.ts +0 -12
  40. package/dist/providers/browserbase-net.js +0 -95
  41. package/dist/providers/browserbase.d.ts +0 -138
  42. package/dist/providers/browserbase.js +0 -294
  43. package/dist/providers/kernel.d.ts +0 -58
  44. package/dist/providers/kernel.js +0 -291
  45. /package/dist/{providers → core}/cdp-call.d.ts +0 -0
  46. /package/dist/{providers → core}/cdp-call.js +0 -0
@@ -1,13 +1,11 @@
1
1
  // How an adapter uses a host's session vault (core/vault.ts): restore a kept sign-in when a session is created, before the driver attaches, and capture
2
- // it when the session is released or a person hands it back. The state stays in memory and crosses only the host's port: nothing here logs a value, and
3
- // a provider's context id is registered with the run's redactor the moment it is seen. A restore or capture that fails never fails the browser: the session
2
+ // it when the session is released or a person hands it back. Only a local Chrome's state is kept (its cookies and local storage, over CDP). The state
3
+ // stays in memory and crosses only the host's port: nothing here logs a value. A restore or capture that fails never fails the browser: the session
4
4
  // starts signed out, or ends without a fresh capture, and a process warning says which, with no value in it.
5
- import { randomBytes } from "node:crypto";
6
5
  import { BrowserFailureError } from "./core/custody.js";
7
6
  import { browserFailure } from "./core/failures.js";
8
- import { MIN_REDACTED_VALUE_LENGTH } from "./core/redact.js";
9
7
  import { keptFor } from "./core/driving.js";
10
- import { clampSessionCookieAgeMs, coversEveryOrigin, vaultTarget } from "./core/vault.js";
8
+ import { clampSessionCookieAgeMs, vaultTarget } from "./core/vault.js";
11
9
  import { captureCdpState, connectCdp, restoreCdpState } from "./providers/cdp-session.js";
12
10
  /** `null` when the host gave no vault. A bad age cap throws here, so a host learns at setup. */
13
11
  export function vaultRuntime(options, track, warn, now = () => new Date(), limits = {}) {
@@ -37,21 +35,12 @@ async function within(work, ms, onTimeout = () => { }) {
37
35
  }
38
36
  }
39
37
  const refused = (message) => new BrowserFailureError(browserFailure("refused", message));
40
- /** A secret too short for the redactor to scrub is not used as one: the redactor ignores values under its minimum, so it would leak. */
41
- function trackSecret(rt, secret, what) {
42
- if (secret.length < MIN_REDACTED_VALUE_LENGTH) {
43
- rt.warn(`the session vault's ${what} is too short for the redactor to scrub, so it is not used`);
44
- return false;
45
- }
46
- rt.track(secret);
47
- return true;
48
- }
49
38
  const HELD_FAILED = "the vault could not be read at the start, so a saved sign-in may exist under this key and is left untouched: this session's sign-in is not captured";
50
39
  const HELD_UNUSED = "the vault holds a saved sign-in this session could not use, and it is left untouched: this session's sign-in is not captured";
51
- /** What the create does with the vault: the spec the provider is asked for (a kept context or profile for Browserbase and Kernel) and a step that runs after the
52
- * browser is attached and before the driver is (a local Chrome's cookies and local storage). The record the adapter stores is made from the ORIGINAL spec, never this one. */
40
+ /** What the create does with the vault: a step that runs after the browser is attached and before the driver is (a local Chrome's cookies and local storage).
41
+ * The spec is the one given, and the record the adapter stores is made from it. */
53
42
  export async function planRestore(rt, target, provider, spec) {
54
- const plain = { spec, afterAttach: null, vaulted: false, fresh: false };
43
+ const plain = { spec, afterAttach: null, vaulted: false };
55
44
  if (!rt || !target)
56
45
  return plain;
57
46
  let checked;
@@ -66,8 +55,6 @@ export async function planRestore(rt, target, provider, spec) {
66
55
  rt.warn("this browser provider cannot keep a session in a vault (a Chrome attached by endpoint is offered only when the host sets ownBrowser: true), so nothing was restored or will be captured");
67
56
  return plain;
68
57
  }
69
- if (vault.kind === "context" && vault.contextIdsInClear)
70
- throw refused("browser vault: this provider writes its context ids to a clear file, so a vault cannot use it. Give it a profile store that keeps ids in memory (memoryProfileStore). No session was started.");
71
58
  // A vault that stops answering never holds the session back: it starts signed out.
72
59
  let kept = null;
73
60
  let holdBack;
@@ -78,40 +65,17 @@ export async function planRestore(rt, target, provider, spec) {
78
65
  holdBack = HELD_FAILED;
79
66
  rt.warn(`the session vault could not restore (${kindOf(error)}); the session starts signed out`);
80
67
  }
81
- if (vault.kind === "context") {
82
- if (kept && (kept.kind !== "provider-context" || kept.provider !== vault.provider)) {
83
- rt.warn(`the vault holds a ${kept.kind} state this ${vault.provider} provider cannot use; it was ignored`);
84
- kept = null;
85
- holdBack = HELD_UNUSED;
86
- }
87
- // A context is a whole browser profile: it comes back only for a request that covers every origin it was saved for, never for some of them.
88
- if (kept?.kind === "provider-context" && !coversEveryOrigin(checked.origins, kept.origins)) {
89
- rt.warn("the vault holds a context whose saved origins this request does not cover every origin of (or records none); it was not restored");
90
- kept = null;
91
- holdBack = HELD_UNUSED;
92
- }
93
- if (kept?.kind === "provider-context" && !trackSecret(rt, kept.contextId, "context id")) {
94
- kept = null;
95
- holdBack = HELD_UNUSED;
96
- }
97
- if (kept?.kind === "provider-context")
98
- return { spec: vault.provider === "browserbase" ? { ...spec, contextId: kept.contextId, profile: undefined } : { ...spec, profile: { name: kept.contextId, save: true } }, afterAttach: null, vaulted: true, fresh: false };
99
- // A saved sign-in may exist that this session did not take: nothing persists for it, and it is never captured.
100
- if (holdBack)
101
- return { spec, afterAttach: null, vaulted: true, fresh: false, holdBack };
102
- // Nothing kept: a context that persists is made for this session, its id held in memory and given to the vault right after the create.
103
- return { spec: { ...spec, contextId: undefined, profile: { name: `vault-${randomBytes(9).toString("hex")}`, save: true } }, afterAttach: null, vaulted: true, fresh: true };
104
- }
105
68
  if (!kept)
106
69
  return { ...plain, vaulted: true, ...(holdBack ? { holdBack } : {}) };
107
- if (kept.kind !== "cdp") {
108
- rt.warn(`the vault holds a ${kept.kind} state a local Chrome cannot use; it was ignored`);
70
+ // A host's vault may hold a state of a kind this package does not keep (a hosted vendor's context, from before): left untouched, never replaced.
71
+ const kind = kept.kind;
72
+ if (kind !== "cdp") {
73
+ rt.warn(`the vault holds a ${typeof kind === "string" ? kind.slice(0, 40) : "different"} state a local Chrome cannot use; it was ignored`);
109
74
  return { ...plain, vaulted: true, holdBack: HELD_UNUSED };
110
75
  }
111
76
  return {
112
77
  spec,
113
78
  vaulted: true,
114
- fresh: false,
115
79
  afterAttach: async (attached) => {
116
80
  let link;
117
81
  try {
@@ -148,13 +112,6 @@ export function captureFor(rt, target, provider, ref, options = { vaulted: true
148
112
  }
149
113
  return;
150
114
  }
151
- if (vault.kind === "context" && !options.vaulted) {
152
- if (!warnedLate) {
153
- warnedLate = true;
154
- rt.warn("this session started with no vault target, so its provider holds no saved context for it: its sign-in cannot be kept. Set the target before the session starts");
155
- }
156
- return;
157
- }
158
115
  const stop = new AbortController();
159
116
  let link;
160
117
  // Numbered when it starts: an older capture that is still reading when a newer one of the same key begins writes nothing.
@@ -168,38 +125,26 @@ export function captureFor(rt, target, provider, ref, options = { vaulted: true
168
125
  if ((rt.latest.get(key) ?? 0) < attempt)
169
126
  rt.latest.set(key, attempt);
170
127
  const capturedAt = rt.now();
128
+ const gate = options.gate?.() ?? null;
129
+ let interrupted = false;
171
130
  let state;
172
- if (vault.kind === "context") {
173
- const id = vault.contextOf(ref);
174
- if (!id) {
175
- rt.warn("this provider no longer knows the context this session runs on (the run restarted), so its sign-in was not captured; the context the vault holds stands");
131
+ const off = gate?.onChange((now) => { if (now === "person")
132
+ interrupted = true; });
133
+ try {
134
+ const attached = await provider.attach(ref, stop.signal);
135
+ link = await connectCdp(attached.sdkCdpUrl);
136
+ if (stop.signal.aborted) {
137
+ link.close();
176
138
  return;
177
139
  }
178
- if (!trackSecret(rt, id, "context id"))
179
- return;
180
- state = { kind: "provider-context", capturedAt: capturedAt.toISOString(), provider: vault.provider, contextId: id, origins: [...checked.origins] };
140
+ state = await captureCdpState(link, checked.origins, capturedAt);
181
141
  }
182
- else {
183
- const gate = options.gate?.() ?? null;
184
- let interrupted = false;
185
- const off = gate?.onChange((now) => { if (now === "person")
186
- interrupted = true; });
187
- try {
188
- const attached = await provider.attach(ref, stop.signal);
189
- link = await connectCdp(attached.sdkCdpUrl);
190
- if (stop.signal.aborted) {
191
- link.close();
192
- return;
193
- }
194
- state = await captureCdpState(link, checked.origins, capturedAt);
195
- }
196
- finally {
197
- off?.();
198
- }
199
- if (interrupted || (gate && keptFor(gate) === "person_driving")) {
200
- rt.warn("a person began driving while the session was being read, so that capture was discarded; the last capture stands");
201
- return;
202
- }
142
+ finally {
143
+ off?.();
144
+ }
145
+ if (interrupted || (gate && keptFor(gate) === "person_driving")) {
146
+ rt.warn("a person began driving while the session was being read, so that capture was discarded; the last capture stands");
147
+ return;
203
148
  }
204
149
  // Nothing is written once the deadline has passed or a newer capture of this key has begun: an older read never replaces a newer one.
205
150
  if (stop.signal.aborted || rt.latest.get(key) !== attempt)
@@ -1,3 +1,4 @@
1
+ import { type ScreenshotOptions } from "../../core/images.js";
1
2
  import type { CDP } from "./cdp.js";
2
3
  /** The schemes a page is sent to: the web and the blank page, never a file of this machine or the browser's own pages. */
3
4
  export declare const NAVIGABLE: RegExp;
@@ -23,16 +24,6 @@ export declare class Page {
23
24
  }): Promise<void>;
24
25
  clickAt(x: number, y: number): Promise<void>;
25
26
  moveTo(x: number, y: number): Promise<void>;
26
- /** `clip` in CSS pixels from the viewport's corner, as the page tools give it; the browser's own is from the document's. */
27
- screenshot(options?: {
28
- type?: "png" | "jpeg";
29
- quality?: number;
30
- fullPage?: boolean;
31
- clip?: {
32
- x: number;
33
- y: number;
34
- width: number;
35
- height: number;
36
- };
37
- }): Promise<string>;
27
+ /** The driver's options as core/images.ts captureParams makes them CDP's, on the page's layout as it is now. */
28
+ screenshot(options?: ScreenshotOptions): Promise<string>;
38
29
  }
@@ -2,9 +2,10 @@
2
2
  // e7007f219b10fa2c2baae1bf3e2f902a5a2706fd, src/page.ts. MIT License, Copyright (c) 2026 Browser Use contributors; the
3
3
  // license's full text is in this package's NOTICE, and UPSTREAM.json beside this file records the source.
4
4
  // Changes: the Page class only (no Tabs, no snapshot of its own: ax.ts's is the driver's); goto refuses a scheme other
5
- // than http, https and about:blank; screenshot takes the driver's format, quality, clip and full-page options; untyped
6
- // CDP params and results.
5
+ // than http, https and about:blank; screenshot takes the driver's options (format, quality, clip, full page and scale),
6
+ // sent as core/images.ts captureParams makes them; untyped CDP params and results.
7
7
  import { setTimeout as delay } from "node:timers/promises";
8
+ import { captureParams } from "../../core/images.js";
8
9
  const contextLost = /Execution context was destroyed|Cannot find context|Cannot find default execution context/;
9
10
  /** The schemes a page is sent to: the web and the blank page, never a file of this machine or the browser's own pages. */
10
11
  export const NAVIGABLE = /^(https?:\/\/|about:blank$)/i;
@@ -89,24 +90,10 @@ export class Page {
89
90
  throw new Error("Coordinates must be finite.");
90
91
  await this.cdp("Input.dispatchMouseEvent", { type: "mouseMoved", x, y });
91
92
  }
92
- /** `clip` in CSS pixels from the viewport's corner, as the page tools give it; the browser's own is from the document's. */
93
+ /** The driver's options as core/images.ts captureParams makes them CDP's, on the page's layout as it is now. */
93
94
  async screenshot(options = {}) {
94
- const type = options.type ?? "png";
95
- let clip;
96
- if (options.clip) {
97
- const scroll = await this.evaluate(() => ({ x: scrollX, y: scrollY })).catch(() => ({ x: 0, y: 0 }));
98
- clip = { ...options.clip, x: options.clip.x + scroll.x, y: options.clip.y + scroll.y, scale: 1 };
99
- }
100
- else if (options.fullPage) {
101
- const { cssContentSize } = await this.cdp("Page.getLayoutMetrics");
102
- clip = { x: 0, y: 0, width: Math.ceil(cssContentSize.width), height: Math.ceil(cssContentSize.height), scale: 1 };
103
- }
104
- const { data } = await this.cdp("Page.captureScreenshot", {
105
- format: type,
106
- ...(type === "jpeg" && options.quality !== undefined ? { quality: Math.round(options.quality) } : {}),
107
- ...(options.fullPage && !options.clip ? { captureBeyondViewport: true } : {}),
108
- ...(clip ? { clip } : {}),
109
- });
95
+ const layout = await this.cdp("Page.getLayoutMetrics");
96
+ const { data } = await this.cdp("Page.captureScreenshot", captureParams(options, layout));
110
97
  return data;
111
98
  }
112
99
  }
package/package.json CHANGED
@@ -1,12 +1,11 @@
1
1
  {
2
2
  "name": "@parcha/pi-browser",
3
- "version": "0.1.0-beta.35",
3
+ "version": "0.1.0-beta.37",
4
4
  "description": "Your agent gets its own browser, and you can take over and hand it back.",
5
5
  "keywords": [
6
6
  "pi-durable",
7
7
  "browser",
8
- "stagehand",
9
- "browserbase"
8
+ "stagehand"
10
9
  ],
11
10
  "type": "module",
12
11
  "license": "Apache-2.0",
@@ -27,10 +26,6 @@
27
26
  "types": "./dist/live-view/index.d.ts",
28
27
  "import": "./dist/live-view/index.js"
29
28
  },
30
- "./providers/browserbase": {
31
- "types": "./dist/providers/browserbase.d.ts",
32
- "import": "./dist/providers/browserbase.js"
33
- },
34
29
  "./providers/cdp": {
35
30
  "types": "./dist/providers/cdp.d.ts",
36
31
  "import": "./dist/providers/cdp.js"
@@ -43,10 +38,6 @@
43
38
  "types": "./dist/providers/chrome-args.d.ts",
44
39
  "import": "./dist/providers/chrome-args.js"
45
40
  },
46
- "./providers/kernel": {
47
- "types": "./dist/providers/kernel.d.ts",
48
- "import": "./dist/providers/kernel.js"
49
- },
50
41
  "./driver/stagehand": {
51
42
  "types": "./dist/driver/stagehand.d.ts",
52
43
  "import": "./dist/driver/stagehand.js"
@@ -87,14 +78,10 @@
87
78
  "zod": "~4.6.6"
88
79
  },
89
80
  "peerDependencies": {
90
- "@browserbasehq/sdk": ">=2.20.0 <3",
91
- "@earendil-works/chord": "1.5.0",
92
- "@earendil-works/pi-durable": "1.5.0"
81
+ "@earendil-works/chord": "1.5.2",
82
+ "@earendil-works/pi-durable": "1.5.2"
93
83
  },
94
84
  "peerDependenciesMeta": {
95
- "@browserbasehq/sdk": {
96
- "optional": true
97
- },
98
85
  "@earendil-works/chord": {
99
86
  "optional": true
100
87
  },
@@ -103,9 +90,9 @@
103
90
  }
104
91
  },
105
92
  "devDependencies": {
106
- "@earendil-works/chord": "1.5.0",
107
- "@earendil-works/pi-ai": "1.5.0",
108
- "@earendil-works/pi-durable": "1.5.0"
93
+ "@earendil-works/chord": "1.5.2",
94
+ "@earendil-works/pi-ai": "1.5.2",
95
+ "@earendil-works/pi-durable": "1.5.2"
109
96
  },
110
97
  "repository": {
111
98
  "type": "git",
@@ -1,12 +0,0 @@
1
- /** Rewrite a Browserbase connect URL onto the credential proxy: only `*.browserbase.com` hosts, the signing query kept. */
2
- export declare function rewriteConnectUrl(connectUrl: string, connectBaseUrl: string | undefined | null): string;
3
- /** Direct, never through the HTTP(S) env proxy: it rejects CONNECT and the CDP WebSocket cannot ride it. Under `node
4
- * --use-env-proxy` NO_PROXY is re-read per request, so listing these hosts bypasses it. */
5
- export declare function browserbaseNoProxyHosts(env: NodeJS.ProcessEnv): string[];
6
- export declare function applyBrowserbaseNoProxy(env?: NodeJS.ProcessEnv): string[];
7
- /** A second provider binding the same URL to a different proxy is refused, never switched: the signed URL would go to
8
- * it. */
9
- export declare function bindConnectDial(connectUrl: string, connectBaseUrl: string | null): void;
10
- export declare function unbindConnectDial(connectUrl: string): void;
11
- export declare function connectDialUrl(url: string): string;
12
- export declare function installWebSocketWrapper(): void;
@@ -1,95 +0,0 @@
1
- import { browserbaseHoldings } from "./shared.js";
2
- /** Rewrite a Browserbase connect URL onto the credential proxy: only `*.browserbase.com` hosts, the signing query kept. */
3
- export function rewriteConnectUrl(connectUrl, connectBaseUrl) {
4
- if (!connectUrl || !connectBaseUrl)
5
- return connectUrl;
6
- try {
7
- const target = new URL(connectBaseUrl);
8
- const u = new URL(connectUrl);
9
- if (!/(?:^|\.)browserbase\.com$/i.test(u.hostname))
10
- return connectUrl;
11
- u.protocol = target.protocol;
12
- u.host = target.host;
13
- u.pathname = target.pathname.replace(/\/$/, "") + u.pathname;
14
- return u.toString();
15
- }
16
- catch {
17
- return connectUrl;
18
- }
19
- }
20
- /** Direct, never through the HTTP(S) env proxy: it rejects CONNECT and the CDP WebSocket cannot ride it. Under `node
21
- * --use-env-proxy` NO_PROXY is re-read per request, so listing these hosts bypasses it. */
22
- export function browserbaseNoProxyHosts(env) {
23
- const hosts = new Set();
24
- for (const key of ["BROWSERBASE_BASE_URL", "BROWSERBASE_CONNECT_BASE_URL"]) {
25
- const raw = String(env[key] || "").trim();
26
- if (!raw)
27
- continue;
28
- try {
29
- hosts.add(new URL(raw).hostname);
30
- }
31
- catch { }
32
- }
33
- if (!String(env.BROWSERBASE_CONNECT_BASE_URL || "").trim())
34
- hosts.add(".browserbase.com");
35
- return [...hosts];
36
- }
37
- export function applyBrowserbaseNoProxy(env = process.env) {
38
- const hosts = browserbaseNoProxyHosts(env);
39
- if (!hosts.length)
40
- return hosts;
41
- for (const target of env === process.env ? [env] : [env, process.env]) {
42
- for (const key of ["NO_PROXY", "no_proxy"]) {
43
- const merged = String(target[key] || "").split(",").map((h) => h.trim()).filter(Boolean);
44
- for (const h of hosts)
45
- if (!merged.includes(h))
46
- merged.push(h);
47
- target[key] = merged.join(",");
48
- }
49
- }
50
- return hosts;
51
- }
52
- /** The driver keeps the raw connect URL (the extension in the cloud browser dials it back and reaches only
53
- * Browserbase); this process's socket dials the proxy, so the rewrite happens at dial time, never in a record. */
54
- /** Per-socket targets, so two providers with different proxies never send one's signed URL to the other's proxy. */
55
- const { boundDials } = browserbaseHoldings;
56
- /** A second provider binding the same URL to a different proxy is refused, never switched: the signed URL would go to
57
- * it. */
58
- export function bindConnectDial(connectUrl, connectBaseUrl) {
59
- const target = connectBaseUrl?.trim() ?? "";
60
- const bound = boundDials.get(connectUrl);
61
- if (bound !== undefined && bound !== target)
62
- throw new Error("this Browserbase session is already attached through another credential proxy");
63
- boundDials.set(connectUrl, target);
64
- }
65
- export function unbindConnectDial(connectUrl) {
66
- boundDials.delete(connectUrl);
67
- if (![...boundDials.values()].some(Boolean))
68
- restoreWebSocket();
69
- }
70
- export function connectDialUrl(url) {
71
- const bound = boundDials.get(url);
72
- if (bound !== undefined)
73
- return bound ? rewriteConnectUrl(url, bound) : url;
74
- return url;
75
- }
76
- /** Wraps the process WebSocket only while a session is bound to a proxy; the native one returns with the last binding. A wrapper
77
- * installed on top cannot be removed, so ours stays under it and, with no bindings, passes every URL through. */
78
- let wrapped = null;
79
- export function installWebSocketWrapper() {
80
- if (typeof globalThis.WebSocket !== "function" || (wrapped && globalThis.WebSocket === wrapped.wrapper))
81
- return;
82
- const original = globalThis.WebSocket;
83
- const wrapper = function (url, protocols) { return new original(connectDialUrl(String(url)), protocols); };
84
- wrapper.prototype = original.prototype;
85
- for (const k of ["CONNECTING", "OPEN", "CLOSING", "CLOSED"])
86
- wrapper[k] = original[k];
87
- globalThis.WebSocket = wrapper;
88
- wrapped = { original, wrapper };
89
- }
90
- function restoreWebSocket() {
91
- if (!wrapped || globalThis.WebSocket !== wrapped.wrapper)
92
- return;
93
- globalThis.WebSocket = wrapped.original;
94
- wrapped = null;
95
- }
@@ -1,138 +0,0 @@
1
- import type { BrowserProvider, Geo, PriceTable, SessionSpec } from "../core/host.js";
2
- import { type CdpSession } from "./cdp-call.js";
3
- import { type ProfileStore } from "./profiles.js";
4
- export { rewriteConnectUrl, browserbaseNoProxyHosts, applyBrowserbaseNoProxy } from "./browserbase-net.js";
5
- export { fileProfileStore, memoryProfileStore, type ProfileStore } from "./profiles.js";
6
- export type BrowserbaseSdk = {
7
- sessions: {
8
- create(body: BrowserbaseSessionBody, options?: RequestOptions): Promise<{
9
- id: string;
10
- connectUrl: string;
11
- }>;
12
- list(query: {
13
- q?: string;
14
- status?: string;
15
- }, options?: RequestOptions): Promise<Array<{
16
- id: string;
17
- status?: string;
18
- userMetadata?: Record<string, unknown>;
19
- }>>;
20
- retrieve(id: string, options?: RequestOptions): Promise<{
21
- id: string;
22
- status?: string;
23
- connectUrl?: string;
24
- }>;
25
- update(id: string, body: {
26
- status: "REQUEST_RELEASE";
27
- }, options?: RequestOptions): Promise<unknown>;
28
- debug(id: string, options?: RequestOptions): Promise<{
29
- debuggerFullscreenUrl?: string;
30
- debuggerUrl?: string;
31
- pages?: Array<{
32
- id?: string;
33
- url?: string;
34
- title?: string;
35
- debuggerFullscreenUrl?: string;
36
- }>;
37
- }>;
38
- recording?: {
39
- downloads: {
40
- create(id: string): Promise<{
41
- downloads?: RecordingDownload[];
42
- }>;
43
- list(id: string): Promise<{
44
- downloads?: RecordingDownload[];
45
- }>;
46
- };
47
- };
48
- };
49
- extensions: {
50
- create(body: {
51
- file: unknown;
52
- }, options?: RequestOptions): Promise<{
53
- id: string;
54
- }>;
55
- };
56
- contexts: {
57
- create(body: {
58
- projectId?: string;
59
- }, options?: RequestOptions): Promise<{
60
- id: string;
61
- }>;
62
- };
63
- get<T = unknown>(path: string, options?: RequestOptions & {
64
- query?: Record<string, unknown>;
65
- headers?: Record<string, string>;
66
- __binaryResponse?: boolean;
67
- }): Promise<T>;
68
- };
69
- type BrowserbaseSessionBody = {
70
- proxies: boolean | Array<Record<string, unknown>>;
71
- timeout: number;
72
- keepAlive: boolean;
73
- browserSettings: {
74
- solveCaptchas: boolean;
75
- viewport: SessionSpec["viewport"];
76
- verified?: boolean;
77
- context?: {
78
- id: string;
79
- persist: boolean;
80
- };
81
- allowedDomains?: string[];
82
- };
83
- userMetadata: Record<string, string>;
84
- region?: string;
85
- extensionId?: string;
86
- projectId?: string;
87
- };
88
- type RequestOptions = {
89
- maxRetries?: number;
90
- timeout?: number;
91
- signal?: AbortSignal;
92
- };
93
- type RecordingDownload = {
94
- pageId?: string;
95
- status?: string;
96
- downloadUrl?: string;
97
- };
98
- export type BrowserbaseOptions = {
99
- /** Reads BROWSERBASE_API_KEY (or BB_API_KEY), _BASE_URL, _CONNECT_BASE_URL, _PROJECT_ID. Default: process.env. */
100
- env?: NodeJS.ProcessEnv;
101
- client?: BrowserbaseSdk;
102
- /** The Stagehand extension's Browserbase id. Default: uploaded once per process. */
103
- extensionId?: () => Promise<string>;
104
- prices?: Partial<PriceTable>;
105
- downloadBehavior?: (dialUrl: string) => Promise<DownloadSetting | void>;
106
- confirm?: {
107
- polls: number;
108
- intervalMs: number;
109
- };
110
- sleep?: (ms: number) => Promise<void>;
111
- /** Where profile names find their Browserbase contexts. Default: a file under the user's config directory. */
112
- profiles?: ProfileStore;
113
- /** How long a release that saved a profile waits for Browserbase to write the context back. */
114
- profileSettleMs?: number;
115
- };
116
- /** `Browser.setDownloadBehavior` lasts only as long as the socket that sent it, so the socket stays open until
117
- * `close()`. */
118
- export type DownloadSetting = Pick<CdpSession, "close" | "open">;
119
- /** Into `downloadPath` (default `downloads`, Browserbase's synced-downloads rule); the socket stays open. */
120
- export declare const setDownloadBehavior: (url: string, options?: {
121
- downloadPath?: string;
122
- timeoutMs?: number;
123
- }) => Promise<DownloadSetting>;
124
- export type BrowserbaseProvider = BrowserProvider & {
125
- readonly name: "browserbase";
126
- };
127
- /** ISO alpha-2 country, US state abbreviation, upper-case city; no two-letter country, no geolocation. */
128
- export declare function browserbaseGeolocation(raw: Partial<Geo> | null | undefined): Geo | null;
129
- export declare function proxiesField(proxies: SessionSpec["proxies"]): boolean | Array<Record<string, unknown>>;
130
- export declare function sessionCreateBody(spec: SessionSpec, extra?: {
131
- extensionId?: string;
132
- projectId?: string;
133
- context?: {
134
- id: string;
135
- persist: boolean;
136
- };
137
- }): BrowserbaseSessionBody;
138
- export declare function browserbaseProvider(options?: BrowserbaseOptions): BrowserbaseProvider;