I’m having trouble with Puppeteer and Chrome extensions on Ubuntu. My setup works fine locally, but on Linux, I can’t find the service_worker.
Here’s what I’m doing:
const browserSetup = {
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(browserSetup);
// Check for service_worker
await browser.waitForTarget(
(target) => target.type() === 'service_worker' && target.url().includes('background.js'),
{ timeout: 15000 }
);
const targets = await browser.targets();
const extTarget = targets.find(t => t.type() === 'service_worker');
The browser runs fine, but I can’t find the service_worker. I’ve checked the extension files are in the right place. I’m using Puppeteer version 23.9.0.
Any ideas why the service_worker isn’t showing up on Linux?
hey man, i had similar issues. try adding ‘–disable-gpu’ to ur args. also, check if ur extension is compatible with the chrome version puppeteer uses. sometimes thats the culprit. if nothin works, maybe try downgrading puppeteer to an older version. good luck!
I’ve dealt with similar headaches when working with Puppeteer and Chrome extensions on different environments. One thing that’s often overlooked is permissions. On Linux, make sure the extension directory and all its files have the correct read permissions for the user running the script.
Another trick that’s helped me is to add a small delay after launching the browser before checking for targets. Sometimes the service worker needs a moment to initialize. You could try something like:
await new Promise(resolve => setTimeout(resolve, 5000));
before your waitForTarget call.
Also, double-check that your extension’s manifest.json is set up correctly for manifest v3, which uses service workers instead of background pages. If it’s still using the old format, that could explain why the service_worker isn’t showing up.
Lastly, if all else fails, you might want to try running Puppeteer in non-headless mode (set headless: false) just for debugging. This can sometimes reveal issues that aren’t apparent in headless mode.
I’ve encountered similar issues with Puppeteer and Chrome extensions on Linux environments. One potential solution that worked for me was to include the ‘–user-data-dir’ argument in your browserSetup. This ensures Chrome uses a persistent profile, which aids in loading extensions correctly.
Check that your extPath is absolute, as relative paths can be problematic in Linux environments. Additionally, consider increasing the timeout for waitForTarget, as service worker initialization might take longer on some systems. Finally, verify that you’re using a version of Chrome compatible with Puppeteer 23.9.0 to avoid any version mismatch issues.