Skip to content
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

Closed
pipi1007 opened this issue May 17, 2020 · 4 comments
Closed

[BUG] Header not persisted on request #2272

pipi1007 opened this issue May 17, 2020 · 4 comments

Comments

@pipi1007
Copy link
Member

Context:

  • Playwright Version: 1.0.2
  • Operating System: Windows
  • Node version: [e.g. 10.12, 10.14]
  • Browser: Chrome
  • Extra: [any specific details about your environment]

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.

@pavelfeldman
Copy link
Member

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.

@pipi1007
Copy link
Member Author

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?

@pavelfeldman
Copy link
Member

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?

@pipi1007
Copy link
Member Author

Just gave it a try and it is working, thanks for the suggestion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants