fix: update preferred revision after Launcher is created (#5640)

Fixes an edge case where Puppeteer looked for a Chromium revision when launching Firefox.

Allow appropriate Launcher to be instantiated when calling `Puppeteer.connect`.

Add an example of running Firefox.
This commit is contained in:
Maja Frydrychowicz
2020-04-14 12:42:48 -04:00
committed by GitHub
parent df8125056a
commit d817ae5a4b
3 changed files with 68 additions and 2 deletions

View File

@@ -40,13 +40,29 @@ module.exports = class {
}
/**
* @param {!(Launcher.BrowserOptions & {browserWSEndpoint?: string, browserURL?: string, transport?: !Puppeteer.ConnectionTransport})} options
* @param {!(Launcher.BrowserOptions & {browserWSEndpoint?: string, browserURL?: string, transport?: !Puppeteer.ConnectionTransport}) & {product?: string}=} options
* @return {!Promise<!Puppeteer.Browser>}
*/
connect(options) {
this._productName = options.product;
return this._launcher.connect(options);
}
/**
* @param {string} name
*/
set _productName(name) {
this._changedProduct = this.__productName !== name;
this.__productName = name;
}
/**
* @return {string}
*/
get _productName() {
return this.__productName;
}
/**
* @return {string}
*/
@@ -58,7 +74,7 @@ module.exports = class {
* @return {!Puppeteer.ProductLauncher}
*/
get _launcher() {
if (!this._lazyLauncher || this._lazyLauncher.product !== this._productName) {
if (!this._lazyLauncher || this._lazyLauncher.product !== this._productName || this._changedProduct) {
// @ts-ignore
const packageJson = require('../package.json');
switch (this._productName) {
@@ -69,6 +85,7 @@ module.exports = class {
default:
this._preferredRevision = packageJson.puppeteer.chromium_revision;
}
this._changedProduct = false;
this._lazyLauncher = Launcher(this._projectRoot, this._preferredRevision, this._isPuppeteerCore, this._productName);
}
return this._lazyLauncher;