addyosmani / critical

Extract & Inline Critical-path CSS in HTML pages
Apache License 2.0
10.01k stars 372 forks source link

Set headers or Cookies for request in CLI #596

Open superdav42 opened 3 months ago

superdav42 commented 3 months ago

Hi, I'm trying to generate critical css for a url that needs a specific cookie to be accessible. I'm working with the CLI since my project is not based on node. It seems like it might be possible to send the right headers with the cli but I'm not sure exact options I should use. I've tried:

DEBUG="critical:*" critical 'https://www.example.com/' --request-headers 'cookie: key=value;'

But it fails with:

Error: Expected value which is `plain object`, received value of type `string`.

Full debug shows:

Fetching resource: https://www.example.com/ {
  headers: 'cookie: key=value;',
  method: 'head',
  https: { rejectUnauthorized: true }
}

Obviously it's expecting headers to be an object and not a string but it seems impossible to make it an option just with cli options. Is there a trick to make it work?

bezoerb commented 1 month ago

Hey @superdav42,

thanks for reporting the issue. I build something so you could pass a JSON string as CLI argument:

node cli.js  'https://www.example.com/' --request-headers='{"cookie":"key=value"}'
bezoerb commented 1 month ago

can you try v7.2.0 please?