How to use the chrome-launcher.launch 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 GoogleChrome / rendertron / src / main.js View on Github external
response.end(img);
    track('screenshot', now() - start);
  } catch (err) {
    response.status(400).send('Cannot render requested URL');
    console.error('Cannot render requested URL');
    console.error(err);
  }
});

app.get('/_ah/health', (request, response) => response.send('OK'));

app.stop = async() => {
  await config.chrome.kill();
};

const appPromise = chromeLauncher.launch({
  chromeFlags: ['--headless', '--disable-gpu', '--remote-debugging-address=0.0.0.0'],
  port: 0
}).then((chrome) => {
  console.log('Chrome launched with debugging on port', chrome.port);
  config.chrome = chrome;
  config.port = chrome.port;
  // Don't open a port when running from inside a module (eg. tests). Importing
  // module can control this.
  if (!module.parent) {
    app.listen(PORT, function() {
      console.log('Listening on port', PORT);
    });
  }
  return app;
}).catch((error) => {
  console.error(error);
github redbadger / website-honestly / lighthouse / runner.js View on Github external
function runLighthouse({ targetUrl }) {
  const chromeFlags = [
    '--headless',
    '--no-sandbox', // chrome sandboxing requires docker container to have the
    // `SYS_ADMIN` capability added which is not supported by GitHub actions
  ];

  return chromeLauncher.launch({ chromeFlags }).then(chrome => {
    const opts = {
      port: chrome.port,
      output: 'html',
    };

    const config = null;

    return lighthouse(targetUrl, opts, config).then(results => {
      // use results.lhr for the JS-consumable output
      // https://github.com/GoogleChrome/lighthouse/blob/master/types/lhr.d.ts
      // use results.report for the HTML/JSON/CSV output as a string
      // use results.artifacts for the trace/screenshots/other specific case you need (rarer)
      return chrome.kill().then(() => results);
    });
  });
}
github justinribeiro / lighthouse-action / src / chrome.js View on Github external
async function launchChromeAndRunLighthouse(url, opts, config) {
  // eslint-disable-next-line no-unused-vars
  const chrome = await chromeLauncher.launch({
    port: 9222,
    logLevel: 'silent',
    chromeFlags: ['--headless', '--disable-gpu'],
  });

  const browser = await puppeteer.connect({
    browserURL: 'http://localhost:9222',
  });

  browser.on('targetchanged', async target => {
    const page = await target.page();

    if (NETWORK[opts.connection]) {
      await page
        .target()
        .createCDPSession()
github ngrx / platform / projects / ngrx.io / scripts / test-pwa-score.js View on Github external
function launchChromeAndRunLighthouse(url, flags, config) {
  return chromeLauncher.launch(CHROME_LAUNCH_OPTS).then(chrome => {
    flags.port = chrome.port;
    return lighthouse(url, flags, config).
      then(results => chrome.kill().then(() => results)).
      catch(err => chrome.kill().then(() => { throw err; }, () => { throw err; }));
  });
}
github amio / pageshot / lib / chrome-daemon.js View on Github external
function launch ({port = 9222}) {
  return chromeLauncher.launch({
    port: port,
    chromeFlags: ['--headless', '--disable-gpu', '--no-sandbox', '--hide-scrollbars']
  }).then(chrome => {
    console.log(`Chrome debugging port running on ${chrome.port}`)
    instances.push({port, chrome})
  })
}
github qlik-oss / after-work.js / src / browser / chrome-runner.js View on Github external
module.exports = function runChromeHeadless(url) {
  chromeLauncher.launch({
    chromeFlags: ['--headless', '--disable-gpu'],
  }).then((chrome) => {
    console.log(`Chrome debugging port running on ${chrome.port}`);
    CDP({ port: chrome.port }, (client) => {
      const { Runtime, Page } = client;
      Promise.all([Runtime.enable(), Page.enable()])
        .then(() => {
          Runtime.consoleAPICalled((msg) => {
            if (msg.type === 'log') {
              const args = msg.args.map(e => e.value);
              let log = util.format.apply(null, args);
              log = log.replace('\u2713', 'v');
              log = log.replace(/[\w-]+\.spec\.js/, '\u001b[0m\u001b[31m$&\u001b[90m');
              console.log(log);
            }
          });
github Raathigesh / majestic / app / src / server / index.ts View on Github external
engine.getVersion().then((version: string) => {
        console.log(
          `${chalk.black.bgYellow.bold(`Majestic v${version}`)}\n${chalk.white(
            'Zero config UI for Jest'
          )}`
        );

        if (args.app) {
          chromeLauncher
            .launch({
              startingUrl: `http://localhost:${port}`,
              chromeFlags: [`--app=http://localhost:${port}`]
            })
            .then((chrome: any) => {
              console.log('Opening app');
            });
        } else {
          if (!args.dev && autoLaunch) {
            opn(`http://localhost:${port}`);
          }

          console.log(`visit ${chalk.green(`http://localhost:${port}`)}`);
        }
      });
      register('ui', getRemoteMethods(engine), (remote: any) => {
github krausest / js-framework-benchmark / webdriver-ts / src / forkedBenchmarkRunner.ts View on Github external
"--disable-background-timer-throttling",
            "--disable-cache",
            "--disable-translate",
            "--disable-sync",
            "--disable-extensions",
            "--disable-default-apps",
            "--window-size=1200,800"
        ],
        onlyCategories: ['performance'],
        port: benchmarkOptions.remoteDebuggingPort
    };

    try {
        let options : any = {chromeFlags: opts.chromeFlags, logLevel: "info"};
        if (benchmarkOptions.chromeBinaryPath) options.chromePath = benchmarkOptions.chromeBinaryPath;
        let chrome = await chromeLauncher.launch(options);
        opts.port = chrome.port;
        let results = null;
        try {
            results = await lighthouse(`http://localhost:${benchmarkOptions.port}/${framework.uri}/`, opts, null);
            await chrome.kill();
        } catch (error) {
            console.log("error running lighthouse", error);
            await chrome.kill();
            throw error;
        }
        //console.log("lh result", results);

        let LighthouseData: LighthouseData = {
            TimeToConsistentlyInteractive: extractRawValue(results.lhr, 'interactive'),
            ScriptBootUpTtime: Math.max(16, extractRawValue(results.lhr, 'bootup-time')),
            MainThreadWorkCost: extractRawValue(results.lhr, 'mainthread-work-breakdown'),
github siteriaitaliana / plugin-lighthouse / lib / index.js View on Github external
function launchChromeAndRunLighthouse(url, flags = {}, config = null) {
  return chromeLauncher.launch(flags).then(chrome => {
    return lighthouse(url, flags, config).then(results =>
      chrome.kill().then(() => results)
    );
  });
}
github elmsln / WCFactory / packages / generator-wcfactory / generators / element / lighthouse.js View on Github external
function launchChromeAndRunLighthouse(url, flags, config = null) {
  return chromeLauncher.launch().then(chrome => {
    flags.port = chrome.port;
    return lighthouse(url, flags, config).then(results =>
      chrome.kill().then(() => results)
    );
  });
}