mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
feat(Launcher): introduce appMode option
The patch introduces a new appMode option to the launcher. This is an experimental option, thus we don't document it.
This commit is contained in:
parent
1c292e9253
commit
a6cf8237b8
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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<!Browser>}
|
||||
*/
|
||||
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<!Browser>}
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<!Page>}
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user