Repository navigation
Conversation
Part of ChromeDevTools#2639. Picks up ChromeDevTools#2758. Moves the list_pages handler test and the new_page/navigate_page URL validation tests in tests/tools/pages.test.ts from a real browser to createHandlerMocks. Flag-dependent cases pass the option directly (createHandlerMocks({javascriptEvaluation: false}) and {fileNavigations: false}) instead of parsing CLI flags, and args is destructured from createHandlerMocks(). Rejected URLs now assert that no tab is opened (context.newPage) and no navigation happens (page.pptrPage.goto).
OrKoN
self-requested a review
October 16, 2026 08:07
OrKoN
requested changes
Oct 16, 2026
OrKoN
left a comment
Collaborator
There was a problem hiding this comment.
One more improvement:
tests/tools/pages.test.ts(all fivenavigate_pagecases): assertsinon.assert.notCalled(page.waitForEventsAfterAction)instead ofnotCalled(page.pptrPage.goto).gotoruns inside the callback passed topage.waitForEventsAfterAction(), which is a stub on the mockMcpPageand never invokes the callback, so the current assertion passes even when validation is removed;waitForEventsAfterActionis the first call the handler makes aftervalidateUrl().
Nits
tests/tools/pages.test.ts(navigate_pagecases): also addsinon.assert.notCalled(page.pptrPage.evaluateOnNewDocument)in one case withinitScriptset, or drop thegotoassertion entirely;evaluateOnNewDocumentis the onlypptrPagecall the handler makes directly before the action callback.
goto runs inside the waitForEventsAfterAction callback, which the mock page never invokes, so asserting goto was not called proved nothing. Assert that waitForEventsAfterAction is not called instead, and that the initScript is not registered for a rejected URL.
Contributor
Author
|
Thanks, good catch. Done in 5fd68f6: all five |
OrKoN
approved these changes
Oct 16, 2026
OrKoN
enabled auto-merge
October 16, 2026 08:47
zjdCander
pushed a commit
to zjdCander/chrome-devtools-mcp
that referenced
this pull request
Oct 19, 2026
## Summary Add a **Pre-submit checklist** section to `AGENTS.md`. Each item comes from a recent review finding or a landed bug fix in this repository. The checklist has five groups: - **Scope and PR description**: one change per PR, title and commit type match, description lists every behavior change and matches the diff, `npm run gen` and `npm run format` ran. - **Design**: fix in the lowest layer that owns the data, fix upstream (Puppeteer, devtools-frontend) first, one helper for repeated code, options objects instead of positional `undefined` arguments, validation in Zod schemas. - **Correctness and edge cases**: no stale state after a failed call, artifacts written before a throw, abandoned async continuations, mutex guards, file removal races, `dispose()` releases every resource, secrets never reach logs, path parameters validated even when they parse as URLs. - **Tests**: every new function has a test, no vacuous assertions, `notCalled` targets the first call after validation, exact-argument assertions, reusable stubs in `tests/mocks.ts`, bounded timeouts, no second CDP session for event waits. - **Documentation and output**: tool descriptions state when a parameter is ignored, skills stay generic, one-sentence inline comments. Sources: review comments on ChromeDevTools#2679, ChromeDevTools#2797, ChromeDevTools#2859, ChromeDevTools#2881, ChromeDevTools#2901, ChromeDevTools#3048, ChromeDevTools#3082, ChromeDevTools#3109, ChromeDevTools#3120, ChromeDevTools#3132, ChromeDevTools#3134, ChromeDevTools#3139, ChromeDevTools#3148, ChromeDevTools#3156, ChromeDevTools#3158, ChromeDevTools#3161, ChromeDevTools#3182, ChromeDevTools#3183, ChromeDevTools#3186, ChromeDevTools#3187, ChromeDevTools#3188, ChromeDevTools#3189, ChromeDevTools#3192, ChromeDevTools#3196, ChromeDevTools#3197, ChromeDevTools#3198, ChromeDevTools#3203, ChromeDevTools#3204, and fixes ChromeDevTools#3150, ChromeDevTools#3160, ChromeDevTools#3185, ChromeDevTools#3202, ChromeDevTools#3207, ChromeDevTools#3208. Existing content in `AGENTS.md` is unchanged. Closes ChromeDevTools#3222
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.
Part of #2639. Picks up #2758 (closed as stale) and applies the review feedback from it.
The
list_pageshandler test and the URL validation tests fornew_pageandnavigate_pageonly check that the handler validates its input and stops early, so they don't need a real browser. This migrates them in place tocreateHandlerMocks, followingAGENTS.md:list_pages› list pages: assertssetIncludePages(true),setListThirdPartyDeveloperTools()andsetListWebMcpTools().new_page› javascript/data/vbscript URLs,file:URLs, unparsable URL,chrome:/chrome-untrusted:URLs,chrome-extension:URLs: assert the exact error and thatcontext.newPageis never called, so no tab is opened for a rejected URL.navigate_page› the same five cases: assert the exact error and thatpage.pptrPage.gotois never called.As requested in #2758, the flag-dependent cases pass the option directly (
createHandlerMocks({javascriptEvaluation: false}),createHandlerMocks({fileNavigations: false})) instead of parsing CLI flags, and every migrated test destructuresargsfromcreateHandlerMocks()instead of callingcreateMockParsedArguments().The rest of the file still uses the real browser and is unchanged: closed-page recovery, extension pages and service workers, side panels, dialogs,
chrome://newtab/, background/focus, isolated contexts, history navigation,beforeunload,initScript, resize andget_tab_id.validateUrlitself stays covered bytests/utils/url.test.ts.Testing
npm run build && NODE_TEST_REPORTER=spec node scripts/test.js tests/tools/pages.test.ts: 63/63 pass (63 before as well).list pagesgoes from about 650 ms to about 35 ms; the URL validation tests from 35–100 ms to 20–40 ms.PUPPETEER_EXECUTABLE_PATHpointing at a nonexistent binary, so none of them starts Chrome.setListWebMcpTools()fromlist_pagesfailslist pages;validateUrlaftercontext.newPageinnew_pagefails all fivenew_pagecases onnotCalled(context.newPage);javascriptEvaluation/fileNavigationsasundefinedandcategoryExtensions: truetovalidateUrlfails the javascript, file and chrome-extension cases in both tools;validateUrlcall fromnavigate_pagefails all fivenavigate_pagecases.eslintandprettierare clean; onlytests/tools/pages.test.tschanges.