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

perf(memory): release old navigation request in NetworkCollector#1200

Merged
Lightning00Blade merged 3 commits intoChromeDevTools:mainfrom
flobo3:fix/memory-leak-page-collector
Mar 20, 2026
Merged

perf(memory): release old navigation request in NetworkCollector#1200
Lightning00Blade merged 3 commits intoChromeDevTools:mainfrom
flobo3:fix/memory-leak-page-collector

Conversation

@flobo3
Copy link
Copy Markdown
Contributor

@flobo3 flobo3 commented Mar 17, 2026

Issue #1192

Problem

In --autoConnect mode, chrome-devtools-mcp experiences a severe memory leak (~13 MB/min) when Chrome is actively used. This eventually leads to OOM crashes or kernel panics.

The root cause is in src/PageCollector.ts:

  1. NetworkCollector overrides splitAfterNavigation but forgets to call navigations.splice(this.#maxNavigationSaved), causing the array of navigations to grow infinitely.
  2. Even within a single navigation (e.g., in long-lived SPA applications), the navigations[0] array grows infinitely because there is no limit on the number of items collected per navigation. Since HTTPRequest objects are heavy, this quickly exhausts memory.

Solution

  1. Changed #maxNavigationSaved to protected maxNavigationSaved so subclasses can access it.
  2. Added navigations.splice(this.maxNavigationSaved) to NetworkCollector.splitAfterNavigation to ensure old navigations are properly discarded.
  3. Introduced protected maxItemsPerNavigation = 5000 to limit the number of items stored per navigation. When the limit is reached, the oldest item is removed (shift()), preventing unbounded memory growth in SPAs.

Tested locally by running npm run build and verifying the fix.

@google-cla
Copy link
Copy Markdown

google-cla bot commented Mar 17, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@flobo3 flobo3 force-pushed the fix/memory-leak-page-collector branch from e58c401 to 673f7bc Compare March 17, 2026 17:14
@flobo3 flobo3 force-pushed the fix/memory-leak-page-collector branch from 673f7bc to 31ae91b Compare March 18, 2026 17:08
@wolfib
Copy link
Copy Markdown
Contributor

wolfib commented Mar 19, 2026

Thank you!

Adding the missing splice(..) to the NetworkCollector LGTM. I'm not so sure about the maxItemsPerNavigation change, is it possible that this throws away data we actually want to keep? Here are my suggestions:

  • Create a separate PRe for the introduction of maxItemsPerNavigation.
  • In this PR, add a test to PageCollector.test.ts which verifies that NetworkCollector doesn't grow beyond maxNavigationSaved
  • Ensure that package-lock.json is not changed (npm ci instead of npm i might help).

@flobo3 flobo3 force-pushed the fix/memory-leak-page-collector branch from 31ae91b to f4813c5 Compare March 19, 2026 13:02
@flobo3
Copy link
Copy Markdown
Contributor Author

flobo3 commented Mar 19, 2026

Thanks for the review!

I have updated the PR according to your suggestions:

  1. Reverted the maxItemsPerNavigation change (I will create a separate PR for it).
  2. Added navigations.splice(3) to NetworkCollector (hardcoded to 3 to match the private #maxNavigationSaved in the base class).
  3. Added a test in PageCollector.test.ts to verify that NetworkCollector doesn't grow beyond maxNavigationSaved.
  4. Reverted package-lock.json changes.

Let me know if anything else is needed!

@flobo3 flobo3 force-pushed the fix/memory-leak-page-collector branch from f4813c5 to 709f530 Compare March 19, 2026 13:07
@Lightning00Blade Lightning00Blade requested a review from wolfib March 19, 2026 13:15
@Lightning00Blade Lightning00Blade changed the title fix(memory): prevent unbounded growth of navigations array in PageCollector perf(memory): release old navigation request in NetworkCollector Mar 19, 2026
@wolfib
Copy link
Copy Markdown
Contributor

wolfib commented Mar 19, 2026

Thanks! Just 1 more nit: could you please go back to maxNavigationSaved being protected instead of hardcoding it in the derived class?

@flobo3 flobo3 force-pushed the fix/memory-leak-page-collector branch from 709f530 to 778c04f Compare March 19, 2026 15:06
@flobo3
Copy link
Copy Markdown
Contributor Author

flobo3 commented Mar 19, 2026

Done! Changed #maxNavigationSaved to protected maxNavigationSaved and updated the derived class to use it instead of the hardcoded value.

@wolfib
Copy link
Copy Markdown
Contributor

wolfib commented Mar 19, 2026

Cool! Now only the test needs fixing.

@flobo3 flobo3 force-pushed the fix/memory-leak-page-collector branch from 778c04f to 5f4af57 Compare March 19, 2026 16:04
Comment thread src/PageCollector.ts Outdated
@flobo3 flobo3 force-pushed the fix/memory-leak-page-collector branch from e6f3325 to de37c18 Compare March 20, 2026 09:58
@flobo3
Copy link
Copy Markdown
Contributor Author

flobo3 commented Mar 20, 2026

Done! I've reverted the + 1 back to this.maxNavigationSaved in both places and updated the test to expect 3 navigations instead of 4. Thanks for the clarification!

Copy link
Copy Markdown
Collaborator

@Lightning00Blade Lightning00Blade left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@Lightning00Blade Lightning00Blade added this pull request to the merge queue Mar 20, 2026
Merged via the queue into ChromeDevTools:main with commit 1e6456c Mar 20, 2026
18 checks passed
github-merge-queue bot pushed a commit that referenced this pull request Mar 20, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.20.3](chrome-devtools-mcp-v0.20.2...chrome-devtools-mcp-v0.20.3)
(2026-03-20)


### 🛠️ Fixes

* mark categoryExtensions flag mutually exclusive with autoConnect
([#1202](#1202))
([8c2a7fc](8c2a7fc)),
closes
[#1072](#1072)


### ⚡ Performance

* **memory:** release old navigation request in NetworkCollector
([#1200](#1200))
([1e6456c](1e6456c))
* use CDP to find open DevTools pages (reland)
([#1210](#1210))
([53483bc](53483bc))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
OrKoN pushed a commit to mvanhorn/chrome-devtools-mcp that referenced this pull request Apr 1, 2026
…omeDevTools#1200)

Issue ChromeDevTools#1192

## Problem
In `--autoConnect` mode, `chrome-devtools-mcp` experiences a severe
memory leak (~13 MB/min) when Chrome is actively used. This eventually
leads to OOM crashes or kernel panics.

The root cause is in `src/PageCollector.ts`:
1. `NetworkCollector` overrides `splitAfterNavigation` but forgets to
call `navigations.splice(this.#maxNavigationSaved)`, causing the array
of navigations to grow infinitely.
2. Even within a single navigation (e.g., in long-lived SPA
applications), the `navigations[0]` array grows infinitely because there
is no limit on the number of items collected per navigation. Since
`HTTPRequest` objects are heavy, this quickly exhausts memory.

## Solution
1. Changed `#maxNavigationSaved` to `protected maxNavigationSaved` so
subclasses can access it.
2. Added `navigations.splice(this.maxNavigationSaved)` to
`NetworkCollector.splitAfterNavigation` to ensure old navigations are
properly discarded.
3. Introduced `protected maxItemsPerNavigation = 5000` to limit the
number of items stored per navigation. When the limit is reached, the
oldest item is removed (`shift()`), preventing unbounded memory growth
in SPAs.

Tested locally by running `npm run build` and verifying the fix.

---------

Co-authored-by: Wolfgang Beyer <woolfi.b@gmail.com>
OrKoN pushed a commit to mvanhorn/chrome-devtools-mcp that referenced this pull request Apr 1, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.20.3](ChromeDevTools/chrome-devtools-mcp@chrome-devtools-mcp-v0.20.2...chrome-devtools-mcp-v0.20.3)
(2026-03-20)


### 🛠️ Fixes

* mark categoryExtensions flag mutually exclusive with autoConnect
([ChromeDevTools#1202](ChromeDevTools#1202))
([8c2a7fc](ChromeDevTools@8c2a7fc)),
closes
[ChromeDevTools#1072](ChromeDevTools#1072)


### ⚡ Performance

* **memory:** release old navigation request in NetworkCollector
([ChromeDevTools#1200](ChromeDevTools#1200))
([1e6456c](ChromeDevTools@1e6456c))
* use CDP to find open DevTools pages (reland)
([ChromeDevTools#1210](ChromeDevTools#1210))
([53483bc](ChromeDevTools@53483bc))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants