Fix Request/Response correlation: implement requestId-based tracking in playwright-adapter#39
Draft
Copilot wants to merge 4 commits into
Draft
Fix Request/Response correlation: implement requestId-based tracking in playwright-adapter#39Copilot wants to merge 4 commits into
Copilot wants to merge 4 commits into
Conversation
Co-authored-by: Miguel0888 <40050873+Miguel0888@users.noreply.github.com>
Co-authored-by: Miguel0888 <40050873+Miguel0888@users.noreply.github.com>
Co-authored-by: Miguel0888 <40050873+Miguel0888@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix request/response correlation in Playwright adapter
Fix Request/Response correlation: implement requestId-based tracking in playwright-adapter
Nov 14, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Network event handlers (
onRequest,onRequestFinished,onRequestFailed,onResponse) were creating newRequestImplinstances per event, breaking object identity semantics.ResponseImpl.request()always returned null.Changes
PageImpl: Request lifecycle management
Map<String, RequestImpl> requestsByIdkeyed by BiDi requestIdonRequest: creates and caches RequestImpl by requestIdonRequestFinished/onRequestFailed: retrieves cached instance, enriches with response/error data, removes from maponResponse: passes cached RequestImpl to ResponseImpl constructorextractRequestId(WDBaseParameters)helperRequestImpl: Mutable enrichment
failureandresponsefrom final to mutableenrichWithResponse(ResponseCompleted)andenrichWithError(FetchError)public methodsResponseImpl: Request reference
Request requestparameterrequest()returns the provided Request instanceResult
All events for a logical request now share the same
RequestImplinstance:Enables robust in-flight request tracking, waitForNetworkIdle implementation, and proper Playwright network API semantics.
Testing
Added
RequestResponseCorrelationTestwith 5 unit tests covering enrichment methods, object identity, and edge cases. All tests passing. CodeQL: 0 vulnerabilities.Original prompt
This section details on the original issue you should resolve
<issue_title>Playwright adapter: Request/Response correlation broken (RequestImpl instances + ResponseImpl.request())</issue_title>
<issue_description>## Severity
High priority: This directly affects correct behavior of Playwright-style network APIs and makes it impossible to reliably correlate requests and responses from the TestRunner (and anywhere else that uses
onRequest,onRequestFinished,onRequestFailed, oronResponse).Problem
In the current
playwright-adapterimplementation:PageImpl.onRequest/onRequestFinished/onRequestFailedeach create a newRequestImplonRequest(network.beforeRequestSent) →new RequestImpl(WDNetworkEvent.BeforeRequestSent)onRequestFinished(network.responseCompleted) →new RequestImpl(WDNetworkEvent.ResponseCompleted)onRequestFailed(network.fetchError) →new RequestImpl(WDNetworkEvent.FetchError)RequestImplper real network request, and no map keyed byrequestId.ResponseImpl.request()always returnsnullResponseImpltherequestfield is never set (constructor leaves it asnull).response.request()frompage.onResponse(...)cannot be used to correlate back toRequest.There is no internal mapping from BiDi
requestId→RequestImplthat would allow Playwright semantics to be respected.This is not compatible with the official Playwright semantics, where all events for a single underlying browser request operate on the same
Requestobject, andresponse.request()returns that same instance.Why this matters
For features like:
waitForNetworkIdle-like behavior purely on top of Playwright APIs (onRequest,onRequestFinished,onRequestFailed,onResponse),we need to be able to rely on:
Requestidentity being stable across events (onRequest→onRequestFinished/onRequestFailed), andResponse.request()returning that sameRequestinstance.Derzeit ist das nicht gegeben, wodurch z. B. ein Counter im TestRunner, der Requests aus
onRequestmerkt und inonRequestFinished/onRequestFailedwieder entfernt, nicht sicher mit Objektidentität arbeiten kann. Außerdem istresponse.request()derzeit unbrauchbar.Expected behavior (aligned with Playwright API)
For each real network request:
RequestImplinstance representing it.page.onRequest(handler)is called with that instance when the request starts.page.onRequestFinished(handler)(andpage.onRequestFailed(handler)) are called with the sameRequestImplinstance when the request completes or fails.page.onResponse(handler)receives aResponseImplwhoserequest()method returns the sameRequestImplinstance.Suggested implementation approach
Introduce a
Map<String, RequestImpl>keyed by BiDirequestIdin the adapter (likely inBrowserImplorPageImpl, wherever network events are routed):On
BeforeRequestSent:requestIdfrom the BiDi event.RequestImplonce:RequestImpl req = new RequestImpl(beforeRequestSent).requestsByIdunder thatrequestId.onRequesthandlers withreq.On
ResponseCompleted:requestId.RequestImpl req = requestsById.get(requestId).reqis null (edge case), create it and store it, but ideal is to re-use the existing.reqwith response data (rather than building a newRequestImpl).onRequestFinishedwith thisreq.requestIdfrom the map once the lifecycle is finished.On
FetchError:requestId, enrichreqwith error data, callonRequestFailedwith the same instance.In
ResponseImpl:requestIdand reuse theRequestImplfromrequestsById.requestfield in the constructor so thatresponse.request()returns the correct, sharedRequestImpl.Ensure that
offRequest,offRequestFinished,offRequestFailed,offResponseinPageImplstill work by keeping the{handler -> adapter}maps you already have, but the objects passed to handlers should be the sharedRequestImpl/ResponseImplinstances from the maps.Acceptance criteria
onRequest,onRequestFinished,onRequestFailedandonResponsefor a given logical request all see the sameRequestobject (identity stable for that request).ResponseImpl.request()returns a non-nullRequestthat equals the one fromonRequest.A simple test like:
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.