Reputation: 3407
I'm trying to perform audit using Lighthouse DevTools. My site requires authentication. When I run the test the lighthouse logs me out and only anayses /login.
How can I get Lighthouse DevTools to analyse my site? Can I supply login credentials?
Upvotes: 14
Views: 12783
Reputation: 387
If you are using local storage in order to preserve an authenticated state after refresh (for example storing a user's token, and on refresh using that token in order to login like a lot of SPA's) I found a solution that might work : https://github.com/GoogleChrome/lighthouse/issues/1418#issuecomment-397753583
If using chrome dev tools to run light house :
If using the lighthouse cli tool :
--disable-storage-reset
flag , and you can also add the --view
flag in order to open a tab for the report.So the command will be :
lighthouse <url> --port <port_chrome_debugger_opened> --disable-storage-reset --view
Verifying it tested the logged in page
Upvotes: 14
Reputation: 3407
I had to install node 10.16.3 first (node.js > 10.0.0).
nvm install 10.16.3 will show error
Could not download npm for node v10.16.3.
Download npm version what you want - https://github.com/npm/cli/releases I had downloaded 6.9.0 npm version - https://github.com/npm/cli/archive/v6.9.0.zip It should be extracted to C:\Users\xxx\AppData\Roaming\nvm\v10.16.3\node_modules\npm
then go to C:\Users\xxx\AppData\Roaming\nvm\v10.16.3\node_modules\npm\bin and copy two npm files. first (npm .cmd file), second (npm file) then paste both files in C:\Users\xxx\AppData\Roaming\nvm\v10.16.3
open cmd and run command node -v and npm -v
After that lighthouse CLI works as expected.
The command still does not work though. :/
I have followed the advice of JoostS - Testing a site with authentication The technique does not work. It opens up an new, not logged in window, and behaves just like you would expect without the --port argument.
Upvotes: 0
Reputation: 12590
See Testing on a site with authentication in the official readme:
When installed globally via npm i -g lighthouse or yarn global add lighthouse, chrome-debug is added to your PATH. This binary launches a standalone Chrome instance with an open debugging port.
Upvotes: 4