browser-pilot 0.0.13 → 0.0.14

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.
@@ -1,8 +1,8 @@
1
- import { C as CDPClient } from './client-DRqxBdHv.cjs';
1
+ import { C as CDPClient } from './client-Ck2nQksT.cjs';
2
2
  import { TargetInfo } from './cdp.cjs';
3
3
  import { b as ConnectOptions } from './types--wXNHUwt.cjs';
4
- import { H as Page } from './types-BXMGFtnB.cjs';
5
- export { k as ActionOptions, l as ActionResult, m as ConsoleHandler, n as ConsoleMessage, o as ConsoleMessageType, p as CustomSelectConfig, D as Dialog, q as DialogHandler, r as DialogType, s as Download, E as ElementInfo, t as ElementNotFoundError, u as EmulationState, v as ErrorHandler, ah as FailureHint, F as FileInput, w as FillOptions, x as FormField, y as FormOption, G as GeolocationOptions, I as InteractiveElement, N as NavigationError, z as NetworkIdleOptions, J as PageError, K as PageSnapshot, L as SnapshotNode, M as SnapshotOptions, O as SubmitOptions, T as TimeoutError, Q as TypeOptions, U as UserAgentMetadata, V as UserAgentOptions, W as ViewportOptions, X as WaitForOptions } from './types-BXMGFtnB.cjs';
4
+ import { J as Page } from './types-BSoh5v1Y.cjs';
5
+ export { l as ActionOptions, m as ActionResult, n as ConsoleHandler, o as ConsoleMessage, p as ConsoleMessageType, q as CustomSelectConfig, D as Dialog, r as DialogHandler, s as DialogType, t as Download, E as ElementInfo, u as ElementNotFoundError, v as EmulationState, w as ErrorHandler, ai as FailureHint, F as FileInput, x as FillOptions, y as FormField, z as FormOption, G as GeolocationOptions, I as InteractiveElement, N as NavigationError, H as NetworkIdleOptions, K as PageError, L as PageSnapshot, M as SnapshotNode, O as SnapshotOptions, Q as SubmitOptions, T as TimeoutError, U as TypeOptions, V as UserAgentMetadata, W as UserAgentOptions, X as ViewportOptions, Y as WaitForOptions } from './types-BSoh5v1Y.cjs';
6
6
 
7
7
  /**
8
8
  * Browser class - manages CDP connection and pages
@@ -34,6 +34,15 @@ declare class Browser {
34
34
  private pages;
35
35
  private pageCounter;
36
36
  private constructor();
37
+ /**
38
+ * Create a Browser from an existing CDPClient (used by daemon fast-path).
39
+ * The caller is responsible for the CDP connection lifecycle.
40
+ */
41
+ static fromCDP(cdp: CDPClient, sessionInfo: {
42
+ wsUrl: string;
43
+ provider?: string;
44
+ sessionId?: string;
45
+ }): Browser;
37
46
  /**
38
47
  * Connect to a browser instance
39
48
  */
package/dist/browser.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { C as CDPClient } from './client-DRqxBdHv.js';
1
+ import { C as CDPClient } from './client-Ck2nQksT.js';
2
2
  import { TargetInfo } from './cdp.js';
3
3
  import { b as ConnectOptions } from './types--wXNHUwt.js';
4
- import { H as Page } from './types-CzgQjai9.js';
5
- export { k as ActionOptions, l as ActionResult, m as ConsoleHandler, n as ConsoleMessage, o as ConsoleMessageType, p as CustomSelectConfig, D as Dialog, q as DialogHandler, r as DialogType, s as Download, E as ElementInfo, t as ElementNotFoundError, u as EmulationState, v as ErrorHandler, ah as FailureHint, F as FileInput, w as FillOptions, x as FormField, y as FormOption, G as GeolocationOptions, I as InteractiveElement, N as NavigationError, z as NetworkIdleOptions, J as PageError, K as PageSnapshot, L as SnapshotNode, M as SnapshotOptions, O as SubmitOptions, T as TimeoutError, Q as TypeOptions, U as UserAgentMetadata, V as UserAgentOptions, W as ViewportOptions, X as WaitForOptions } from './types-CzgQjai9.js';
4
+ import { J as Page } from './types-CjT0vClo.js';
5
+ export { l as ActionOptions, m as ActionResult, n as ConsoleHandler, o as ConsoleMessage, p as ConsoleMessageType, q as CustomSelectConfig, D as Dialog, r as DialogHandler, s as DialogType, t as Download, E as ElementInfo, u as ElementNotFoundError, v as EmulationState, w as ErrorHandler, ai as FailureHint, F as FileInput, x as FillOptions, y as FormField, z as FormOption, G as GeolocationOptions, I as InteractiveElement, N as NavigationError, H as NetworkIdleOptions, K as PageError, L as PageSnapshot, M as SnapshotNode, O as SnapshotOptions, Q as SubmitOptions, T as TimeoutError, U as TypeOptions, V as UserAgentMetadata, W as UserAgentOptions, X as ViewportOptions, Y as WaitForOptions } from './types-CjT0vClo.js';
6
6
 
7
7
  /**
8
8
  * Browser class - manages CDP connection and pages
@@ -34,6 +34,15 @@ declare class Browser {
34
34
  private pages;
35
35
  private pageCounter;
36
36
  private constructor();
37
+ /**
38
+ * Create a Browser from an existing CDPClient (used by daemon fast-path).
39
+ * The caller is responsible for the CDP connection lifecycle.
40
+ */
41
+ static fromCDP(cdp: CDPClient, sessionInfo: {
42
+ wsUrl: string;
43
+ provider?: string;
44
+ sessionId?: string;
45
+ }): Browser;
37
46
  /**
38
47
  * Connect to a browser instance
39
48
  */
