@handstage/core 0.0.4 → 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
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
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@handstage/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -18,7 +18,6 @@
|
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@types/bun": "1.3.14",
|
|
20
20
|
"@types/node": "^25.9.1",
|
|
21
|
-
"@types/ws": "^8.18.1",
|
|
22
21
|
"typescript": "^6.0.3"
|
|
23
22
|
},
|
|
24
23
|
"peerDependencies": {
|
|
@@ -29,7 +28,6 @@
|
|
|
29
28
|
"chrome-launcher": "^1.2.1",
|
|
30
29
|
"devtools-protocol": "^0.0.1632630",
|
|
31
30
|
"uuid": "^14.0.0",
|
|
32
|
-
"ws": "^8.20.1",
|
|
33
31
|
"zod": "^4.4.3"
|
|
34
32
|
}
|
|
35
33
|
}
|
package/src/v3/index.ts
CHANGED
|
@@ -1,13 +1,5 @@
|
|
|
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
|
|
|
5
4
|
export * from "./types/public/index"
|
|
6
5
|
export { __internalMaybeRunShutdownSupervisorFromArgv, V3, V3 as Handstage }
|
|
7
|
-
|
|
8
|
-
export default {
|
|
9
|
-
...PublicApi,
|
|
10
|
-
V3,
|
|
11
|
-
Handstage: V3,
|
|
12
|
-
__internalMaybeRunShutdownSupervisorFromArgv,
|
|
13
|
-
}
|
package/src/v3/launch/local.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { type LaunchedChrome, launch } from "chrome-launcher"
|
|
2
|
-
import WebSocket from "ws"
|
|
3
2
|
import { ConnectionTimeoutError } from "../types/public/sdkErrors"
|
|
4
3
|
|
|
5
4
|
interface LaunchLocalOptions {
|
|
@@ -110,7 +109,7 @@ function probeWebSocket(wsUrl: string, timeoutMs: number): Promise<void> {
|
|
|
110
109
|
settled = true
|
|
111
110
|
clearTimeout(timer)
|
|
112
111
|
try {
|
|
113
|
-
ws.
|
|
112
|
+
ws.close()
|
|
114
113
|
} catch {}
|
|
115
114
|
if (error) {
|
|
116
115
|
reject(error)
|
|
@@ -122,7 +121,11 @@ function probeWebSocket(wsUrl: string, timeoutMs: number): Promise<void> {
|
|
|
122
121
|
finish(new Error(`websocket probe timeout after ${timeoutMs}ms`))
|
|
123
122
|
}, timeoutMs)
|
|
124
123
|
|
|
125
|
-
ws.
|
|
126
|
-
ws.
|
|
124
|
+
ws.addEventListener("open", () => finish(), { once: true })
|
|
125
|
+
ws.addEventListener(
|
|
126
|
+
"error",
|
|
127
|
+
(error: any) => finish(error.error || new Error("WebSocket error")),
|
|
128
|
+
{ once: true },
|
|
129
|
+
)
|
|
127
130
|
})
|
|
128
131
|
}
|
package/src/v3/understudy/cdp.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { Protocol } from "devtools-protocol"
|
|
2
|
-
import WebSocket from "ws"
|
|
3
2
|
import { HANDSTAGE_VERSION } from "../../version"
|
|
4
3
|
import {
|
|
5
4
|
CDPConnectionClosedError,
|
|
@@ -221,23 +220,28 @@ export class CDPConnection extends BaseCDPConnection {
|
|
|
221
220
|
"User-Agent": `Handstage/${HANDSTAGE_VERSION}`,
|
|
222
221
|
...options?.headers,
|
|
223
222
|
}
|
|
223
|
+
// @ts-expect-error: Modern runtimes like Bun support headers in native WebSocket
|
|
224
224
|
const ws = new WebSocket(wsUrl, { headers })
|
|
225
225
|
await new Promise<void>((resolve, reject) => {
|
|
226
|
-
ws.
|
|
227
|
-
ws.
|
|
226
|
+
ws.addEventListener("open", () => resolve(), { once: true })
|
|
227
|
+
ws.addEventListener("error", (e: any) => reject(e.error || e), {
|
|
228
|
+
once: true,
|
|
229
|
+
})
|
|
228
230
|
})
|
|
229
231
|
const transport: CDPTransport = {
|
|
230
232
|
send: (message) => ws.send(message),
|
|
231
233
|
close: () => ws.close(),
|
|
232
234
|
}
|
|
233
|
-
ws.
|
|
234
|
-
if (transport.onmessage) transport.onmessage(data.toString())
|
|
235
|
+
ws.addEventListener("message", (event: any) => {
|
|
236
|
+
if (transport.onmessage) transport.onmessage(event.data.toString())
|
|
235
237
|
})
|
|
236
|
-
ws.
|
|
237
|
-
if (transport.onclose)
|
|
238
|
+
ws.addEventListener("close", (event: any) => {
|
|
239
|
+
if (transport.onclose)
|
|
240
|
+
transport.onclose(`code=${event.code} reason=${event.reason}`)
|
|
238
241
|
})
|
|
239
|
-
ws.
|
|
240
|
-
if (transport.onerror)
|
|
242
|
+
ws.addEventListener("error", (event: any) => {
|
|
243
|
+
if (transport.onerror)
|
|
244
|
+
transport.onerror(event.error || new Error("WebSocket error"))
|
|
241
245
|
})
|
|
242
246
|
return new CDPConnection(transport)
|
|
243
247
|
}
|