Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/playwright-core/src/server/firefox/protocol.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ export namespace Protocol {
frameId: string;
message: string;
stack: string;
location: {
location?: {
columnNumber: number;
lineNumber: number;
url: string;
Expand Down Expand Up @@ -1205,4 +1205,4 @@ export namespace Protocol {
"Network.fulfillInterceptedRequest": Network.fulfillInterceptedRequestReturnValue;
"Network.getResponseBody": Network.getResponseBodyReturnValue;
}
}
}
5 changes: 4 additions & 1 deletion packages/playwright-core/src/server/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ export type PageError = {
location: types.ConsoleMessageLocation,
};

const emptyConsoleMessageLocation: types.ConsoleMessageLocation = { url: '', lineNumber: 0, columnNumber: 0 };

export class Page extends SdkObject<PageEventMap> {
static Events = PageEvent;

Expand Down Expand Up @@ -432,7 +434,8 @@ export class Page extends SdkObject<PageEventMap> {
return marked === -1 ? this._consoleMessages : this._consoleMessages.slice(marked + 1);
}

addPageError(error: Error, location: types.ConsoleMessageLocation) {
addPageError(error: Error, location: types.ConsoleMessageLocation | undefined) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as far as i can tell, every place that invokes this is guaranteed to have a valid location

looking at the source we have, every path to this can be traced back to Runtime.prototype._registerConsoleServiceListener

the issue mentions that this was observed via camoufox, so perhaps that patch has another callsite that needs to be fixed instead?

location ??= emptyConsoleMessageLocation;
const pageError: PageError = { error, location };
this._pageErrors.push(pageError);
ensureArrayLimit(this._pageErrors, 200); // Avoid unbounded memory growth.
Expand Down
13 changes: 13 additions & 0 deletions tests/library/browsercontext-events.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,19 @@ test('weberror event should include location', async ({ page, server }) => {
expect(location.column).toBeGreaterThan(0); // column is not consistent across browsers
});

test('weberror event should tolerate missing location', async ({ page, toImpl }) => {
const [webError, pageError] = await Promise.all([
page.context().waitForEvent('weberror'),
page.waitForEvent('pageerror'),
Promise.resolve().then(() => toImpl(page).addPageError(new Error('boom'), undefined)),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we normally want to test actual browser behaviors instead of something artificial like this

is there some HTML/JS that exhibits this behavior instead?

]);

expect(webError.page()).toBe(page);
expect(webError.error().message).toBe('boom');
expect(webError.location()).toEqual({ url: '', line: 0, column: 0 });
expect(pageError.message).toBe('boom');
});

test('pageload event should work @smoke', async ({ page, server }) => {
const [eventPage] = await Promise.all([
page.context().waitForEvent('pageload'),
Expand Down