From 7d1f7a5aac64037a949991206a85ff4faa0304db Mon Sep 17 00:00:00 2001 From: Paul Irish Date: Mon, 17 Sep 2018 14:54:20 -0700 Subject: [PATCH] Revert defaultFlags change (#70) (#122) --- README.md | 10 ++-------- src/chrome-launcher.ts | 27 +++++++++++++-------------- test/chrome-launcher-test.ts | 18 +++++++++++++++--- 3 files changed, 30 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 1f4a895d1..76579dcdc 100644 --- a/README.md +++ b/README.md @@ -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 @@ -100,11 +99,6 @@ chrome.pid: number; chrome.process: childProcess ``` -### `.defaultFlags()` - -Returns an `Array` 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 diff --git a/src/chrome-launcher.ts b/src/chrome-launcher.ts index 0a2371ca4..1e02c7a3a 100644 --- a/src/chrome-launcher.ts +++ b/src/chrome-launcher.ts @@ -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}; @@ -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; @@ -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)); @@ -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(); diff --git a/test/chrome-launcher-test.ts b/test/chrome-launcher-test.ts index 3e7055260..38df29ccb 100644 --- a/test/chrome-launcher-test.ts +++ b/test/chrome-launcher-test.ts @@ -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')); @@ -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']