Skip to content

refactor(build): split Puppeteer and DevTools into a separate bundle - #3510

Merged
yulunz merged 1 commit into
mainfrom
refactor/lazy-split-third-party-bundle
Nov 18, 2026
Merged

yulunz merged 1 commit into
mainfrom
refactor/lazy-split-third-party-bundle

Conversation

@yulunz

@yulunz yulunz commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Refs #3427

Lazy loading part 1 of 11. The next parts (stacked on this PR) move one module at a time off third_party/browser.js.

Goal (point 5 of #3427): an idle MCP server should not load Puppeteer and the DevTools frontend.

What

src/third_party/index.ts was bundled into a single third_party/index.js (8.07 MiB in debug builds). Node evaluates an ES module file in full, so importing zod from that bundle also ran Puppeteer and the DevTools frontend. Nothing can be loaded lazily until that code is in a separate file.

This PR adds a second entry point, src/third_party/browser.ts, and a second bundle, third_party/browser.js:

Entry Contents
index.ts (light) core-js polyfills, MCP SDK, zod, ajv, cli.js re-exports, JSON schema and Lighthouse types, the toon/gcf/Lighthouse loaders (dynamic import() only), puppeteer's DisposableStack/AsyncDisposableStack/SuppressedError (used by utils/polyfill.ts at startup)
browser.ts (heavy) puppeteer-core (default export, API classes, Cdp* internals, Mutex, Deferred, export type *), @puppeteer/browsers, the DevTools namespace (mcp.js) and the DevToolsRoot experiment registration

browser.ts starts with import './index.js' (external), so the core-js polyfills always run before any Puppeteer or DevTools code and are not copied into the second bundle.

Other changes:

  • src/BUILD.gn: new third_party_browser_bundle target. The BiDi external and the @puppeteer/browsers-only externals (modern-tar, proxy-agent, yargs, yauzl) move from the index bundle to it. The new bundle is added to third_party_notices and to group("all").
  • About 70 files in src/ and tests/ now import Puppeteer and DevTools values and types from third_party/browser.js. Imports that contain only types became import type.
  • scripts/verify-npm-package.js checks that third_party/browser.js is in the package. Updated the message of the no-direct-third-party-imports ESLint rule, the AGENTS.md checklist item and the comment in tests/setupDevTools.ts.

No behavior change: both bundles still load at startup, through the same modules as before. Later PRs remove the startup imports of browser.js.

Bundle sizes

Build Before: index.js After: index.js After: browser.js After: total
debug (npm run build) 8,457,245 B (8.07 MiB) 1,281,621 B (1.22 MiB) 7,174,671 B (6.84 MiB) 8,456,292 B
release (npm run build:release) 4,615,362 B (4.40 MiB) 598,567 B (585 KiB) 4,011,121 B (3.83 MiB) 4,609,688 B

What's in each bundle now (debug, from the metafiles):

  • index.js: @modelcontextprotocol/server 582 KiB, ajv 208 KiB, zod 207 KiB, core-js 139 KiB, uri-js 48 KiB, @modelcontextprotocol/core 34 KiB, puppeteer-core disposable.js 8 KiB.
  • browser.js: devtools-frontend 5,869 KiB, puppeteer-core 833 KiB, ws 125 KiB, @puppeteer/browsers 111 KiB.

The new bundles contain exactly the same input files as the old index.js, plus browser.ts. I compared the input lists in the metafiles. THIRD_PARTY_NOTICES therefore lists the same packages.

Modules in both bundles

I compared third_party_index_bundle.meta.json with third_party_browser_bundle.meta.json. One module is in both:

Module Size (debug) Why it's safe
puppeteer-core/lib/puppeteer/util/disposable.js 8.5 KiB index.ts re-exports DisposableStack, AsyncDisposableStack and SuppressedError for utils/polyfill.ts, and Puppeteer imports the module internally. The module uses Symbol.dispose ??= … and exports globalThis.DisposableStack ?? Polyfill (the same pattern for the other two). polyfill.ts sets those globals from index.js before browser.js is evaluated, so both copies resolve to the same symbols and classes. Nothing uses instanceof with these classes.

Mutex, Deferred and TimeoutError are only in browser.js. utils/timeout.ts uses Deferred.create({timeout}), which rejects with Puppeteer's TimeoutError. A second copy of Deferred would throw a TimeoutError class that fails instanceof checks against the class from browser.js.

Testing

  • npm run format, npm run build, npm run build:release.
  • npm run verify-npm-package: third_party/browser.js is in the package.
  • npm run test: everything passed except one test. The failing test was LogpointManager > resolves original sources and re-binds after a rebuilt bundle, which threw No parsed script or original source file matches "app.ts" from LogpointManager.#findUISourceCode. It passed twice when re-run alone (npm run test tests/LogpointManager.test.ts), so it looks flaky (timing). The changes in this PR don't touch it.

@OrKoN OrKoN left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM @zyzyzyryxy FYI in case some changes to import would be needed

Move puppeteer-core, @puppeteer/browsers and the DevTools frontend code
from third_party/index.js into a new third_party/browser.js bundle.
index.js keeps the MCP SDK, zod, ajv and the lazy loaders. Both bundles
are still loaded at startup, so behavior does not change. This is a
prerequisite for loading browser.js on the first tool call (#3427).
@yulunz
yulunz force-pushed the refactor/lazy-split-third-party-bundle branch from 946dc96 to b21ab65 Compare November 18, 2026 18:00
@yulunz
yulunz added this pull request to the merge queue Nov 18, 2026
Merged via the queue into main with commit 1067857 Nov 18, 2026
17 checks passed
@yulunz
yulunz deleted the refactor/lazy-split-third-party-bundle branch November 18, 2026 18:17
mvanhorn added a commit to mvanhorn/chrome-devtools-mcp that referenced this pull request Nov 18, 2026
Resolve conflicts with the Puppeteer and DevTools bundle split (ChromeDevTools#3510):
export Coverage from third_party/browser.ts and import types there.
thebiz72 pushed a commit to thebiz72/chrome-devtools-mcp that referenced this pull request Nov 19, 2026
…omeDevTools#3518)

Refs ChromeDevTools#3427

Lazy loading part 2 of 11, stacked on ChromeDevTools#3510. The server still loads
`third_party/browser.js` at startup through `index.ts`, `McpContext` and
`McpResponse`, until a follow-up PR loads it on the first tool call.

## What moved

- `telemetry/flagUtils.ts` used `DevTools.Platform.StringUtilities`
(only `toSnakeCase`). `third_party/index.ts` now re-exports the small
`core/platform/StringUtilities.js` module of the DevTools frontend by
file path, not through `mcp.js`, and `flagUtils.ts` imports it from
there. No upstream code is copied into this repository.
- New `tests/browser-imports.test.ts`: `tests/browser-imports.test.ts`
walks the static imports of the built JS and fails if a listed module
reaches `third_party/browser.js`. The graph walk moves from
`tests/cli-imports.test.ts` to a shared `tests/importGraph.ts` helper.
It has a required `includeDynamicImports` option: the CLI test keeps
following dynamic imports (`true`), and the new test checks static
imports only (`false`).

The test starts with one entry, `telemetry/flagUtils.js`. Each following
PR in this series adds the module it migrates.

## Modules now in both bundles

| Module | Size (debug) | Why it's safe |
|---|---|---|
| `devtools-frontend/front_end/core/platform/StringUtilities.ts` | 19.2
KiB | Pure functions, no module state, and its only import is a type. |

## Test plan

- `npm run test tests/browser-imports.test.ts tests/cli-imports.test.ts
tests/telemetry/flagUtils.test.ts
tests/telemetry/ClearcutLogger.test.ts`.
- `npm run format` and `npm run build`.
- `tests/browser-imports.test.ts` fails without the source change and
passes with it.
mijanurecon452-tech pushed a commit to mijanurecon452-tech/chrome-devtools-mcp that referenced this pull request Nov 24, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.14.0](ChromeDevTools/chrome-devtools-mcp@chrome-devtools-mcp-v1.13.0...chrome-devtools-mcp-v1.14.0)
(2026-11-24)


### 🎉 Features

* add --backgroundNewPages to keep new_page tabs in the background
([ChromeDevTools#3539](ChromeDevTools#3539))
([7a39d6d](ChromeDevTools@7a39d6d))
* add abort and allow-origin network mocks
([ChromeDevTools#3421](ChromeDevTools#3421))
([eb4b53d](ChromeDevTools@eb4b53d))
* add inspect-in-devtools skill and claude plugin command
([ChromeDevTools#2696](ChromeDevTools#2696))
([aa977a6](ChromeDevTools@aa977a6))
* add network requests from service workers
([ChromeDevTools#3554](ChromeDevTools#3554))
([11162da](ChromeDevTools@11162da))
* add service workers to get_console_message
([ChromeDevTools#3537](ChromeDevTools#3537))
([2e247a4](ChromeDevTools@2e247a4))
* include computed styles in get_css_styles
([ChromeDevTools#3538](ChromeDevTools#3538))
([cf98d8b](ChromeDevTools@cf98d8b))
* list errors a page raises while a tool runs
([ChromeDevTools#3431](ChromeDevTools#3431))
([d5d30bd](ChromeDevTools@d5d30bd))
* resolve CSS custom variable values inline in `get_css_styles`
([ChromeDevTools#3481](ChromeDevTools#3481))
([8ba2ac9](ChromeDevTools@8ba2ac9))
* support transparent screenshots
([ChromeDevTools#3457](ChromeDevTools#3457))
([045fb8c](ChromeDevTools@045fb8c))
* **telemetry:** send startup events directly from the server process
([ChromeDevTools#3511](ChromeDevTools#3511))
([b14eb81](ChromeDevTools@b14eb81))


### 🛠️ Fixes

* accept POSIX root URIs from WSL2 clients on a Windows server
([ChromeDevTools#3380](ChromeDevTools#3380))
([4b9acc9](ChromeDevTools@4b9acc9))
* align root plugin.json name with marketplace entry
([ChromeDevTools#3474](ChromeDevTools#3474))
([1424980](ChromeDevTools@1424980))
* **cli:** enable off by default categories in CLI except PWA
([ChromeDevTools#3595](ChromeDevTools#3595))
([0ff265d](ChromeDevTools@0ff265d))
* **cli:** handle array of strings correctly
([ChromeDevTools#3593](ChromeDevTools#3593))
([d197b28](ChromeDevTools@d197b28))
* **cli:** match yargs-parser when detecting negative numbers
([ChromeDevTools#3548](ChromeDevTools#3548))
([eb9b030](ChromeDevTools@eb9b030))
* **cli:** pass option values starting with `-` through to tools
([ChromeDevTools#3501](ChromeDevTools#3501))
([ec0abfc](ChromeDevTools@ec0abfc))
* **cli:** preserve daemon PID when SIGKILL fails
([ChromeDevTools#3485](ChromeDevTools#3485))
([0788697](ChromeDevTools@0788697))
* **cli:** reuse live daemons after EPERM
([ChromeDevTools#3452](ChromeDevTools#3452))
([1417f93](ChromeDevTools@1417f93))
* **cli:** strip terminal escape sequences from tool output and errors
([ChromeDevTools#3536](ChromeDevTools#3536))
([ec2fb15](ChromeDevTools@ec2fb15))
* **config:** reject --browserUrl values without an http(s) scheme
([ChromeDevTools#3437](ChromeDevTools#3437))
([e40cef6](ChromeDevTools@e40cef6))
* **config:** reject --viewport values with more than two parts
([ChromeDevTools#3577](ChromeDevTools#3577))
([ab911a6](ChromeDevTools@ab911a6))
* **console:** keep stack traces of messages from earlier navigations
([ChromeDevTools#3397](ChromeDevTools#3397))
([e8798d6](ChromeDevTools@e8798d6))
* **console:** resolve Error arguments on the session of their handle
([ChromeDevTools#3408](ChromeDevTools#3408))
([4c6c767](ChromeDevTools@4c6c767))
* dedicated worker can now build a stack trace
([ChromeDevTools#3572](ChromeDevTools#3572))
([9762165](ChromeDevTools@9762165)),
closes
[ChromeDevTools#2962](ChromeDevTools#2962)
* do not queue unknown page ids
([ChromeDevTools#3599](ChromeDevTools#3599))
([4dc8cbc](ChromeDevTools@4dc8cbc))
* **emulation:** reject non-string extraHttpHeaders values
([ChromeDevTools#3484](ChromeDevTools#3484))
([64d4726](ChromeDevTools@64d4726))
* explain DevToolsActivePort permission errors during autoConnect
([ChromeDevTools#3487](ChromeDevTools#3487))
([0e49c59](ChromeDevTools@0e49c59))
* **extensions:** preserve list_extensions fields in JSON output
([ChromeDevTools#3592](ChromeDevTools#3592))
([02b146b](ChromeDevTools@02b146b))
* **input:** allow multi-file upload_file through chooser-opening
elements
([ChromeDevTools#3436](ChromeDevTools#3436))
([ef680a3](ChromeDevTools@ef680a3))
* **input:** return when click_at, type_text, drag or press_key opens a
dialog
([ChromeDevTools#3576](ChromeDevTools#3576))
([7bcb86d](ChromeDevTools@7bcb86d))
* keep temp files under the temp dir
([ChromeDevTools#3372](ChromeDevTools#3372))
([d666acf](ChromeDevTools@d666acf))
* remove commands from claude plugin
([ChromeDevTools#3469](ChromeDevTools#3469))
([e2f08b4](ChromeDevTools@e2f08b4))
* respect tool timeouts in CLI daemon responses
([ChromeDevTools#3443](ChromeDevTools#3443))
([86a1c23](ChromeDevTools@86a1c23))
* **snapshot:** keep extra element UIDs reusable
([ChromeDevTools#3493](ChromeDevTools#3493))
([4559cd5](ChromeDevTools@4559cd5))
* treat local host name and interface addresses as local browser
endpoints
([ChromeDevTools#3463](ChromeDevTools#3463))
([cf587b4](ChromeDevTools@cf587b4))
* use exception events instead of Runtime.exceptionThrown
([ChromeDevTools#3553](ChromeDevTools#3553))
([437f394](ChromeDevTools@437f394))
* validate heap snapshot className regex
([ChromeDevTools#3030](ChromeDevTools#3030))
([343e6b1](ChromeDevTools@343e6b1))
* validate install_pwa and launch_pwa URLs against navigation policy
([ChromeDevTools#3464](ChromeDevTools#3464))
([057a6aa](ChromeDevTools@057a6aa))
* wait for parsed scripts before reporting an unknown logpoint URL
([ChromeDevTools#3461](ChromeDevTools#3461))
([404f331](ChromeDevTools@404f331))


### 📄 Documentation

* clarify that Chrome may clamp resize_page dimensions
([ChromeDevTools#3583](ChromeDevTools#3583))
([b5a41e0](ChromeDevTools@b5a41e0)),
closes
[ChromeDevTools#2998](ChromeDevTools#2998)
* explain the light and browser third-party bundles in AGENTS.md
([ChromeDevTools#3529](ChromeDevTools#3529))
([835c09a](ChromeDevTools@835c09a))
* fix typos in comments, tests and skill docs
([ChromeDevTools#3489](ChromeDevTools#3489))
([f312b72](ChromeDevTools@f312b72))


### ⚡ Performance

* **telemetry:** start the watchdog process on the first event that
needs it
([ChromeDevTools#3513](ChromeDevTools#3513))
([a4c550d](ChromeDevTools@a4c550d))


### 🏗️ Refactor

* **build:** split Puppeteer and DevTools into a separate bundle
([ChromeDevTools#3510](ChromeDevTools#3510))
([1067857](ChromeDevTools@1067857))
* **config:** import ConfigWatcher without the browser bundle
([ChromeDevTools#3520](ChromeDevTools#3520))
([24dba69](ChromeDevTools@24dba69))
* create BrowserManager without the browser bundle
([ChromeDevTools#3563](ChromeDevTools#3563))
([e8763f9](ChromeDevTools@e8763f9))
* **formatters:** rename MAX_NAME_LENGTH to
HEAP_SNAPSHOT_MAX_NAME_LENGTH
([ChromeDevTools#3591](ChromeDevTools#3591))
([92250bc](ChromeDevTools@92250bc))
* load DevTools in HeapSnapshotManager on first use
([ChromeDevTools#3564](ChromeDevTools#3564))
([d8035c6](ChromeDevTools@d8035c6))
* load McpResponse when ToolHandler builds a response
([ChromeDevTools#3565](ChromeDevTools#3565))
([e4669b3](ChromeDevTools@e4669b3))
* **telemetry:** extract sending to Clearcut into sendToClearcut()
([ChromeDevTools#3509](ChromeDevTools#3509))
([7354c59](ChromeDevTools@7354c59))
* **telemetry:** generate the session id in ClearcutLogger
([ChromeDevTools#3516](ChromeDevTools#3516))
([ea19ce7](ChromeDevTools@ea19ce7))
* **telemetry:** import flagUtils without the browser bundle
([ChromeDevTools#3518](ChromeDevTools#3518))
([ab046de](ChromeDevTools@ab046de))
* **third_party:** re-export Mutex from the light bundle
([ChromeDevTools#3566](ChromeDevTools#3566))
([48466c4](ChromeDevTools@48466c4))
* **tools:** import emulation without the browser bundle
([ChromeDevTools#3521](ChromeDevTools#3521))
([c5d5d7f](ChromeDevTools@c5d5d7f))
* **tools:** import input without the browser bundle
([ChromeDevTools#3522](ChromeDevTools#3522))
([bdecb63](ChromeDevTools@bdecb63))
* **tools:** import logpoints without the browser bundle
([ChromeDevTools#3525](ChromeDevTools#3525))
([71098b0](ChromeDevTools@71098b0))
* **tools:** import memory without the browser bundle
([ChromeDevTools#3526](ChromeDevTools#3526))
([ebb27f9](ChromeDevTools@ebb27f9))
* **tools:** import performance without the browser bundle
([ChromeDevTools#3524](ChromeDevTools#3524))
([ba76587](ChromeDevTools@ba76587))
* **tools:** import snapshot without the browser bundle
([ChromeDevTools#3523](ChromeDevTools#3523))
([110d7f3](ChromeDevTools@110d7f3))
* **utils:** import text utilities without the browser bundle
([ChromeDevTools#3519](ChromeDevTools#3519))
([8029df8](ChromeDevTools@8029df8))

---
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.

2 participants