Bypassing Cookie Consent Banners in Lighthouse and WebPageTest
When it comes to testing pages using Lighthouse, WebPageTest or other similar tools, cookie and similar consent banners are a pain!
They can cause layout shifts, on mobile the banner is sometimes the element for Largest Contentful Paint (LCP), they visually obscure other parts of the page, and if implemented correctly only some of the page's resources will be fetched.
When analysing sites one of my first steps is to work out how to bypass any consent banners so I can get a more complete view of page performance.
This post covers some of the performance issues related to consent banners, how I bypass the banners, and my approach to working out which cookies or localStorage items I need to set to bypass them.
Some banners are displayed at the top of the page before other content and there's a danger that if the banner is inserted after rendering starts, the content below them will shift downwards.
In a filmstrip of gov.uk there's layout shift at 0.7s when the consent banner is displayed (they have plans to address the issue in the future)
Another is to use a pop-over approach where the consent banner is positioned over the page content.
Largest Contentful Paint
On some pages, and particularly on mobile, parts of the consent banner get detected as the Largest Content Paint.
Currys PC World have this issue on their category pages, but not on their product pages, so removing the banner is important if we want get comparable measurements between the different page types.
There are other sites with very similar banners but yet another element is counted as the Largest Contentful Paint, so checking which element is being used is important.
Obscure Key Content
Filmstrips are a powerful way to convey performance to anyone regardless of their web performance knowledge and I rely on them to help clients understand what the current experience and to demonstrate how it improves as optimisations are implemented.
And as consent banners can cover up the key content, they just get in the way!
Partial Measurement
In countries where opt-in consent is required for 3rd-party data collection, the banner should delay the load of such scripts until consent is given.
These extra scripts influence performance – at the very least they'll increase the total bytes downloaded but often they'll also introduce long tasks, layout shifts and other behaviour that affects performance metrics too.
Bypassing Cookie Consent
Some sites add a 'developer option' to their consent banners, for example a query string parameter that prevents the banner from being displayed.
This makes testing with and without consent banners much easier but often this option doesn't exist, and sometimes banners are provided by a third-party services so typically in these cases cookies need to be set to avoid them.
Lighthouse
By default, Lighthouse doesn't support cookies, so web.dev/measure, Page Speed Insights etc. will test the site with the consent banner shown.
And if the consent banner is configured correctly then in opt-in e.g. GDPR, regions the Lighthouse score will be based on a partial page load i.e. without any 3rd-party tags.
But Publisher Ad Audits for Lighthouse does allow cookies to be set – click on the Advanced Settings button, and paste cookie in the relevant field.
If you need a score or advice on how to improve using this version of Lighthouse is a quick way to get that.
I want waterfalls so I can dig into network performance, filmstrips to demonstrate the benefits of optimisations, and Request Maps help understand the 3rd-parties on a page.
And most of the time I use WebPageTest to generate this data with one of these two approaches for bypassing consent banners.
I either set cookies via the setCookie script command: