Repository navigation
Conversation
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).
Every module under src/tools/, plus flagUtils.ts, utils/text.ts and ConfigWatcher.ts, can now be imported without loading third_party/browser.js: - Re-export StringUtilities, Debouncer and PredefinedNetworkConditions from the light third_party/index.js. - Add loadBrowser() and use it for TimeoutError and the DevTools tracing categories inside tool handlers. - Load PerformanceTrace.js lazily in the performance tools. - Move the browser-free logpoint parsing to utils/logpoint.ts and MAX_NAME_LENGTH to formatters/constants.ts, since tool schemas use them. - Add a test that walks the static imports of these modules. The server still loads browser.js at startup (#3427).
yulunz
force-pushed
the
refactor/lazy-split-third-party-bundle
branch
from
November 17, 2026 21:41
ab0c0fe to
946dc96
Compare
Collaborator
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #3427
Part 2 of the lazy-loading series, stacked on #3510. The server still loads
browser.jsat startup until a follow-up PR.What
Every module under
src/tools/can now be imported without loadingthird_party/browser.js. So cantelemetry/flagUtils.ts,utils/text.tsandconfig/ConfigWatcher.ts. The server still loadsbrowser.jsat startup throughindex.ts,McpContext,McpResponseand others. A follow-up PR changesMcpServerto load it on the first tool call.Changes:
StringUtilitiesandDebouncer(flagUtils.ts,utils/text.ts,ConfigWatcher.ts):third_party/index.tsre-exports these two small devtools-frontend modules by file path (core/platform/StringUtilities.js,core/common/Debouncer.js), not throughmcp.js. No upstream code is copied into this repository.PredefinedNetworkConditions(tools/emulation.tsuses it in its schema): now re-exported fromthird_party/index.ts(puppeteer-core/internal/cdp/PredefinedNetworkConditions.js) instead ofbrowser.ts.McpPage.tsandWaitForHelper.tsimport it from there too.loadBrowser()inthird_party/index.ts: a cachedimport('./browser.js'), likeloadLighthouse()../browser.jsis marked external in the index bundle.tools/input.tsandtools/snapshot.tsgetTimeoutErrorfrom it inside the error path, so it is still the class Puppeteer throws.handleActionError()ininput.tsis now async and its three callers await it.tools/performance.tsreadsDevTools.Tracing*CategoriesandCrUXManagerthrough it inside the handler.tools/performance.ts:parseRawTraceBufferandtraceResultIsSuccessare loaded withawait import('../processors/PerformanceTrace.js')instopTracingAndAppendOutput().tools/lighthouse.tsreachedbrowser.jsonly throughperformance.ts.tools/logpoints.ts: its schema description usesLOGPOINT_FORMAT, so a lazy import is not enough. The browser-free parts ofLogpointManager.tsmove to a newsrc/utils/logpoint.ts:LOGPOINT_FORMAT,parseLogpoint(),LogpointErrorand theLogpointOptions/Logpoint/GeneratedLocationinterfaces.LogpointManager.ts,McpPage.ts,LogpointFormatter.ts,ToolDefinition.tsand the tests import them from there.tools/memory.ts: its schema description usesMAX_NAME_LENGTH. The constant moves fromHeapSnapshotFormatter.ts, which usesDevTools.I18nat load time, to a newsrc/formatters/constants.ts.tests/browser-imports.test.ts. It walks the static imports of the built JS from each of these entry points and fails with the import chain if one reachesthird_party/browser.js:tools/tools.js,telemetry/flagUtils.js,utils/text.js,config/ConfigWatcher.js. It also checks thatloadBrowser()returns thebrowser.jsmodule. The graph walk fromtests/cli-imports.test.tsmoves to a sharedtests/importGraph.tshelper with anincludeDynamicImportsoption. The new test passesfalse, the CLI test keepstrue.No behavior change. Tool names, schemas and descriptions are unchanged, and so is the error handling. The only difference is that a few values are read from a module that is already loaded, after an extra
await.Modules in both bundles
These modules are now in both
third_party/index.jsandthird_party/browser.js:puppeteer-core/…/util/disposable.jsdevtools-frontend/front_end/core/platform/StringUtilities.tsdevtools-frontend/front_end/core/common/Debouncer.tstestDebounceOverrideflag, and no code in this repository callsenableTestOverride().puppeteer-core/…/cdp/PredefinedNetworkConditions.jspage.emulateNetworkConditions(), and nothing compares it by identity.TimeoutError,DeferredandMutexremain only inbrowser.js.Bundle sizes
index.jsbrowser.jsTesting
npm run format,npm run build.tests/browser-imports.test.tspasses. On refactor(build): split Puppeteer and DevTools into a separate bundle #3510 the same check finds chains such astools/tools.js -> tools/emulation.js -> third_party/browser.js.npm run test: all tests pass.