puppeteer: page.setExtraHTTPHeaders cause 'ERR_INVALID_ARGUMENT' error

Steps to reproduce

Tell us about your environment:

  • Puppeteer version: 1.20.0
  • Platform / OS version: mac OS
  • URLs (if applicable):
  • Node.js version: v11.11.0

What steps will reproduce the problem?

const puppeteer = require('puppeteer');
(async () => {
    const browser = await puppeteer.launch({
        headless: false,
        ignoreHTTPSErrors: true,
        ignoreDefaultArgs: ["--enable-automation"],
        args: [
            '–no-sandbox',
        ]
    });
    const page = await browser.newPage();
    await page.setExtraHTTPHeaders(
        {'proxy-authorization': 'test'}
    );
    await page.goto('http://example.com/');
    await page.waitFor(10000);
    await browser.close();
})();

What is the expected result? go to the url success

What happens instead?

(node:86672) UnhandledPromiseRejectionWarning: Error: net::ERR_INVALID_ARGUMENT at http://example.com/
    at navigate (/Users/andrew/Documents/otherProject/vs/demo/node_modules/puppeteer/lib/FrameManager.js:120:37)
    at processTicksAndRejections (internal/process/next_tick.js:81:5)
  -- ASYNC --
    at Frame.<anonymous> (/Users/andrew/Documents/otherProject/vs/demo/node_modules/puppeteer/lib/helper.js:111:15)
    at Page.goto (/Users/andrew/Documents/otherProject/vs/demo/node_modules/puppeteer/lib/Page.js:674:49)
    at Page.<anonymous> (/Users/andrew/Documents/otherProject/vs/demo/node_modules/puppeteer/lib/helper.js:112:23)
    at /Users/andrew/Documents/otherProject/vs/demo/demo.js:16:16
    at processTicksAndRejections (internal/process/next_tick.js:81:5)

But, if I replace header proxy-authorization to proxyauthorization, it’s fine. So,it seems that it’s not allowed containing ‘-’ in header, is this corrent? Or is it an issue?

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 9
  • Comments: 16

Most upvoted comments

We’re getting the same ERR_INVALID_ARGUMENT error when setting a Host header via page.setExtraHTTPHeaders() and loading http://localhost/path/to/tested/page. When I curl it, I get the response I expect:

curl -H "Host: [REDACTED]" http://localhost/path/to/tested/page

Using v2.0.0.

If you want to pass proxy-authorization then use below code instead of page.setExtraHTTPHeaders():

await page.authenticate({username:'', password:''})