Skip to content

feat: report navigated URL in action responses#1954

Open
masamaru0513 wants to merge 2 commits intoChromeDevTools:mainfrom
masamaru0513:feat/report-navigated-url
Open

feat: report navigated URL in action responses#1954
masamaru0513 wants to merge 2 commits intoChromeDevTools:mainfrom
masamaru0513:feat/report-navigated-url

Conversation

@masamaru0513
Copy link
Copy Markdown
Contributor

@masamaru0513 masamaru0513 commented Apr 24, 2026

Summary

Report the new page URL when an action triggers a navigation, so there is no need to re-query the pages list.

Fixes #243

Note: I am aware of the existing #1853 which addresses the same issue. This PR incorporates the review feedback from #1853 (by @Lightning00Blade) — specifically using navigatedToUrl naming, extracting a shared appendNavigatedToUrl helper in WaitForHelper, and applying it to evaluate_script as well.

Changes

  • McpPage.waitForEventsAfterAction now compares the page URL before and after the action, returning {navigatedToUrl} when a navigation occurred
  • Added appendNavigatedToUrl helper in WaitForHelper.ts for consistent URL reporting across tools
  • All input tools (click, click_at, hover, fill, fill_form, type_text, drag, press_key) use the helper to append Navigated to <URL> when a navigation is detected
  • evaluate_script also reports navigated URLs using the same helper
  • No change to navigate_page or new_page since they already report the URL explicitly

Output example

Before:

Successfully clicked on the element

After:

Successfully clicked on the element
Navigated to https://www.iana.org/help/example-domains

Testing

  • Unit tests added for:
    • Click triggering navigation → reports URL
    • Click without navigation → no "Navigated to" in response
  • Manual verification:
    • click on a link → reports navigated URL ✅
    • press_key Enter on a focused link → reports navigated URL ✅
    • evaluate_script with window.location.href change → reports navigated URL ✅
    • evaluate_script without navigation → no "Navigated to" ✅
    • Hash-only change (anchor link) → no "Navigated to" (same-document navigations are excluded by WaitForHelper) ✅
    • navigate_page back/forward → existing behavior preserved ✅

@masamaru0513 masamaru0513 force-pushed the feat/report-navigated-url branch 2 times, most recently from ccf84a8 to ca993a0 Compare April 24, 2026 13:06
Comment thread src/tools/pages.ts Outdated
Comment thread src/tools/pages.ts Outdated
Comment thread src/McpPage.ts Outdated
Comment thread tests/tools/input.test.ts Outdated
@wolfib wolfib requested a review from Lightning00Blade April 29, 2026 16:49
@wolfib
Copy link
Copy Markdown
Contributor

wolfib commented Apr 29, 2026

Thanks! This mostly looks good to me, added a few comments.
@Lightning00Blade PTAL since you reviewed the previous PR

Report the new page URL when an action (click, fill, press_key, etc.)
triggers a navigation. The URL is detected by comparing the page URL
before and after waitForEventsAfterAction.

Fixes ChromeDevTools#243
@masamaru0513 masamaru0513 force-pushed the feat/report-navigated-url branch from ca993a0 to b78a69b Compare April 30, 2026 11:53
@masamaru0513
Copy link
Copy Markdown
Contributor Author

masamaru0513 commented Apr 30, 2026

Thanks for the review @wolfib! Addressed the feedback:

  • Removed new_page URL reporting (page list already covers it)
  • Reverted navigate_page to use the requested URL (showing both requested + final in page list is more informative)
  • Shortened McpPage.ts to a ternary
  • Updated test to use server.getRoute with strictEqual

Please take another look when you get a chance.

@wolfib
Copy link
Copy Markdown
Contributor

wolfib commented Apr 30, 2026

Thanks! The update LGTM, but I defer to @Lightning00Blade

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.

Actions that result in a navigation should report the new page URL in the response

2 participants