feat: support PLAYWRIGHT_DOWNLOAD_HOST (#1179)
This patch starts respecting `PLAYWRIGHT_DOWNLOAD_HOST` env variable in `playwright` package and it's vendored flavors (`playwright-firefox`, `playwright-chromium` and `playwright-webkit`). Fixes #1045
This commit is contained in:
parent
d5951b4fc4
commit
08fbc92752
11
docs/api.md
11
docs/api.md
|
|
@ -31,6 +31,7 @@
|
|||
- [class: ChromiumTarget](#class-chromiumtarget)
|
||||
- [class: FirefoxBrowser](#class-firefoxbrowser)
|
||||
- [class: WebKitBrowser](#class-webkitbrowser)
|
||||
- [Environment Variables](#environment-variables)
|
||||
- [Working with selectors](#working-with-selectors)
|
||||
- [Working with Chrome Extensions](#working-with-chrome-extensions)
|
||||
<!-- GEN:stop -->
|
||||
|
|
@ -3848,6 +3849,16 @@ WebKit browser instance does not expose WebKit-specific features.
|
|||
- [browser.newPage([options])](#browsernewpageoptions)
|
||||
<!-- GEN:stop -->
|
||||
|
||||
### Environment Variables
|
||||
|
||||
> **NOTE** [playwright-core](https://www.npmjs.com/package/playwright-core) **does not** respect environment variables.
|
||||
|
||||
Playwright looks for certain [environment variables](https://en.wikipedia.org/wiki/Environment_variable) to aid its operations.
|
||||
If Playwright doesn't find them in the environment, a lowercased variant of these variables will be used from the [npm config](https://docs.npmjs.com/cli/config).
|
||||
|
||||
- `PLAYWRIGHT_DOWNLOAD_HOST` - overwrite URL prefix that is used to download browsers. Note: this includes protocol and might even include path prefix. By default, Playwright uses `https://storage.googleapis.com` to download Chromium and `https://playwright.azureedge.net` to download Webkit & Firefox.
|
||||
|
||||
|
||||
### Working with selectors
|
||||
|
||||
Selector describes an element in the page. It can be used to obtain `ElementHandle` (see [page.$()](#pageselector) for example) or shortcut element operations to avoid intermediate handle (see [page.click()](#pageclickselector-options) for example).
|
||||
|
|
|
|||
1
index.js
1
index.js
|
|
@ -18,5 +18,6 @@ const {Playwright} = require('./lib/server/playwright.js');
|
|||
module.exports = new Playwright({
|
||||
downloadPath: __dirname,
|
||||
browsers: ['webkit', 'chromium', 'firefox'],
|
||||
respectEnvironmentVariables: false,
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -19,5 +19,6 @@ const {Playwright} = require('playwright-core/lib/server/playwright.js');
|
|||
module.exports = new Playwright({
|
||||
downloadPath: __dirname,
|
||||
browsers: ['chromium'],
|
||||
respectEnvironmentVariables: true,
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -19,5 +19,6 @@ const {Playwright} = require('playwright-core/lib/server/playwright.js');
|
|||
module.exports = new Playwright({
|
||||
downloadPath: __dirname,
|
||||
browsers: ['firefox'],
|
||||
respectEnvironmentVariables: true,
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -19,5 +19,6 @@ const {Playwright} = require('playwright-core/lib/server/playwright.js');
|
|||
module.exports = new Playwright({
|
||||
downloadPath: __dirname,
|
||||
browsers: ['webkit'],
|
||||
respectEnvironmentVariables: true,
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -18,5 +18,6 @@ const {Playwright} = require('playwright-core/lib/server/playwright.js');
|
|||
module.exports = new Playwright({
|
||||
downloadPath: __dirname,
|
||||
browsers: ['webkit', 'chromium', 'firefox'],
|
||||
respectEnvironmentVariables: true,
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -38,10 +38,12 @@ import { BrowserContext } from '../browserContext';
|
|||
|
||||
export class Chromium implements BrowserType {
|
||||
private _downloadPath: string;
|
||||
private _downloadHost: string;
|
||||
readonly _revision: string;
|
||||
|
||||
constructor(downloadPath: string, preferredRevision: string) {
|
||||
constructor(downloadPath: string, downloadHost: (string|undefined), preferredRevision: string) {
|
||||
this._downloadPath = downloadPath;
|
||||
this._downloadHost = downloadHost || 'https://storage.googleapis.com';
|
||||
this._revision = preferredRevision;
|
||||
}
|
||||
|
||||
|
|
@ -221,7 +223,7 @@ export class Chromium implements BrowserType {
|
|||
|
||||
const defaultOptions = {
|
||||
path: path.join(this._downloadPath, '.local-chromium'),
|
||||
host: 'https://storage.googleapis.com',
|
||||
host: this._downloadHost,
|
||||
platform: (() => {
|
||||
const platform = os.platform();
|
||||
if (platform === 'darwin')
|
||||
|
|
|
|||
|
|
@ -39,10 +39,12 @@ const mkdtempAsync = platform.promisify(fs.mkdtemp);
|
|||
|
||||
export class Firefox implements BrowserType {
|
||||
private _downloadPath: string;
|
||||
private _downloadHost: string;
|
||||
readonly _revision: string;
|
||||
|
||||
constructor(downloadPath: string, preferredRevision: string) {
|
||||
constructor(downloadPath: string, downloadHost: (string|undefined), preferredRevision: string) {
|
||||
this._downloadPath = downloadPath;
|
||||
this._downloadHost = downloadHost || 'https://playwright.azureedge.net';
|
||||
this._revision = preferredRevision;
|
||||
}
|
||||
|
||||
|
|
@ -219,7 +221,7 @@ export class Firefox implements BrowserType {
|
|||
|
||||
const defaultOptions = {
|
||||
path: path.join(this._downloadPath, '.local-firefox'),
|
||||
host: 'https://playwright.azureedge.net',
|
||||
host: this._downloadHost,
|
||||
platform: (() => {
|
||||
const platform = os.platform();
|
||||
if (platform === 'darwin')
|
||||
|
|
|
|||
|
|
@ -30,6 +30,12 @@ for (const className in api) {
|
|||
helper.installApiHooks(className[0].toLowerCase() + className.substring(1), (api as any)[className]);
|
||||
}
|
||||
|
||||
type PlaywrightOptions = {
|
||||
downloadPath: string,
|
||||
browsers: Array<('firefox'|'webkit'|'chromium')>,
|
||||
respectEnvironmentVariables: boolean,
|
||||
};
|
||||
|
||||
export class Playwright {
|
||||
readonly selectors = api.Selectors._instance();
|
||||
readonly devices: types.Devices;
|
||||
|
|
@ -38,18 +44,27 @@ export class Playwright {
|
|||
readonly firefox: (Firefox|undefined);
|
||||
readonly webkit: (WebKit|undefined);
|
||||
|
||||
constructor(options: {downloadPath: string, browsers: Array<('firefox'|'webkit'|'chromium')>}) {
|
||||
constructor(options: PlaywrightOptions) {
|
||||
const {
|
||||
downloadPath,
|
||||
browsers,
|
||||
respectEnvironmentVariables,
|
||||
} = options;
|
||||
this.devices = DeviceDescriptors;
|
||||
this.errors = { TimeoutError };
|
||||
const downloadHost = respectEnvironmentVariables ? getFromENV('PLAYWRIGHT_DOWNLOAD_HOST') : undefined;
|
||||
if (browsers.includes('chromium'))
|
||||
this.chromium = new Chromium(downloadPath, packageJSON.playwright.chromium_revision);
|
||||
this.chromium = new Chromium(downloadPath, downloadHost, packageJSON.playwright.chromium_revision);
|
||||
if (browsers.includes('webkit'))
|
||||
this.webkit = new WebKit(downloadPath, packageJSON.playwright.webkit_revision);
|
||||
this.webkit = new WebKit(downloadPath, downloadHost, packageJSON.playwright.webkit_revision);
|
||||
if (browsers.includes('firefox'))
|
||||
this.firefox = new Firefox(downloadPath, packageJSON.playwright.firefox_revision);
|
||||
this.firefox = new Firefox(downloadPath, downloadHost, packageJSON.playwright.firefox_revision);
|
||||
}
|
||||
}
|
||||
|
||||
function getFromENV(name: string): (string|undefined) {
|
||||
let value = process.env[name];
|
||||
value = value || process.env[`npm_config_${name.toLowerCase()}`];
|
||||
value = value || process.env[`npm_package_config_${name.toLowerCase()}`];
|
||||
return value;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,10 +41,12 @@ import { BrowserContext } from '../browserContext';
|
|||
|
||||
export class WebKit implements BrowserType {
|
||||
private _downloadPath: string;
|
||||
private _downloadHost: string;
|
||||
readonly _revision: string;
|
||||
|
||||
constructor(downloadPath: string, preferredRevision: string) {
|
||||
constructor(downloadPath: string, downloadHost: (string|undefined), preferredRevision: string) {
|
||||
this._downloadPath = downloadPath;
|
||||
this._downloadHost = downloadHost || 'https://playwright.azureedge.net';
|
||||
this._revision = preferredRevision;
|
||||
}
|
||||
|
||||
|
|
@ -203,7 +205,7 @@ export class WebKit implements BrowserType {
|
|||
|
||||
const defaultOptions = {
|
||||
path: path.join(this._downloadPath, '.local-webkit'),
|
||||
host: 'https://playwright.azureedge.net',
|
||||
host: this._downloadHost,
|
||||
platform: (() => {
|
||||
const platform = os.platform();
|
||||
if (platform === 'darwin')
|
||||
|
|
|
|||
Loading…
Reference in a new issue