fix(engine): ignore benign media request aborts (#2423)

This commit is contained in:
Miguel Ángel
2026-07-16 18:20:25 -04:00
committed by GitHub
parent f0aee28551
commit 08dbb7db37
2 changed files with 61 additions and 4 deletions
@@ -10,6 +10,7 @@ import {
isFontResourceError,
isDrawElementVerificationError,
sanitizeDiagnosticUrl,
shouldIgnoreRequestFailureDiagnostic,
} from "./frameCapture.js";
describe("isFontResourceError", () => {
@@ -224,6 +225,37 @@ describe("navigation diagnostics", () => {
}),
).toBe("[Browser:HTTP403] GET https://cdn.example.com/frame.png resource=image Forbidden");
});
it("ignores benign media aborts without hiding real request failures", () => {
expect(
shouldIgnoreRequestFailureDiagnostic({
resourceType: "media",
url: "http://127.0.0.1:4173/assets/video.mp4",
failureText: "net::ERR_ABORTED",
}),
).toBe(true);
expect(
shouldIgnoreRequestFailureDiagnostic({
resourceType: "other",
url: "http://127.0.0.1:4173/assets/audio.oga?cache=1",
failureText: "net::ERR_ABORTED",
}),
).toBe(true);
expect(
shouldIgnoreRequestFailureDiagnostic({
resourceType: "media",
url: "http://127.0.0.1:4173/assets/video.mp4",
failureText: "net::ERR_FAILED",
}),
).toBe(false);
expect(
shouldIgnoreRequestFailureDiagnostic({
resourceType: "script",
url: "http://127.0.0.1:4173/assets/app.js",
failureText: "net::ERR_ABORTED",
}),
).toBe(false);
});
});
describe("DrawElementVerificationError details", () => {
+29 -4
View File
@@ -497,6 +497,27 @@ export function formatRequestFailureDiagnostic(input: {
);
}
/**
* Chromium reports media loads that it intentionally cancels during probing as
* request failures. They are expected when the probe discovers or seeks local
* audio/video and do not indicate a missing asset.
*/
export function shouldIgnoreRequestFailureDiagnostic(input: {
resourceType: string;
url: string;
failureText: string;
}): boolean {
if (input.failureText !== "net::ERR_ABORTED") return false;
if (input.resourceType === "media") return true;
try {
return /\.(?:aac|flac|m4a|mp3|mp4|mov|oga|ogg|ogv|wav|webm)$/i.test(
new URL(input.url).pathname,
);
} catch {
return false;
}
}
export function formatHttpErrorDiagnostic(input: {
method: string;
resourceType: string;
@@ -1828,16 +1849,20 @@ export async function initializeSession(session: CaptureSession): Promise<void>
});
page.on("requestfailed", (request) => {
if (request.resourceType() === "script") {
const resourceType = request.resourceType();
const url = request.url();
const failureText = request.failure()?.errorText ?? "unknown";
if (resourceType === "script") {
recordScriptLoadFailure(session, request.url());
}
if (shouldIgnoreRequestFailureDiagnostic({ resourceType, url, failureText })) return;
appendBrowserDiagnostic(
session,
formatRequestFailureDiagnostic({
method: request.method(),
resourceType: request.resourceType(),
url: request.url(),
failureText: request.failure()?.errorText ?? "unknown",
resourceType,
url,
failureText,
}),
);
});