chromium: [BUG] Does not work with chrome extensions
Environment
chromiumVersion: 117.0.0puppeteer-coreVersion:- Node.js Version: 18.16.0
- Lambda Runtime:
nodejs18.x
Expected Behavior
Hello there, thanks for maintaining this library!
I don’t exactly know if it’s a bug report, a question, or a feature request, but here’s what I have a problem with: I want to start chromium with --headless=new and start it with an extension that uses the tabCapture API: puppeteer-stream. This library adds the extension with the launch args:
--load-extension--disable-extensions-except--allowlisted-extension-id
When I test it locally with the exact same launch options and the same chrome version, it works without a problem. On AWS Lambda, this does not work sadly.
Current Behavior
The browser starts successfully and does not produce any warning or error logs (with dumpio and a --log-level arg) and I can interact with it as usual. But as soon as the puppeteer-stream library executes browser.waitForTarget to wait for the background service worker of the chrome extenion, it fails with the TimeoutError.
I added event listeners to log created and destroyed targets, and the extension does not pop up. Maybe the custom compiled chromium version does not support extensions?
Steps to Reproduce
const { getStream, launch } = require('puppeteer-stream');
const puppeteer = require('puppeteer-core');
const chromium = require('@sparticuz/chromium');
const fs = require('node:fs');
chromium.setHeadlessMode = 'new'
chromium.setGraphisMode = true
/**
* Args that are forbidden for chromium for video and audio capturing to work properly.
* Some of these args are set by us and some are set by "puppeteer-stream".
*/
const FORBIDDEN_PUPPETEER_ARGS = [
'--disable-extensions',
'--mute-audio',
'--window-size',
'--disable-component-extensions-with-background-pages',
'--disable-default-apps',
'--headless',
]
exports.handler = async (event, context, callback) => {
let result = null;
let browser = null;
try {
browser = await launch(
{
launch: async (opts: PuppeteerLaunchOptions) => {
const options: PuppeteerLaunchOptions = { ...opts, headless: 'new' }
const extensionPath = options.args!.find((arg) => arg.startsWith('--load-extension='))!.split('=')[1]
console.log('debug', 'Loading extension', { extensionPath, contents: fs.readdirSync(extensionPath) })
console.log('debug', 'Launching browser', options)
return puppeteer.launch(options)
},
},
{
executablePath: await chromium.executablePath(),
args: [
chromium.args.filter((arg) => FORBIDDEN_PUPPETEER_ARGS.every((forbidden) => !arg.startsWith(forbidden))),
`--window-size=1920,1080`,
'--start-fullscreen',
`--ozone-override-screen-size=1920,1080`,
'--headless=new',
],
ignoreDefaultArgs: true,
waitForInitialPage: false,
defaultViewport: null,
ignoreHTTPErrors: true,
},
)
let page = await browser.newPage();
await page.goto(event.url || 'https://example.com');
const stream = await getStream(page, { audio: true, video: true });
const output = '/tmp/testfile.webm';
const file = fs.createWriteStream(output);
stream.pipe(file);
await new Promise((resolve) => {
setTimeout(async () => {
await stream.destroy()
file.close()
console.log('debug', 'Destroyed stream')
resolve(true)
}, 1000 * 10); // 10 seconds
});
const fileSize = fs.statSync(output).size
return callback(null, JSON.stringify({ fileSize }))
} catch (error) {
return callback(error);
} finally {
if (browser !== null) {
await browser.close();
}
}
return callback(null, result);
};
–>
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 16 (1 by maintainers)
@pantajoe your solution is much simpler. I installed virtual display server xvfb to get it to work in headful. Still a bot though.
Happy to help 😃 Just for clarification: I don’t use this package anymore but install the default puppeteer chromium or I install it via a system package.
Sure, I get wanting to make sure 😄 The reason is plain and simple: We tried using AWS Lambda with customer docker images before porting our serverless functions to GCP. Unfortunately, we found that the same restrictions apply 😬 We used alpine and tried installing chromium both via the default alpine repository as well as with this package and both approaches did not work at all. Chromium installed via alpine did not even start which is why this package here exists. And using this package’s custom chromium had exactly this limitation that extensions do not work.
No, we shifted to Google Cloud Platforms and ended up using Google Cloud Run with
@google-cloud/functions-frameworkand custom Docker images.On GCP, you can even run headful chromium with puppeteer. So yeah 🤷🏽♂️