Skip to content

Commit

Permalink
Revert defaultFlags change (#70) (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirish committed Sep 17, 2018
1 parent c885065 commit 7d1f7a5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 25 deletions.
10 changes: 2 additions & 8 deletions README.md
Expand Up @@ -64,10 +64,9 @@ npm install chrome-launcher
// Default: 'silent'
logLevel: 'verbose'|'info'|'error'|'silent';

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

// (optional) Interval in ms, which defines how often launcher checks browser port to be ready.
// Default: 500
Expand Down Expand Up @@ -100,11 +99,6 @@ chrome.pid: number;
chrome.process: childProcess
```

### `.defaultFlags()`

Returns an `Array<string>` of the default [flags](docs/chrome-flags-for-tools.md) 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

Expand Down
27 changes: 13 additions & 14 deletions src/chrome-launcher.ts
Expand Up @@ -35,7 +35,7 @@ export interface Options {
chromePath?: string;
userDataDir?: string|boolean;
logLevel?: 'verbose'|'info'|'error'|'silent';
ignoreDefaultFlags?: boolean;
enableExtensions?: boolean;
connectionPollInterval?: number;
maxConnectionRetries?: number;
envVars?: {[key: string]: string|undefined};
Expand Down Expand Up @@ -95,7 +95,7 @@ class Launcher {
private outFile?: number;
private errFile?: number;
private chromePath?: string;
private ignoreDefaultFlags?: boolean;
private enableExtensions?: boolean;
private chromeFlags: string[];
private requestedPort?: number;
private connectionPollInterval: number;
Expand Down Expand Up @@ -123,7 +123,7 @@ class Launcher {
this.chromeFlags = defaults(this.opts.chromeFlags, []);
this.requestedPort = defaults(this.opts.port, 0);
this.chromePath = this.opts.chromePath;
this.ignoreDefaultFlags = defaults(this.opts.ignoreDefaultFlags, false);
this.enableExtensions = defaults(this.opts.enableExtensions, false);
this.connectionPollInterval = defaults(this.opts.connectionPollInterval, 500);
this.maxConnectionRetries = defaults(this.opts.maxConnectionRetries, 50);
this.envVars = defaults(opts.envVars, Object.assign({}, process.env));
Expand All @@ -142,29 +142,28 @@ class Launcher {
}

private get flags() {
const flags = this.ignoreDefaultFlags ? [] : DEFAULT_FLAGS;
flags.push(`--remote-debugging-port=${this.port}`);

if (getPlatform() === 'linux') {
flags.push('--disable-setuid-sandbox');
}
let flags = DEFAULT_FLAGS.concat([`--remote-debugging-port=${this.port}`]);

// Place Chrome profile in a custom location we'll rm -rf later
if (!this.useDefaultProfile) {
// Place Chrome profile in a custom location we'll rm -rf later
// If in WSL, we need to use the Windows format
flags.push(`--user-data-dir=${isWsl ? toWinDirFormat(this.userDataDir) : this.userDataDir}`);
}

if (this.enableExtensions) {
flags = flags.filter(flag => flag !== '--disable-extensions');
}

if (getPlatform() === 'linux') {
flags.push('--disable-setuid-sandbox');
}

flags.push(...this.chromeFlags);
flags.push(this.startingUrl);

return flags;
}

defaultFlags() {
return DEFAULT_FLAGS;
}

// Wrapper function to enable easy testing.
makeTmpDir() {
return makeTmpDir();
Expand Down
18 changes: 15 additions & 3 deletions test/chrome-launcher-test.ts
Expand Up @@ -107,14 +107,16 @@ describe('Launcher', () => {
await chromeInstance.kill();
});

it('gets all default flags', async () => {
// TODO: restore when the ignoreDefaultFlags commit is reintroduced.
it.skip('gets all default flags', async () => {
const chromeInstance = new Launcher();
const flags = chromeInstance.defaultFlags();
assert.ok(flags.length);
assert.deepStrictEqual(flags, DEFAULT_FLAGS);
});

it('removes all default flags', async () => {
// TODO: restore when the ignoreDefaultFlags commit is reintroduced.
it.skip('removes all default flags', async () => {
const spawnStub = await launchChromeWithOpts({ignoreDefaultFlags: true});
const chromeFlags = spawnStub.getCall(0).args[1] as string[];
assert.ok(!chromeFlags.includes('--disable-extensions'));
Expand All @@ -139,7 +141,17 @@ describe('Launcher', () => {
assert.deepEqual(spawnOptions.env, envVars);
});

it('ensure specific flags are present when passed and defaults are ignored', async () => {
// TODO: remove when the ignoreDefaultFlags commit is reintroduced.
it('removes --disable-extensions from flags on enableExtensions', async () => {
const spawnStub = await launchChromeWithOpts({
enableExtensions: true
});
const chromeFlags = spawnStub.getCall(0).args[1] as string[];
assert.ok(!chromeFlags.includes('--disable-extensions'));
});

// TODO: restore when the ignoreDefaultFlags commit is reintroduced.
it.skip('ensure specific flags are present when passed and defaults are ignored', async () => {
const spawnStub = await launchChromeWithOpts({
ignoreDefaultFlags: true,
chromeFlags: ['--disable-extensions', '--mute-audio', '--no-first-run']
Expand Down

0 comments on commit 7d1f7a5

Please sign in to comment.