Skip to content

Latest commit

 

History

History
44 lines (29 loc) · 2.22 KB

authenticated-pages.md

File metadata and controls

44 lines (29 loc) · 2.22 KB

Running Lighthouse on Authenticated Pages

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:

Option 1: Script the login with Puppeteer

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.

Option 2: Leverage logged-in state with Chrome DevTools

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.

Option 3: Pass custom request headers with Lighthouse CLI

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.

Option 4: Open a debug instance of Chrome and manually log in

  1. Globally install lighthouse: 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.
  2. Run chrome-debug. This logs the debugging port of your Chrome instance.
  3. Navigate to your site and log in.
  4. In a separate terminal, run lighthouse http://mysite.com --disable-storage-reset --port port-number, using the port number from chrome-debug.

Option 5: Reuse a prepared Chrome User Profile

This option is currently under development. Track or join the discussion here: #8957.