How to use the chrome-launcher.Launcher function in chrome-launcher

To help you get started, we’ve selected a few chrome-launcher examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github adieuadieu / serverless-chrome / packages / lambda / src / index.js View on Github external
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)
github preactjs / preact-cli / tests / lib / chrome.js View on Github external
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 };
};
github addyosmani / webpack-lighthouse-plugin / src / lighthouse-bin.js View on Github external
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;