fix(engine): a script URL Node cannot parse no longer stops the render (#8723)

This commit is contained in:
Miguel Ángel
2026-11-24 19:23:04 +00:00
committed by GitHub
parent 85953d1788
commit 416d9e036c
2 changed files with 44 additions and 3 deletions
@@ -1,6 +1,10 @@
import { describe, expect, it, vi } from "vitest";
import type { CaptureSession } from "./frameCapture.js";
import { classifyScriptLoadCause, recordSubTimelineWarning } from "./frameCapture.js";
import {
classifyScriptLoadCause,
recordFailedRequest,
recordSubTimelineWarning,
} from "./frameCapture.js";
const SERVER = "http://localhost:4100";
@@ -41,6 +45,42 @@ describe("classifyScriptLoadCause", () => {
});
});
// fails without the fix: Node's URL parser threw on a host the browser had accepted, from inside a page listener
describe("a script URL Node cannot parse", () => {
const unparseable = ["http://xn--a.com/lib.js", "https://xn--ab-m1t.com/lib.js"];
it.each(unparseable)("classifies %s as remote instead of throwing", (url) => {
expect(() => new URL(url)).toThrow();
expect(classifyScriptLoadCause(url, SERVER, "net::ERR_NAME_NOT_RESOLVED")).toEqual({
origin: "remote",
code: "net::ERR_NAME_NOT_RESOLVED",
});
expect(classifyScriptLoadCause(url, SERVER, 404)).toEqual({
origin: "remote",
code: "http-404",
});
});
it.each(unparseable)("records the failed request %s and keeps going", (url) => {
const session = {
serverUrl: SERVER,
scriptLoadFailures: [],
pageErrors: [],
browserConsoleBuffer: [],
} as unknown as CaptureSession;
recordFailedRequest(session, {
resourceType: () => "script",
url: () => url,
method: () => "GET",
failure: () => ({ errorText: "net::ERR_NAME_NOT_RESOLVED" }),
});
expect(session.scriptLoadFailures).toEqual([url]);
expect(session.scriptLoadCauses).toEqual([
{ origin: "remote", code: "net::ERR_NAME_NOT_RESOLVED" },
]);
});
});
describe("the script-failure warning", () => {
it("names the closed origin and code of each failed script before the free text, so a cut message keeps them", () => {
vi.spyOn(console, "warn").mockImplementation(() => {});
+3 -2
View File
@@ -3000,9 +3000,10 @@ export function classifyScriptLoadCause(
failure: string | number,
): ScriptLoadCause {
let origin: ScriptLoadOrigin = "unknown";
const parsed = URL.canParse(url) ? new URL(url) : undefined;
if (url.startsWith(`${serverUrl}/`)) origin = "local";
else if (/^https?:\/\//.test(url)) {
origin = CDN_HOSTS.test(new URL(url).hostname) ? "cdn" : "remote";
origin = parsed && CDN_HOSTS.test(parsed.hostname) ? "cdn" : "remote";
}
const code =
typeof failure === "number"
@@ -3010,7 +3011,7 @@ export function classifyScriptLoadCause(
: /^net::ERR_[A-Z0-9_]{1,40}$/.test(failure)
? failure
: "unknown";
const lib = origin === "cdn" ? cdnLib(new URL(url)) : undefined;
const lib = origin === "cdn" && parsed ? cdnLib(parsed) : undefined;
return lib ? { origin, code, lib } : { origin, code };
}