44 * SPDX-License-Identifier: Apache-2.0
55 */
66
7- import type * as CdpProtocol from '../node_modules/chrome-devtools-frontend/front_end/generated/protocol-proxy-api.js' ;
87import { IssuesManager , Issue } from '../node_modules/chrome-devtools-frontend/mcp/mcp.js' ;
98
109import {
@@ -45,6 +44,7 @@ export class PageCollector<T> {
4544 collector : ( item : T ) => void ,
4645 ) => ListenerMap < PageEvents > ;
4746 #listeners = new WeakMap < Page , ListenerMap > ( ) ;
47+ #seenIssueKeys = new WeakMap < Page , Set < string > > ( ) ;
4848 #maxNavigationSaved = 3 ;
4949
5050 /**
@@ -121,14 +121,22 @@ export class PageCollector<T> {
121121 }
122122
123123 protected async subscribeForIssues ( page : Page ) {
124+ if ( this instanceof NetworkCollector ) return ;
125+ if ( ! this . #seenIssueKeys. has ( page ) ) {
126+ this . #seenIssueKeys. set ( page , new Set ( ) ) ;
127+ }
124128 const session = await page . createCDPSession ( ) ;
125- session . on ( 'Audits.issueAdded' , ( data ) => { // TODO unsubscribe
129+ session . on ( 'Audits.issueAdded' , data => { // TODO unsubscribe
126130 // @ts -expect-error Types of protocol from Puppeteer and CDP are incopatible for Issues
127- const issue = IssuesManager . createIssuesFromProtocolIssue ( null , data . issue ) [ 0 ] ; // returns issue wrapped in array, need to get first element
128- if ( ! issue ) {
129- return ;
130- }
131- page . emit ( 'issue' , issue ) ;
131+ const issue = IssuesManager . createIssuesFromProtocolIssue ( null , data . issue ) [ 0 ] ; // returns issue wrapped in array, need to get first element
132+ if ( ! issue ) {
133+ return ;
134+ }
135+ const seenKeys = this . #seenIssueKeys. get ( page ) ! ;
136+ const primaryKey = issue . primaryKey ( ) ;
137+ if ( seenKeys . has ( primaryKey ) ) return ;
138+ seenKeys . add ( primaryKey ) ;
139+ page . emit ( 'issue' , issue ) ;
132140 } ) ;
133141 await session . send ( 'Audits.enable' ) ;
134142 }
@@ -151,6 +159,7 @@ export class PageCollector<T> {
151159 }
152160 }
153161 this . storage . delete ( page ) ;
162+ this . #seenIssueKeys. delete ( page ) ;
154163 }
155164
156165 getData ( page : Page , includePreservedData ?: boolean ) : T [ ] {
0 commit comments