diff --git a/packages/cli/src/capture/navigateForCapture.ts b/packages/cli/src/capture/navigateForCapture.ts index 0e9c1b60c5..d5dd323d6c 100644 --- a/packages/cli/src/capture/navigateForCapture.ts +++ b/packages/cli/src/capture/navigateForCapture.ts @@ -9,8 +9,6 @@ export { isNavigationTimeoutError }; export const NETWORK_IDLE_ATTEMPT_MS = 30_000; -/** Chromium's words for a proxy in the way: the tunnel to the site was refused or not made, or the proxy itself - * could not be reached. */ const PROXY_FAILURES = { "net::ERR_TUNNEL_CONNECTION_FAILED": (host: string) => `Your network's proxy refused the connection to ${host}. Ask whoever runs it to allow ${host}.`, @@ -19,17 +17,11 @@ const PROXY_FAILURES = { } as const; const PROXY_FAILURE = new RegExp(Object.keys(PROXY_FAILURES).join("|")); -/** The error as the person should read it when their network's proxy was the problem; any other error as is. */ export function explainProxyRefusal(err: unknown, url: string): unknown { const said = err instanceof Error ? err.message : String(err); const code = PROXY_FAILURE.exec(said)?.[0] as keyof typeof PROXY_FAILURES | undefined; if (!code) return err; - let host = "the site"; - try { - host = new URL(url).host; - } catch { - // expected: an unparseable address is not echoed - } + const host = URL.canParse(url) ? new URL(url).host : "the site"; return new Error(`${PROXY_FAILURES[code](host)} (${code})`, { cause: err }); }