-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Header not persisted on request #2272
Comments
Request interception does not modify the original request headers by design - in your code you obtain and modify the copy of the headers and continue the route with it. In your concrete scenario, you could simply put a symbol on a request with the request time. Would you mind sharing more about your use case? We were considering exposing timing info on requests and responses and it is important for us to know what you are after. |
We are trying to setup a probe to monitor our service and we'd like to measure latencies on each request. Intercepted headers are persisted on request by puppeteer. It'd be nice if playwright can also persist intercepted headers so I can tag the request and do stuff like measuring latency. Could you please elaborate on how to put a symbol on the request? |
I mean a simple property on request: request['requestTime'] = new Date().toISOString(); or a symbol, which is better in a sense that it won't clash with internal properties: const requestTime = Symbol('requestTime');
request[requestTime] = ... and then you simply read it off the same request object. Would that work for you? |
Just gave it a try and it is working, thanks for the suggestion. |
Context:
Code Snippet
Help us help you! Put down a short code snippet that illustrates your bug and
that we can run and debug locally. For example:
page.route('**', (route: Route, request: Request) => {
const headers = request.headers();
headers['customHeader'] = new Date().toISOString();
route.continue({ headers });
});
page.on('response', (response: Response) => {
const latency =
new Date().getTime() - new Date(response.request().headers()['customHeader']).getTime();
Describe the bug
}
latency is NaN because the customHeader info set in route override is lost on response handler.
The text was updated successfully, but these errors were encountered: