lighthouse/chrome-launcher
Sam Saccone cc5485fead Enable typescript coverage metrics for coveralls.
use nyc + lcov merge to generate a combined coverage report.

Fixes #2374
2017-06-19 20:49:14 -07:00
..
test extract logger from lighthouse (#2528) 2017-06-19 18:30:12 -07:00
.clang-format Extract chrome-launcher to a standalone thing. (#2245) 2017-05-13 15:40:33 -07:00
.npmignore Prep export of launcher as a standalone module (#2358) 2017-06-13 13:23:12 -04:00
README.md docs (launcher): add primary benefits (#2508) 2017-06-15 13:30:23 -04:00
ask.ts Compact the license header (chrome-launcher & cli) 2017-06-05 19:21:13 -07:00
chrome-finder.ts Compact the license header (chrome-launcher & cli) 2017-06-05 19:21:13 -07:00
chrome-launcher.ts extract logger from lighthouse (#2528) 2017-06-19 18:30:12 -07:00
compiled-check.js fixed incorrect comments (#2392) 2017-05-30 12:16:18 -07:00
flags.ts Compact the license header (chrome-launcher & cli) 2017-06-05 19:21:13 -07:00
index.ts improve typescript declaration imports (#2513) 2017-06-16 09:18:29 -07:00
manual-chrome-launcher.js Update manual-chrome-launcher.js 2017-05-31 11:18:29 -07:00
package.json Enable typescript coverage metrics for coveralls. 2017-06-19 20:49:14 -07:00
random-port.ts Compact the license header (chrome-launcher & cli) 2017-06-05 19:21:13 -07:00
tsconfig.json Extract chrome-launcher to a standalone thing. (#2245) 2017-05-13 15:40:33 -07:00
utils.ts Compact the license header (chrome-launcher & cli) 2017-06-05 19:21:13 -07:00
yarn.lock Enable typescript coverage metrics for coveralls. 2017-06-19 20:49:14 -07:00

README.md

Chrome Launcher NPM chrome-launcher package

Launch Google Chrome with ease from node.

  • Disables many Chrome services that add noise to automated scenarios
  • Opens up the browser's remote-debugging-port on an available port
  • Automagically locates a Chrome binary to launch
  • Uses a fresh Chrome profile for each launch, and cleans itself up on kill()
  • Binds Ctrl-C (by default) to terminate the Chrome process
  • Exposes a small set of options for configurability over these details

Installing

yarn add chrome-launcher

# or with npm:
npm install chrome-launcher

API

.launch([opts])

Launch options

{
  // (optional) remote debugging port number to use. If provided port is already busy, launch() will reject
  // Default: an available port is autoselected
  port: number;

  // (optional) Additional flags to pass to Chrome, for example: ['--headless', '--disable-gpu']
  // See all flags here: http://peter.sh/experiments/chromium-command-line-switches/
  // Do note, many flags are set by default: https://github.com/GoogleChrome/lighthouse/blob/master/chrome-launcher/flags.ts
  chromeFlags: Array<string>;
  
  // (optional) Close the Chrome process on `Ctrl-C`
  // Default: true
  handleSIGINT: boolean;

  // (optional) Explicit path of intended Chrome binary
  // By default, any detected Chrome Canary or Chrome (stable) will be launched
  chromePath: string;

  // (optional) Chrome profile path to use
  // By default, a fresh Chrome profile will be created
  userDataDir: string;

  // (optional) Starting URL to open the browser with
  // Default: `about:blank`
  startingUrl: string;
};

Launched chrome interface

.launch().then(chrome => ...

// The remote debugging port exposed by the launched chrome
chrome.port: number;

// Method kill Chrome (and cleanup the profile folder)
chrome.kill: () => Promise<{}>;

// The process id
chrome.pid: number;

Examples

Launching chrome:

const chromeLauncher = require('chrome-launcher');

chromeLauncher.launch({
  startingUrl: 'https://google.com'
}).then(chrome => {
  console.log(`Chrome debugging port running on ${chrome.port}`);
});

Launching headless chrome:

const chromeLauncher = require('chrome-launcher');

chromeLauncher.launch({
  startingUrl: 'https://google.com',
  chromeFlags: ['--headless', '--disable-gpu']
}).then(chrome => {
  console.log(`Chrome debugging port running on ${chrome.port}`);
});