Skip to content

Commit

Permalink
launcher: support enabling extension loading (#2650)
Browse files Browse the repository at this point in the history
  • Loading branch information
ragingwind authored and brendankenny committed Jul 20, 2017
1 parent 6f53ab9 commit c942d17
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
4 changes: 4 additions & 0 deletions chrome-launcher/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ npm install chrome-launcher
// (optional) Logging level: verbose, info, error, silent
// Default: 'info'
logLevel: string;

// (optional) Enable extension loading
// Default: false
enableExtensions: boolean
};
```

Expand Down
9 changes: 8 additions & 1 deletion chrome-launcher/chrome-launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface Options {
chromePath?: string;
userDataDir?: string;
logLevel?: string;
enableExtensions?: boolean;
}

export interface LaunchedChrome {
Expand Down Expand Up @@ -71,6 +72,7 @@ export class Launcher {
private outFile?: number;
private errFile?: number;
private chromePath?: string;
private enableExtensions?: boolean;
private chromeFlags: string[];
private requestedPort?: number;
private chrome?: childProcess.ChildProcess;
Expand All @@ -94,15 +96,20 @@ export class Launcher {
this.chromeFlags = defaults(this.opts.chromeFlags, []);
this.requestedPort = defaults(this.opts.port, 0);
this.chromePath = this.opts.chromePath;
this.enableExtensions = defaults(this.opts.enableExtensions, false);
}

private get flags() {
const flags = DEFAULT_FLAGS.concat([
let flags = DEFAULT_FLAGS.concat([
`--remote-debugging-port=${this.port}`,
// Place Chrome profile in a custom location we'll rm -rf later
`--user-data-dir=${this.userDataDir}`
]);

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

if (process.platform === 'linux') {
flags.push('--disable-setuid-sandbox');
}
Expand Down
20 changes: 20 additions & 0 deletions chrome-launcher/test/chrome-launcher-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,24 @@ describe('Launcher', () => {
assert.strictEqual(pid, chromeInstance.pid);
await chromeInstance.kill();
});

it('removes --disable-extensions from flags on enableExtensions', async () => {
const spawnStub = stub().returns({pid: 'some_pid'});

const chromeInstance = new Launcher(
{enableExtensions: true},
{fs: fsMock as any, rimraf: spy() as any, spawn: spawnStub as any});
stub(chromeInstance, 'waitUntilReady').returns(Promise.resolve());

chromeInstance.prepare();

try {
await chromeInstance.launch();
} catch (err) {
return Promise.reject(err);
}

const chromeFlags = spawnStub.getCall(0).args[1] as string[];
assert.ok(!chromeFlags.includes('--disable-extensions'));
});
});
2 changes: 1 addition & 1 deletion chrome-launcher/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"target": "es2016",
"noImplicitAny": true,
"inlineSourceMap": true,
"noEmitOnError": false,
Expand Down

0 comments on commit c942d17

Please sign in to comment.