diff --git a/docs/api.md b/docs/api.md index 0e20758280a..6eec55c17b1 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.defaultArgs()](#puppeteerdefaultargs) * [puppeteer.executablePath()](#puppeteerexecutablepath) * [puppeteer.launch([options])](#puppeteerlaunchoptions) - [class: Browser](#class-browser) @@ -246,6 +247,9 @@ puppeteer.launch().then(async browser => { This methods attaches Puppeteer to an existing Chromium instance. +#### puppeteer.defaultArgs() +- returns: <[Array]<[string]>> The default flags that Chromium will be launched with. + #### 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). @@ -256,6 +260,7 @@ This methods attaches Puppeteer to an existing Chromium instance. - `executablePath` <[string]> Path to a Chromium or Chrome executable to run instead of bundled Chromium. If `executablePath` is a relative path, then it is resolved relative to [current working directory](https://nodejs.org/api/process.html#process_process_cwd). - `slowMo` <[number]> Slows down Puppeteer operations by the specified amount of milliseconds. Useful so that you can see what is going on. - `args` <[Array]<[string]>> Additional arguments to pass to the browser instance. List of Chromium flags can be found [here](http://peter.sh/experiments/chromium-command-line-switches/). + - `ignoreDefaultArgs` <[boolean]> Do not use [`puppeteer.defaultArgs()`](#puppeteerdefaultargs). Dangerous option; use with care. Defaults to `false`. - `handleSIGINT` <[boolean]> Close browser process on Ctrl-C. Defaults to `true`. - `handleSIGTERM` <[boolean]> Close browser process on SIGTERM. Defaults to `true`. - `handleSIGHUP` <[boolean]> Close browser process on SIGHUP. Defaults to `true`. @@ -269,12 +274,12 @@ This methods attaches Puppeteer to an existing Chromium instance. The method launches a browser instance with given arguments. The browser will be closed when the parent node.js process is closed. > **NOTE** Puppeteer can also be used to control the Chrome browser, but it works best with the version of Chromium it is bundled with. There is no - guarantee it will work with any other version. Use `executablePath` option with extreme caution. + guarantee it will work with any other version. Use `executablePath` option with extreme caution. If Google Chrome (rather than Chromium) is preferred, a [Chrome Canary](https://www.google.com/chrome/browser/canary.html) or [Dev Channel](https://www.chromium.org/getting-involved/dev-channel) build is suggested. > > In [puppeteer.launch([options])](#puppeteerlaunchoptions) above, any mention of Chromium also applies to Chrome. > -> See [`this article`](https://www.howtogeek.com/202825/what%E2%80%99s-the-difference-between-chromium-and-chrome/) for a description +> See [`this article`](https://www.howtogeek.com/202825/what%E2%80%99s-the-difference-between-chromium-and-chrome/) for a description of the differences between Chromium and Chrome. [`This article`](https://chromium.googlesource.com/chromium/src/+/lkcr/docs/chromium_browser_vs_google_chrome.md) describes some differences for Linux users. ### class: Browser diff --git a/lib/Launcher.js b/lib/Launcher.js index 728705ea4e7..76311858842 100644 --- a/lib/Launcher.js +++ b/lib/Launcher.js @@ -61,10 +61,13 @@ class Launcher { static async launch(options) { options = Object.assign({}, options || {}); let temporaryUserDataDir = null; - const chromeArguments = [].concat(DEFAULT_ARGS); + const chromeArguments = []; + if (!options.ignoreDefaultArgs) + chromeArguments.push(...DEFAULT_ARGS); + if (options.appMode) options.headless = false; - else + else if (!options.ignoreDefaultArgs) chromeArguments.push(...AUTOMATION_ARGS); if (!options.args || !options.args.some(arg => arg.startsWith('--user-data-dir'))) { @@ -172,6 +175,13 @@ class Launcher { } } + /** + * @return {!Array} + */ + static defaultArgs() { + return DEFAULT_ARGS.concat(AUTOMATION_ARGS); + } + /** * @return {string} */ diff --git a/lib/Puppeteer.js b/lib/Puppeteer.js index 0a44db1d097..ac151f257a9 100644 --- a/lib/Puppeteer.js +++ b/lib/Puppeteer.js @@ -39,6 +39,13 @@ class Puppeteer { static executablePath() { return Launcher.executablePath(); } + + /** + * @return {!Array} + */ + static defaultArgs() { + return Launcher.defaultArgs(); + } } module.exports = Puppeteer; diff --git a/test/test.js b/test/test.js index ea9cc07391a..7bf7c02e0b1 100644 --- a/test/test.js +++ b/test/test.js @@ -202,6 +202,10 @@ describe('Puppeteer', function() { rm(userDataDir); expect(cookie).toBe('foo=true'); }); + it('should return the default chrome arguments', async() => { + const args = puppeteer.defaultArgs(); + expect(args).toContain('--no-first-run'); + }); }); describe('Puppeteer.connect', function() { it('should be able to connect multiple times to the same browser', async({server}) => {