fix: support authenticated remote CDP URLs (#895) (thanks @mukhtharcm)

This commit is contained in:
Peter Steinberger
2026-01-16 08:31:51 +00:00
parent 8e80823b03
commit bf15c87d2b
15 changed files with 179 additions and 100 deletions

View File

@@ -8,6 +8,7 @@ import { ensurePortAvailable } from "../infra/ports.js";
import { createSubsystemLogger } from "../logging.js";
import { CONFIG_DIR } from "../utils.js";
import { getHeadersWithAuth, normalizeCdpWsUrl } from "./cdp.js";
import { appendCdpPath } from "./cdp.helpers.js";
import {
type BrowserExecutable,
resolveBrowserExecutableForPlatform,
@@ -71,10 +72,10 @@ async function fetchChromeVersion(cdpUrl: string, timeoutMs = 500): Promise<Chro
const ctrl = new AbortController();
const t = setTimeout(() => ctrl.abort(), timeoutMs);
try {
const base = cdpUrl.replace(/\/$/, "");
const res = await fetch(`${base}/json/version`, {
const versionUrl = appendCdpPath(cdpUrl, "/json/version");
const res = await fetch(versionUrl, {
signal: ctrl.signal,
headers: getHeadersWithAuth(`${base}/json/version`),
headers: getHeadersWithAuth(versionUrl),
});
if (!res.ok) return null;
const data = (await res.json()) as ChromeVersion;
@@ -99,7 +100,11 @@ export async function getChromeWebSocketUrl(
async function canOpenWebSocket(wsUrl: string, timeoutMs = 800): Promise<boolean> {
return await new Promise<boolean>((resolve) => {
const ws = new WebSocket(wsUrl, { handshakeTimeout: timeoutMs });
const headers = getHeadersWithAuth(wsUrl);
const ws = new WebSocket(wsUrl, {
handshakeTimeout: timeoutMs,
...(Object.keys(headers).length ? { headers } : {}),
});
const timer = setTimeout(
() => {
try {