File tree Expand file tree Collapse file tree 2 files changed +24
-3
lines changed
Expand file tree Collapse file tree 2 files changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -62,7 +62,7 @@ export class PageCollector<T> {
6262 collector : ( item : T ) => void ,
6363 ) => ListenerMap < PageEvents > ;
6464 #listeners = new WeakMap < Page , ListenerMap > ( ) ;
65- # maxNavigationSaved = 3 ;
65+ protected maxNavigationSaved = 3 ;
6666
6767 /**
6868 * This maps a Page to a list of navigations with a sub-list
@@ -159,7 +159,7 @@ export class PageCollector<T> {
159159 }
160160 // Add the latest navigation first
161161 navigations . unshift ( [ ] ) ;
162- navigations . splice ( this . # maxNavigationSaved) ;
162+ navigations . splice ( this . maxNavigationSaved ) ;
163163 }
164164
165165 protected cleanupPageDestroyed ( page : Page ) {
@@ -183,7 +183,7 @@ export class PageCollector<T> {
183183 }
184184
185185 const data : T [ ] = [ ] ;
186- for ( let index = this . # maxNavigationSaved; index >= 0 ; index -- ) {
186+ for ( let index = this . maxNavigationSaved ; index >= 0 ; index -- ) {
187187 if ( navigations [ index ] ) {
188188 data . push ( ...navigations [ index ] ) ;
189189 }
@@ -409,5 +409,6 @@ export class NetworkCollector extends PageCollector<HTTPRequest> {
409409 } else {
410410 navigations . unshift ( [ ] ) ;
411411 }
412+ navigations . splice ( this . maxNavigationSaved ) ;
412413 }
413414}
Original file line number Diff line number Diff line change @@ -284,6 +284,26 @@ describe('NetworkCollector', () => {
284284 page . emit ( 'request' , request ) ;
285285 assert . equal ( collector . getData ( page , true ) . length , 3 ) ;
286286 } ) ;
287+
288+ it ( 'should not grow beyond maxNavigationSaved' , async ( ) => {
289+ const collector = new NetworkCollector ( browser ) ;
290+ await collector . init ( [ page ] ) ;
291+
292+ // Simulate 5 navigations (maxNavigationSaved is 3)
293+ for ( let i = 0 ; i < 5 ; i ++ ) {
294+ const req = getMockRequest ( {
295+ url : `http://example.com/nav${ i } ` ,
296+ isNavigationRequest : true ,
297+ frame : mainFrame ,
298+ } ) ;
299+ page . emit ( 'request' , req ) ;
300+ page . emit ( 'framenavigated' , mainFrame ) ;
301+ }
302+
303+ // We expect 4 arrays in navigations (current + 3 saved)
304+ // Each navigation has 1 request, so total should be 4
305+ assert . equal ( collector . getData ( page , true ) . length , 4 ) ;
306+ } ) ;
287307} ) ;
288308
289309describe ( 'ConsoleCollector' , ( ) => {
You can’t perform that action at this time.
0 commit comments