diff --git a/README.md b/README.md index 0bb85d66c..873d63a09 100644 --- a/README.md +++ b/README.md @@ -106,6 +106,12 @@ Returns an `Array` of the default [flags](docs/chrome-flags-for-tools.md Note: This array will exclude the following flags: `--remote-debugging-port` `--disable-setuid-sandbox` `--user-data-dir`. +### `ChromeLauncher.getInstallations()` + +Returns an `Array` of paths to available Chrome installations. When `chromePath` is not provided to `.launch()`, the first installation returned from this method is used instead. + +Note: This method performs synchronous I/O operations. + ## Examples #### Launching chrome: diff --git a/src/chrome-launcher.ts b/src/chrome-launcher.ts index 94252cf2d..e16427c5d 100644 --- a/src/chrome-launcher.ts +++ b/src/chrome-launcher.ts @@ -167,6 +167,10 @@ class Launcher { return DEFAULT_FLAGS.slice(); } + static getInstallations() { + return chromeFinder[getPlatform() as SupportedPlatforms](); + } + // Wrapper function to enable easy testing. makeTmpDir() { return makeTmpDir(); @@ -205,7 +209,7 @@ class Launcher { } } if (this.chromePath === undefined) { - const installations = await chromeFinder[getPlatform() as SupportedPlatforms](); + const installations = Launcher.getInstallations(); if (installations.length === 0) { throw new ChromeNotInstalledError(); } diff --git a/test/chrome-launcher-test.ts b/test/chrome-launcher-test.ts index cd08b5e65..8005303a9 100644 --- a/test/chrome-launcher-test.ts +++ b/test/chrome-launcher-test.ts @@ -133,6 +133,12 @@ describe('Launcher', () => { assert.ok(!chromeFlags.includes('--disable-extensions')); }); + it('searches for available installations', async () => { + const installations = Launcher.getInstallations(); + assert.ok(Array.isArray(installations)); + assert.ok(installations.length >= 1); + }); + it('removes --user-data-dir if userDataDir is false', async () => { const spawnStub = await launchChromeWithOpts(); const chromeFlags = spawnStub.getCall(0).args[1] as string[];