Skip to content

feat: report new URL after actions that trigger navigation#1853

Open
rogeroliveira84 wants to merge 1 commit intoChromeDevTools:mainfrom
rogeroliveira84:feat/report-navigation-url
Open

feat: report new URL after actions that trigger navigation#1853
rogeroliveira84 wants to merge 1 commit intoChromeDevTools:mainfrom
rogeroliveira84:feat/report-navigation-url

Conversation

@rogeroliveira84
Copy link
Copy Markdown

Summary

  • Input tools (click, fill, press_key, hover, drag, type_text, fill_form, click_at) and evaluate_script now append a Page navigated to <url>. line to the response when the action triggers a cross-document navigation.
  • WaitForHelper.waitForEventsAfterAction returns {navigated: boolean} instead of void, surfacing the navigation signal that was already being detected internally.
  • No change to navigate_page or new_page since they already report the URL explicitly.

Fixes #243

Why

Today, if a click causes a page navigation, the response says "Successfully clicked on the element" with no indication that the page URL changed. The agent has to make an extra list_pages call to discover where it landed. This saves that round-trip for every navigation-triggering action.

Design

The existing waitForNavigationStarted in WaitForHelper already knows whether a cross-document navigation started. We propagate that signal as {navigated: boolean} through the return value of waitForEventsAfterActionMcpPageContextPage interface, and let each handler append the URL line when navigated is true.

Same-document (history API) navigations remain filtered out by the existing waitForNavigationStarted logic, matching current behavior. Click-opens-new-tab is a separate concern (#367).

Test plan

  • New test: click on a link that causes navigation → response includes Page navigated to <url>.
  • New test: click on a button that doesn't navigate → no navigation line in response
  • Full test suite (563 tests) passes
  • TypeScript typecheck clean
  • ESLint + Prettier clean

@google-cla
Copy link
Copy Markdown

google-cla bot commented Apr 12, 2026

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.

Click, fill, press_key, drag, hover, type_text, and evaluate_script
already wait for cross-document navigations triggered by the action,
but the resulting URL was never surfaced to the agent. Callers had to
follow up with list_pages to figure out where they landed.

Propagate a {navigated: boolean} result out of WaitForHelper up through
McpPage so each handler can append a "Page navigated to <url>." line
when the action actually caused a navigation. Same-document (history
API) navigations are still filtered out by waitForNavigationStarted,
matching existing behavior.

Fixes ChromeDevTools#243
@rogeroliveira84 rogeroliveira84 force-pushed the feat/report-navigation-url branch from 5a3832c to d281454 Compare April 12, 2026 04:13
Copy link
Copy Markdown
Collaborator

@Lightning00Blade Lightning00Blade left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR,
there are some comments that would need to be address before we can merge.

Comment thread src/WaitForHelper.ts
this.#abortController.abort();
}

return {navigated};
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.

I think we can simplify this can just provide the URL here if it was changed.

Suggested change
return {navigated};
return {
...(navigated ? {url: this.#page.url()} : {})
};

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.

Actually let's call it navigatedToUrl to be more explicit.

Comment thread src/WaitForHelper.ts
* Whether a cross-document navigation started and finished during the
* action. Same-document (history API) navigations are not reported.
*/
navigated: boolean;
Copy link
Copy Markdown
Collaborator

@Lightning00Blade Lightning00Blade Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the above change this will become

Suggested change
navigated: boolean;
navigatedToUrl?: string;

Comment thread src/WaitForHelper.ts
export interface WaitForEventsResult {
/**
* Whether a cross-document navigation started and finished during the
* action. Same-document (history API) navigations are not reported.
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.

This is wrong we use Puppeteer waitForNavigation and that does support same-document navigation
https://pptr.dev/api/puppeteer.page.waitfornavigation

Comment thread src/tools/input.ts
);
}

function appendNavigationIfAny(
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.

Let's rename it to appendWaitForResult to match the interface we provide.
We can also move this into the WaitForHelper file as we can use in other places as well.

Comment thread src/tools/script.ts
const result = await selectedPage.waitForEventsAfterAction(async () => {
await performEvaluation(worker, fnString, [], response);
});
if (result.navigated) {
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.

This should use the helper.

Comment thread src/tools/script.ts
const result = await mcpPage.waitForEventsAfterAction(async () => {
await performEvaluation(evaluatable, fnString, args, response);
});
if (result.navigated) {
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.

Same here.

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