123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895 |
- const os = require('os');
- const path = require('path');
- const http = require('http');
- const https = require('https');
- const URL = require('url');
- const removeFolder = require('rimraf');
- const childProcess = require('child_process');
- const BrowserFetcher = require('./BrowserFetcher');
- const {Connection} = require('./Connection');
- const {Browser} = require('./Browser');
- const readline = require('readline');
- const fs = require('fs');
- const {helper, assert, debugError} = require('./helper');
- const debugLauncher = require('debug')(`puppeteer:launcher`);
- const {TimeoutError} = require('./Errors');
- const WebSocketTransport = require('./WebSocketTransport');
- const PipeTransport = require('./PipeTransport');
- const mkdtempAsync = helper.promisify(fs.mkdtemp);
- const removeFolderAsync = helper.promisify(removeFolder);
- const writeFileAsync = helper.promisify(fs.writeFile);
- class BrowserRunner {
-
- constructor(executablePath, processArguments, tempDirectory) {
- this._executablePath = executablePath;
- this._processArguments = processArguments;
- this._tempDirectory = tempDirectory;
- this.proc = null;
- this.connection = null;
- this._closed = true;
- this._listeners = [];
- }
-
- start(options = {}) {
- const {
- handleSIGINT,
- handleSIGTERM,
- handleSIGHUP,
- dumpio,
- env,
- pipe
- } = options;
-
- let stdio = ['pipe', 'pipe', 'pipe'];
- if (pipe) {
- if (dumpio)
- stdio = ['ignore', 'pipe', 'pipe', 'pipe', 'pipe'];
- else
- stdio = ['ignore', 'ignore', 'ignore', 'pipe', 'pipe'];
- }
- assert(!this.proc, 'This process has previously been started.');
- debugLauncher(`Calling ${this._executablePath} ${this._processArguments.join(' ')}`);
- this.proc = childProcess.spawn(
- this._executablePath,
- this._processArguments,
- {
-
-
-
- detached: process.platform !== 'win32',
- env,
- stdio
- }
- );
- if (dumpio) {
- this.proc.stderr.pipe(process.stderr);
- this.proc.stdout.pipe(process.stdout);
- }
- this._closed = false;
- this._processClosing = new Promise((fulfill, reject) => {
- this.proc.once('exit', () => {
- this._closed = true;
-
- if (this._tempDirectory) {
- removeFolderAsync(this._tempDirectory)
- .then(() => fulfill())
- .catch(err => console.error(err));
- } else {
- fulfill();
- }
- });
- });
- this._listeners = [ helper.addEventListener(process, 'exit', this.kill.bind(this)) ];
- if (handleSIGINT)
- this._listeners.push(helper.addEventListener(process, 'SIGINT', () => { this.kill(); process.exit(130); }));
- if (handleSIGTERM)
- this._listeners.push(helper.addEventListener(process, 'SIGTERM', this.close.bind(this)));
- if (handleSIGHUP)
- this._listeners.push(helper.addEventListener(process, 'SIGHUP', this.close.bind(this)));
- }
-
- close() {
- if (this._closed)
- return Promise.resolve();
- helper.removeEventListeners(this._listeners);
- if (this._tempDirectory) {
- this.kill();
- } else if (this.connection) {
-
- this.connection.send('Browser.close').catch(error => {
- debugError(error);
- this.kill();
- });
- }
- return this._processClosing;
- }
-
- kill() {
- helper.removeEventListeners(this._listeners);
- if (this.proc && this.proc.pid && !this.proc.killed && !this._closed) {
- try {
- if (process.platform === 'win32')
- childProcess.execSync(`taskkill /pid ${this.proc.pid} /T /F`);
- else
- process.kill(-this.proc.pid, 'SIGKILL');
- } catch (error) {
-
- }
- }
-
- try {
- removeFolder.sync(this._tempDirectory);
- } catch (error) { }
- }
-
- async setupConnection(options) {
- const {
- usePipe,
- timeout,
- slowMo,
- preferredRevision
- } = options;
- if (!usePipe) {
- const browserWSEndpoint = await waitForWSEndpoint(this.proc, timeout, preferredRevision);
- const transport = await WebSocketTransport.create(browserWSEndpoint);
- this.connection = new Connection(browserWSEndpoint, transport, slowMo);
- } else {
- const transport = new PipeTransport((this.proc.stdio[3]), (this.proc.stdio[4]));
- this.connection = new Connection('', transport, slowMo);
- }
- return this.connection;
- }
- }
- class ChromeLauncher {
-
- constructor(projectRoot, preferredRevision, isPuppeteerCore) {
- this._projectRoot = projectRoot;
- this._preferredRevision = preferredRevision;
- this._isPuppeteerCore = isPuppeteerCore;
- }
-
- async launch(options = {}) {
- const {
- ignoreDefaultArgs = false,
- args = [],
- dumpio = false,
- executablePath = null,
- pipe = false,
- env = process.env,
- handleSIGINT = true,
- handleSIGTERM = true,
- handleSIGHUP = true,
- ignoreHTTPSErrors = false,
- defaultViewport = {width: 800, height: 600},
- slowMo = 0,
- timeout = 30000
- } = options;
- const profilePath = path.join(os.tmpdir(), 'puppeteer_dev_chrome_profile-');
- const chromeArguments = [];
- if (!ignoreDefaultArgs)
- chromeArguments.push(...this.defaultArgs(options));
- else if (Array.isArray(ignoreDefaultArgs))
- chromeArguments.push(...this.defaultArgs(options).filter(arg => !ignoreDefaultArgs.includes(arg)));
- else
- chromeArguments.push(...args);
- let temporaryUserDataDir = null;
- if (!chromeArguments.some(argument => argument.startsWith('--remote-debugging-')))
- chromeArguments.push(pipe ? '--remote-debugging-pipe' : '--remote-debugging-port=0');
- if (!chromeArguments.some(arg => arg.startsWith('--user-data-dir'))) {
- temporaryUserDataDir = await mkdtempAsync(profilePath);
- chromeArguments.push(`--user-data-dir=${temporaryUserDataDir}`);
- }
- let chromeExecutable = executablePath;
- if (!executablePath) {
- const {missingText, executablePath} = resolveExecutablePath(this);
- if (missingText)
- throw new Error(missingText);
- chromeExecutable = executablePath;
- }
- const usePipe = chromeArguments.includes('--remote-debugging-pipe');
- const runner = new BrowserRunner(chromeExecutable, chromeArguments, temporaryUserDataDir);
- runner.start({handleSIGHUP, handleSIGTERM, handleSIGINT, dumpio, env, pipe: usePipe});
- try {
- const connection = await runner.setupConnection({usePipe, timeout, slowMo, preferredRevision: this._preferredRevision});
- const browser = await Browser.create(connection, [], ignoreHTTPSErrors, defaultViewport, runner.proc, runner.close.bind(runner));
- await browser.waitForTarget(t => t.type() === 'page');
- return browser;
- } catch (error) {
- runner.kill();
- throw error;
- }
- }
-
- defaultArgs(options = {}) {
- const chromeArguments = [
- '--disable-background-networking',
- '--enable-features=NetworkService,NetworkServiceInProcess',
- '--disable-background-timer-throttling',
- '--disable-backgrounding-occluded-windows',
- '--disable-breakpad',
- '--disable-client-side-phishing-detection',
- '--disable-component-extensions-with-background-pages',
- '--disable-default-apps',
- '--disable-dev-shm-usage',
- '--disable-extensions',
- '--disable-features=TranslateUI',
- '--disable-hang-monitor',
- '--disable-ipc-flooding-protection',
- '--disable-popup-blocking',
- '--disable-prompt-on-repost',
- '--disable-renderer-backgrounding',
- '--disable-sync',
- '--force-color-profile=srgb',
- '--metrics-recording-only',
- '--no-first-run',
- '--enable-automation',
- '--password-store=basic',
- '--use-mock-keychain',
- ];
- const {
- devtools = false,
- headless = !devtools,
- args = [],
- userDataDir = null
- } = options;
- if (userDataDir)
- chromeArguments.push(`--user-data-dir=${userDataDir}`);
- if (devtools)
- chromeArguments.push('--auto-open-devtools-for-tabs');
- if (headless) {
- chromeArguments.push(
- '--headless',
- '--hide-scrollbars',
- '--mute-audio'
- );
- }
- if (args.every(arg => arg.startsWith('-')))
- chromeArguments.push('about:blank');
- chromeArguments.push(...args);
- return chromeArguments;
- }
-
- executablePath() {
- return resolveExecutablePath(this).executablePath;
- }
-
- get product() {
- return 'chrome';
- }
-
- async connect(options) {
- const {
- browserWSEndpoint,
- browserURL,
- ignoreHTTPSErrors = false,
- defaultViewport = {width: 800, height: 600},
- transport,
- slowMo = 0,
- } = options;
- assert(Number(!!browserWSEndpoint) + Number(!!browserURL) + Number(!!transport) === 1, 'Exactly one of browserWSEndpoint, browserURL or transport must be passed to puppeteer.connect');
- let connection = null;
- if (transport) {
- connection = new Connection('', transport, slowMo);
- } else if (browserWSEndpoint) {
- const connectionTransport = await WebSocketTransport.create(browserWSEndpoint);
- connection = new Connection(browserWSEndpoint, connectionTransport, slowMo);
- } else if (browserURL) {
- const connectionURL = await getWSEndpoint(browserURL);
- const connectionTransport = await WebSocketTransport.create(connectionURL);
- connection = new Connection(connectionURL, connectionTransport, slowMo);
- }
- const {browserContextIds} = await connection.send('Target.getBrowserContexts');
- return Browser.create(connection, browserContextIds, ignoreHTTPSErrors, defaultViewport, null, () => connection.send('Browser.close').catch(debugError));
- }
- }
- class FirefoxLauncher {
-
- constructor(projectRoot, preferredRevision, isPuppeteerCore) {
- this._projectRoot = projectRoot;
- this._preferredRevision = preferredRevision;
- this._isPuppeteerCore = isPuppeteerCore;
- }
-
- async launch(options = {}) {
- const {
- ignoreDefaultArgs = false,
- args = [],
- dumpio = false,
- executablePath = null,
- pipe = false,
- env = process.env,
- handleSIGINT = true,
- handleSIGTERM = true,
- handleSIGHUP = true,
- ignoreHTTPSErrors = false,
- defaultViewport = {width: 800, height: 600},
- slowMo = 0,
- timeout = 30000,
- extraPrefsFirefox = {}
- } = options;
- const firefoxArguments = [];
- if (!ignoreDefaultArgs)
- firefoxArguments.push(...this.defaultArgs(options));
- else if (Array.isArray(ignoreDefaultArgs))
- firefoxArguments.push(...this.defaultArgs(options).filter(arg => !ignoreDefaultArgs.includes(arg)));
- else
- firefoxArguments.push(...args);
- let temporaryUserDataDir = null;
- if (!firefoxArguments.includes('-profile') && !firefoxArguments.includes('--profile')) {
- temporaryUserDataDir = await this._createProfile(extraPrefsFirefox);
- firefoxArguments.push('--profile');
- firefoxArguments.push(temporaryUserDataDir);
- }
- let executable = executablePath;
- if (!executablePath) {
- const {missingText, executablePath} = resolveExecutablePath(this);
- if (missingText)
- throw new Error(missingText);
- executable = executablePath;
- }
- const runner = new BrowserRunner(executable, firefoxArguments, temporaryUserDataDir);
- runner.start({handleSIGHUP, handleSIGTERM, handleSIGINT, dumpio, env, pipe});
- try {
- const connection = await runner.setupConnection({usePipe: pipe, timeout, slowMo, preferredRevision: this._preferredRevision});
- const browser = await Browser.create(connection, [], ignoreHTTPSErrors, defaultViewport, runner.proc, runner.close.bind(runner));
- await browser.waitForTarget(t => t.type() === 'page');
- return browser;
- } catch (error) {
- runner.kill();
- throw error;
- }
- }
-
- async connect(options) {
- const {
- browserWSEndpoint,
- browserURL,
- ignoreHTTPSErrors = false,
- defaultViewport = {width: 800, height: 600},
- transport,
- slowMo = 0,
- } = options;
- assert(Number(!!browserWSEndpoint) + Number(!!browserURL) + Number(!!transport) === 1, 'Exactly one of browserWSEndpoint, browserURL or transport must be passed to puppeteer.connect');
- let connection = null;
- if (transport) {
- connection = new Connection('', transport, slowMo);
- } else if (browserWSEndpoint) {
- const connectionTransport = await WebSocketTransport.create(browserWSEndpoint);
- connection = new Connection(browserWSEndpoint, connectionTransport, slowMo);
- } else if (browserURL) {
- const connectionURL = await getWSEndpoint(browserURL);
- const connectionTransport = await WebSocketTransport.create(connectionURL);
- connection = new Connection(connectionURL, connectionTransport, slowMo);
- }
- const {browserContextIds} = await connection.send('Target.getBrowserContexts');
- return Browser.create(connection, browserContextIds, ignoreHTTPSErrors, defaultViewport, null, () => connection.send('Browser.close').catch(debugError));
- }
-
- executablePath() {
- const executablePath = process.env.PUPPETEER_EXECUTABLE_PATH || process.env.npm_config_puppeteer_executable_path || process.env.npm_package_config_puppeteer_executable_path;
-
- if (!executablePath)
- throw new Error('Please set PUPPETEER_EXECUTABLE_PATH to a Firefox binary.');
- return executablePath;
- }
-
- get product() {
- return 'firefox';
- }
-
- defaultArgs(options = {}) {
- const firefoxArguments = [
- '--remote-debugging-port=0',
- '--no-remote',
- '--foreground',
- ];
- const {
- devtools = false,
- headless = !devtools,
- args = [],
- userDataDir = null
- } = options;
- if (userDataDir) {
- firefoxArguments.push('--profile');
- firefoxArguments.push(userDataDir);
- }
- if (headless)
- firefoxArguments.push('--headless');
- if (devtools)
- firefoxArguments.push('--devtools');
- if (args.every(arg => arg.startsWith('-')))
- firefoxArguments.push('about:blank');
- firefoxArguments.push(...args);
- return firefoxArguments;
- }
-
- async _createProfile(extraPrefs) {
- const profilePath = await mkdtempAsync(path.join(os.tmpdir(), 'puppeteer_dev_firefox_profile-'));
- const prefsJS = [];
- const userJS = [];
- const server = 'dummy.test';
- const defaultPreferences = {
-
- 'app.normandy.api_url': '',
-
- 'app.update.checkInstallTime': false,
-
- 'app.update.disabledForTesting': true,
-
- 'apz.content_response_timeout': 60000,
-
-
- 'browser.contentblocking.features.standard': '-tp,tpPrivate,cookieBehavior0,-cm,-fp',
-
-
-
- 'browser.dom.window.dump.enabled': true,
-
- 'browser.newtabpage.activity-stream.feeds.section.topstories': false,
-
- 'browser.newtabpage.enabled': false,
-
-
- 'browser.pagethumbnails.capturing_disabled': true,
-
- 'browser.safebrowsing.blockedURIs.enabled': false,
- 'browser.safebrowsing.downloads.enabled': false,
- 'browser.safebrowsing.malware.enabled': false,
- 'browser.safebrowsing.passwords.enabled': false,
- 'browser.safebrowsing.phishing.enabled': false,
-
- 'browser.search.update': false,
-
- 'browser.sessionstore.resume_from_crash': false,
-
- 'browser.shell.checkDefaultBrowser': false,
-
- 'browser.startup.homepage': 'about:blank',
-
- 'browser.startup.homepage_override.mstone': 'ignore',
-
- 'browser.startup.page': 0,
-
-
-
- 'browser.tabs.disableBackgroundZombification': false,
-
- 'browser.tabs.warnOnCloseOtherTabs': false,
-
- 'browser.tabs.warnOnOpen': false,
-
- 'browser.uitour.enabled': false,
-
-
- 'browser.urlbar.suggest.searches': false,
-
- 'browser.usedOnWindows10.introURL': '',
-
- 'browser.warnOnQuit': false,
-
-
- 'datareporting.healthreport.about.reportUrl': `http://${server}/dummy/abouthealthreport/`,
- 'datareporting.healthreport.documentServerURI': `http://${server}/dummy/healthreport/`,
- 'datareporting.healthreport.logging.consoleEnabled': false,
- 'datareporting.healthreport.service.enabled': false,
- 'datareporting.healthreport.service.firstRun': false,
- 'datareporting.healthreport.uploadEnabled': false,
- 'datareporting.policy.dataSubmissionEnabled': false,
- 'datareporting.policy.dataSubmissionPolicyAccepted': false,
- 'datareporting.policy.dataSubmissionPolicyBypassNotification': true,
-
-
- 'devtools.jsonview.enabled': false,
-
- 'dom.disable_open_during_load': false,
-
-
- 'dom.file.createInChild': true,
-
- 'dom.ipc.reportProcessHangs': false,
-
- 'dom.max_chrome_script_run_time': 0,
- 'dom.max_script_run_time': 0,
-
-
- 'extensions.autoDisableScopes': 0,
- 'extensions.enabledScopes': 5,
-
- 'extensions.getAddons.cache.enabled': false,
-
- 'extensions.installDistroAddons': false,
-
- 'extensions.screenshots.disabled': true,
-
- 'extensions.update.enabled': false,
-
- 'extensions.update.notifyUser': false,
-
- 'extensions.webservice.discoverURL': `http://${server}/dummy/discoveryURL`,
-
- 'focusmanager.testmode': true,
-
- 'general.useragent.updates.enabled': false,
-
-
- 'geo.provider.testing': true,
-
- 'geo.wifi.scan': false,
-
- 'hangmonitor.timeout': 0,
-
- 'javascript.options.showInConsole': true,
-
- 'media.gmp-manager.updateEnabled': false,
-
-
- 'network.cookie.cookieBehavior': 0,
-
- 'network.http.prompt-temp-redirect': false,
-
-
- 'network.http.speculative-parallel-limit': 0,
-
- 'network.manage-offline-status': false,
-
- 'network.sntp.pools': server,
-
- 'plugin.state.flash': 0,
- 'privacy.trackingprotection.enabled': false,
-
-
- 'remote.enabled': true,
-
- 'security.certerrors.mitm.priming.enabled': false,
-
-
- 'security.fileuri.strict_origin_policy': false,
-
- 'security.notification_enable_delay': 0,
-
- 'services.settings.server': `http://${server}/dummy/blocklist/`,
-
-
- 'signon.autofillForms': false,
-
-
- 'signon.rememberSignons': false,
-
- 'startup.homepage_welcome_url': 'about:blank',
-
- 'startup.homepage_welcome_url.additional': '',
-
- 'toolkit.cosmeticAnimations.enabled': false,
-
- 'toolkit.telemetry.server': `https://${server}/dummy/telemetry/`,
-
- 'toolkit.startup.max_resumed_crashes': -1,
- };
- Object.assign(defaultPreferences, extraPrefs);
- for (const [key, value] of Object.entries(defaultPreferences))
- userJS.push(`user_pref(${JSON.stringify(key)}, ${JSON.stringify(value)});`);
- await writeFileAsync(path.join(profilePath, 'user.js'), userJS.join('\n'));
- await writeFileAsync(path.join(profilePath, 'prefs.js'), prefsJS.join('\n'));
- return profilePath;
- }
- }
- function waitForWSEndpoint(browserProcess, timeout, preferredRevision) {
- return new Promise((resolve, reject) => {
- const rl = readline.createInterface({ input: browserProcess.stderr });
- let stderr = '';
- const listeners = [
- helper.addEventListener(rl, 'line', onLine),
- helper.addEventListener(rl, 'close', () => onClose()),
- helper.addEventListener(browserProcess, 'exit', () => onClose()),
- helper.addEventListener(browserProcess, 'error', error => onClose(error))
- ];
- const timeoutId = timeout ? setTimeout(onTimeout, timeout) : 0;
-
- function onClose(error) {
- cleanup();
- reject(new Error([
- 'Failed to launch the browser process!' + (error ? ' ' + error.message : ''),
- stderr,
- '',
- 'TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/master/docs/troubleshooting.md',
- '',
- ].join('\n')));
- }
- function onTimeout() {
- cleanup();
- reject(new TimeoutError(`Timed out after ${timeout} ms while trying to connect to the browser! Only Chrome at revision r${preferredRevision} is guaranteed to work.`));
- }
-
- function onLine(line) {
- stderr += line + '\n';
- const match = line.match(/^DevTools listening on (ws:\/\/.*)$/);
- if (!match)
- return;
- cleanup();
- resolve(match[1]);
- }
- function cleanup() {
- if (timeoutId)
- clearTimeout(timeoutId);
- helper.removeEventListeners(listeners);
- }
- });
- }
- function getWSEndpoint(browserURL) {
- let resolve, reject;
- const promise = new Promise((res, rej) => { resolve = res; reject = rej; });
- const endpointURL = URL.resolve(browserURL, '/json/version');
- const protocol = endpointURL.startsWith('https') ? https : http;
- const requestOptions = Object.assign(URL.parse(endpointURL), { method: 'GET' });
- const request = protocol.request(requestOptions, res => {
- let data = '';
- if (res.statusCode !== 200) {
-
- res.resume();
- reject(new Error('HTTP ' + res.statusCode));
- return;
- }
- res.setEncoding('utf8');
- res.on('data', chunk => data += chunk);
- res.on('end', () => resolve(JSON.parse(data).webSocketDebuggerUrl));
- });
- request.on('error', reject);
- request.end();
- return promise.catch(e => {
- e.message = `Failed to fetch browser webSocket url from ${endpointURL}: ` + e.message;
- throw e;
- });
- }
- function resolveExecutablePath(launcher) {
-
- if (!launcher._isPuppeteerCore) {
- const executablePath = process.env.PUPPETEER_EXECUTABLE_PATH || process.env.npm_config_puppeteer_executable_path || process.env.npm_package_config_puppeteer_executable_path;
- if (executablePath) {
- const missingText = !fs.existsSync(executablePath) ? 'Tried to use PUPPETEER_EXECUTABLE_PATH env variable to launch browser but did not find any executable at: ' + executablePath : null;
- return { executablePath, missingText };
- }
- }
- const browserFetcher = new BrowserFetcher(launcher._projectRoot);
- if (!launcher._isPuppeteerCore) {
- const revision = process.env['PUPPETEER_CHROMIUM_REVISION'];
- if (revision) {
- const revisionInfo = browserFetcher.revisionInfo(revision);
- const missingText = !revisionInfo.local ? 'Tried to use PUPPETEER_CHROMIUM_REVISION env variable to launch browser but did not find executable at: ' + revisionInfo.executablePath : null;
- return {executablePath: revisionInfo.executablePath, missingText};
- }
- }
- const revisionInfo = browserFetcher.revisionInfo(launcher._preferredRevision);
- const missingText = !revisionInfo.local ? `Browser is not downloaded. Run "npm install" or "yarn install"` : null;
- return {executablePath: revisionInfo.executablePath, missingText};
- }
- function Launcher(projectRoot, preferredRevision, isPuppeteerCore, product) {
-
- if (!product && !isPuppeteerCore)
- product = process.env.PUPPETEER_PRODUCT || process.env.npm_config_puppeteer_product || process.env.npm_package_config_puppeteer_product;
- switch (product) {
- case 'firefox':
- return new FirefoxLauncher(projectRoot, preferredRevision, isPuppeteerCore);
- case 'chrome':
- default:
- return new ChromeLauncher(projectRoot, preferredRevision, isPuppeteerCore);
- }
- }
- module.exports = Launcher;
|