@handstage/core 0.0.4 → 0.0.5
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@handstage/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
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
|
}
|