Is it possible to set cookies to Page Speed Insights tests?

3.5k views Asked by At

When using WebPageTest it is possible to use custom scripts to set cookies. Is it possible to do the same on PageSpeed Insights or lighthouse?

For example in the European Union you may want to set cookies to disable the cookie consent popup which will not appear for repeat users who have already consented to the website's cookie policy.

1

There are 1 answers

1
GrahamTheDev On BEST ANSWER

Page Speed Insights

Page Speed Insights (PSI) is designed for simulating a first time user to the site, so your cookies popup would always show.

It does not cache cookies or anything else. There is no way to send cookies to PSI.

Lighthouse in the browser

If you are using Lighthouse in the browser simply untick the "Clear Storage" option in the top bar (you may have to click the gear icon top right to reveal this) and at that point run the page twice (once to set the cache), cookies will be stored and you will record a run with cached images, files etc.

If you wanted to create a run where cookies are stored but nothing else is cached you could go to the application tab in developer tools and remove everything other than the cookies.

However as this is not indicative of a real world scenario I do not see the benefit and is only included as it answers the original question.

Lighthouse CLI + Puppeteer

Your final option for complete control would be to run Lighthouse CLI on your own machine.

The source code for Lighthouse is available on GitHub, takes a short while to set up, installing chromium etc. but it is worth it.

At that point you have more control, if you partner it with Puppeteer then you have all the control to set individual cookies etc.

However it does appear that you should be able to pass cookies directly to Lighthouse via config according to this thread, but it might not work and ultimately ends up recommending puppeteer. Perhaps that is a feature that will get improved upon soon.