Repository navigation
fix: close the failed tab and restore selection when new_page navigation fails - #3019
chiragjangiir wants to merge 5 commits 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. |
f22d4b1 to
ac06b08
Compare
…ion fails A failed new_page navigation left the newly created tab open and selected, accumulating stray tabs and silently misrouting page-scoped tools under --no-page-id-routing. Restore the pre-call state by re-selecting the previously selected page and closing the failed tab, then surface the original navigation error. Fixes ChromeDevTools#2925 🤖 Generated with Codebuff
ac06b08 to
c0e30f6
Compare
…s selection `new_page` creates and selects a tab before navigating, so a failed navigation left that tab open as the selected page while the error response listed no pages: the caller could not tell that either had happened, and with pageId routing off the next page-scoped call silently ran on the leftover tab. Close the tab this call created — by its own id, never by whatever happens to be selected now — and put the selection back where it was. `background: true` is no exception: `McpContext.newPage` selects every page it creates, so the same failure moved the selection there too. A tab that could not be closed is reported in the response with its id and the selection that was kept, so a failure never leaves state the caller cannot see. 🤖 Generated with Codebuff
One test for each way the tab can be lost — a blocklist refusal, an allowlist refusal, a refused connection, a navigation timeout, `background: true`, and a dialog that pauses the renderer — each asserting the pages and the selection are the ones from before the call. Nine of the ten fail against `main`. Plus the state that is not simply undone: a page that already held a dialog keeps it and stays selected, a tab that could not be closed is named in the response along with the selection that was restored, a URL rejected before a tab exists closes nothing and re-selects nothing, and a page-scoped call with pageId routing off still runs on the page selected before the failure. 🤖 Generated with Codebuff
The tool description and the skill now state that a failed load closes the tab it opened, keeps the previously selected page selected, and reports the tab by id instead when it could not be closed, so a caller knows the error left no new page to target. `src/config/cli-options.ts` and `docs/tool-reference.md` are generated from the description; both are the output of `npm run gen`. 🤖 Generated with Codebuff
|
I have reworked this so it covers every failure class in the issue's table, including two the first revision missed. What the first revision got wrong. It found the tab to close by asking for the currently selected page, and closed it only if that happened to be the tab this call created. Had anything else moved the selection in between, the tab would have been left open and the fix would have skipped itself silently. It also swallowed a cleanup failure in an empty What changed.
Coverage. Ten tests, one per criterion in the issue. Nine fail against One judgement call worth your review. When a load is blocked by a dialog ( Overlap with #2928. Both PRs need the created page's identity in the handler and both widen Docs. Verification. |
|
Thanks for the PR and the clear write-up! #2928 was opened earlier for #2925 and also preserves the new tab when |
fix: close the failed tab and restore selection when
new_pagenavigation failsFixes #2925
Problem
new_pagecreates its tab and selects it (inMcpContext.newPage) before navigation starts. When thegotothen fails — blocked by--blockedUrlPattern/--allowedUrlPattern, connection refused, or navigation timeout — the tool returnsisError: truewith only the navigation error, but:Agents accumulate stray error tabs with a moved
[selected]marker, and under--no-page-id-routingthe next page-scoped call (e.g.evaluate_script) silently runs on the leftover tab instead of the page the agent was working on.Fix
In the
new_pagehandler (src/tools/pages.ts), when navigation fails after the tab was created:isError: trueand the original message are kept.This implements the first outcome the issue accepts: no tab from the failed call remains open, and the previously selected page stays selected. The tab is identified by the id of the page
context.newPage()returned, so a selection that moved for any other reason cannot make the cleanup close the wrong page — or skip itself.background: trueneeds no separate handling:McpContext.newPageselects every page it creates andbackgroundonly keeps it from being brought to the front, so a failed background load moves the selection exactly like a foreground one.If the tab cannot be closed, the response says so instead of hiding it — it names the tab and the selection that was kept, and lists the pages, while the original navigation error is still what is thrown:
Dialog-blocked loads. A load whose page opens a dialog during parse can only fail (
gotocannot settle while the renderer is paused), so this closes that tab like any other failure. Closing a page with a dialog open is safe here — measured at 8 ms with no error — and it keeps the guarantee uniform: after any failednew_page, no tab from that call is open and the selection is unchanged. #2928 takes the other split and keeps the tab forhandle_dialog; if you prefer that, the change is small and I will make it, but as #2928 stands the kept tab is still not named in the error.To get the created page's id in the handler,
Context.newPagereturnsMcpPage, which is whatMcpContext.newPagealready returns.Testing
tests/tools/pages.test.tsgains a test per failure class and per state that is not simply undone. Nine of the ten fail againstmain:maincloses the tab when the navigation is blockedcloses the tab when the URL is not in the allowed listcloses the tab when the connection is refusedcloses the tab when the navigation times outcloses the tab when it was opened in the backgroundcloses the tab when a dialog blocks the loadkeeps another page and its dialog when the load failsreports a tab it could not close and keeps the navigation errorleaves page-scoped calls on the page selected before a failed new_pageleaves the pages and the selection alone when the URL is rejected before a tab existsThe connection-refused and timeout cases use a loopback port with no listener and a loopback server that never answers, so they need no network. The routing case drives
evaluate_scriptwithpageIdRouting: falseand asserts the script ran on the page selected before the failure.npm run test:no-build— 1342 tests, 1339 pass, 0 fail, 3 skipped (two Windows-only named-pipe tests, one fullscreen window-state test).npm run typecheck,npm run check-format— pass.npm run genleaves no diff, so the generated docs are current.Docs
new_page's description now states what a failure leaves behind, anddocs/tool-reference.mdandsrc/config/cli-options.tsare thenpm run genoutput for it.skills/chrome-devtools/SKILL.mdno longer reads as if everynew_pageyields a page id to target.Notes
new_pagerejected by URL validation (e.g.chrome://settings) is unchanged: it throws before any tab is created, so nothing is closed and nothing is re-selected.new_pageis unchanged,background: trueincluded.navigate_pagefailure semantics are untouched: it reports in-band on the selected page.