Skip to content
Merged
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
16 changes: 14 additions & 2 deletions src/PageCollector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,16 @@ import {
export class UncaughtError {
readonly message: string;
readonly stackTrace?: Protocol.Runtime.StackTrace;
readonly targetId: string;

constructor(message: string, stackTrace?: Protocol.Runtime.StackTrace) {
constructor(
message: string,
stackTrace: Protocol.Runtime.StackTrace | undefined,
targetId: string,
) {
this.message = message;
this.stackTrace = stackTrace;
this.targetId = targetId;
}
}

Expand Down Expand Up @@ -257,11 +263,14 @@ class PageEventSubscriber {
#seenIssues = new Set<DevTools.AggregatedIssue>();
#page: Page;
#session: CDPSession;
#targetId: string;

constructor(page: Page) {
this.#page = page;
// @ts-expect-error use existing CDP client (internal Puppeteer API).
this.#session = this.#page._client() as CDPSession;
// @ts-expect-error use internal Puppeteer API to get target ID
this.#targetId = this.#session.target()._targetId;
}

#resetIssueAggregator() {
Expand Down Expand Up @@ -323,7 +332,10 @@ class PageEventSubscriber {
const messageWithRest = exception?.description?.split('\n at ', 2) ?? [];
const message = text + ' ' + (messageWithRest[0] ?? '');

this.#page.emit('uncaughtError', new UncaughtError(message, stackTrace));
this.#page.emit(
'uncaughtError',
new UncaughtError(message, stackTrace, this.#targetId),
);
};

// On navigation, we reset issue aggregation.
Expand Down
1 change: 1 addition & 0 deletions tests/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ export function getMockPage(): Page {
send: () => {
// no-op
},
target: () => ({_targetId: '<mock target ID>'}),
};
return {
mainFrame() {
Expand Down