Skip to content

Commit

Permalink
[api] add Puppeteer.executablePath() method (puppeteer#771)
Browse files Browse the repository at this point in the history
This patch adds Puppeteer.executablePath() method to query the path
of bundled chromium.

Fixes puppeteer#745
  • Loading branch information
aslushnikov authored Sep 14, 2017
1 parent 89e923d commit d7e6736
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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`.
Expand Down
8 changes: 8 additions & 0 deletions lib/Launcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<!Browser>}
Expand Down
7 changes: 7 additions & 0 deletions lib/Puppeteer.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ class Puppeteer {
static connect(options) {
return Launcher.connect(options);
}

/**
* @return {string}
*/
static executablePath() {
return Launcher.executablePath();
}
}

module.exports = Puppeteer;
Expand Down
6 changes: 6 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit d7e6736

Please sign in to comment.