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

I’m having trouble with Puppeteer and Chrome extensions on Ubuntu. The extension loads fine locally, but on Linux, I can’t find the service_worker.

Here’s my setup:

const browserConfig = {
  headless: 'new',
  devtools: true,
  env: { LD_LIBRARY_PATH: '/shared-lib/linux' },
  args: [
    `--disable-extensions-except=${extPath}`,
    `--load-extension=${extPath}`,
    '--no-sandbox',
    '--disable-setuid-sandbox',
    '--deterministic-fetch',
    '--no-first-run',
    '--disable-background-timer-throttling',
  ],
};

const browser = await puppeteer.launch(browserConfig);

I’m using this to check for the service_worker:

await browser.waitForTarget(
  target => target.type() === 'service_worker' && target.url().includes('background.js'),
  { timeout: 15000 }
);

const targets = await browser.targets();
const extensionTarget = targets.find(target => target.type() === 'service_worker');

The browser runs fine, but I get a timeout error when checking for the service_worker. I’ve checked that the extension files are in the right place.

I’m using puppeteer version 23.9.0. Any ideas why the service_worker isn’t being detected on Linux?

I’ve dealt with this exact problem before, and it can be frustrating. One thing that worked for me was increasing the timeout for the waitForTarget function. Sometimes, especially on slower systems or VMs, 15 seconds isn’t enough. Try bumping it up to 30 or even 60 seconds.

Another trick that helped was adding a small delay after launching the browser before checking for targets. Something like:

const browser = await puppeteer.launch(browserConfig);
await new Promise(resolve => setTimeout(resolve, 5000)); // 5-second delay

This gives the extension a bit more time to initialize. Also, make sure your extension is compatible with the Chrome version Puppeteer is using. You can check this by running browser.version() and comparing it to your extension’s supported versions.

If all else fails, you might need to dig into Chrome’s debug logs. You can enable verbose logging by adding ‘–enable-logging=stderr’ to your args and checking the output for any extension-related errors.

hey there, i had a similar issue. try adding ‘–enable-features=NetworkServiceInProcess’ to ur args. also, check if ur extension’s manifest.json has the right permissions. sometimes it’s just a permissions thing. if that don’t work, maybe try an older puppeteer version? good luck!

I’ve encountered similar issues with Puppeteer and Chrome extensions on Linux systems. One thing that helped me was explicitly setting the user data directory. Try adding this to your browserConfig:

userDataDir: '/path/to/user/data/dir'

Also, ensure you’re using the latest Chrome version compatible with your Puppeteer version. Sometimes, mismatches can cause detection problems.

If that doesn’t work, you might want to try launching Chrome in non-headless mode temporarily to see if the extension loads visually. This can help isolate whether it’s a Puppeteer detection issue or an extension loading problem.

Lastly, double-check your extension’s manifest file. Make sure it’s properly configured for Manifest V3, as older versions might not work correctly with newer Chrome and Puppeteer versions.