mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
feat(Launcher): introduce pipe option (#2288)
This patch introduces a new `pipe` option to the launcher to connect over a pipe. In certain environments, exposing web socket for remote debugging is a security risk. Pipe connection eliminates this risk.
This commit is contained in:
committed by
Andrey Lushnikov
parent
f51a315911
commit
94c32e4bc8
@@ -50,12 +50,11 @@ const AUTOMATION_ARGS = [
|
||||
'--enable-automation',
|
||||
'--password-store=basic',
|
||||
'--use-mock-keychain',
|
||||
'--remote-debugging-port=0',
|
||||
];
|
||||
|
||||
class Launcher {
|
||||
/**
|
||||
* @param {!Object=} options
|
||||
* @param {!LaunchOptions=} options
|
||||
* @return {!Promise<!Browser>}
|
||||
*/
|
||||
static async launch(options) {
|
||||
@@ -67,11 +66,14 @@ class Launcher {
|
||||
chromeArguments.push(...DEFAULT_ARGS);
|
||||
if (options.appMode) {
|
||||
options.headless = false;
|
||||
chromeArguments.push('--remote-debugging-pipe');
|
||||
options.pipe = true;
|
||||
} else if (!options.ignoreDefaultArgs) {
|
||||
chromeArguments.push(...AUTOMATION_ARGS);
|
||||
}
|
||||
|
||||
if (!options.ignoreDefaultArgs || !chromeArguments.some(argument => argument.startsWith('--remote-debugging-')))
|
||||
chromeArguments.push(options.pipe ? '--remote-debugging-pipe' : '--remote-debugging-port=0');
|
||||
|
||||
if (!options.args || !options.args.some(arg => arg.startsWith('--user-data-dir'))) {
|
||||
if (!options.userDataDir)
|
||||
temporaryUserDataDir = await mkdtempAsync(CHROME_PROFILE_PATH);
|
||||
@@ -100,8 +102,10 @@ class Launcher {
|
||||
if (Array.isArray(options.args))
|
||||
chromeArguments.push(...options.args);
|
||||
|
||||
|
||||
const usePipe = chromeArguments.includes('--remote-debugging-pipe');
|
||||
const stdio = ['pipe', 'pipe', 'pipe'];
|
||||
if (options.appMode)
|
||||
if (usePipe)
|
||||
stdio.push('pipe', 'pipe');
|
||||
const chromeProcess = childProcess.spawn(
|
||||
chromeExecutable,
|
||||
@@ -147,7 +151,7 @@ class Launcher {
|
||||
let connection = null;
|
||||
try {
|
||||
const connectionDelay = options.slowMo || 0;
|
||||
if (!options.appMode) {
|
||||
if (!usePipe) {
|
||||
const timeout = helper.isNumber(options.timeout) ? options.timeout : 30000;
|
||||
const browserWSEndpoint = await waitForWSEndpoint(chromeProcess, timeout);
|
||||
connection = await Connection.createForWebSocket(browserWSEndpoint, connectionDelay);
|
||||
@@ -277,4 +281,25 @@ function waitForWSEndpoint(chromeProcess, timeout) {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @typedef {Object} LaunchOptions
|
||||
* @property {boolean=} ignoreHTTPSErrors
|
||||
* @property {boolean=} headless
|
||||
* @property {string=} executablePath
|
||||
* @property {number=} slowMo
|
||||
* @property {!Array<string>=} args
|
||||
* @property {boolean=} ignoreDefaultArgs
|
||||
* @property {boolean=} handleSIGINT
|
||||
* @property {boolean=} handleSIGTERM
|
||||
* @property {boolean=} handleSIGHUP
|
||||
* @property {number=} timeout
|
||||
* @property {boolean=} dumpio
|
||||
* @property {string=} userDataDir
|
||||
* @property {!Object<string, string | undefined>=} env
|
||||
* @property {boolean=} devtools
|
||||
* @property {boolean=} pipe
|
||||
* @property {boolean=} appMode
|
||||
*/
|
||||
|
||||
|
||||
module.exports = Launcher;
|
||||
|
||||
Reference in New Issue
Block a user