Skip to content

feat: report newly opened pages in the action response - #2504

Open
ZayanKhan-12 wants to merge 1 commit into
ChromeDevTools:mainfrom
ZayanKhan-12:feat/367-click-new-tab
Open

feat: report newly opened pages in the action response#2504
ZayanKhan-12 wants to merge 1 commit into
ChromeDevTools:mainfrom
ZayanKhan-12:feat/367-click-new-tab

Conversation

@ZayanKhan-12

Copy link
Copy Markdown
Contributor

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

  • WaitForHelper now listens for the page's popup event while the action runs and reports newPagesOpened in WaitForEventsResult (alongside the existing navigatedToUrl). This automatically covers every input tool that uses waitForEventsAfterAction (click, click_at, fill, press_key, etc.).
  • McpResponse.attachWaitForResult() calls the existing setIncludePages(true) when a new page was opened, reusing the exact same page-list formatting as list_pages — no new format is introduced.
  • A note line and structuredContent.newPagesOpened are emitted next to the existing Page 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

Successfully clicked on the element

After

Successfully clicked on the element
The action opened a new page. See the list of pages below and call select_page to switch to a page.
## Pages
1: My test page (about:blank) [selected]
2: about:blank

(sample captured from the new test run)

Testing

  • npm run build — pass
  • npm run test:no-build — full suite pass (exit 0)
  • new test: input > click > reports newly opened pages proves a window.open click surfaces the note and the ## Pages list
  • npm run check-format — pass
  • node scripts/generate-docs.ts — no doc changes (no tool descriptions/schemas touched)

Fixes #367

🤖 Generated with Claude Code

@google-cla

google-cla Bot commented Aug 8, 2026

Copy link
Copy Markdown

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
@ZayanKhan-12
ZayanKhan-12 force-pushed the feat/367-click-new-tab branch from 692eab2 to e96fc9a Compare August 8, 2026 21:46
@OrKoN
OrKoN requested a review from Lightning00Blade August 10, 2026 08:37
Comment thread src/WaitForHelper.ts
/** Track all dialogs as they pause the renderer. */
#dialogDetected = false;
/** Whether the action opened one or more new pages. */
#newPagesOpened = false;

@Lightning00Blade Lightning00Blade Aug 10, 2026

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.

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

The idea makes sense, but the approach would be better if we only say what was opened.

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.

return all pages when click web element

3 participants