豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

Commit b5369a6

Browse files
authored
chore: include target ID in UncaughtError (#873)
1 parent 613ba24 commit b5369a6

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/PageCollector.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,16 @@ import {
2525
export class UncaughtError {
2626
readonly message: string;
2727
readonly stackTrace?: Protocol.Runtime.StackTrace;
28+
readonly targetId: string;
2829

29-
constructor(message: string, stackTrace?: Protocol.Runtime.StackTrace) {
30+
constructor(
31+
message: string,
32+
stackTrace: Protocol.Runtime.StackTrace | undefined,
33+
targetId: string,
34+
) {
3035
this.message = message;
3136
this.stackTrace = stackTrace;
37+
this.targetId = targetId;
3238
}
3339
}
3440

@@ -257,11 +263,14 @@ class PageEventSubscriber {
257263
#seenIssues = new Set<DevTools.AggregatedIssue>();
258264
#page: Page;
259265
#session: CDPSession;
266+
#targetId: string;
260267

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

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

326-
this.#page.emit('uncaughtError', new UncaughtError(message, stackTrace));
335+
this.#page.emit(
336+
'uncaughtError',
337+
new UncaughtError(message, stackTrace, this.#targetId),
338+
);
327339
};
328340

329341
// On navigation, we reset issue aggregation.

tests/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ export function getMockPage(): Page {
282282
send: () => {
283283
// no-op
284284
},
285+
target: () => ({_targetId: '<mock target ID>'}),
285286
};
286287
return {
287288
mainFrame() {

0 commit comments

Comments
 (0)