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.
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. A workaround is to use Puppeteer’s page.setCookie
.
npm i -g lighthouse
or yarn global add lighthouse
. chrome-debug
is now in your PATH. This binary launches a standalone Chrome instance with an open debugging port.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.