Skip to content

Keep the status of a request the browser answered and then cancelled - #662

Open
vishnuv688 wants to merge 2 commits into
mainfrom
fix/bidi-started-response-status
Open

vishnuv688 wants to merge 2 commits into
mainfrom
fix/bidi-started-response-status

Conversation

@vishnuv688

@vishnuv688 vishnuv688 commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

What & why

Fixes #658.

Chrome stops loading a script once its response comes back as a 404. Over BiDi it then sends network.fetchError with net::ERR_ABORTED and never sends network.responseCompleted. Every adapter closed that row from the fetch error alone, so a missing script showed as status 0 with no response headers, exactly like a request blocked before it was sent. Someone reading the Network tab or a trace could not tell that the server had answered 404.

Each adapter now subscribes to network.responseStarted and keeps the status, status text and headers of each hop, keyed by the hop's row id. When a fetch error closes a hop that already had an answer, the row keeps that status and those headers, with the browser's error text in error. The missing script now reads as 404 Not Found, error net::ERR_ABORTED. A request that fails before any answer still closes as status 0 with the error text.

Chrome 158 delivered responseStarted before beforeRequestSent for these requests, so the answer is kept whether or not the request's row exists yet. Each session keeps at most 256 answers, and an entry is removed once its hop fails.

Type of change

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Polish (an improvement to an existing feature)
  • Breaking change (existing behavior changes for users)
  • Documentation
  • Internal (build, CI, dependencies, tooling)

Packages touched

  • shared (types and contracts)
  • core (framework-agnostic capture/reporting)
  • elements (published element/snapshot API — @wdio/elements)
  • service (WebdriverIO adapter)
  • nightwatch-devtools (Nightwatch adapter)
  • selenium-devtools (Selenium adapter)
  • selenium-devtools-py (Selenium Python adapter)
  • backend (server)
  • app (UI)
  • script (page-injected runtime)
  • trace (Trace mode)
  • otel (@wdio/opentelemetry, the wdio-otel CLI)
  • conformance (cross-adapter conformance suite)

shared only gains mirror vectors, and selenium-devtools only gains their runner. Nightwatch takes the fix through core.

Capability matrix

  • packages/conformance/src/features.ts updated, and tables regenerated with pnpm docs:capabilities, if this adds or changes user-facing behaviour

Not needed: this corrects the status a row already shows. No capability is added or changed.

Notes for reviewers

Why not only in core. The logic lives in core (handleBidiResponseStarted, failedRowFields). The WebdriverIO service still has its own BiDi network handlers until #653 moves it onto core's, so it registers a network.responseStarted listener and calls the core helpers. The Python adapter cannot import core, so it mirrors the logic. A new failedAfterResponse section in mirror-vectors.json (5 cases) holds the TypeScript and Python versions equal.

Reading responseStarted off the socket. selenium-webdriver's network inspector passes every network frame to every callback without its method. A responseStarted frame therefore looks exactly like a responseCompleted, so core subscribes and reads it off the raw socket by method, as it already does for fetchError. One side effect: the inspector's completed handler now also receives responseStarted, so a row can close when its headers arrive and is then replaced by the real completion. A request still downloading its body can show as finished slightly early in the live Network tab. The network-capture rule records this.

Known residual (Python). Selenium's Python event manager runs each BiDi callback on its own thread. If the fetch error is handled before its responseStarted, the row still closes as status 0. The rule records this too.

File size. core/bidi.ts would have grown to 588 lines. The header and timing helpers and the new started-response logic moved into their own files, so it is now 507 (511 on main). Public exports are unchanged.

Tests. The new core, service and Python tests use the event order Chrome 158 sent: responseStarted, then beforeRequestSent, then fetchError. They fail without the fix. Full JS suite and typecheck pass. The Python suite passes apart from two driver-retention instrumentation tests that fail on main in the same environment.

Subscribing responseStarted in the WDIO service. WebdriverIO's own network manager subscribes beforeRequestSent, responseCompleted and fetchError, but not responseStarted (only browser.mock() does). A listener alone never fires, so the service subscribes that one event itself at session start. If the browser refuses, the service logs a warning and keeps every listener; the row then closes as status 0, as before.

Known gap (WDIO, reloadSession). The subscription is made once at session start. A session that a test replaces with reloadSession probably lacks it, so a 404 script after a reload may still read as status 0. Not checked in a browser.

Verified in a real browser. A WebdriverIO spec against a page whose script returns 404 (Chrome 158, headless). Before the fix, the trace's row for the script read status 0, net::ERR_ABORTED, with no headers. It now reads 404 Not Found with the server's response headers. The trace writer does not store a row's error, so the zip no longer shows net::ERR_ABORTED for this row; the live dashboard still has it. Selenium and Nightwatch take the fix through core, which subscribes the event itself. They were not run in a browser for this PR.

Screenshots / recordings

None: this changes no UI.

🤖 Generated with Claude Code

Chrome stops loading a script whose response is a 404 and sends
network.fetchError (net::ERR_ABORTED) instead of responseCompleted, so
the row closed as status 0 with no headers and a missing script was
indistinguishable from a blocked request. Every adapter now keeps the
hop's network.responseStarted answer and closes a failed hop with that
status and its headers, beside the browser's error. Chrome can send
responseStarted before beforeRequestSent, so the answer is kept by row
id whether or not the row exists yet.

Fixes #658
@vishnuv688 vishnuv688 self-assigned this Dec 4, 2026
@vercel

vercel Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
devtools Ready Ready Preview Dec 4, 2026 5:47am UTC

Request Review

@greptile-apps

greptile-apps Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 4/5RetriggerView in Greptile

[Medium impact] The change reaches network capture across the core, WebdriverIO, and Selenium adapters.

The PR still needs the earlier trace-export and telemetry fix before merging.

Findings

  1. P1 Saved traces lose cancellations ▶
  2. P2 Python replaces empty response text ▶

Summary

The PR keeps the browser's response status and headers when a later cancellation ends a request.

  • Failed network rows keep the response the browser already sent.

Reviews (2) · Last reviewed commit: "Subscribe network.responseStarted in the..." · Reviewed by Greptile

Comment on lines +73 to +75
status: answered.status,
statusText: answered.statusText ?? errorText,
error: errorText,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Saved traces lose cancellations

Keeping the response status now hides browser cancellations after trace export. networkRequestToHar drops error, and harToNetworkRequest does not restore it. A cancelled 404 script loses its net::ERR_ABORTED reason. A response answered with 200 and then cancelled looks successful and no longer produces an OpenTelemetry request.failed event.

Preserve error through trace export and import, and make the telemetry check honor it.

status=0,
status_text=reason,
status=answered["status"] if answered else 0,
status_text=(answered and answered["status_text"]) or reason,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Python replaces empty response text

For an answered request with statusText: "", Python replaces the empty string with the browser error, while TypeScript preserves it. Python therefore reports net::ERR_ABORTED as the response text even though the browser supplied an empty string. Check for None rather than truthiness, and add this case to failedAfterResponse.

WebdriverIO's network manager subscribes beforeRequestSent,
responseCompleted and fetchError, but not responseStarted; only
browser.mock() adds it. The service's responseStarted listener therefore
never fired, and a 404 script still closed as status 0 in a real run.
The service now subscribes the event itself at session start, and keeps
every listener if the browser refuses it.

This branch has not been deployed

No deployments
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.

A 404 script is recorded as net::ERR_ABORTED with status 0, because no adapter reads network.responseStarted

1 participant