Skip to content

Commit 709f530

Browse files
committed
fix(memory): prevent unbounded growth of navigations array in PageCollector
1 parent 8c2a7fc commit 709f530

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

src/PageCollector.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,5 +409,6 @@ export class NetworkCollector extends PageCollector<HTTPRequest> {
409409
} else {
410410
navigations.unshift([]);
411411
}
412+
navigations.splice(3); // Hardcoded to match #maxNavigationSaved since it's private in base class
412413
}
413414
}

tests/PageCollector.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff 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

289309
describe('ConsoleCollector', () => {

0 commit comments

Comments
 (0)