[api] add Puppeteer.executablePath() method (#771)

This patch adds Puppeteer.executablePath() method to query the path
of bundled chromium.

Fixes #745
This commit is contained in:
Andrey Lushnikov 2017-09-13 17:39:18 -07:00 committed by GitHub
parent 89e923d5f0
commit d7e673645a
4 changed files with 25 additions and 0 deletions

View File

@ -10,6 +10,7 @@
* [Environment Variables](#environment-variables) * [Environment Variables](#environment-variables)
* [class: Puppeteer](#class-puppeteer) * [class: Puppeteer](#class-puppeteer)
+ [puppeteer.connect(options)](#puppeteerconnectoptions) + [puppeteer.connect(options)](#puppeteerconnectoptions)
+ [puppeteer.executablePath()](#puppeteerexecutablepath)
+ [puppeteer.launch([options])](#puppeteerlaunchoptions) + [puppeteer.launch([options])](#puppeteerlaunchoptions)
* [class: Browser](#class-browser) * [class: Browser](#class-browser)
+ [browser.close()](#browserclose) + [browser.close()](#browserclose)
@ -174,6 +175,9 @@ puppeteer.launch().then(async browser => {
This methods attaches Puppeteer to an existing Chromium instance. This methods attaches Puppeteer to an existing Chromium instance.
#### puppeteer.executablePath()
- returns: <[string]> A path where Puppeteer expects to find bundled Chromium. Chromium might not exist there if the download was skipped with [`PUPPETEER_SKIP_CHROMIUM_DOWNLOAD`](#environment-variables).
#### puppeteer.launch([options]) #### puppeteer.launch([options])
- `options` <[Object]> Set of configurable options to set on the browser. Can have the following fields: - `options` <[Object]> Set of configurable options to set on the browser. Can have the following fields:
- `ignoreHTTPSErrors` <[boolean]> Whether to ignore HTTPS errors during navigation. Defaults to `false`. - `ignoreHTTPSErrors` <[boolean]> Whether to ignore HTTPS errors during navigation. Defaults to `false`.

View File

@ -111,6 +111,14 @@ class Launcher {
} }
} }
/**
* @return {string}
*/
static executablePath() {
const revisionInfo = Downloader.revisionInfo(Downloader.currentPlatform(), ChromiumRevision);
return revisionInfo.executablePath;
}
/** /**
* @param {string} options * @param {string} options
* @return {!Promise<!Browser>} * @return {!Promise<!Browser>}

View File

@ -32,6 +32,13 @@ class Puppeteer {
static connect(options) { static connect(options) {
return Launcher.connect(options); return Launcher.connect(options);
} }
/**
* @return {string}
*/
static executablePath() {
return Launcher.executablePath();
}
} }
module.exports = Puppeteer; module.exports = Puppeteer;

View File

@ -133,6 +133,12 @@ describe('Puppeteer', function() {
originalBrowser.close(); originalBrowser.close();
})); }));
}); });
describe('Puppeteer.executablePath', function() {
it('should work', SX(async function() {
const executablePath = puppeteer.executablePath();
expect(fs.existsSync(executablePath)).toBe(true);
}));
});
}); });
describe('Page', function() { describe('Page', function() {