Description
Problem
We wish to intercept and modify PlayWright HAR requests and responses.
There does not appear to be a way of doing this directly on routeFromHAR
, so the repo below demonstrates an attempt to use both page.route
and routeFromHAR
together.
Needless to say, the technique does not work.
Use-case
The JSON RPC spec requires an id
at the root-level of a request.
In our own JSON RPC implementation, we are using a randomly generated prefix for our id
s. They are generated on Application startup, and include an incrementing counter as a suffix:
const id = `${jsonRpcAppLoadId}_${requestCounter}`;
Unfortunately, a random value in a payload means the HAR feature of PlayWright treats all requests as unique, and it will fail to load and serve a saved HAR from file.
We're reluctant to change the way these id
s are calculated because we have a micro-frontend architecture. This means multiple apps could, in the same page, call the same back-end APIs, and we'd like to ensure responses get routed to the right requesters.
Proposition
To either:
-
Permit the use of both
routeFromHAR
andpage.route
together. -
To extend the
options
object ofrouteFromHAR
with a handler in a similar way topage.route
works.
Either solution would allow requests to be modified before the HAR files are saved, and responses to also be modified after they have been loaded from file.