I am experiencing difficulties when launching Puppeteer locally. The extension loads fine, and the service_worker is detected as long as headless is set to any value. Here’s the configuration code for the browser:
const extensionDirectory = path.join(__dirname, 'my_extension');
const browserInstance = await puppeteer.launch({
headless: 'new',
devtools: true,
env: {
LD_LIBRARY_PATH: '/shared-lib/linux',
},
args: [
`--disable-extensions-except=${extensionDirectory}`,
`--load-extension=${extensionDirectory}`,
'--no-sandbox',
'--disable-setuid-sandbox',
'--deterministic-fetch',
'--no-first-run',
'--disable-background-timer-throttling',
],
});
This is my test code to verify the loading of the service_worker:
await browserInstance.waitForTarget(
target => {
return target.type() === 'service_worker' && target.url().endsWith('background.js');
},
{ timeout: 15000 }
);
const allTargets = await browserInstance.targets();
extensionServiceWorker = allTargets.find(target => target.type() === 'service_worker');
However, on Ubuntu/Linux, I can’t locate the service_worker, leading to a timeout error. The browser itself operates smoothly, but it’s unclear if the extension is functioning properly since I can’t confirm its loading status. It’s worth noting that I’m not encountering any additional errors, just the service_worker timeout, which persists regardless of timeout extension attempts.
Initially, I suspected that the extension might not be correctly placed in my directory, but I verified this with the following function:
function checkExtensionValidity(extensionPath, absolutePath) {
const manifestFilePath = path.join(extensionPath, 'manifest.json');
if (fs.existsSync(manifestFilePath)) {
console.log(`Manifest file located at: ${manifestFilePath}`);
} else {
console.log(`Manifest file missing from: ${extensionPath}`);
throw new Error(`Invalid extension path: ${extensionPath}`);
}
if (fs.existsSync(path.join(extensionPath, 'node_modules'))) {
console.log(`node_modules present in: ${extensionPath}`);
} else {
console.log(`node_modules absent in: ${extensionPath}`);
}
}
For reference, I’m using the following version of Puppeteer:
"puppeteer": "^23.9.0",