Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ export class BrowserContextDispatcher extends Dispatcher<BrowserContext, channel
error: serializeError(pageError.error),
page: PageDispatcher.from(this, page),
location: {
url: pageError.location.url,
line: pageError.location.lineNumber,
column: pageError.location.columnNumber,
url: pageError.location?.url ?? '',
line: pageError.location?.lineNumber ?? 0,
column: pageError.location?.columnNumber ?? 0,
},
});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/playwright-core/src/server/firefox/protocol.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ export namespace Protocol {
frameId: string;
message: string;
stack: string;
location: {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this file is generated, it means that the bug is on the firefox end where it doesn't send the location and we should fix it there

location?: {
columnNumber: number;
lineNumber: number;
url: string;
Expand Down
4 changes: 2 additions & 2 deletions packages/playwright-core/src/server/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ const navigationMarkSymbol = Symbol('navigationMark');

export type PageError = {
error: Error,
location: types.ConsoleMessageLocation,
location: types.ConsoleMessageLocation | undefined,
};

export class Page extends SdkObject<PageEventMap> {
Expand Down Expand Up @@ -432,7 +432,7 @@ 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) {
const pageError: PageError = { error, location };
this._pageErrors.push(pageError);
ensureArrayLimit(this._pageErrors, 200); // Avoid unbounded memory growth.
Expand Down
6 changes: 3 additions & 3 deletions packages/playwright-core/src/server/trace/recorder/tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -643,9 +643,9 @@ export class Tracing extends SdkObject implements InstrumentationListener, Snaps
params: {
error: serializeError(pageError.error),
location: {
url: pageError.location.url,
line: pageError.location.lineNumber,
column: pageError.location.columnNumber,
url: pageError.location?.url ?? '',
line: pageError.location?.lineNumber ?? 0,
column: pageError.location?.columnNumber ?? 0,
},
},
pageId: page.guid,
Expand Down
25 changes: 25 additions & 0 deletions tests/library/browsercontext-events.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,28 @@ test('download event should work @smoke', async ({ page, server }) => {
expect(download.suggestedFilename()).toBe('file.txt');
expect(download.page()).toBe(page);
});

test('weberror event should not crash when Firefox omits location in uncaughtError', {
annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/41169' },
}, async ({ page, toImpl, browserName }) => {
// Firefox can omit the location field in Page.uncaughtError protocol events
// when an uncaught error fires during mid-navigation. Inject a synthetic event
// without location to verify the driver does not crash.
test.skip(browserName !== 'firefox', 'Firefox-only: tests FF protocol behaviour');
const webErrors: Error[] = [];
page.context().on('weberror', e => webErrors.push(e.error()));
const pageErrors: Error[] = [];
page.on('pageerror', e => pageErrors.push(e));

(toImpl(page) as any).delegate._session.emit('Page.uncaughtError', {
frameId: '',
message: 'Error: no-location-error',
stack: '',
// location intentionally absent — simulates the protocol omitting it
});

await page.waitForTimeout(500);
expect(pageErrors).toHaveLength(1);
expect(pageErrors[0].message).toBe('no-location-error');
expect(webErrors).toHaveLength(1);
});