chore(browser): format CDP helpers

This commit is contained in:
Peter Steinberger
2026-01-01 16:19:37 +00:00
parent c8c84bc419
commit a248bea50f
2 changed files with 14 additions and 13 deletions

View File

@@ -353,14 +353,17 @@ async function canOpenWebSocket(
): Promise<boolean> { ): Promise<boolean> {
return await new Promise<boolean>((resolve) => { return await new Promise<boolean>((resolve) => {
const ws = new WebSocket(wsUrl, { handshakeTimeout: timeoutMs }); const ws = new WebSocket(wsUrl, { handshakeTimeout: timeoutMs });
const timer = setTimeout(() => { const timer = setTimeout(
try { () => {
ws.terminate(); try {
} catch { ws.terminate();
// ignore } catch {
} // ignore
resolve(false); }
}, Math.max(50, timeoutMs + 25)); resolve(false);
},
Math.max(50, timeoutMs + 25),
);
ws.once("open", () => { ws.once("open", () => {
clearTimeout(timer); clearTimeout(timer);
try { try {

View File

@@ -1,8 +1,9 @@
import fs from "node:fs"; import fs from "node:fs";
import type { Server } from "node:http";
import os from "node:os"; import os from "node:os";
import path from "node:path"; import path from "node:path";
import type { Server } from "node:http";
import { runExec } from "../process/exec.js";
import { createTargetViaCdp } from "./cdp.js"; import { createTargetViaCdp } from "./cdp.js";
import { import {
isChromeCdpReady, isChromeCdpReady,
@@ -14,7 +15,6 @@ import {
} from "./chrome.js"; } from "./chrome.js";
import type { ResolvedBrowserConfig } from "./config.js"; import type { ResolvedBrowserConfig } from "./config.js";
import { resolveTargetIdFromTabs } from "./target-id.js"; import { resolveTargetIdFromTabs } from "./target-id.js";
import { runExec } from "../process/exec.js";
export type BrowserTab = { export type BrowserTab = {
targetId: string; targetId: string;
@@ -223,9 +223,7 @@ export function createBrowserRouteContext(
attachRunning(relaunched); attachRunning(relaunched);
if (!(await isReachable(600))) { if (!(await isReachable(600))) {
throw new Error( throw new Error("Chrome CDP websocket is not reachable after restart.");
"Chrome CDP websocket is not reachable after restart.",
);
} }
}; };