Chrome extension not detected by Puppeteer: service_worker missing in browser.targets

Hey folks, I’m stuck with a Puppeteer issue. It works fine on my local machine, but on Ubuntu, I can’t seem to load my Chrome extension properly.

The browser launches okay, but when I try to find the service_worker, it times out. I’ve tried increasing the timeout, but no luck. Here’s a snippet of my setup:

const browser = await puppeteer.launch({
  headless: 'new',
  args: [
    `--load-extension=${myExtensionPath}`,
    '--no-sandbox'
  ]
});

// Trying to find the service_worker
await browser.waitForTarget(
  target => target.type() === 'service_worker',
  { timeout: 15000 }
);

I’ve checked that my extension files are in the right place. The browser runs fine, but I can’t tell if the extension is actually loaded. Any ideas what might be causing this? I’m using Puppeteer version 23.9.0.

Has anyone encountered this before? What am I missing here?

I’ve encountered this issue before when working with Puppeteer and Chrome extensions. One thing that often gets overlooked is the permissions for the extension directory on Ubuntu. Make sure the user running the Puppeteer script has read access to the extension files.

Also, have you verified that the extension is actually loaded in the browser? You can add a debug step to list all active extensions:

const extensions = await browser.targets();
const serviceWorkers = extensions.filter(t => t.type() === 'service_worker');
console.log(serviceWorkers);

This will help you confirm if the extension is loaded but not detected as a service worker. If it’s not showing up at all, you might need to investigate Chrome’s startup flags or potential conflicts with other installed extensions on your Ubuntu system.

I’ve dealt with similar issues when deploying Puppeteer scripts on different environments. One thing that’s often overlooked is the difference in Chrome versions between your local machine and the Ubuntu server. Puppeteer relies on a specific version of Chrome, and mismatches can cause unexpected behavior.

Try explicitly specifying the Chrome executable path in your Puppeteer launch options. You can do this by adding the ‘executablePath’ option and pointing it to the Chrome binary on your Ubuntu system. Something like:

const browser = await puppeteer.launch({
  headless: 'new',
  executablePath: '/usr/bin/google-chrome',
  args: [
    `--load-extension=${myExtensionPath}`,
    '--no-sandbox'
  ]
});

Also, double-check your extension’s manifest file. Make sure it’s compatible with the Chrome version you’re using on Ubuntu. Sometimes, subtle differences in manifest requirements can cause loading issues.

If these don’t work, you might want to try running Puppeteer in non-headless mode temporarily to see if you can spot any visual cues about the extension loading process. Good luck troubleshooting!

hey mate, had similar headache. try adding ‘–disable-extensions-except=${myExtensionPath}’ to ur args. it forces chrome to only load ur extension. Also, double-check ur extension path on Ubuntu - sometimes file structure can be tricky. good luck!