browser-pilot 0.0.11 → 0.0.13

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,14 +1,6 @@
1
- // src/cdp/protocol.ts
2
- var CDPError = class extends Error {
3
- code;
4
- data;
5
- constructor(error) {
6
- super(error.message);
7
- this.name = "CDPError";
8
- this.code = error.code;
9
- this.data = error.data;
10
- }
11
- };
1
+ import {
2
+ CDPError
3
+ } from "./chunk-JXAUPHZM.mjs";
12
4
 
13
5
  // src/cdp/transport.ts
14
6
  function createTransport(wsUrl, options = {}) {
@@ -39,13 +31,28 @@ function createTransport(wsUrl, options = {}) {
39
31
  resolveClose();
40
32
  return;
41
33
  }
42
- const onClose = () => {
34
+ let settled = false;
35
+ let fallbackTimer;
36
+ const finish = () => {
37
+ if (settled) return;
38
+ settled = true;
39
+ if (fallbackTimer) clearTimeout(fallbackTimer);
43
40
  ws.removeEventListener("close", onClose);
44
41
  resolveClose();
45
42
  };
43
+ const onClose = () => {
44
+ finish();
45
+ };
46
46
  ws.addEventListener("close", onClose);
47
- ws.close();
48
- setTimeout(resolveClose, 5e3);
47
+ try {
48
+ if (ws.readyState === WebSocket.OPEN || ws.readyState === WebSocket.CONNECTING) {
49
+ ws.close();
50
+ }
51
+ } catch {
52
+ finish();
53
+ return;
54
+ }
55
+ fallbackTimer = setTimeout(finish, 200);
49
56
  });
50
57
  },
51
58
  onMessage(handler) {
@@ -170,7 +177,7 @@ async function createCDPClient(wsUrl, options = {}) {
170
177
  throw new Error("CDP client is not connected");
171
178
  }
172
179
  const id = ++messageId;
173
- const effectiveSessionId = sessionId ?? currentSessionId;
180
+ const effectiveSessionId = sessionId === null ? void 0 : sessionId ?? currentSessionId;
174
181
  const request = { id, method };
175
182
  if (params !== void 0) {
176
183
  request.params = params;
@@ -245,7 +252,6 @@ async function createCDPClient(wsUrl, options = {}) {
245
252
  }
246
253
 
247
254
  export {
248
- CDPError,
249
255
  createTransport,
250
256
  createCDPClient
251
257
  };
@@ -0,0 +1,15 @@
1
+ // src/cdp/protocol.ts
2
+ var CDPError = class extends Error {
3
+ code;
4
+ data;
5
+ constructor(error) {
6
+ super(error.message);
7
+ this.name = "CDPError";
8
+ this.code = error.code;
9
+ this.data = error.data;
10
+ }
11
+ };
12
+
13
+ export {
14
+ CDPError
15
+ };