easrng's blog

How to use extensions in headless Puppeteer

I am working on a project that involves scraping pages with Puppeteer while certain extensions are activated, and it was proving to be a challenge. It turns out when headless is set to true, extensions and some other browser features don't work, and this was an issue because I didn't want to need to run an X server just to do some web scraping. After a multi-hour misadventure with Xvfb, I decided to see if a Wayland dummy server would be easier to set up. First I checked whether Chromium even has Wayland support, and I found out you needed to add some flags (--enable-features=UseOzonePlatform --ozone-platform=wayland) and then it would work. I was curious about the "Ozone Platform" thing, and it turns out that it's an abstraction layer for Chrome's renderer, with backends for X11, Wayland, and (drumroll please) Headless! This is somehow different from what Puppeteer is doing, but it works amazingly. No display servers, no extra binaries, just add 2 flags and extensions will work.

TL;DR: To make extensions work on Puppeteer, turn off headless mode and add --enable-features=UseOzonePlatform --ozone-platform=headless to the arguments.