From f1aa18af4e713abfb170e1f9f1d3a3d378b32987 Mon Sep 17 00:00:00 2001 From: Vse Mozhet Byt Date: Tue, 10 Oct 2017 03:25:25 +0300 Subject: [PATCH] feat(Launcher): add devtools option (#953) This patch adds a `devtools` option to the launcher that adds the `--auto-open-devtools-for-tabs` argument to the launched chrome. Fixes #864. --- docs/api.md | 3 ++- lib/Launcher.js | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/api.md b/docs/api.md index 264175be4535d..715b1f8d20eb1 100644 --- a/docs/api.md +++ b/docs/api.md @@ -211,7 +211,7 @@ This methods attaches Puppeteer to an existing Chromium instance. #### 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`. - - `headless` <[boolean]> Whether to run Chromium in [headless mode](https://developers.google.com/web/updates/2017/04/headless-chrome). Defaults to `true`. + - `headless` <[boolean]> Whether to run Chromium in [headless mode](https://developers.google.com/web/updates/2017/04/headless-chrome). Defaults to `true` unless the `devtools` option is `true`. - `executablePath` <[string]> Path to a Chromium 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 Chromium instance. List of Chromium flags can be found [here](http://peter.sh/experiments/chromium-command-line-switches/). @@ -220,6 +220,7 @@ This methods attaches Puppeteer to an existing Chromium instance. - `dumpio` <[boolean]> Whether to pipe browser process stdout and stderr into `process.stdout` and `process.stderr`. Defaults to `false`. - `userDataDir` <[string]> Path to a [User Data Directory](https://chromium.googlesource.com/chromium/src/+/master/docs/user_data_dir.md). - `env` <[Object]> Specify environment variables that will be visible to Chromium. Defaults to `process.env`. + - `devtools` <[boolean]> Wether to auto-open DevTools window for each tab. If this option is `true`, the `headless` option will be set `false`. - returns: <[Promise]<[Browser]>> Promise which resolves to browser instance. The method launches a browser instance with given arguments. The browser will be closed when the parent node.js process is closed. diff --git a/lib/Launcher.js b/lib/Launcher.js index c906125477b17..a6e8cd9dff54a 100644 --- a/lib/Launcher.js +++ b/lib/Launcher.js @@ -72,6 +72,10 @@ class Launcher { chromeArguments.push(`--user-data-dir=${options.userDataDir || temporaryUserDataDir}`); } + if (options.devtools === true) { + chromeArguments.push('--auto-open-devtools-for-tabs'); + options.headless = false; + } if (typeof options.headless !== 'boolean' || options.headless) { chromeArguments.push( '--headless',