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

Cannot specify --extra-headers CLI option, errors with "Invalid parameters (headers: object expected)" #231

Open
mikehenrty opened this issue May 29, 2020 · 0 comments

Comments

@mikehenrty
Copy link

Config / CLI options

Using a JS config file, I am correctly able to specify additional request headers, like so:

module.exports = {
  flags: {
    chromeFlags: '--headless --disable-gpu --no-sandbox"',
    extraHeaders: {
      'My-Special-Header': 'data'
    },
  }
}

But when I try to speficy these extra headers using CLI options like:

pwmetrics --extra-headers "{\"My-Special-Header\":\"data\"}" https://www.example.com --chrome-flags="--headless --disable-gpu --no-sandbox"

I see this error Protocol error (Network.setExtraHTTPHeaders): Invalid parameters (headers: object expected)

I believe the problem is here:

this.flags = Object.assign({}, this.flags, opts.flags);

The option flag for pwmetrics gets captured as a string, and then pass straight into the NodeJS Lighthouse Runner as a string. Since the runner expects an object rather than string, we see the aforementioned error:

lhResults = await lighthouse(this.url, this.flags, perfConfig);

One possible solution would be to special case the opts.flags.extraHeaders argument, and JSON.parse it.

Note, it seems other projects have had similar issues: sitespeedio/plugin-lighthouse#30

Environment

  1. pwmetrics version:
    4.2.3 (lighthouse 5.2.0)
    Note sure if relevant, but I also have Lighthouse 6 installed globally through yarn

  2. Chrome version:
    "chrome-launcher": "^0.10.2"

  3. OS version:
    Linux, 5.6.15-arch

@mikehenrty mikehenrty changed the title Cannot specify --extra-headers CLI option, errors with "Protocol error (Network.setExtraHTTPHeaders): Invalid parameters (headers: object expected)" Cannot specify --extra-headers CLI option, errors with "Invalid parameters (headers: object expected)" May 30, 2020
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

1 participant