diff --git a/src/browser/cdp.helpers.ts b/src/browser/cdp.helpers.ts index dc7e681483..eae8ef989e 100644 --- a/src/browser/cdp.helpers.ts +++ b/src/browser/cdp.helpers.ts @@ -113,6 +113,11 @@ function createCdpSender(ws: WebSocket) { } export async function fetchJson(url: string, timeoutMs = 1500, init?: RequestInit): Promise { + const res = await fetchChecked(url, timeoutMs, init); + return (await res.json()) as T; +} + +async function fetchChecked(url: string, timeoutMs = 1500, init?: RequestInit): Promise { const ctrl = new AbortController(); const t = setTimeout(ctrl.abort.bind(ctrl), timeoutMs); try { @@ -121,24 +126,14 @@ export async function fetchJson(url: string, timeoutMs = 1500, init?: Request if (!res.ok) { throw new Error(`HTTP ${res.status}`); } - return (await res.json()) as T; + return res; } finally { clearTimeout(t); } } export 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); - } + await fetchChecked(url, timeoutMs, init); } export async function withCdpSocket(