Skip to content

[Feature] Intercepting HAR requests/responses #29190

Open
@shuckster

Description

@shuckster

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 ids. 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 ids 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:

  1. Permit the use of both routeFromHAR and page.route together.

  2. To extend the options object of routeFromHAR with a handler in a similar way to page.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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions