@@ -25,10 +25,16 @@ import {
2525export 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.
0 commit comments