feat: report newly opened pages in the action response - #2504
feat: report newly opened pages in the action response#2504ZayanKhan-12 wants to merge 1 commit into
Conversation
|
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. |
When a click (or another input action) opens a new page, e.g. via a link with target=_blank or window.open(), the response now includes a note and the list of open pages so that clients can perceive the new page without calling list_pages. The page list is only included when a new page was actually opened during the action. Fixes ChromeDevTools#367
692eab2 to
e96fc9a
Compare
| /** Track all dialogs as they pause the renderer. */ | ||
| #dialogDetected = false; | ||
| /** Whether the action opened one or more new pages. */ | ||
| #newPagesOpened = false; |
There was a problem hiding this comment.
Looked though the code, we can be explicit and return the page that was open.
Puppeteer creates a single object so from then we can update the snapshot and return only what page data was opened rather then returning the full list and leaving AI to try to figure it out.
Lightning00Blade
left a comment
There was a problem hiding this comment.
The idea makes sense, but the approach would be better if we only say what was opened.
What
When a click opens a new page (link with
target=_blank,window.open()), the tool response now says so and includes the list of open pages. Previously the response only said "Successfully clicked on the element", so clients could not perceive that a new tab/window had opened and assumed the click had no effect.How
WaitForHelpernow listens for the page'spopupevent while the action runs and reportsnewPagesOpenedinWaitForEventsResult(alongside the existingnavigatedToUrl). This automatically covers every input tool that useswaitForEventsAfterAction(click,click_at,fill,press_key, etc.).McpResponse.attachWaitForResult()calls the existingsetIncludePages(true)when a new page was opened, reusing the exact same page-list formatting aslist_pages— no new format is introduced.structuredContent.newPagesOpenedare emitted next to the existingPage navigated to …handling.Token-conscious per the discussion in #367: the page list is only attached when a new page actually opened during the action; responses for ordinary clicks are unchanged, and no snapshot/tree is included.
Before
After
(sample captured from the new test run)
Testing
npm run build— passnpm run test:no-build— full suite pass (exit 0)input > click > reports newly opened pagesproves awindow.openclick surfaces the note and the## Pageslistnpm run check-format— passnode scripts/generate-docs.ts— no doc changes (no tool descriptions/schemas touched)Fixes #367
🤖 Generated with Claude Code