зеркало из https://github.com/mozilla/gecko-dev.git
bug 1599400: remote: vendor puppeteer to c5a72e9
This contains maja_zf's browser picker changes. Differential Revision: https://phabricator.services.mozilla.com/D54695 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
a731b16af1
Коммит
86fc45b83b
|
@ -8,8 +8,8 @@ node6
|
|||
test
|
||||
utils/node6-transform
|
||||
|
||||
# exclude internal type definition files
|
||||
/lib/*.d.ts
|
||||
# exclude internal type definitions
|
||||
/lib/externs.d.ts
|
||||
|
||||
# repeats from .gitignore
|
||||
node_modules
|
||||
|
|
|
@ -259,8 +259,9 @@ Releasing to npm consists of the following phases:
|
|||
1. On your local machine, pull from [upstream](https://github.com/GoogleChrome/puppeteer) and make sure the last commit is the one just merged.
|
||||
2. Run `git status` and make sure there are no untracked files.
|
||||
- **WHY**: this is to avoid adding unnecessary files to the npm package.
|
||||
3. Run [`npx pkgfiles`](https://www.npmjs.com/package/pkgfiles) to make sure you don't publish anything unnecessary.
|
||||
4. Run `npm publish`. This publishes the `puppeteer` package.
|
||||
3. Run `npm install` to make sure the latest `lib/protocol.d.ts` is generated.
|
||||
4. Run [`npx pkgfiles`](https://www.npmjs.com/package/pkgfiles) to make sure you don't publish anything unnecessary.
|
||||
5. Run `npm publish`. This publishes the `puppeteer` package.
|
||||
3. Publish `puppeteer-core` to npm.
|
||||
1. Run `./utils/prepare_puppeteer_core.js`. The script changes the name inside `package.json` to `puppeteer-core`.
|
||||
2. Run `npm publish`. This publishes the `puppeteer-core` package.
|
||||
|
|
|
@ -389,7 +389,7 @@ If Puppeteer doesn't find them in the environment during the installation step,
|
|||
- `PUPPETEER_DOWNLOAD_HOST` - overwrite URL prefix that is used to download Chromium. Note: this includes protocol and might even include path prefix. Defaults to `https://storage.googleapis.com`.
|
||||
- `PUPPETEER_CHROMIUM_REVISION` - specify a certain version of Chromium you'd like Puppeteer to use. See [puppeteer.launch([options])](#puppeteerlaunchoptions) on how executable path is inferred. **BEWARE**: Puppeteer is only [guaranteed to work](https://github.com/GoogleChrome/puppeteer/#q-why-doesnt-puppeteer-vxxx-work-with-chromium-vyyy) with the bundled Chromium, use at your own risk.
|
||||
- `PUPPETEER_EXECUTABLE_PATH` - specify an executable path to be used in `puppeteer.launch`. See [puppeteer.launch([options])](#puppeteerlaunchoptions) on how the executable path is inferred. **BEWARE**: Puppeteer is only [guaranteed to work](https://github.com/GoogleChrome/puppeteer/#q-why-doesnt-puppeteer-vxxx-work-with-chromium-vyyy) with the bundled Chromium, use at your own risk.
|
||||
- `PUPPETEER_PRODUCT` - specify which browser you'd like Puppeteer to use. Must be one of `chrome` or `firefox`. This is exposed in [`puppeteer.product`](#puppeteerproduct)
|
||||
- `PUPPETEER_PRODUCT` - specify which browser you'd like Puppeteer to use. Must be one of `chrome` or `firefox`. Setting `product` programmatically in [puppeteer.launch([options])](#puppeteerlaunchoptions) supercedes this environment variable. The product is exposed in [`puppeteer.product`](#puppeteerproduct)
|
||||
|
||||
> **NOTE** PUPPETEER_* env variables are not accounted for in the [`puppeteer-core`](https://www.npmjs.com/package/puppeteer-core) package.
|
||||
|
||||
|
@ -527,6 +527,7 @@ try {
|
|||
|
||||
#### puppeteer.launch([options])
|
||||
- `options` <[Object]> Set of configurable options to set on the browser. Can have the following fields:
|
||||
- `product` <[string]> Which browser to launch. At this time, this is either `chrome` or `firefox`. See also `PUPPETEER_PRODUCT`.
|
||||
- `ignoreHTTPSErrors` <[boolean]> Whether to ignore HTTPS errors during navigation. Defaults to `false`.
|
||||
- `headless` <[boolean]> Whether to run browser in [headless mode](https://developers.google.com/web/updates/2017/04/headless-chrome). Defaults to `true` unless the `devtools` option is `true`.
|
||||
- `executablePath` <[string]> Path to a browser executable to run instead of the bundled Chromium. If `executablePath` is a relative path, then it is resolved relative to [current working directory](https://nodejs.org/api/process.html#process_process_cwd). **BEWARE**: Puppeteer is only [guaranteed to work](https://github.com/GoogleChrome/puppeteer/#q-why-doesnt-puppeteer-vxxx-work-with-chromium-vyyy) with the bundled Chromium, use at your own risk.
|
||||
|
@ -549,7 +550,7 @@ try {
|
|||
- `env` <[Object]> Specify environment variables that will be visible to the browser. Defaults to `process.env`.
|
||||
- `devtools` <[boolean]> Whether to auto-open a DevTools panel for each tab. If this option is `true`, the `headless` option will be set `false`.
|
||||
- `pipe` <[boolean]> Connects to the browser over a pipe instead of a WebSocket. Defaults to `false`.
|
||||
- `extraPrefs` <[Object]> Additional [preferences](https://developer.mozilla.org/en-US/docs/Mozilla/Preferences/Preference_reference) that can be passed to Firefox (see `PUPPETEER_PRODUCT`)
|
||||
- `extraPrefsFirefox` <[Object]> Additional [preferences](https://developer.mozilla.org/en-US/docs/Mozilla/Preferences/Preference_reference) that can be passed to Firefox (see `PUPPETEER_PRODUCT`)
|
||||
- returns: <[Promise]<[Browser]>> Promise which resolves to browser instance.
|
||||
|
||||
|
||||
|
@ -571,7 +572,7 @@ const browser = await puppeteer.launch({
|
|||
#### puppeteer.product
|
||||
- returns: <[string]> returns the name of the browser that is under automation ("chrome" or "firefox")
|
||||
|
||||
The product is set by the `PUPPETEER_PRODUCT` environment variable and defaults to `chrome`. Firefox support is experimental.
|
||||
The product is set by the `PUPPETEER_PRODUCT` environment variable or the `product` option in [puppeteer.launch([options])](#puppeteerlaunchoptions) and defaults to `chrome`. Firefox support is experimental.
|
||||
|
||||
|
||||
### class: BrowserFetcher
|
||||
|
|
|
@ -28,4 +28,11 @@ const packageJson = require('./package.json');
|
|||
const preferredRevision = packageJson.puppeteer.chromium_revision;
|
||||
const isPuppeteerCore = packageJson.name === 'puppeteer-core';
|
||||
|
||||
module.exports = new Puppeteer(__dirname, preferredRevision, isPuppeteerCore);
|
||||
const puppeteer = new Puppeteer(__dirname, preferredRevision, isPuppeteerCore);
|
||||
|
||||
// The introspection in `Helper.installAsyncStackHooks` references `Puppeteer._launcher`
|
||||
// before the Puppeteer ctor is called, such that an invalid Launcher is selected at import,
|
||||
// so we reset it.
|
||||
puppeteer._lazyLauncher = undefined;
|
||||
|
||||
module.exports = puppeteer;
|
||||
|
|
|
@ -141,14 +141,14 @@ class BrowserRunner {
|
|||
childProcess.execSync(`taskkill /pid ${this.proc.pid} /T /F`);
|
||||
else
|
||||
process.kill(-this.proc.pid, 'SIGKILL');
|
||||
} catch (e) {
|
||||
} catch (error) {
|
||||
// the process might have already stopped
|
||||
}
|
||||
}
|
||||
// Attempt to remove temporary profile directory to avoid littering.
|
||||
try {
|
||||
removeFolder.sync(this._tempDirectory);
|
||||
} catch (e) { }
|
||||
} catch (error) { }
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -175,6 +175,9 @@ class BrowserRunner {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @implements {!Puppeteer.ProductLauncher}
|
||||
*/
|
||||
class ChromeLauncher {
|
||||
/**
|
||||
* @param {string} projectRoot
|
||||
|
@ -243,9 +246,9 @@ class ChromeLauncher {
|
|||
const browser = await Browser.create(connection, [], ignoreHTTPSErrors, defaultViewport, runner.proc, runner.close.bind(runner));
|
||||
await browser.waitForTarget(t => t.type() === 'page');
|
||||
return browser;
|
||||
} catch (e) {
|
||||
} catch (error) {
|
||||
runner.kill();
|
||||
throw e;
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -310,6 +313,13 @@ class ChromeLauncher {
|
|||
return resolveExecutablePath(this).executablePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {string}
|
||||
*/
|
||||
get product() {
|
||||
return 'chrome';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {!(Launcher.BrowserOptions & {browserWSEndpoint?: string, browserURL?: string, transport?: !Puppeteer.ConnectionTransport})} options
|
||||
* @return {!Promise<!Browser>}
|
||||
|
@ -344,7 +354,9 @@ class ChromeLauncher {
|
|||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @implements {!Puppeteer.ProductLauncher}
|
||||
*/
|
||||
class FirefoxLauncher {
|
||||
/**
|
||||
* @param {string} projectRoot
|
||||
|
@ -358,7 +370,7 @@ class FirefoxLauncher {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param {!(Launcher.LaunchOptions & Launcher.ChromeArgOptions & Launcher.BrowserOptions & {extraPrefs?: !object})=} options
|
||||
* @param {!(Launcher.LaunchOptions & Launcher.ChromeArgOptions & Launcher.BrowserOptions & {extraPrefsFirefox?: !object})=} options
|
||||
* @return {!Promise<!Browser>}
|
||||
*/
|
||||
async launch(options = {}) {
|
||||
|
@ -376,7 +388,7 @@ class FirefoxLauncher {
|
|||
defaultViewport = {width: 800, height: 600},
|
||||
slowMo = 0,
|
||||
timeout = 30000,
|
||||
extraPrefs = {}
|
||||
extraPrefsFirefox = {}
|
||||
} = options;
|
||||
|
||||
const firefoxArguments = [];
|
||||
|
@ -390,7 +402,7 @@ class FirefoxLauncher {
|
|||
let temporaryUserDataDir = null;
|
||||
|
||||
if (!firefoxArguments.includes('-profile') && !firefoxArguments.includes('--profile')) {
|
||||
temporaryUserDataDir = await this._createProfile(extraPrefs);
|
||||
temporaryUserDataDir = await this._createProfile(extraPrefsFirefox);
|
||||
firefoxArguments.push('--profile');
|
||||
firefoxArguments.push(temporaryUserDataDir);
|
||||
}
|
||||
|
@ -411,9 +423,9 @@ class FirefoxLauncher {
|
|||
const browser = await Browser.create(connection, [], ignoreHTTPSErrors, defaultViewport, runner.proc, runner.close.bind(runner));
|
||||
await browser.waitForTarget(t => t.type() === 'page');
|
||||
return browser;
|
||||
} catch (e) {
|
||||
} catch (error) {
|
||||
runner.kill();
|
||||
throw e;
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -460,6 +472,13 @@ class FirefoxLauncher {
|
|||
return executablePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {string}
|
||||
*/
|
||||
get product() {
|
||||
return 'firefox';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {!Launcher.ChromeArgOptions=} options
|
||||
* @return {!Array<string>}
|
||||
|
@ -496,211 +515,19 @@ class FirefoxLauncher {
|
|||
*/
|
||||
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 = {
|
||||
// Make sure Shield doesn't hit the network.
|
||||
'app.normandy.api_url': '',
|
||||
// Disable Firefox old build background check
|
||||
'app.update.checkInstallTime': false,
|
||||
// Disable automatically upgrading Firefox
|
||||
'app.update.disabledForTesting': true,
|
||||
|
||||
// Increase the APZ content response timeout to 1 minute
|
||||
'apz.content_response_timeout': 60000,
|
||||
|
||||
// Prevent various error message on the console
|
||||
// jest-puppeteer asserts that no error message is emitted by the console
|
||||
'browser.contentblocking.features.standard': '-tp,tpPrivate,cookieBehavior0,-cm,-fp',
|
||||
|
||||
|
||||
// Enable the dump function: which sends messages to the system
|
||||
// console
|
||||
// https://bugzilla.mozilla.org/show_bug.cgi?id=1543115
|
||||
'browser.dom.window.dump.enabled': true,
|
||||
// Disable topstories
|
||||
'browser.newtabpage.activity-stream.feeds.section.topstories': false,
|
||||
// Always display a blank page
|
||||
'browser.newtabpage.enabled': false,
|
||||
// Background thumbnails in particular cause grief: and disabling
|
||||
// thumbnails in general cannot hurt
|
||||
'browser.pagethumbnails.capturing_disabled': true,
|
||||
|
||||
// Disable safebrowsing components.
|
||||
'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,
|
||||
|
||||
// Disable updates to search engines.
|
||||
'browser.search.update': false,
|
||||
// Do not restore the last open set of tabs if the browser has crashed
|
||||
'browser.sessionstore.resume_from_crash': false,
|
||||
// Skip check for default browser on startup
|
||||
'browser.shell.checkDefaultBrowser': false,
|
||||
|
||||
// Disable newtabpage
|
||||
'browser.startup.homepage': 'about:blank',
|
||||
// Do not redirect user when a milstone upgrade of Firefox is detected
|
||||
'browser.startup.homepage_override.mstone': 'ignore',
|
||||
// Start with a blank page about:blank
|
||||
'browser.startup.page': 0,
|
||||
|
||||
// Do not allow background tabs to be zombified on Android: otherwise for
|
||||
// tests that open additional tabs: the test harness tab itself might get
|
||||
// unloaded
|
||||
'browser.tabs.disableBackgroundZombification': false,
|
||||
// Do not warn when closing all other open tabs
|
||||
'browser.tabs.warnOnCloseOtherTabs': false,
|
||||
// Do not warn when multiple tabs will be opened
|
||||
'browser.tabs.warnOnOpen': false,
|
||||
|
||||
// Disable the UI tour.
|
||||
'browser.uitour.enabled': false,
|
||||
// Turn off search suggestions in the location bar so as not to trigger
|
||||
// network connections.
|
||||
'browser.urlbar.suggest.searches': false,
|
||||
// Disable first run splash page on Windows 10
|
||||
'browser.usedOnWindows10.introURL': '',
|
||||
// Do not warn on quitting Firefox
|
||||
'browser.warnOnQuit': false,
|
||||
|
||||
// Do not show datareporting policy notifications which can
|
||||
// interfere with tests
|
||||
'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 JSONViewer sometimes fails to load dependencies with its require.js.
|
||||
// This doesn't affect Puppeteer but spams console (Bug 1424372)
|
||||
'devtools.jsonview.enabled': false,
|
||||
|
||||
// Disable popup-blocker
|
||||
'dom.disable_open_during_load': false,
|
||||
|
||||
// Enable the support for File object creation in the content process
|
||||
// Required for |Page.setFileInputFiles| protocol method.
|
||||
'dom.file.createInChild': true,
|
||||
|
||||
// Disable the ProcessHangMonitor
|
||||
'dom.ipc.reportProcessHangs': false,
|
||||
|
||||
// Disable slow script dialogues
|
||||
'dom.max_chrome_script_run_time': 0,
|
||||
'dom.max_script_run_time': 0,
|
||||
|
||||
// Only load extensions from the application and user profile
|
||||
// AddonManager.SCOPE_PROFILE + AddonManager.SCOPE_APPLICATION
|
||||
'extensions.autoDisableScopes': 0,
|
||||
'extensions.enabledScopes': 5,
|
||||
|
||||
// Disable metadata caching for installed add-ons by default
|
||||
'extensions.getAddons.cache.enabled': false,
|
||||
|
||||
// Disable installing any distribution extensions or add-ons.
|
||||
'extensions.installDistroAddons': false,
|
||||
|
||||
// Disabled screenshots extension
|
||||
'extensions.screenshots.disabled': true,
|
||||
|
||||
// Turn off extension updates so they do not bother tests
|
||||
'extensions.update.enabled': false,
|
||||
|
||||
// Turn off extension updates so they do not bother tests
|
||||
'extensions.update.notifyUser': false,
|
||||
|
||||
// Make sure opening about:addons will not hit the network
|
||||
'extensions.webservice.discoverURL': `http://${server}/dummy/discoveryURL`,
|
||||
|
||||
// Allow the application to have focus even it runs in the background
|
||||
'focusmanager.testmode': true,
|
||||
// Disable useragent updates
|
||||
'general.useragent.updates.enabled': false,
|
||||
// Always use network provider for geolocation tests so we bypass the
|
||||
// macOS dialog raised by the corelocation provider
|
||||
'geo.provider.testing': true,
|
||||
// Do not scan Wifi
|
||||
'geo.wifi.scan': false,
|
||||
// No hang monitor
|
||||
'hangmonitor.timeout': 0,
|
||||
// Show chrome errors and warnings in the error console
|
||||
'javascript.options.showInConsole': true,
|
||||
|
||||
// Disable download and usage of OpenH264: and Widevine plugins
|
||||
'media.gmp-manager.updateEnabled': false,
|
||||
// Prevent various error message on the console
|
||||
// jest-puppeteer asserts that no error message is emitted by the console
|
||||
'network.cookie.cookieBehavior': 0,
|
||||
|
||||
// Do not prompt for temporary redirects
|
||||
'network.http.prompt-temp-redirect': false,
|
||||
|
||||
// Disable speculative connections so they are not reported as leaking
|
||||
// when they are hanging around
|
||||
'network.http.speculative-parallel-limit': 0,
|
||||
|
||||
// Do not automatically switch between offline and online
|
||||
'network.manage-offline-status': false,
|
||||
|
||||
// Make sure SNTP requests do not hit the network
|
||||
'network.sntp.pools': `${server}`,
|
||||
|
||||
// Disable Flash.
|
||||
'plugin.state.flash': 0,
|
||||
|
||||
'privacy.trackingprotection.enabled': false,
|
||||
|
||||
// Enable Remote Agent
|
||||
const prefsJs = [];
|
||||
const userJs = [];
|
||||
const preferences = {
|
||||
// https://bugzilla.mozilla.org/show_bug.cgi?id=1544393
|
||||
'remote.enabled': true,
|
||||
|
||||
// Don't do network connections for mitm priming
|
||||
'security.certerrors.mitm.priming.enabled': false,
|
||||
// Local documents have access to all other local documents,
|
||||
// including directory listings
|
||||
'security.fileuri.strict_origin_policy': false,
|
||||
// Do not wait for the notification button security delay
|
||||
'security.notification_enable_delay': 0,
|
||||
|
||||
// Ensure blocklist updates do not hit the network
|
||||
'services.settings.server': `http://${server}/dummy/blocklist/`,
|
||||
|
||||
// Do not automatically fill sign-in forms with known usernames and
|
||||
// passwords
|
||||
'signon.autofillForms': false,
|
||||
// Disable password capture, so that tests that include forms are not
|
||||
// influenced by the presence of the persistent doorhanger notification
|
||||
'signon.rememberSignons': false,
|
||||
|
||||
// Disable first-run welcome page
|
||||
'startup.homepage_welcome_url': 'about:blank',
|
||||
|
||||
// Disable first-run welcome page
|
||||
'startup.homepage_welcome_url.additional': '',
|
||||
|
||||
// Disable browser animations (tabs, fullscreen, sliding alerts)
|
||||
'toolkit.cosmeticAnimations.enabled': false,
|
||||
|
||||
// We want to collect telemetry, but we don't want to send in the results
|
||||
'toolkit.telemetry.server': `https://${server}/dummy/telemetry/`,
|
||||
// Prevent starting into safe mode after application crashes
|
||||
'toolkit.startup.max_resumed_crashes': -1,
|
||||
|
||||
// https://bugzilla.mozilla.org/show_bug.cgi?id=1543115
|
||||
'browser.dom.window.dump.enabled': true
|
||||
};
|
||||
|
||||
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'));
|
||||
Object.assign(preferences, extraPrefs);
|
||||
for (const [key, value] of Object.entries(preferences))
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -714,7 +541,7 @@ class FirefoxLauncher {
|
|||
*/
|
||||
function waitForWSEndpoint(browserProcess, timeout, preferredRevision) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const rl = readline.createInterface({ input: browserProcess.stderr});
|
||||
const rl = readline.createInterface({ input: browserProcess.stderr });
|
||||
let stderr = '';
|
||||
const listeners = [
|
||||
helper.addEventListener(rl, 'line', onLine),
|
||||
|
@ -825,13 +652,16 @@ function resolveExecutablePath(launcher) {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param {string} product
|
||||
* @param {string} projectRoot
|
||||
* @param {string} preferredRevision
|
||||
* @param {boolean} isPuppeteerCore
|
||||
* @return {ChromeLauncher|FirefoxLauncher}
|
||||
* @param {string=} product
|
||||
* @return {!Puppeteer.ProductLauncher}
|
||||
*/
|
||||
function Launcher(product, projectRoot, preferredRevision, isPuppeteerCore) {
|
||||
function Launcher(projectRoot, preferredRevision, isPuppeteerCore, product) {
|
||||
// puppeteer-core doesn't take into account PUPPETEER_* env variables.
|
||||
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);
|
||||
|
|
|
@ -18,8 +18,6 @@ const BrowserFetcher = require('./BrowserFetcher');
|
|||
const Errors = require('./Errors');
|
||||
const DeviceDescriptors = require('./DeviceDescriptors');
|
||||
|
||||
const PRODUCT = process.env.PUPPETEER_PRODUCT || process.env.npm_config_puppeteer_product || process.env.npm_package_config_puppeteer_product;
|
||||
|
||||
module.exports = class {
|
||||
/**
|
||||
* @param {string} projectRoot
|
||||
|
@ -28,14 +26,17 @@ module.exports = class {
|
|||
*/
|
||||
constructor(projectRoot, preferredRevision, isPuppeteerCore) {
|
||||
this._projectRoot = projectRoot;
|
||||
this._launcher = Launcher(PRODUCT, projectRoot, preferredRevision, isPuppeteerCore);
|
||||
this._preferredRevision = preferredRevision;
|
||||
this._isPuppeteerCore = isPuppeteerCore;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {!(Launcher.LaunchOptions & Launcher.ChromeArgOptions & Launcher.BrowserOptions & {extraPrefs?: !object})=} options
|
||||
* @param {!(Launcher.LaunchOptions & Launcher.ChromeArgOptions & Launcher.BrowserOptions & {product?: string, extraPrefsFirefox?: !object})=} options
|
||||
* @return {!Promise<!Puppeteer.Browser>}
|
||||
*/
|
||||
launch(options) {
|
||||
if (!this._productName && options)
|
||||
this._productName = options.product;
|
||||
return this._launcher.launch(options);
|
||||
}
|
||||
|
||||
|
@ -54,11 +55,21 @@ module.exports = class {
|
|||
return this._launcher.executablePath();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {!Puppeteer.ProductLauncher}
|
||||
*/
|
||||
get _launcher() {
|
||||
if (!this._lazyLauncher)
|
||||
this._lazyLauncher = Launcher(this._projectRoot, this._preferredRevision, this._isPuppeteerCore, this._productName);
|
||||
return this._lazyLauncher;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {string}
|
||||
*/
|
||||
get product() {
|
||||
return PRODUCT || 'chrome';
|
||||
return this._launcher.product;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -44,6 +44,14 @@ declare global {
|
|||
onclose?: () => void,
|
||||
}
|
||||
|
||||
export interface ProductLauncher {
|
||||
launch(object)
|
||||
connect(object)
|
||||
executablePath: () => string,
|
||||
defaultArgs(object)
|
||||
product:string,
|
||||
}
|
||||
|
||||
export interface ChildProcess extends child_process.ChildProcess { }
|
||||
|
||||
export type Viewport = {
|
||||
|
|
|
@ -24,7 +24,7 @@ const statAsync = helper.promisify(fs.stat);
|
|||
const TMP_FOLDER = path.join(os.tmpdir(), 'pptr_tmp_folder-');
|
||||
const utils = require('./utils');
|
||||
|
||||
module.exports.addTests = function({testRunner, expect, defaultBrowserOptions, puppeteer, CHROME, puppeteerPath}) {
|
||||
module.exports.addTests = function({testRunner, expect, defaultBrowserOptions, puppeteer, CHROME, FFOX, JUGGLER, puppeteerPath}) {
|
||||
const {describe, xdescribe, fdescribe, describe_fails_ffox} = testRunner;
|
||||
const {it, fit, xit, it_fails_ffox} = testRunner;
|
||||
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
|
||||
|
@ -199,6 +199,12 @@ module.exports.addTests = function({testRunner, expect, defaultBrowserOptions, p
|
|||
expect(puppeteer.defaultArgs({userDataDir: 'foo'})).toContain('foo');
|
||||
}
|
||||
});
|
||||
it('should report the correct product', async() => {
|
||||
if (CHROME)
|
||||
expect(puppeteer.product).toBe('chrome');
|
||||
else if (FFOX && !JUGGLER)
|
||||
expect(puppeteer.product).toBe('firefox');
|
||||
});
|
||||
it('should work with no default arguments', async() => {
|
||||
const options = Object.assign({}, defaultBrowserOptions);
|
||||
options.ignoreDefaultArgs = true;
|
||||
|
|
|
@ -38,8 +38,8 @@ module.exports.addTests = ({testRunner, product, puppeteerPath}) => {
|
|||
let extraLaunchOptions = {};
|
||||
try {
|
||||
extraLaunchOptions = JSON.parse(process.env.EXTRA_LAUNCH_OPTIONS || '{}');
|
||||
} catch (e) {
|
||||
console.warn(`${YELLOW_COLOR}Error parsing EXTRA_LAUNCH_OPTIONS: ${e.message}. Skipping.${RESET_COLOR}`);
|
||||
} catch (error) {
|
||||
console.warn(`${YELLOW_COLOR}Error parsing EXTRA_LAUNCH_OPTIONS: ${error.message}. Skipping.${RESET_COLOR}`);
|
||||
}
|
||||
|
||||
const defaultBrowserOptions = Object.assign({
|
||||
|
@ -54,9 +54,9 @@ module.exports.addTests = ({testRunner, product, puppeteerPath}) => {
|
|||
if (defaultBrowserOptions.executablePath) {
|
||||
console.warn(`${YELLOW_COLOR}WARN: running ${product} tests with ${defaultBrowserOptions.executablePath}${RESET_COLOR}`);
|
||||
} else {
|
||||
const path = puppeteer.executablePath();
|
||||
if (!fs.existsSync(path))
|
||||
throw new Error(`Browser is not downloaded at ${path}. Run 'npm install' and try to re-run tests`);
|
||||
const executablePath = puppeteer.executablePath();
|
||||
if (!fs.existsSync(executablePath))
|
||||
throw new Error(`Browser is not downloaded at ${executablePath}. Run 'npm install' and try to re-run tests`);
|
||||
}
|
||||
|
||||
const suffix = JUGGLER ? 'firefox' : product.toLowerCase();
|
||||
|
|
|
@ -69,8 +69,8 @@ declare global {
|
|||
}
|
||||
}
|
||||
}
|
||||
// empty export to keep file a module
|
||||
export {}
|
||||
|
||||
export default Protocol;
|
||||
`;
|
||||
const outputPath = path.join(__dirname, '..', '..', 'lib', 'protocol.d.ts');
|
||||
require('fs').writeFileSync(outputPath, output);
|
||||
|
|
Загрузка…
Ссылка в новой задаче