package/dist/browser.mjs CHANGED
@@ -2,14 +2,14 @@ import {
2
2
  Browser,
3
3
  Page,
4
4
  connect
5
- } from "./chunk-VDAMDOS6.mjs";
6
- import "./chunk-HP6R3W32.mjs";
5
+ } from "./chunk-IN5HPAPB.mjs";
6
+ import "./chunk-KIFB526Y.mjs";
7
7
  import "./chunk-BRAFQUMG.mjs";
8
8
  import {
9
9
  ElementNotFoundError,
10
10
  NavigationError,
11
11
  TimeoutError
12
- } from "./chunk-A2ZRAEO3.mjs";
12
+ } from "./chunk-XMJABKCF.mjs";
13
13
  import "./chunk-JXAUPHZM.mjs";
14
14
  export {
15
15
  Browser,
package/dist/cdp.cjs CHANGED
@@ -22,10 +22,16 @@ var cdp_exports = {};
22
22
  __export(cdp_exports, {
23
23
  CDPError: () => CDPError,
24
24
  createCDPClient: () => createCDPClient,
25
+ createCDPClientFromTransport: () => createCDPClientFromTransport,
25
26
  createTransport: () => createTransport
26
27
  });
27
28
  module.exports = __toCommonJS(cdp_exports);
28
29
 
30
+ // src/utils/json.ts
31
+ function isRecord(value) {
32
+ return typeof value === "object" && value !== null;
33
+ }
34
+
29
35
  // src/cdp/protocol.ts
30
36
  var CDPError = class extends Error {
31
37
  code;
@@ -140,9 +146,16 @@ function getReadyStateString(state) {
140
146
  }
141
147
 
142
148
  // src/cdp/client.ts
149
+ function createCDPClientFromTransport(transport, options = {}) {
150
+ return buildCDPClient(transport, options);
151
+ }
143
152
  async function createCDPClient(wsUrl, options = {}) {
144
- const { debug = false, timeout = 3e4 } = options;
153
+ const { timeout = 3e4 } = options;
145
154
  const transport = await createTransport(wsUrl, { timeout });
155
+ return buildCDPClient(transport, options);
156
+ }
157
+ function buildCDPClient(transport, options = {}) {
158
+ const { debug = false, timeout = 3e4 } = options;
146
159
  let messageId = 0;
147
160
  let currentSessionId;
148
161
  let connected = true;
@@ -152,7 +165,19 @@ async function createCDPClient(wsUrl, options = {}) {
152
165
  transport.onMessage((raw) => {
153
166
  let msg;
154
167
  try {
155
- msg = JSON.parse(raw);
168
+ const parsed = JSON.parse(raw);
169
+ if (!isRecord(parsed)) {
170
+ if (debug) console.error("[CDP] Ignoring non-object message:", raw);
171
+ return;
172
+ }
173
+ if ("id" in parsed && typeof parsed["id"] === "number") {
174
+ msg = parsed;
175
+ } else if ("method" in parsed && typeof parsed["method"] === "string") {
176
+ msg = parsed;
177
+ } else {
178
+ if (debug) console.error("[CDP] Ignoring invalid message shape:", raw);
179
+ return;
180
+ }
156
181
  } catch {
157
182
  if (debug) console.error("[CDP] Failed to parse message:", raw);
158
183
  return;
@@ -265,6 +290,9 @@ async function createCDPClient(wsUrl, options = {}) {
265
290
  onAny(handler) {
266
291
  anyEventHandlers.add(handler);
267
292
  },
293
+ offAny(handler) {
294
+ anyEventHandlers.delete(handler);
295
+ },
268
296
  async close() {
269
297
  connected = false;
270
298
  await transport.close();
@@ -290,5 +318,6 @@ async function createCDPClient(wsUrl, options = {}) {
290
318
  0 && (module.exports = {
291
319
  CDPError,
292
320
  createCDPClient,
321
+ createCDPClientFromTransport,
293
322
  createTransport
294
323
  });
package/dist/cdp.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- export { C as CDPClient, a as CDPClientOptions, T as Transport, d as TransportOptions, c as createCDPClient, b as createTransport } from './client-DRqxBdHv.cjs';
1
+ export { C as CDPClient, a as CDPClientOptions, T as Transport, e as TransportOptions, c as createCDPClient, b as createCDPClientFromTransport, d as createTransport } from './client-Ck2nQksT.cjs';
2
2
 
3
3
  /**
4
4
  * CDP Protocol type definitions
package/dist/cdp.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { C as CDPClient, a as CDPClientOptions, T as Transport, d as TransportOptions, c as createCDPClient, b as createTransport } from './client-DRqxBdHv.js';
1
+ export { C as CDPClient, a as CDPClientOptions, T as Transport, e as TransportOptions, c as createCDPClient, b as createCDPClientFromTransport, d as createTransport } from './client-Ck2nQksT.js';
2
2
 
3
3
  /**
4
4
  * CDP Protocol type definitions
package/dist/cdp.mjs CHANGED
@@ -1,12 +1,14 @@
1
1
  import {
2
2
  createCDPClient,
3
+ createCDPClientFromTransport,
3
4
  createTransport
4
- } from "./chunk-HP6R3W32.mjs";
5
+ } from "./chunk-KIFB526Y.mjs";
5
6
  import {
6
7
  CDPError
7
8
  } from "./chunk-JXAUPHZM.mjs";
8
9
  export {
9
10
  CDPError,
10
11
  createCDPClient,
12
+ createCDPClientFromTransport,
11
13
  createTransport
12
14
  };