@@ -6,7 +6,6 @@ import {
|
6 | 6 | type SsrFPolicy, |
7 | 7 | resolvePinnedHostnameWithPolicy, |
8 | 8 | } from "../infra/net/ssrf.js"; |
9 | | -import { rawDataToString } from "../infra/ws.js"; |
10 | 9 | import { redactSensitiveText } from "../logging/redact.js"; |
11 | 10 | import { getDirectAgentForCdp, withNoProxyForCdpUrl } from "./cdp-proxy-bypass.js"; |
12 | 11 | import { CDP_HTTP_REQUEST_TIMEOUT_MS, CDP_WS_HANDSHAKE_TIMEOUT_MS } from "./cdp-timeouts.js"; |
@@ -151,6 +150,22 @@ export type CdpSendFn = (
|
151 | 150 | sessionId?: string, |
152 | 151 | ) => Promise<unknown>; |
153 | 152 | |
| 153 | +function rawCdpMessageToString(data: WebSocket.RawData): string { |
| 154 | +if (typeof data === "string") { |
| 155 | +return data; |
| 156 | +} |
| 157 | +if (Buffer.isBuffer(data)) { |
| 158 | +return data.toString("utf8"); |
| 159 | +} |
| 160 | +if (Array.isArray(data)) { |
| 161 | +return Buffer.concat(data).toString("utf8"); |
| 162 | +} |
| 163 | +if (ArrayBuffer.isView(data)) { |
| 164 | +return Buffer.from(data.buffer, data.byteOffset, data.byteLength).toString("utf8"); |
| 165 | +} |
| 166 | +return Buffer.from(data).toString("utf8"); |
| 167 | +} |
| 168 | + |
154 | 169 | export function getHeadersWithAuth(url: string, headers: Record<string, string> = {}) { |
155 | 170 | const mergedHeaders = { ...headers }; |
156 | 171 | try { |
@@ -246,7 +261,7 @@ function createCdpSender(ws: WebSocket) {
|
246 | 261 | |
247 | 262 | ws.on("message", (data) => { |
248 | 263 | try { |
249 | | -const parsed = JSON.parse(rawDataToString(data)) as CdpResponse; |
| 264 | +const parsed = JSON.parse(rawCdpMessageToString(data)) as CdpResponse; |
250 | 265 | if (typeof parsed.id !== "number") { |
251 | 266 | return; |
252 | 267 | } |
|