Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prep export of launcher as a standalone module #2358

Merged
merged 6 commits into from
Jun 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ echo "Upload the package zip to CWS dev dashboard"

echo "Verify the npm package won't include unncessary files"
yarn global add irish-pub pkgfiles
irish-pub; pkgfiles;
irish-pub; pkgfiles;

echo "ship it"
npm publish
Expand All @@ -110,6 +110,17 @@ echo "Generate the release notes, and update the release page"
echo "Inform various peoples"
```

### Releasing chrome launcher.

```sh
cd chrome-launcher
echo "build the launcher source code"
yarn build
yarn version
echo "version bump will be committed"
npm publish
```

### Canary release

```sh
Expand Down
11 changes: 11 additions & 0 deletions chrome-launcher/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# folders
.vscode/
test/

# dev files
.appveyor.yml
.editorconfig
.eslintignore
.eslintrc.js
.travis.yml
gulpfile.js
95 changes: 95 additions & 0 deletions chrome-launcher/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Chrome Launcher

Launch Google Chrome with ease from node.

### Installing

```
yarn add chrome-launcher
```

or

```
npm install chrome-launcher
```


## API

### `.launch([opts])`

#### Launch options

```ts
{
// (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 => ...`

```ts
// 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:

```js
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:

```js
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}`);
});
```
2 changes: 1 addition & 1 deletion chrome-launcher/chrome-launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {DEFAULT_FLAGS} from './flags';
import {makeTmpDir, defaults, delay} from './utils';
import * as net from 'net';
const rimraf = require('rimraf');
const log = require('../lighthouse-core/lib/log');
const log = require('lighthouse/lighthouse-core/lib/log');
const spawn = childProcess.spawn;
const execSync = childProcess.execSync;
const isWindows = process.platform === 'win32';
Expand Down
11 changes: 8 additions & 3 deletions chrome-launcher/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"name": "chrome-launcher",
"private": true,
"main": "chrome-launcher.js",
"scripts": {
"build": "tsc",
Expand All @@ -19,6 +18,12 @@
"dependencies": {
"@types/core-js": "^0.9.41",
"@types/mkdirp": "^0.3.29",
"@types/node": "6.0.66"
}
"@types/node": "6.0.66",
"lighthouse": "2.1"
},
"version": "0.1.0",
"description": "Launch latest Chrome with the devtools-protocol port open",
"repository": "https://github.com/GoogleChrome/lighthouse/tree/master/chrome-launcher",
"author": "The Chromium Authors",
"license": "Apache-2.0"
}
Loading