mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
cleanup: Use ES6 default params (#447)
This commit is contained in:
committed by
Andrey Lushnikov
parent
271fd09379
commit
5d6d3e0a81
@@ -47,55 +47,54 @@ const DEFAULT_ARGS = [
|
||||
|
||||
class Launcher {
|
||||
/**
|
||||
* @param {!Object} options
|
||||
* @param {!Object=} options
|
||||
* @return {!Promise<!Browser>}
|
||||
*/
|
||||
static async launch(options) {
|
||||
options = options || {};
|
||||
let userDataDir = [
|
||||
static async launch(options = {}) {
|
||||
const userDataDir = [
|
||||
CHROME_PROFILE_PATH,
|
||||
process.pid,
|
||||
++browserId,
|
||||
crypto.randomBytes(8 / 2).toString('hex') // add random salt 8 characters long.
|
||||
].join('-');
|
||||
|
||||
let chromeArguments = DEFAULT_ARGS.concat([
|
||||
const chromeArguments = DEFAULT_ARGS.concat([
|
||||
`--user-data-dir=${userDataDir}`,
|
||||
]);
|
||||
if (typeof options.headless !== 'boolean' || options.headless) {
|
||||
chromeArguments.push(
|
||||
`--headless`,
|
||||
`--disable-gpu`,
|
||||
`--hide-scrollbars`,
|
||||
'--headless',
|
||||
'--disable-gpu',
|
||||
'--hide-scrollbars',
|
||||
'--mute-audio'
|
||||
);
|
||||
}
|
||||
let chromeExecutable = options.executablePath;
|
||||
if (typeof chromeExecutable !== 'string') {
|
||||
let revisionInfo = Downloader.revisionInfo(Downloader.currentPlatform(), ChromiumRevision);
|
||||
const revisionInfo = Downloader.revisionInfo(Downloader.currentPlatform(), ChromiumRevision);
|
||||
console.assert(revisionInfo.downloaded, `Chromium revision is not downloaded. Run "npm install"`);
|
||||
chromeExecutable = revisionInfo.executablePath;
|
||||
}
|
||||
if (Array.isArray(options.args))
|
||||
chromeArguments.push(...options.args);
|
||||
|
||||
let chromeProcess = childProcess.spawn(chromeExecutable, chromeArguments, {});
|
||||
const chromeProcess = childProcess.spawn(chromeExecutable, chromeArguments, {});
|
||||
if (options.dumpio) {
|
||||
chromeProcess.stdout.pipe(process.stdout);
|
||||
chromeProcess.stderr.pipe(process.stderr);
|
||||
}
|
||||
|
||||
// Cleanup as processes exit.
|
||||
let listeners = [
|
||||
const listeners = [
|
||||
helper.addEventListener(process, 'exit', killChromeAndCleanup),
|
||||
helper.addEventListener(chromeProcess, 'exit', killChromeAndCleanup),
|
||||
];
|
||||
if (options.handleSIGINT !== false)
|
||||
listeners.push(helper.addEventListener(process, 'SIGINT', killChromeAndCleanup));
|
||||
try {
|
||||
let connectionDelay = options.slowMo || 0;
|
||||
let browserWSEndpoint = await waitForWSEndpoint(chromeProcess, options.timeout || 30 * 1000);
|
||||
let connection = await Connection.create(browserWSEndpoint, connectionDelay);
|
||||
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, killChromeAndCleanup);
|
||||
} catch (e) {
|
||||
killChromeAndCleanup();
|
||||
|
||||
Reference in New Issue
Block a user