@handstage/core 0.0.5 → 0.0.6
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/dist/v3/index.js +0 -7
- package/dist/v3/launch/local.js +3 -4
- package/dist/v3/understudy/cdp.js +11 -9
- package/package.json +1 -1
package/dist/v3/index.js
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
1
|
import { maybeRunShutdownSupervisorFromArgv as __internalMaybeRunShutdownSupervisorFromArgv } from "./shutdown/supervisor";
|
|
2
|
-
import * as PublicApi from "./types/public/index";
|
|
3
2
|
import { V3 } from "./v3";
|
|
4
3
|
export * from "./types/public/index";
|
|
5
4
|
export { __internalMaybeRunShutdownSupervisorFromArgv, V3, V3 as Handstage };
|
|
6
|
-
export default {
|
|
7
|
-
...PublicApi,
|
|
8
|
-
V3,
|
|
9
|
-
Handstage: V3,
|
|
10
|
-
__internalMaybeRunShutdownSupervisorFromArgv,
|
|
11
|
-
};
|
package/dist/v3/launch/local.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { launch } from "chrome-launcher";
|
|
2
|
-
import WebSocket from "ws";
|
|
3
2
|
import { ConnectionTimeoutError } from "../types/public/sdkErrors";
|
|
4
3
|
export async function launchLocalChrome(opts) {
|
|
5
4
|
const connectTimeoutMs = opts.connectTimeoutMs ?? 15_000;
|
|
@@ -77,7 +76,7 @@ function probeWebSocket(wsUrl, timeoutMs) {
|
|
|
77
76
|
settled = true;
|
|
78
77
|
clearTimeout(timer);
|
|
79
78
|
try {
|
|
80
|
-
ws.
|
|
79
|
+
ws.close();
|
|
81
80
|
}
|
|
82
81
|
catch { }
|
|
83
82
|
if (error) {
|
|
@@ -89,7 +88,7 @@ function probeWebSocket(wsUrl, timeoutMs) {
|
|
|
89
88
|
const timer = setTimeout(() => {
|
|
90
89
|
finish(new Error(`websocket probe timeout after ${timeoutMs}ms`));
|
|
91
90
|
}, timeoutMs);
|
|
92
|
-
ws.
|
|
93
|
-
ws.
|
|
91
|
+
ws.addEventListener("open", () => finish(), { once: true });
|
|
92
|
+
ws.addEventListener("error", (error) => finish(error.error || new Error("WebSocket error")), { once: true });
|
|
94
93
|
});
|
|
95
94
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import WebSocket from "ws";
|
|
2
1
|
import { HANDSTAGE_VERSION } from "../../version";
|
|
3
2
|
import { CDPConnectionClosedError, PageNotFoundError, } from "../types/public/sdkErrors";
|
|
4
3
|
export class BaseCDPConnection {
|
|
@@ -94,26 +93,29 @@ export class CDPConnection extends BaseCDPConnection {
|
|
|
94
93
|
"User-Agent": `Handstage/${HANDSTAGE_VERSION}`,
|
|
95
94
|
...options?.headers,
|
|
96
95
|
};
|
|
96
|
+
// @ts-expect-error: Modern runtimes like Bun support headers in native WebSocket
|
|
97
97
|
const ws = new WebSocket(wsUrl, { headers });
|
|
98
98
|
await new Promise((resolve, reject) => {
|
|
99
|
-
ws.
|
|
100
|
-
ws.
|
|
99
|
+
ws.addEventListener("open", () => resolve(), { once: true });
|
|
100
|
+
ws.addEventListener("error", (e) => reject(e.error || e), {
|
|
101
|
+
once: true,
|
|
102
|
+
});
|
|
101
103
|
});
|
|
102
104
|
const transport = {
|
|
103
105
|
send: (message) => ws.send(message),
|
|
104
106
|
close: () => ws.close(),
|
|
105
107
|
};
|
|
106
|
-
ws.
|
|
108
|
+
ws.addEventListener("message", (event) => {
|
|
107
109
|
if (transport.onmessage)
|
|
108
|
-
transport.onmessage(data.toString());
|
|
110
|
+
transport.onmessage(event.data.toString());
|
|
109
111
|
});
|
|
110
|
-
ws.
|
|
112
|
+
ws.addEventListener("close", (event) => {
|
|
111
113
|
if (transport.onclose)
|
|
112
|
-
transport.onclose(`code=${code} reason=${reason}`);
|
|
114
|
+
transport.onclose(`code=${event.code} reason=${event.reason}`);
|
|
113
115
|
});
|
|
114
|
-
ws.
|
|
116
|
+
ws.addEventListener("error", (event) => {
|
|
115
117
|
if (transport.onerror)
|
|
116
|
-
transport.onerror(error);
|
|
118
|
+
transport.onerror(event.error || new Error("WebSocket error"));
|
|
117
119
|
});
|
|
118
120
|
return new CDPConnection(transport);
|
|
119
121
|
}
|