GoogleChrome / lighthouse

Automated auditing, performance metrics, and best practices for the web.
https://developer.chrome.com/docs/lighthouse/overview/
Apache License 2.0
28.01k stars 9.31k forks source link

Lighthouse CLI pass mulitple cookies via --extra-headers #16027

Closed pascalknupper closed 1 week ago

pascalknupper commented 1 month ago

Question about how to add multiple cookies with different domains

Currently I´m implementing some Lighthouse checks via the CLI tool. Right now I´m facing an issue with adding mulitple cookies to my tests. Adding a single cookie works seamlessly. Adding 2 or more cookies via the CLI seems to be not working.

What is the correct syntax for adding multiple cookies with different domains via Lighthouse CLI?

 lighthouse --extra-headers="{\"Cookie\":\"Cookie1=value1&domain=.foo.com; Cookie2=value2&domain=.bar.com\"}" --chrome-flags="--headless" "https://www.google.de" --only-categories=accessibility,performance
connorjclark commented 1 month ago

Not sure about CLI, but you may have an easier time using a json file to provide cookies.

lighthouse <url> --extra-headers=./path/to/file.json                                               Path to JSON file of HTTP Header key/value pairs to send in requests

This will let you ignore any escaping needed for your terminal, and just store the values in a plain json object.

pascalknupper commented 4 weeks ago

@connorjclark May I ask what would be the syntax of the json object?

{"Cookie":"Cookie1=value1&domain=.foo.com; Cookie2=value2&domain=.bar.com"}
connorjclark commented 4 weeks ago

Yes, that is how to set a header value, just a simple json object. The value within the Cookie field is exactly what you'd see in the headers in devtools/curl.