Skip to content

feat(mcp): surface non-2xx navigation status#41589

Merged
Skn0tt merged 2 commits into
microsoft:mainfrom
Skn0tt:mcp-navigate-status
Jul 2, 2026
Merged

feat(mcp): surface non-2xx navigation status#41589
Skn0tt merged 2 commits into
microsoft:mainfrom
Skn0tt:mcp-navigate-status

Conversation

@Skn0tt

@Skn0tt Skn0tt commented Jul 2, 2026

Copy link
Copy Markdown
Member

browser_navigate reports URL, title and a console-error count, but not the HTTP status. So a page that comes back 4xx/5xx looks like a successful navigation - the only hint is the error count, which is noisy (a favicon 404 bumps it just the same) and means the agent has to go read browser_console_messages or enumerate browser_network_requests to find out what actually happened.

This adds a Page status line to the page header, but only when the main document is non-2xx:

- Page URL: http://localhost:8402/locked
- Page Title: Payment Required
- Page status: 402 Payment Required   👈
- Console: 2 errors, 0 warnings

A normal 200 shows nothing extra, so the common case stays quiet. It mirrors the existing Page status: crashed line, and the status is captured from the main-frame navigation response, so it also covers reload and back/forward and clears again once you land on a 2xx.

Nothing new is exposed here - the status was always reachable via the console text or the network list. It's a discoverability fix: promote "the document came back non-2xx" to a first-class fact on the result an agent already reads, instead of something it has to go digging for.

This came out of looking at how HTTP 402 paywalls surface to a browser agent. One related gap I hit but left out of here: browser_route can't scope a route to a single request (no times/once), which matters when you want to attach a one-shot header to exactly the next navigation. That's a separate, generic change - I'll do it in its own PR.

Add a `Page status` line to the browser_navigate page header, shown only
when the main document response is non-2xx. Mirrors the existing
`Page status: crashed` line and clears once a 2xx navigation lands.
@Skn0tt Skn0tt requested a review from dgozman July 2, 2026 09:26
@github-actions

This comment has been minimized.

Comment thread packages/playwright-core/src/tools/backend/response.ts Outdated
Rename the navigation status line to `HTTP status:` and only record the
final landing response, so an intermediate redirect (e.g. 302) never shows.
@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Test results for "MCP"

7474 passed, 1132 skipped


Merge workflow run.

@Skn0tt Skn0tt merged commit 45897ce into microsoft:main Jul 2, 2026
18 checks passed
@Skn0tt

Skn0tt commented Jul 2, 2026

Copy link
Copy Markdown
Member Author

Not following up with another PR, so noting it here: the payment side needs no new tooling, browser_run_code_unsafe covers it fine:

async (page) => {
  await page.route(lockedUrl, route =>
    route.continue({ headers: { ...route.request().headers(), 'X-PAYMENT': signature } }),
    { times: 1 });
  await page.goto(lockedUrl);
}

yury-s added a commit to microsoft/playwright-mcp that referenced this pull request Jul 9, 2026
## What's New

### New Tools

- **`browser_find`** — Search the accessibility snapshot of the current
page for text or a regular expression. Returns matching snapshot nodes
with a few lines of surrounding context (like search snippets), which is
cheaper than capturing the whole snapshot when you only need to locate
an element and its ref
([#41605](microsoft/playwright#41605),
[#41654](microsoft/playwright#41654))

### Tool Improvements

- **Less verbose snapshots** — Accessibility snapshots are distilled to
reduce noise and token usage
([#41604](microsoft/playwright#41604))
- **Mobile & device emulation** — New `--mobile` flag and `--device`
option to emulate mobile devices from the CLI
([#41657](microsoft/playwright#41657))
- **Navigation status** — `browser_navigate` now surfaces non-2xx
navigation status codes
([#41589](microsoft/playwright#41589))

## Bug Fixes

- Enable the chromium sandbox for the default browser
([#41652](microsoft/playwright#41652))
- Close the isolated HTTP client context on disconnect
([#41560](microsoft/playwright#41560))
- Wait for the client event stream before sending server→client requests
([#41559](microsoft/playwright#41559))
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.

2 participants