Default runs of Lighthouse load a page as a "new user", with no previous session or storage data. This means that pages requiring authenticated access do not work without additional setup. You have a few options for running Lighthouse on pages behind a login:
Puppeteer is the most flexible approach for running Lighthouse on pages requiring authentication.
See a working demo at /docs/recipes/auth.
View our full documentation for using Lighthouse along with Puppeteer.
The Audits panel in Chrome DevTools will never clear your cookies, so you can log in to the target site and then run Lighthouse. If localStorage
or indexedDB
is important for your authentication purposes, be sure to uncheck Clear storage
.
CLI:
lighthouse http://www.example.com --view --extra-headers="{\"Authorization\":\"...\"}"
Node:
const result = await lighthouse('http://www.example.com', {
extraHeaders: {
Authorization: '...',
},
});
You could also set the Cookie
header, but beware: it will override any other Cookies you expect to be there. For a more flexible cookie-based approach, use puppeteer (Option 1) instead.
- Globally install lighthouse:
npm i -g lighthouse
oryarn global add lighthouse
.chrome-debug
is now in your PATH. This binary launches a standalone Chrome instance with an open debugging port. - Run chrome-debug. This logs the debugging port of your Chrome instance.
- Navigate to your site and log in.
- In a separate terminal, run
lighthouse http://mysite.com --disable-storage-reset --port port-number
, using the port number from chrome-debug.
This option is currently under development. Track or join the discussion here: #8957.