From a2c695126d103c40ca8e6b13d9a155a2b05626a2 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 15 Feb 2026 18:27:02 +0000 Subject: [PATCH] refactor(browser): reuse CDP fetch helpers --- src/browser/server-context.ts | 32 ++------------------------------ 1 file changed, 2 insertions(+), 30 deletions(-) diff --git a/src/browser/server-context.ts b/src/browser/server-context.ts index 61698f6e701..6e5a60a1420 100644 --- a/src/browser/server-context.ts +++ b/src/browser/server-context.ts @@ -10,7 +10,8 @@ import type { ProfileRuntimeState, ProfileStatus, } from "./server-context.types.js"; -import { appendCdpPath, createTargetViaCdp, getHeadersWithAuth, normalizeCdpWsUrl } from "./cdp.js"; +import { fetchJson, fetchOk } from "./cdp.helpers.js"; +import { appendCdpPath, createTargetViaCdp, normalizeCdpWsUrl } from "./cdp.js"; import { isChromeCdpReady, isChromeReachable, @@ -62,35 +63,6 @@ function normalizeWsUrl(raw: string | undefined, cdpBaseUrl: string): string | u } } -async function fetchJson(url: string, timeoutMs = 1500, init?: RequestInit): Promise { - const ctrl = new AbortController(); - const t = setTimeout(ctrl.abort.bind(ctrl), timeoutMs); - try { - const headers = getHeadersWithAuth(url, (init?.headers as Record) || {}); - const res = await fetch(url, { ...init, headers, signal: ctrl.signal }); - if (!res.ok) { - throw new Error(`HTTP ${res.status}`); - } - return (await res.json()) as T; - } finally { - clearTimeout(t); - } -} - -async function fetchOk(url: string, timeoutMs = 1500, init?: RequestInit): Promise { - const ctrl = new AbortController(); - const t = setTimeout(ctrl.abort.bind(ctrl), timeoutMs); - try { - const headers = getHeadersWithAuth(url, (init?.headers as Record) || {}); - const res = await fetch(url, { ...init, headers, signal: ctrl.signal }); - if (!res.ok) { - throw new Error(`HTTP ${res.status}`); - } - } finally { - clearTimeout(t); - } -} - /** * Create a profile-scoped context for browser operations. */