Repository navigation
Keep the status of a request the browser answered and then cancelled - #662
vishnuv688 wants to merge 2 commits into
Conversation
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
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Confidence Score: 4/5
[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. FindingsSummaryThe PR keeps the browser's response status and headers when a later cancellation ends a request.
Reviews (2) · Last reviewed commit: "Subscribe network.responseStarted in the..." · Reviewed by Greptile |
| status: answered.status, | ||
| statusText: answered.statusText ?? errorText, | ||
| error: errorText, |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
What & why
Fixes #658.
Chrome stops loading a script once its response comes back as a 404. Over BiDi it then sends
network.fetchErrorwithnet::ERR_ABORTEDand never sendsnetwork.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.responseStartedand 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 inerror. The missing script now reads as404 Not Found, errornet::ERR_ABORTED. A request that fails before any answer still closes as status 0 with the error text.Chrome 158 delivered
responseStartedbeforebeforeRequestSentfor 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
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, thewdio-otelCLI)conformance(cross-adapter conformance suite)sharedonly gains mirror vectors, andselenium-devtoolsonly gains their runner. Nightwatch takes the fix throughcore.Capability matrix
packages/conformance/src/features.tsupdated, and tables regenerated withpnpm docs:capabilities, if this adds or changes user-facing behaviourNot 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 incore(handleBidiResponseStarted,failedRowFields). The WebdriverIO service still has its own BiDi network handlers until #653 moves it onto core's, so it registers anetwork.responseStartedlistener and calls the core helpers. The Python adapter cannot importcore, so it mirrors the logic. A newfailedAfterResponsesection inmirror-vectors.json(5 cases) holds the TypeScript and Python versions equal.Reading
responseStartedoff the socket. selenium-webdriver's network inspector passes every network frame to every callback without its method. AresponseStartedframe therefore looks exactly like aresponseCompleted, so core subscribes and reads it off the raw socket by method, as it already does forfetchError. One side effect: the inspector's completed handler now also receivesresponseStarted, 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.tswould 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, thenbeforeRequestSent, thenfetchError. 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
responseStartedin the WDIO service. WebdriverIO's own network manager subscribesbeforeRequestSent,responseCompletedandfetchError, but notresponseStarted(onlybrowser.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 withreloadSessionprobably 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 reads404 Not Foundwith the server's response headers. The trace writer does not store a row'serror, so the zip no longer showsnet::ERR_ABORTEDfor this row; the live dashboard still has it. Selenium and Nightwatch take the fix throughcore, 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