diff --git a/lib/Browser.js b/lib/Browser.js index adf5d13e320..1c516b817d9 100644 --- a/lib/Browser.js +++ b/lib/Browser.js @@ -21,12 +21,13 @@ const EventEmitter = require('events'); class Browser extends EventEmitter { /** * @param {!Connection} connection - * @param {boolean} ignoreHTTPSErrors + * @param {!Object=} options * @param {function():Promise=} closeCallback */ - constructor(connection, ignoreHTTPSErrors, closeCallback) { + constructor(connection, options = {}, closeCallback) { super(); - this._ignoreHTTPSErrors = ignoreHTTPSErrors; + this._ignoreHTTPSErrors = !!options.ignoreHTTPSErrors; + this._appMode = !!options.appMode; this._screenshotTaskQueue = new TaskQueue(); this._connection = connection; this._closeCallback = closeCallback || new Function(); @@ -45,7 +46,7 @@ class Browser extends EventEmitter { async newPage() { const {targetId} = await this._connection.send('Target.createTarget', {url: 'about:blank'}); const client = await this._connection.createSession(targetId); - return await Page.create(client, this._ignoreHTTPSErrors, this._screenshotTaskQueue); + return await Page.create(client, this._ignoreHTTPSErrors, this._appMode, this._screenshotTaskQueue); } /** diff --git a/lib/Launcher.js b/lib/Launcher.js index aacdbe07447..dfc5b50c187 100644 --- a/lib/Launcher.js +++ b/lib/Launcher.js @@ -40,13 +40,15 @@ const DEFAULT_ARGS = [ '--disable-prompt-on-repost', '--disable-sync', '--disable-translate', - '--enable-automation', - '--enable-devtools-experiments', '--metrics-recording-only', '--no-first-run', - '--password-store=basic', '--remote-debugging-port=0', '--safebrowsing-disable-auto-update', +]; + +const AUTOMATION_ARGS = [ + '--enable-automation', + '--password-store=basic', '--use-mock-keychain', ]; @@ -56,9 +58,14 @@ class Launcher { * @return {!Promise} */ static async launch(options) { - options = options || {}; + options = Object.assign({}, options || {}); let temporaryUserDataDir = null; const chromeArguments = [].concat(DEFAULT_ARGS); + if (options.appMode) + options.headless = false; + else + chromeArguments.push(...AUTOMATION_ARGS); + if (!options.args || !options.args.some(arg => arg.startsWith('--user-data-dir'))) { if (!options.userDataDir) temporaryUserDataDir = fs.mkdtempSync(CHROME_PROFILE_PATH); @@ -105,7 +112,7 @@ class Launcher { const connectionDelay = options.slowMo || 0; const browserWSEndpoint = await waitForWSEndpoint(chromeProcess, options.timeout || 30 * 1000); const connection = await Connection.create(browserWSEndpoint, connectionDelay); - return new Browser(connection, !!options.ignoreHTTPSErrors, killChrome); + return new Browser(connection, options, killChrome); } catch (e) { killChrome(); throw e; @@ -150,12 +157,12 @@ class Launcher { } /** - * @param {string} options + * @param {!Object=} options * @return {!Promise} */ - static async connect({browserWSEndpoint, ignoreHTTPSErrors = false}) { - const connection = await Connection.create(browserWSEndpoint); - return new Browser(connection, !!ignoreHTTPSErrors); + static async connect(options = {}) { + const connection = await Connection.create(options.browserWSEndpoint); + return new Browser(connection, options); } } diff --git a/lib/Page.js b/lib/Page.js index e10ca51131f..d6fa1f9c8a3 100644 --- a/lib/Page.js +++ b/lib/Page.js @@ -31,10 +31,11 @@ class Page extends EventEmitter { * @param {!Session} client * @param {string} sessionId * @param {boolean} ignoreHTTPSErrors + * @param {boolean} appMode * @param {!TaskQueue} screenshotTaskQueue * @return {!Promise} */ - static async create(client, ignoreHTTPSErrors, screenshotTaskQueue) { + static async create(client, ignoreHTTPSErrors, appMode, screenshotTaskQueue) { await Promise.all([ client.send('Network.enable', {}), client.send('Page.enable', {}), @@ -46,7 +47,8 @@ class Page extends EventEmitter { const page = new Page(client, ignoreHTTPSErrors, screenshotTaskQueue); await page.goto('about:blank'); // Initialize default page size. - await page.setViewport({width: 800, height: 600}); + if (!appMode) + await page.setViewport({width: 800, height: 600}); return page; }