Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const chromeFlags = [...DEFAULT_CHROME_FLAGS, ...flags]
if (!chromeInstance) {
if (process.env.AWS_EXECUTION_ENV || forceLambdaLauncher) {
chromeInstance = new LambdaChromeLauncher({
chromePath,
chromeFlags,
port,
})
} else {
// This let's us use chrome-launcher in local development,
// but omit it from the lambda function's zip artefact
try {
// eslint-disable-next-line
const { Launcher: LocalChromeLauncher } = require('chrome-launcher')
chromeInstance = new LocalChromeLauncher({ chromePath, chromeFlags: flags, port })
} catch (error) {
throw new Error('@serverless-chrome/lambda: Unable to find "chrome-launcher". ' +
"Make sure it's installed if you wish to develop locally.")
}
}
}
debug('Spawning headless shell')
const launchStartTime = Date.now()
try {
await chromeInstance.launch()
} catch (error) {
debug('Error trying to spawn chrome:', error)
export default async () => {
let launcher = new Launcher({
chromeFlags: [
'--window-size=1024,768',
'--disable-gpu',
'--headless',
'--enable-logging',
'--no-sandbox'
]
});
launcher.pollInterval = 1000;
await log(() => launcher.launch(), 'Launching Chrome');
let protocol = await log(() => setup(launcher.port), 'Connecting to Chrome');
return { launcher, protocol };
};
function launchChromeAndRun(addresses, config, opts) {
opts = opts || {};
const launcher = new chromeLauncher.Launcher({
autoSelectChrome: !opts.selectChrome,
});
cleanup.register(() => launcher.kill());
return launcher
.isDebuggerReady()
.catch(() => {
log.log('Lighthouse CLI', 'Launching Chrome...');
return chromeLauncher.launch().then(chrome => chrome)
})
.then((chrome) => lighthouseRun(addresses, config, opts.lighthouseFlags, chrome))
.then((chrome) => chrome.kill())
.then(_ => Promise.resolve());
}
exports.launchChromeAndRun = launchChromeAndRun;