Skip to content

Commit ce35e95

Browse files
committed
refactor(engine): one page URL for navigation and error attribution
1 parent 12f6bdb commit ce35e95

2 files changed

Lines changed: 9 additions & 17 deletions

File tree

‎packages/engine/src/services/frameCapture.test.ts‎

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,14 @@ describe("classifyPageError", () => {
7272

7373
it("records a syntax error and a thrown string, which carry no error stack", () => {
7474
const syntax = thrown("SyntaxError: Unexpected token ';'", `${server}/comp.js`, []);
75-
const plain = thrown(
76-
undefined,
77-
`${server}/index.html`,
78-
[`${server}/index.html`],
79-
"plain string",
80-
);
75+
const plain = thrown(undefined, doc, [doc], "plain string");
8176
expect(classifyPageError(syntax, doc)).toBe("runtime-error:SyntaxError: Unexpected token ';'");
8277
expect(classifyPageError(plain, doc)).toBe("runtime-error:plain string");
8378
});
8479

8580
it("records a foreign library throwing when the composition called it", () => {
8681
const lib = "https://cdn.example/lib.js";
87-
expect(classifyPageError(thrown("TypeError: x", lib, [lib, `${server}/index.html`]), doc)).toBe(
82+
expect(classifyPageError(thrown("TypeError: x", lib, [lib, doc]), doc)).toBe(
8883
"runtime-error:TypeError: x",
8984
);
9085
});
@@ -100,9 +95,7 @@ describe("classifyPageError", () => {
10095
const abort =
10196
"AbortError: The play() request was interrupted by a call to pause(). https://goo.gl/LdLk22";
10297
expect(classifyPageError(thrown("Error: widget failed", widget, [widget]), doc)).toBeNull();
103-
expect(
104-
classifyPageError(thrown(abort, `${server}/index.html`, [`${server}/index.html`]), doc),
105-
).toBeNull();
98+
expect(classifyPageError(thrown(abort, doc, [doc]), doc)).toBeNull();
10699
});
107100

108101
// initializeSession registers its listeners before the incomplete fake session makes it throw.
@@ -123,9 +116,7 @@ describe("classifyPageError", () => {
123116
browserConsoleBuffer: [],
124117
};
125118
await initializeSession(session as unknown as CaptureSession).catch(() => {});
126-
const error = thrown("ReferenceError: gsap is not defined", `${server}/index.html`, [
127-
`${server}/index.html`,
128-
]);
119+
const error = thrown("ReferenceError: gsap is not defined", doc, [doc]);
129120
runtimeListeners.get("Runtime.exceptionThrown")?.({ exceptionDetails: error });
130121
runtimeListeners.get("Runtime.exceptionThrown")?.({ exceptionDetails: error });
131122
expect(session.pageErrors).toEqual(["runtime-error:ReferenceError: gsap is not defined"]);

‎packages/engine/src/services/frameCapture.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2235,7 +2235,7 @@ export function classifyPageError(
22352235
const origin = new URL(documentUrl).origin;
22362236
const frames = (details.stackTrace?.callFrames ?? []).map((frame) => frame.url);
22372237
// Frameless: a parse error names its script; a browser API rejection names only the document.
2238-
const urls = frames.length > 0 ? frames : details.url === documentUrl ? [] : [details.url];
2238+
const urls = frames.length > 0 ? frames : [details.url].filter((url) => url !== documentUrl);
22392239
return urls.some((url) => url?.startsWith(`${origin}/`)) ? `runtime-error:${firstLine}` : null;
22402240
}
22412241

@@ -2310,16 +2310,17 @@ export async function initializeSession(session: CaptureSession): Promise<void>
23102310
);
23112311
});
23122312

2313+
// Navigate to the file server
2314+
const url = `${serverUrl}/index.html`;
2315+
23132316
// Unlike the pageerror Error, this keeps the script URL of syntax errors and thrown non-errors.
23142317
const runtimeClient = await getCdpSession(page);
23152318
runtimeClient.on("Runtime.exceptionThrown", ({ exceptionDetails }) => {
2316-
const pageError = classifyPageError(exceptionDetails, `${serverUrl}/index.html`);
2319+
const pageError = classifyPageError(exceptionDetails, url);
23172320
if (pageError && !session.pageErrors.includes(pageError)) session.pageErrors.push(pageError);
23182321
});
23192322
await runtimeClient.send("Runtime.enable");
23202323

2321-
// Navigate to the file server
2322-
const url = `${serverUrl}/index.html`;
23232324
const pageNavigationTimeout =
23242325
session.config?.pageNavigationTimeout ?? DEFAULT_CONFIG.pageNavigationTimeout;
23252326
const initStart = Date.now();

0 commit comments

Comments
 (0)