sitespeedio / plugin-lighthouse

Lighthouse plugin for sitespeed.io
MIT License
30 stars 19 forks source link

How to pass cookie to lighthouse as part of sitespeed.io #120

Open dpeddaswamy opened 12 months ago

dpeddaswamy commented 12 months ago

Hi Team, I am using docker sitespeed latest Plus 1 docker image to include sitespeed tests and accessibility tests using Lighthouse plugin. Test urls are saved in .txt file and passing cookie for sitespeed.io on command. But for lighthouse i am unable to send cookie from command. I am using below command.

docker run --rm -v "$(pwd):/sitespeed.io" sitespeedio/sitespeed.io:29.7.0-plus1 TestPlans/APPURLs.txt -n 2 --browsertime.video false --axe.enable --config TestPlans/PageSummaryConfig.json --cookie Jsession=${COOKIE} --plugins.add analysisstorer --plugins.add /lighthouse/index.js --lighthouse.config TestPlans/lhconfig.js ----plugins.remove /gpsi/lib/index.js --outputFolder ./sitespeed-result

Sitespeed results are proper pages. But Cookie is not passing to Lighthouse and page is redirecting to login screen and getting accessibility metrics for that page which is not expected. Also Lighthouse is testing with mobile option. How to do emulation with desktop and network emulation is based on system network.

Could you please help me.

soulgalore commented 11 months ago

Hi @dpeddaswamy Lighthouse use there own Chrome version so when we run we first use Browsretime and the Chrome version in the Docker container, then when everything is finished we use the Chrome version bundled with Lighthouse and run the Lighthouse test. To pass on cookies for Lighthouse checkout the Lighthouse documentation at https://github.com/GoogleChrome/lighthouse

JoshuvaGeorge03 commented 11 months ago

I am also facing these issue...

can we able to re-use authenticated chrome instance for lighthouse testing? rather than again doing authentication for another one plugin...

can we able to do that @soulgalore , please advice... it would be really helpful

soulgalore commented 11 months ago

sitespeed.io and Lighthouse is using different Chrome versions. sitespeed.io rolls with the current stable version of Chrome (that most of your users use). Lighthouse uses whatever that installed with Puppeteer. We use different session, so the only way to do it for Lighthouse is to pass on a cookie.

JoshuvaGeorge03 commented 11 months ago

Thanks for the reply...

I can able to pass the cookies to lighthouse config too, but due to a known issue from lighthouse, we can't able to use cookies to authenticate, as it can be overriden and my webapp won't load at all... Please refer below issue for your reference.

https://github.com/GoogleChrome/lighthouse/issues/6207#issuecomment-500247138

so, if we can able to use already presented chrome instance, then authentication related issue can be solved altogether, and also lighthouse provides a way to use chrome debug instance(https://github.com/GoogleChrome/lighthouse/blob/main/docs/authenticated-pages.md#option-4-open-a-debug-instance-of-chrome-and-manually-log-in) too....

otherwise, I have to maintain another one pupeteer script to do login for lighthouse, this make integration bit harder, as I have to maintin authentication for sitespeed.io and lighthouse in a separate manner.

sorry, if it is something misleading, I would be really happy to find good solution on this to avoid separate maintenance of authentication, Please advice @soulgalore

JoshuvaGeorge03 commented 11 months ago

Also, using this plugin, we can no way of authenticate using puppeteer, As there is no option to support this, Please advice on this

https://github.com/GoogleChrome/lighthouse/blob/main/docs/authenticated-pages.md

soulgalore commented 11 months ago

Thinking the best solution would be to add Lighthouse user journeys or whatever they are calling it? I haven't looked into how that work yet.