fix: upgrade ws to wss for https CDP

This commit is contained in:
Peter Steinberger
2026-01-16 08:44:00 +00:00
parent 52bdf57743
commit 1773f8aea2
3 changed files with 12 additions and 0 deletions

View File

@@ -173,4 +173,12 @@ describe("cdp", () => {
);
expect(normalized).toBe("wss://user:pass@example.com/devtools/browser/ABC?token=abc");
});
it("upgrades ws to wss when CDP uses https", () => {
const normalized = normalizeCdpWsUrl(
"ws://production-sfo.browserless.io",
"https://production-sfo.browserless.io?token=abc",
);
expect(normalized).toBe("wss://production-sfo.browserless.io/?token=abc");
});
});

View File

@@ -16,6 +16,9 @@ export function normalizeCdpWsUrl(wsUrl: string, cdpUrl: string): string {
if (cdpPort) ws.port = cdpPort;
ws.protocol = cdp.protocol === "https:" ? "wss:" : "ws:";
}
if (cdp.protocol === "https:" && ws.protocol === "ws:") {
ws.protocol = "wss:";
}
if (!ws.username && !ws.password && (cdp.username || cdp.password)) {
ws.username = cdp.username;
ws.password = cdp.password;