diff --git a/docs/api.md b/docs/api.md index 22b0b376669..b3200c7fdc6 100644 --- a/docs/api.md +++ b/docs/api.md @@ -10,6 +10,7 @@ * [Environment Variables](#environment-variables) * [class: Puppeteer](#class-puppeteer) + [puppeteer.connect(options)](#puppeteerconnectoptions) + + [puppeteer.executablePath()](#puppeteerexecutablepath) + [puppeteer.launch([options])](#puppeteerlaunchoptions) * [class: Browser](#class-browser) + [browser.close()](#browserclose) @@ -174,6 +175,9 @@ puppeteer.launch().then(async browser => { 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]) - `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`. diff --git a/lib/Launcher.js b/lib/Launcher.js index ecd64b77cae..63b4066dac8 100644 --- a/lib/Launcher.js +++ b/lib/Launcher.js @@ -111,6 +111,14 @@ class Launcher { } } + /** + * @return {string} + */ + static executablePath() { + const revisionInfo = Downloader.revisionInfo(Downloader.currentPlatform(), ChromiumRevision); + return revisionInfo.executablePath; + } + /** * @param {string} options * @return {!Promise} diff --git a/lib/Puppeteer.js b/lib/Puppeteer.js index eaeaf82beec..2caa58be67b 100644 --- a/lib/Puppeteer.js +++ b/lib/Puppeteer.js @@ -32,6 +32,13 @@ class Puppeteer { static connect(options) { return Launcher.connect(options); } + + /** + * @return {string} + */ + static executablePath() { + return Launcher.executablePath(); + } } module.exports = Puppeteer; diff --git a/test/test.js b/test/test.js index a2f5010b74a..5800bd1e91d 100644 --- a/test/test.js +++ b/test/test.js @@ -133,6 +133,12 @@ describe('Puppeteer', function() { 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() {