Skip to content

Commit 835c09a

Browse files
authored
docs: explain the light and browser third-party bundles in AGENTS.md (#3529)
Refs #3427 Lazy loading part 11 of 11, stacked on #3526. 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 Documents the bundle split from this series so that new code keeps tool, config and telemetry modules free of the browser bundle. - **AGENTS.md, new "Third-party bundles" section under "Instructions":** - `src/third_party/index.ts` is the light bundle loaded at startup (MCP SDK, zod, ajv). `src/third_party/browser.ts` is the heavy bundle (Puppeteer, `@puppeteer/browsers`, DevTools frontend) and should only load once a tool call needs it. The wording describes the goal; it does not claim the server already avoids loading `browser.js` at startup. - Types from `browser.js` can be imported anywhere with `import type`. - Tool definitions, config and telemetry modules must not import values from `browser.js`. They get them in the handler via `await loadBrowser()`, a dynamic `import()`, or page and context objects. Values used when the module loads, such as in a schema, must come from modules without browser code, like `utils/logpoint.ts` and `formatters/constants.ts`. - Classes checked with `instanceof` (for example `TimeoutError`) come only from `browser.js`. Small pure modules may be re-exported from `index.ts` by their direct file path. - `tests/browser-imports.test.ts` lists the modules that must not reach `browser.js`, and new tool, config and telemetry modules should be added to it. - **AGENTS.md pre-submit checklist ("Design"):** new item "Tool, config and telemetry modules do not import values from `src/third_party/browser.js`". - **Header comments** at the top of `src/third_party/index.ts` and `src/third_party/browser.ts` saying what belongs in each bundle. At this commit, no module under `src/config/`, `src/telemetry/` or `src/tools/` statically reaches `third_party/browser.js`. I checked this by walking the imports of the built JS, so the rules match the code. ## Test plan - `npm run format`. - `npm run test tests/browser-imports.test.ts tests/cli-imports.test.ts`. The code change is comments only.
1 parent ebb27f9 commit 835c09a

3 files changed

Lines changed: 27 additions & 0 deletions

File tree

β€ŽAGENTS.mdβ€Ž

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,24 @@ This repository contains an MCP server and CLI for Chrome DevTools.
1010
- Use `npm run format` to fix formatting and get linting errors.
1111
- Never modify `third_party/devtools-frontend` except for experimentation: it is a git submodule, a mirror of the actual codebase.
1212

13+
## Third-party bundles
14+
15+
- `src/third_party/index.ts` is the light bundle loaded at startup (MCP SDK,
16+
zod, ajv). `src/third_party/browser.ts` is the heavy bundle (Puppeteer,
17+
`@puppeteer/browsers`, DevTools frontend) and should only load once a tool
18+
call needs it.
19+
- Import types from `browser.js` with `import type` anywhere.
20+
- Tool definitions (`src/tools/`), config and telemetry modules must not import
21+
values from `browser.js`. Get them inside the handler with
22+
`await loadBrowser()` (cached), with a dynamic `import()` of the module that
23+
needs them, or through page and context objects. Values used when the module
24+
loads (for example in a schema) must come from modules without browser code.
25+
- Classes checked with `instanceof` (for example `TimeoutError`) come only from
26+
`browser.js`; never re-export them from `index.ts`. Small pure modules may be
27+
re-exported from `index.ts` by their direct file path.
28+
- `tests/browser-imports.test.ts` lists the modules that must not reach
29+
`browser.js`. Add new tool, config and telemetry modules to it.
30+
1331
## Rules for TypeScript
1432

1533
- Do not use `any` type.
@@ -91,6 +109,8 @@ Complete every item before you upload a PR or push a new revision.
91109
- [ ] If Puppeteer or devtools-frontend owns the bug, fix it there first. Do
92110
not copy or re-implement upstream code in this repository.
93111
- [ ] Puppeteer internals are imported only through `src/third_party/`.
112+
- [ ] Tool, config and telemetry modules do not import values from
113+
`src/third_party/browser.js`.
94114
- [ ] Repeated code is one helper. Extract a helper when the same block
95115
appears two or more times. Prefer an existing helper or a Puppeteer
96116
utility (for example `Deferred`) over a new one.

β€Žsrc/third_party/browser.tsβ€Ž

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7+
// The heavy bundle with Puppeteer, @puppeteer/browsers and the DevTools
8+
// frontend. Only code that runs once a tool call needs a browser or DevTools
9+
// should import values from it.
10+
711
// Runs the polyfills in index.js before Puppeteer and DevTools code.
812
import './index.js';
913

β€Žsrc/third_party/index.tsβ€Ž

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7+
// The light bundle that the server loads at startup: MCP SDK, zod, ajv and
8+
// small modules. Puppeteer and DevTools frontend code belong in browser.ts,
9+
// which loadBrowser() loads on first use.
710
import 'core-js/modules/es.promise.with-resolvers.js';
811
import 'core-js/modules/es.set.union.v2.js';
912
import 'core-js/proposals/iterator-helpers.js';

0 commit comments

Comments
Β (0)