Open mikehenrty opened 4 years ago
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)
Protocol error (Network.setExtraHTTPHeaders): Invalid parameters (headers: object expected)
I believe the problem is here: https://github.com/paulirish/pwmetrics/blob/f8a784fd6930a1e8b79c1a00e7cd129178638edf/lib/index.ts#L61
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: https://github.com/paulirish/pwmetrics/blob/f8a784fd6930a1e8b79c1a00e7cd129178638edf/lib/lh-runner.ts#L43
pwmetrics
One possible solution would be to special case the opts.flags.extraHeaders argument, and JSON.parse it.
opts.flags.extraHeaders
Note, it seems other projects have had similar issues: https://github.com/sitespeedio/plugin-lighthouse/issues/30
pwmetrics version: 4.2.3 (lighthouse 5.2.0) Note sure if relevant, but I also have Lighthouse 6 installed globally through yarn
Chrome version: "chrome-launcher": "^0.10.2"
OS version: Linux, 5.6.15-arch
Config / CLI options
Using a JS config file, I am correctly able to specify additional request headers, like so:
But when I try to speficy these extra headers using CLI options like:
I see this error
Protocol error (Network.setExtraHTTPHeaders): Invalid parameters (headers: object expected)
I believe the problem is here: https://github.com/paulirish/pwmetrics/blob/f8a784fd6930a1e8b79c1a00e7cd129178638edf/lib/index.ts#L61
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: https://github.com/paulirish/pwmetrics/blob/f8a784fd6930a1e8b79c1a00e7cd129178638edf/lib/lh-runner.ts#L43One 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: https://github.com/sitespeedio/plugin-lighthouse/issues/30
Environment
pwmetrics
version: 4.2.3 (lighthouse 5.2.0) Note sure if relevant, but I also have Lighthouse 6 installed globally through yarnChrome version: "chrome-launcher": "^0.10.2"
OS version: Linux, 5.6.15-arch