Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
feat: remove all environment variables and references to puppeteer-core (#47)
Joel Einbinder6fcb4d2f3027
diff --git a/.npmignore b/.npmignoreindex 71a68fec8e..39b253454b 100644--- a/.npmignore+++ b/.npmignore@@ -42,3 +42,6 @@ tsconfig.json# exclude types, see https://github.com/GoogleChrome/puppeteer/issues/3878/index.d.ts++# install.js only does stuff for development+/install.js\ No newline at end of filediff --git a/chromium.js b/chromium.jsindex be153287e4..e6be4d2daa 100644--- a/chromium.js+++ b/chromium.js@@ -22,9 +22,7 @@ for (const className in api.Chromium) {helper.installAsyncStackHooks(api.Chromium[className]);}-// If node does not support async await, use the compiled version.const {Playwright} = require('./lib/chromium/Playwright');const packageJson = require('./package.json');-const isPlaywrightCore = packageJson.name === 'playwright-core';-module.exports = new Playwright(__dirname, packageJson.playwright.chromium_revision, isPlaywrightCore);+module.exports = new Playwright(__dirname, packageJson.playwright.chromium_revision);diff --git a/docs/api.md b/docs/api.mdindex 8dcb95a5b9..6476d7b577 100644--- a/docs/api.md+++ b/docs/api.md@@ -10,8 +10,6 @@<!-- GEN:toc -->- [Overview](#overview)-- [playwright vs playwright-core](#playwright-vs-playwright-core)-- [Environment Variables](#environment-variables)- [Working with Chrome Extensions](#working-with-chrome-extensions)- [class: Playwright](#class-playwright)* [playwright.connect(options)](#playwrightconnectoptions)@@ -339,50 +337,6 @@ The Playwright API is hierarchical and mirrors the browser structure.(Diagram source: [link](https://docs.google.com/drawings/d/1Q_AM6KYs9kbyLZF-Lpp5mtpAWth73Cq8IKCsWYgi8MM/edit?usp=sharing))-### playwright vs playwright-core--Every release since v1.7.0 we publish two packages:-- [playwright](https://www.npmjs.com/package/playwright)-- [playwright-core](https://www.npmjs.com/package/playwright-core)--`playwright` is a *product* for browser automation. When installed, it downloads a version of-Chromium, which it then drives using `playwright-core`. Being an end-user product, `playwright` supports a bunch of convenient `PLAYWRIGHT_*` env variables to tweak its behavior.--`playwright-core` is a *library* to help drive anything that supports DevTools protocol. `playwright-core` doesn't download Chromium when installed. Being a library, `playwright-core` is fully driven-through its programmatic interface and disregards all the `PLAYWRIGHT_*` env variables.--To sum up, the only differences between `playwright-core` and `playwright` are:-- `playwright-core` doesn't automatically download Chromium when installed.-- `playwright-core` ignores all `PLAYWRIGHT_*` env variables.--In most cases, you'll be fine using the `playwright` package.--However, you should use `playwright-core` if:-- you're building another end-user product or library atop of DevTools protocol. For example, one might build a PDF generator using `playwright-core` and write a custom `install.js` script that downloads [`headless_shell`](https://chromium.googlesource.com/chromium/src/+/lkgr/headless/README.md) instead of Chromium to save disk space.-- you're bundling Playwright to use in Chrome Extension / browser with the DevTools protocol where downloading an additional Chromium binary is unnecessary.--When using `playwright-core`, remember to change the *include* line:--```js-const playwright = require('playwright-core');-```--You will then need to call [`playwright.connect([options])`](#playwrightconnectoptions) or [`playwright.launch([options])`](#playwrightlaunchoptions) with an explicit `executablePath` option.--### 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 during the installation step, a lowercased variant of these variables will be used from the [npm config](https://docs.npmjs.com/cli/config).--- `HTTP_PROXY`, `HTTPS_PROXY`, `NO_PROXY` - defines HTTP proxy settings that are used to download and run Chromium.-- `PLAYWRIGHT_SKIP_CHROMIUM_DOWNLOAD` - do not download bundled Chromium during installation step.-- `PLAYWRIGHT_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`.-- `PLAYWRIGHT_CHROMIUM_REVISION` - specify a certain version of Chromium you'd like Playwright to use. See [playwright.launch([options])](#playwrightlaunchoptions) on how executable path is inferred. **BEWARE**: Playwright is only [guaranteed to work](https://github.com/Microsoft/playwright/#q-why-doesnt-playwright-vxxx-work-with-chromium-vyyy) with the bundled Chromium, use at your own risk.-- `PLAYWRIGHT_EXECUTABLE_PATH` - specify an executable path to be used in `playwright.launch`. See [playwright.launch([options])](#playwrightlaunchoptions) on how the executable path is inferred. **BEWARE**: Playwright is only [guaranteed to work](https://github.com/Microsoft/playwright/#q-why-doesnt-playwright-vxxx-work-with-chromium-vyyy) with the bundled Chromium, use at your own risk.--> **NOTE** PLAYWRIGHT_* env variables are not accounted for in the [`playwright-core`](https://www.npmjs.com/package/playwright-core) package.--### Working with Chrome ExtensionsPlaywright can be used for testing Chrome Extensions.@@ -509,10 +463,7 @@ try {> **NOTE** The old way (Playwright versions <= v1.14.0) errors can be obtained with `require('playwright/Errors')`.#### playwright.executablePath()-- returns: <[string]> A path where Playwright expects to find bundled Chromium. Chromium might not exist there if the download was skipped with [`PLAYWRIGHT_SKIP_CHROMIUM_DOWNLOAD`](#environment-variables).--> **NOTE** `playwright.executablePath()` is affected by the `PLAYWRIGHT_EXECUTABLE_PATH` and `PLAYWRIGHT_CHROMIUM_REVISION` env variables. See [Environment Variables](#environment-variables) for details.-+- returns: <[string]> A path where Playwright expects to find bundled Chromium.#### playwright.launch([options])- `options` <[Object]> Set of configurable options to set on the browser. Can have the following fields:diff --git a/firefox.js b/firefox.jsindex 166b1ddb4f..f39d4d51bb 100644--- a/firefox.js+++ b/firefox.js@@ -22,7 +22,6 @@ for (const className in api.Firefox) {helper.installAsyncStackHooks(api.Firefox[className]);}-// If node does not support async await, use the compiled version.const {Playwright} = require('./lib/firefox/Playwright');const packageJson = require('./package.json');diff --git a/install.js b/install.jsindex 0f49b4a11b..12ec4b26d9 100644--- a/install.js+++ b/install.js@@ -1,5 +1,6 @@/*** Copyright 2017 Google Inc. All rights reserved.+ * Modifications copyright (c) Microsoft Corporation.** Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.@@ -14,61 +15,44 @@* limitations under the License.*/-// playwright-core should not install anything.-if (require('./package.json').name === 'playwright-core')- return;--const browserSkips = {Chromium: false, Firefox: false, WebKit: false};-for (const browser of ['Chromium', 'Firefox', 'WebKit']) {- const templates = [- `PLAYWRIGHT_SKIP_${browser}_DOWNLOAD`,- `NPM_CONFIG_PLAYWRIGHT_SKIP_${browser}_DOWNLOAD`,- `NPM_PACKAGE_CONFIG_PLAYWRIGHT_SKIP_${browser}_DOWNLOAD`,- ];- const varNames = [...templates.map(n => n.toUpperCase()), ...templates.map(n => n.toLowerCase())];- for (const varName of varNames) {- if (process.env[varName.toUpperCase()]) {- logPolitely(`**INFO** Skipping ${browser} download. "${varName}" environment variable was found.`);- browserSkips[browser] = true;- break;- }- }-}--const downloadHost = process.env.PLAYWRIGHT_DOWNLOAD_HOST || process.env.npm_config_playwright_download_host || process.env.npm_package_config_playwright_download_host;---if (require('fs').existsSync(require('path').join(__dirname, 'src'))) {- try {- require('child_process').execSync('npm run build', {- stdio: 'ignore'- });- } catch (e) {- }+ // This file is only run when someone clones the github repo for development++try {+ require('child_process').execSync('npm run build', {+ stdio: 'ignore'+ });+} catch (e) {+ console.warn('Build failed');}(async function() {const {generateWebKitProtocol, generateChromeProtocol} = require('./utils/protocol-types-generator/') ;- if (!browserSkips.Chromium) {- const chromeRevision = await downloadBrowser('chromium', require('./chromium').createBrowserFetcher({host: downloadHost}));+ try {+ const chromeRevision = await downloadBrowser('chromium', require('./chromium').createBrowserFetcher());await generateChromeProtocol(chromeRevision);+ } catch (e) {+ console.warn(e.message);}- if (!browserSkips.Firefox)- await downloadBrowser('firefox', require('./firefox').createBrowserFetcher({host: downloadHost}));-- if (!browserSkips.WebKit) {- const webkitRevision = await downloadBrowser('webkit', require('./webkit').createBrowserFetcher({host: downloadHost}));+ try {+ await downloadBrowser('firefox', require('./firefox').createBrowserFetcher());+ } catch (e) {+ console.warn(e.message);+ }+ try {+ const webkitRevision = await downloadBrowser('webkit', require('./webkit').createBrowserFetcher());await generateWebKitProtocol(webkitRevision);+ } catch (e) {+ console.warn(e.message);}})();function getRevision(browser) {if (browser === 'chromium')- return process.env.PLAYWRIGHT_CHROMIUM_REVISION || process.env.npm_config_playwright_chromium_revision || process.env.npm_package_config_playwright_chromium_revision || require('./package.json').playwright.chromium_revision;+ return require('./package.json').playwright.chromium_revision;if (browser === 'firefox')- return process.env.PLAYWRIGHT_FIREFOX_REVISION || process.env.npm_config_playwright_firefox_revision || process.env.npm_package_config_playwright_firefox_revision || require('./package.json').playwright.firefox_revision;+ return require('./package.json').playwright.firefox_revision;if (browser === 'webkit')- return process.env.PLAYWRIGHT_WEBKIT_REVISION || process.env.npm_config_playwright_webkit_revision || process.env.npm_package_config_playwright_webkit_revision || require('./package.json').playwright.webkit_revision;+ return require('./package.json').playwright.webkit_revision;}async function downloadBrowser(browser, browserFetcher) {const revision = getRevision(browser);@@ -79,18 +63,6 @@ async function downloadBrowser(browser, browserFetcher) {if (revisionInfo.local)return revisionInfo;- // Override current environment proxy settings with npm configuration, if any.- const NPM_HTTPS_PROXY = process.env.npm_config_https_proxy || process.env.npm_config_proxy;- const NPM_HTTP_PROXY = process.env.npm_config_http_proxy || process.env.npm_config_proxy;- const NPM_NO_PROXY = process.env.npm_config_no_proxy;-- if (NPM_HTTPS_PROXY)- process.env.HTTPS_PROXY = NPM_HTTPS_PROXY;- if (NPM_HTTP_PROXY)- process.env.HTTP_PROXY = NPM_HTTP_PROXY;- if (NPM_NO_PROXY)- process.env.NO_PROXY = NPM_NO_PROXY;-let progressBar = null;let lastDownloadedBytes = 0;function onProgress(downloadedBytes, totalBytes) {@@ -108,13 +80,7 @@ async function downloadBrowser(browser, browserFetcher) {progressBar.tick(delta);}- try {- await browserFetcher.download(revisionInfo.revision, onProgress);- } catch(error) {- console.error(`ERROR: Failed to download ${browser} ${revision}! Set "PLAYWRIGHT_SKIP_${browser.toUpperCase()}_DOWNLOAD" env variable to skip download.`);- console.error(error);- process.exit(1);- }+ await browserFetcher.download(revisionInfo.revision, onProgress);logPolitely(`${browser} downloaded to ${revisionInfo.folderPath}`);const localRevisions = await browserFetcher.localRevisions();// Remove previous chromium revisions.diff --git a/package.json b/package.jsonindex 4763df4018..51408a677c 100644--- a/package.json+++ b/package.json@@ -2,7 +2,6 @@"name": "playwright","version": "0.9.0-post","description": "A high-level API to control headless Chrome over the DevTools Protocol",- "main": "index.js","repository": "github:Microsoft/playwright","engines": {"node": ">=8.16.0"diff --git a/src/chromium/Launcher.ts b/src/chromium/Launcher.tsindex fec2385564..d740b0e6d3 100644--- a/src/chromium/Launcher.ts+++ b/src/chromium/Launcher.ts@@ -68,12 +68,10 @@ const DEFAULT_ARGS = [export class Launcher {private _projectRoot: string;private _preferredRevision: string;- private _isPlaywrightCore: boolean;- constructor(projectRoot: string, preferredRevision: string, isPlaywrightCore: boolean) {+ constructor(projectRoot: string, preferredRevision: string) {this._projectRoot = projectRoot;this._preferredRevision = preferredRevision;- this._isPlaywrightCore = isPlaywrightCore;}async launch(options: (LauncherLaunchOptions & LauncherChromeArgOptions & LauncherBrowserOptions) = {}): Promise<Browser> {@@ -280,23 +278,7 @@ export class Launcher {}_resolveExecutablePath(): { executablePath: string; missingText: string | null; } {- // playwright-core doesn't take into account PLAYWRIGHT_* env variables.- if (!this._isPlaywrightCore) {- const executablePath = process.env.PLAYWRIGHT_EXECUTABLE_PATH || process.env.npm_config_playwright_executable_path || process.env.npm_package_config_playwright_executable_path;- if (executablePath) {- const missingText = !fs.existsSync(executablePath) ? 'Tried to use PLAYWRIGHT_EXECUTABLE_PATH env variable to launch browser but did not find any executable at: ' + executablePath : null;- return { executablePath, missingText };- }- }const browserFetcher = new BrowserFetcher(this._projectRoot);- if (!this._isPlaywrightCore) {- const revision = process.env['PLAYWRIGHT_CHROMIUM_REVISION'];- if (revision) {- const revisionInfo = browserFetcher.revisionInfo(revision);- const missingText = !revisionInfo.local ? 'Tried to use PLAYWRIGHT_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(this._preferredRevision);const missingText = !revisionInfo.local ? `Chromium revision is not downloaded. Run "npm install" or "yarn install"` : null;return {executablePath: revisionInfo.executablePath, missingText};diff --git a/src/chromium/Playwright.ts b/src/chromium/Playwright.tsindex 9a7eafc6b2..195a9de7ab 100644--- a/src/chromium/Playwright.ts+++ b/src/chromium/Playwright.ts@@ -25,9 +25,9 @@ export class Playwright {private _projectRoot: string;private _launcher: Launcher;- constructor(projectRoot: string, preferredRevision: string, isPlaywrightCore: boolean) {+ constructor(projectRoot: string, preferredRevision: string) {this._projectRoot = projectRoot;- this._launcher = new Launcher(projectRoot, preferredRevision, isPlaywrightCore);+ this._launcher = new Launcher(projectRoot, preferredRevision);}launch(options: (LauncherLaunchOptions & LauncherChromeArgOptions & LauncherBrowserOptions) | undefined): Promise<Browser> {diff --git a/src/webkit/Launcher.ts b/src/webkit/Launcher.tsindex 20ff9b5cfd..4ab5337982 100644--- a/src/webkit/Launcher.ts+++ b/src/webkit/Launcher.ts@@ -139,12 +139,6 @@ export class Launcher {_resolveExecutablePath(): { executablePath: string; missingText: string | null; } {const browserFetcher = new BrowserFetcher(this._projectRoot);- const revision = process.env['PLAYWRIGHT_WEBKIT_REVISION'];- if (revision) {- const revisionInfo = browserFetcher.revisionInfo(revision);- const missingText = !revisionInfo.local ? 'Tried to use PLAYWRIGHT_WEBKIT_REVISION env variable to launch browser but did not find executable at: ' + revisionInfo.executablePath : null;- return {executablePath: revisionInfo.executablePath, missingText};- }const revisionInfo = browserFetcher.revisionInfo(this._preferredRevision);const missingText = !revisionInfo.local ? `WebKit revision is not downloaded. Run "npm install" or "yarn install"` : null;return {executablePath: revisionInfo.executablePath, missingText};diff --git a/utils/prepare_playwright_core.js b/utils/prepare_playwright_core.jsdeleted file mode 100644index f96053c665..0000000000--- a/utils/prepare_playwright_core.js+++ /dev/null@@ -1,25 +0,0 @@-#!/usr/bin/env node-/**- * Copyright 2018 Google Inc. All rights reserved.- *- * Licensed under the Apache License, Version 2.0 (the "License");- * you may not use this file except in compliance with the License.- * You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--const fs = require('fs');-const path = require('path');--const packagePath = path.join(__dirname, '..', 'package.json');-const json = require(packagePath);--json.name = 'playwright-core';-fs.writeFileSync(packagePath, JSON.stringify(json, null, ' '));diff --git a/webkit.js b/webkit.jsindex a439dc7857..081c1e6e4e 100644--- a/webkit.js+++ b/webkit.js@@ -22,7 +22,6 @@ for (const className in api.WebKit) {helper.installAsyncStackHooks(api.WebKit[className]);}-// If node does not support async await, use the compiled version.const {Playwright} = require('./lib/webkit/Playwright');const packageJson = require('./package.json');