GoogleChrome/chrome-launcher

Name: chrome-launcher

Owner: GoogleChrome

Description: Launch Google Chrome with ease from node.

Created: 2017-08-29 21:44:00.0

Updated: 2018-05-11 00:42:51.0

Pushed: 2018-04-16 21:13:17.0

Homepage: https://www.npmjs.com/package/chrome-launcher

Size: 162

Language: TypeScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Chrome Launcher Linux Build Status Windows Build Status NPM chrome-launcher package

Launch Google Chrome with ease from node.

Once launched, interacting with the browser must be done over the devtools protocol, typically via chrome-remote-interface. For many cases Puppeteer is recommended, though it has its own chrome launching mechanism.

Installing
 add chrome-launcher

 with 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
rt: number;

 (optional) Additional flags to pass to Chrome, for example: ['--headless', '--disable-gpu']
 See: https://github.com/GoogleChrome/chrome-launcher/blob/master/docs/chrome-flags-for-tools.md
 Do note, many flags are set by default: https://github.com/GoogleChrome/chrome-launcher/blob/master/src/flags.ts
romeFlags: Array<string>;

 (optional) Close the Chrome process on `Ctrl-C`
 Default: true
ndleSIGINT: boolean;

 (optional) Explicit path of intended Chrome binary
 * If this `chromePath` option is defined, it will be used.
 * Otherwise, the `CHROME_PATH` env variable will be used if set. (`LIGHTHOUSE_CHROMIUM_PATH` is deprecated)
 * Otherwise, a detected Chrome Canary will be used if found
 * Otherwise, a detected Chrome (stable) will be used
romePath: string;

 (optional) Chrome profile path to use, if set to `false` then the default profile will be used.
 By default, a fresh Chrome profile will be created
erDataDir: string | boolean;

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

 (optional) Logging level: verbose, info, error, silent
 Default: 'silent'
gLevel: string;

 (optional) Flags specific in [flags.ts](src/flags.ts) will not be included.
 Typically used with the defaultFlags() method and chromeFlags option.
 Default: false
noreDefaultFlags: boolean;

 (optional) Interval in ms, which defines how often launcher checks browser port to be ready.
 Default: 500
nnectionPollInterval: number;

 (optional) A number of retries, before browser launch considered unsuccessful.
 Default: 50
xConnectionRetries: number;

 (optional) A dict of environmental key value pairs to pass to the spawned chrome process.
vVars: {[key: string]: string};

Launched chrome interface .launch().then(chrome => ...
he remote debugging port exposed by the launched chrome
me.port: number;

ethod to kill Chrome (and cleanup the profile folder)
me.kill: () => Promise<{}>;

he process id
me.pid: number;

he childProcess object for the launched Chrome
me.process: childProcess
.defaultFlags()

Returns an Array<string> of the default flags Chrome is launched with. Typically used along with the ignoreDefaultFlags and chromeFlags options.

Note: This array will exclude the following flags: --remote-debugging-port --disable-setuid-sandbox --user-data-dir.

Examples
Launching chrome:
t chromeLauncher = require('chrome-launcher');

meLauncher.launch({
artingUrl: 'https://google.com'
hen(chrome => {
nsole.log(`Chrome debugging port running on ${chrome.port}`);

Launching headless chrome:
t chromeLauncher = require('chrome-launcher');

meLauncher.launch({
artingUrl: 'https://google.com',
romeFlags: ['--headless', '--disable-gpu']
hen(chrome => {
nsole.log(`Chrome debugging port running on ${chrome.port}`);

Continuous Integration

In a CI environment like Travis, Chrome may not be installed. If you want to use chrome-launcher, Travis can install Chrome at run time with an addon. Alternatively, you can also install Chrome using the download-chrome.sh script.

Then in .travis.yml, use it like so:

uage: node_js
all:
yarn install
re_script:
export DISPLAY=:99.0
export CHROME_PATH="$(pwd)/chrome-linux/chrome"
sh -e /etc/init.d/xvfb start
sleep 3 # wait for xvfb to boot

ns:
rome: stable

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.