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

Referrer should be parameter, not extra header #3090

Closed
schelkun opened this issue Aug 15, 2018 · 1 comment
Closed

Referrer should be parameter, not extra header #3090

schelkun opened this issue Aug 15, 2018 · 1 comment

Comments

@schelkun
Copy link
Contributor

If you look at this line, we trying to get referrer from extraHTTPHeaders:
https://github.com/GoogleChrome/puppeteer/blob/master/lib/Page.js#L565

So, at this code example I forced to clear extra headers for proper resources loading:

await page.setExtraHTTPHeaders({
  referer: 'https://example.com/'
});

await page.goto('https://github.com/');

await page.setExtraHTTPHeaders({});

This is really bad way to set referrer, because even in CDP referrer is specified as a parameter, not header. This is not even funny!
https://github.com/GoogleChrome/puppeteer/blob/master/lib/Page.js#L601

While I'm trying to clear headers after navigation with empty object, page will load resources (like CSS and scripts, images) with a wrong referrer!

Try to set extra header referer on your page and load image, and you will see amazing wrong referer:

ref

So wee need smth like this:

  • referrer as a optional parameter at goto, in this case method will ignore headers referer check
  • referrer as a parameter only (best way)

Now I'm forced to rewrite goto method a little, can we fix it?

@aslushnikov
Copy link
Contributor

Fair. We should add referer to the navigation options and make it override the one
specified via extra http headers.

await page.goto('https://google.com', {
  referer: 'https://example.com'
});

aslushnikov pushed a commit that referenced this issue Sep 3, 2018
If referer is passed to the options object its value will be used as the referer instead of the value set by `Page.setExtraHTTPHeaders()`.

This is the correct way to set referer header: otherwise, the `referer` header will override all the document subrequests.

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

No branches or pull requests

2 participants