Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

docs: unify XYZPlaywright api and docs (#443)

Dmitry Gozman350452c31db5
diff --git a/docs/api.md b/docs/api.md
index aabd9bb36a..adc89c996a 100644
--- a/docs/api.md
+++ b/docs/api.md
@@ -5,6 +5,11 @@
##### Table of Contents
<!-- GEN:toc -->
+- [class: Playwright](#class-playwright)
+ * [playwright.createBrowserFetcher([options])](#playwrightcreatebrowserfetcheroptions)
+ * [playwright.devices](#playwrightdevices)
+ * [playwright.errors](#playwrighterrors)
+ * [playwright.executablePath()](#playwrightexecutablepath)
- [class: Browser](#class-browser)
* [event: 'disconnected'](#event-disconnected)
* [browser.browserContexts()](#browserbrowsercontexts)
@@ -24,17 +29,11 @@
* [browserContext.setGeolocation(geolocation)](#browsercontextsetgeolocationgeolocation)
* [browserContext.setPermissions(origin, permissions[])](#browsercontextsetpermissionsorigin-permissions)
- [class: BrowserFetcher](#class-browserfetcher)
- * [browserFetcher.canDownload(revision)](#browserfetchercandownloadrevision)
- * [browserFetcher.download(revision[, progressCallback])](#browserfetcherdownloadrevision-progresscallback)
+ * [browserFetcher.canDownload([revision])](#browserfetchercandownloadrevision)
+ * [browserFetcher.download([revision, progressCallback])](#browserfetcherdownloadrevision-progresscallback)
* [browserFetcher.localRevisions()](#browserfetcherlocalrevisions)
- * [browserFetcher.remove(revision)](#browserfetcherremoverevision)
- * [browserFetcher.revisionInfo(revision)](#browserfetcherrevisioninforevision)
-- [class: ChromiumBrowserServer](#class-chromiumbrowserserver)
- * [chromiumBrowserServer.close()](#chromiumbrowserserverclose)
- * [chromiumBrowserServer.connect()](#chromiumbrowserserverconnect)
- * [chromiumBrowserServer.connectOptions()](#chromiumbrowserserverconnectoptions)
- * [chromiumBrowserServer.process()](#chromiumbrowserserverprocess)
- * [chromiumBrowserServer.wsEndpoint()](#chromiumbrowserserverwsendpoint)
+ * [browserFetcher.remove([revision])](#browserfetcherremoverevision)
+ * [browserFetcher.revisionInfo([revision])](#browserfetcherrevisioninforevision)
- [class: ConsoleMessage](#class-consolemessage)
* [consoleMessage.args()](#consolemessageargs)
* [consoleMessage.location()](#consolemessagelocation)
@@ -228,6 +227,20 @@
- [class: TimeoutError](#class-timeouterror)
- [class: Accessibility](#class-accessibility)
* [accessibility.snapshot([options])](#accessibilitysnapshotoptions)
+- [class: Coverage](#class-coverage)
+ * [coverage.startCSSCoverage([options])](#coveragestartcsscoverageoptions)
+ * [coverage.startJSCoverage([options])](#coveragestartjscoverageoptions)
+ * [coverage.stopCSSCoverage()](#coveragestopcsscoverage)
+ * [coverage.stopJSCoverage()](#coveragestopjscoverage)
+- [class: Worker](#class-worker)
+ * [worker.evaluate(pageFunction[, ...args])](#workerevaluatepagefunction-args)
+ * [worker.evaluateHandle(pageFunction[, ...args])](#workerevaluatehandlepagefunction-args)
+ * [worker.url()](#workerurl)
+- [class: ChromiumPlaywright](#class-chromiumplaywright)
+ * [chromiumPlaywright.connect(options)](#chromiumplaywrightconnectoptions)
+ * [chromiumPlaywright.defaultArgs([options])](#chromiumplaywrightdefaultargsoptions)
+ * [chromiumPlaywright.launch([options])](#chromiumplaywrightlaunchoptions)
+ * [chromiumPlaywright.launchServer([options])](#chromiumplaywrightlaunchserveroptions)
- [class: ChromiumBrowser](#class-chromiumbrowser)
* [event: 'targetchanged'](#event-targetchanged)
* [event: 'targetcreated'](#event-targetcreated)
@@ -239,21 +252,12 @@
* [chromiumBrowser.stopTracing()](#chromiumbrowserstoptracing)
* [chromiumBrowser.targets(context)](#chromiumbrowsertargetscontext)
* [chromiumBrowser.waitForTarget(predicate[, options])](#chromiumbrowserwaitfortargetpredicate-options)
-- [class: Coverage](#class-coverage)
- * [coverage.startCSSCoverage([options])](#coveragestartcsscoverageoptions)
- * [coverage.startJSCoverage([options])](#coveragestartjscoverageoptions)
- * [coverage.stopCSSCoverage()](#coveragestopcsscoverage)
- * [coverage.stopJSCoverage()](#coveragestopjscoverage)
-- [class: ChromiumPlaywright](#class-chromiumplaywright)
- * [chromiumPlaywright.connect(options)](#chromiumplaywrightconnectoptions)
- * [chromiumPlaywright.createBrowserFetcher([options])](#chromiumplaywrightcreatebrowserfetcheroptions)
- * [chromiumPlaywright.defaultArgs([options])](#chromiumplaywrightdefaultargsoptions)
- * [chromiumPlaywright.devices](#chromiumplaywrightdevices)
- * [chromiumPlaywright.downloadBrowser([options])](#chromiumplaywrightdownloadbrowseroptions)
- * [chromiumPlaywright.errors](#chromiumplaywrighterrors)
- * [chromiumPlaywright.executablePath()](#chromiumplaywrightexecutablepath)
- * [chromiumPlaywright.launch([options])](#chromiumplaywrightlaunchoptions)
- * [chromiumPlaywright.launchServer([options])](#chromiumplaywrightlaunchserveroptions)
+- [class: ChromiumBrowserServer](#class-chromiumbrowserserver)
+ * [chromiumBrowserServer.close()](#chromiumbrowserserverclose)
+ * [chromiumBrowserServer.connect()](#chromiumbrowserserverconnect)
+ * [chromiumBrowserServer.connectOptions()](#chromiumbrowserserverconnectoptions)
+ * [chromiumBrowserServer.process()](#chromiumbrowserserverprocess)
+ * [chromiumBrowserServer.wsEndpoint()](#chromiumbrowserserverwsendpoint)
- [class: ChromiumSession](#class-chromiumsession)
* [chromiumSession.detach()](#chromiumsessiondetach)
* [chromiumSession.send(method[, params])](#chromiumsessionsendmethod-params)
@@ -264,27 +268,106 @@
* [chromiumTarget.page()](#chromiumtargetpage)
* [chromiumTarget.type()](#chromiumtargettype)
* [chromiumTarget.url()](#chromiumtargeturl)
+- [class: FirefoxPlaywright](#class-firefoxplaywright)
+ * [firefoxPlaywright.connect(options)](#firefoxplaywrightconnectoptions)
+ * [firefoxPlaywright.defaultArgs([options])](#firefoxplaywrightdefaultargsoptions)
+ * [firefoxPlaywright.launch([options])](#firefoxplaywrightlaunchoptions)
+ * [firefoxPlaywright.launchServer([options])](#firefoxplaywrightlaunchserveroptions)
+- [class: FirefoxBrowser](#class-firefoxbrowser)
- [class: FirefoxBrowserServer](#class-firefoxbrowserserver)
* [firefoxBrowserServer.close()](#firefoxbrowserserverclose)
* [firefoxBrowserServer.connect()](#firefoxbrowserserverconnect)
* [firefoxBrowserServer.connectOptions()](#firefoxbrowserserverconnectoptions)
* [firefoxBrowserServer.process()](#firefoxbrowserserverprocess)
* [firefoxBrowserServer.wsEndpoint()](#firefoxbrowserserverwsendpoint)
+- [class: WebKitPlaywright](#class-webkitplaywright)
+ * [webkitPlaywright.defaultArgs([options])](#webkitplaywrightdefaultargsoptions)
+ * [webkitPlaywright.launch([options])](#webkitplaywrightlaunchoptions)
+ * [webkitPlaywright.launchServer([options])](#webkitplaywrightlaunchserveroptions)
+- [class: WebKitBrowser](#class-webkitbrowser)
- [class: WebKitBrowserServer](#class-webkitbrowserserver)
* [webKitBrowserServer.close()](#webkitbrowserserverclose)
* [webKitBrowserServer.connect()](#webkitbrowserserverconnect)
* [webKitBrowserServer.connectOptions()](#webkitbrowserserverconnectoptions)
* [webKitBrowserServer.process()](#webkitbrowserserverprocess)
-- [class: Worker](#class-worker)
- * [worker.evaluate(pageFunction[, ...args])](#workerevaluatepagefunction-args)
- * [worker.evaluateHandle(pageFunction[, ...args])](#workerevaluatehandlepagefunction-args)
- * [worker.url()](#workerurl)
-- [class: FirefoxBrowser](#class-firefoxbrowser)
-- [class: WebKitBrowser](#class-webkitbrowser)
- [Working with selectors](#working-with-selectors)
- [Working with Chrome Extensions](#working-with-chrome-extensions)
+- [Download defaults](#download-defaults)
<!-- GEN:stop -->
+### class: Playwright
+
+Playwright module provides a method to launch a browser instance.
+The following is a typical example of using Playwright to drive automation:
+```js
+const playwright = require('playwright')('chromium'); // Or 'firefox' or 'webkit'.
+
+(async () => {
+ const browser = await playwright.launch();
+ const context = await browser.newContext();
+ const page = await context.newPage();
+ await page.goto('http://example.com');
+ // other actions...
+ await browser.close();
+})();
+```
+
+See [chromiumPlaywright.launch([options])](#chromiumplaywrightlaunchoptions), [firefoxPlaywright.launch([options])](#firefoxplaywrightlaunchoptions) or [webkitPlaywright.launch([options])](#webkitplaywrightlaunchoptions) for browser-specific launch methods.
+
+#### playwright.createBrowserFetcher([options])
+- `options` <[Object]>
+ - `host` <[string]> A download host to be used.
+ - `path` <[string]> A path for the downloads folder.
+ - `platform` <[string]> Defaults to the current platform.
+- returns: <[BrowserFetcher]>
+
+See [Download defaults](#download-defaults) for default values.
+
+#### playwright.devices
+- returns: <[Object]>
+
+Returns a list of devices to be used with [`page.emulate(options)`](#pageemulateoptions). Actual list of
+devices can be found in [lib/deviceDescriptors.js](https://github.com/Microsoft/playwright/blob/master/src/deviceDescriptors.ts).
+
+```js
+const playwright = require('playwright')('firefox'); // Or 'chromium' or 'webkit'.
+const iPhone = playwright.devices['iPhone 6'];
+
+(async () => {
+ const browser = await playwright.launch();
+ const context = await browser.newContext();
+ const page = await context.newPage();
+ await page.emulate(iPhone);
+ await page.goto('http://example.com');
+ // other actions...
+ await browser.close();
+})();
+```
+
+#### playwright.errors
+- returns: <[Object]>
+ - `TimeoutError` <[function]> A class of [TimeoutError].
+
+Playwright methods might throw errors if they are unable to fulfill a request. For example, [page.waitForSelector(selector[, options])](#pagewaitforselectorselector-options)
+might fail if the selector doesn't match any nodes during the given timeframe.
+
+For certain types of errors Playwright uses specific error classes.
+These classes are available via [`playwright.errors`](#playwrighterrors)
+
+An example of handling a timeout error:
+```js
+try {
+ await page.waitForSelector('.foo');
+} catch (e) {
+ if (e instanceof playwright.errors.TimeoutError) {
+ // Do something if this is a timeout.
+ }
+}
+```
+
+#### playwright.executablePath()
+- returns: <[string]> A path where Playwright expects to find bundled browser.
+
### class: Browser
* extends: [EventEmitter](https://nodejs.org/api/events.html#events_class_eventemitter)
@@ -531,20 +614,20 @@ Playwright against it:
```js
const browserFetcher = playwright.createBrowserFetcher();
const revisionInfo = await browserFetcher.download('533271');
-const browser = await playwright.launch({executablePath: revisionInfo.executablePath})
+const browser = await playwright.launch({executablePath: revisionInfo.executablePath});
```
> **NOTE** BrowserFetcher is not designed to work concurrently with other
> instances of BrowserFetcher that share the same downloads directory.
-#### browserFetcher.canDownload(revision)
-- `revision` <[string]> a revision to check availability.
+#### browserFetcher.canDownload([revision])
+- `revision` <[string]> a revision to check availability. Defaults to preferred revision.
- returns: <[Promise]<[boolean]>> returns `true` if the revision could be downloaded from the host.
The method initiates a HEAD request to check if the revision is available.
-#### browserFetcher.download(revision[, progressCallback])
-- `revision` <[string]> a revision to download.
+#### browserFetcher.download([revision, progressCallback])
+- `revision` <[string]> a revision to download. Defaults to preferred revision.
- `progressCallback` <[function]([number], [number])> A function that will be called with two arguments:
- `downloadedBytes` <[number]> how many bytes have been downloaded
- `totalBytes` <[number]> how large is the total download.
@@ -555,17 +638,17 @@ The method initiates a HEAD request to check if the revision is available.
- `url` <[string]> URL this revision can be downloaded from
- `local` <[boolean]> whether the revision is locally available on disk
-The method initiates a GET request to download the revision from the host.
+The method initiates a GET request to download the revision from the host. See [Download defaults](#download-defaults) for approximate download size.
#### browserFetcher.localRevisions()
- returns: <[Promise]<[Array]<[string]>>> A list of all revisions available locally on disk.
-#### browserFetcher.remove(revision)
-- `revision` <[string]> a revision to remove. The method will throw if the revision has not been downloaded.
+#### browserFetcher.remove([revision])
+- `revision` <[string]> a revision to remove. Defaults to preferred revision. The method will throw if the revision has not been downloaded.
- returns: <[Promise]> Resolves when the revision has been removed.
-#### browserFetcher.revisionInfo(revision)
-- `revision` <[string]> a revision to get info for.
+#### browserFetcher.revisionInfo([revision])
+- `revision` <[string]> a revision to get info for. Defaults to preferred revision.
- returns: <[Object]>
- `revision` <[string]> the revision the info was created from
- `folderPath` <[string]> path to the extracted revision folder
@@ -573,37 +656,6 @@ The method initiates a GET request to download the revision from the host.
- `url` <[string]> URL this revision can be downloaded from
- `local` <[boolean]> whether the revision is locally available on disk
-### class: ChromiumBrowserServer
-
-#### chromiumBrowserServer.close()
-- returns: <[Promise]>
-
-Closes the browser gracefully and makes sure the process is terminated.
-
-#### chromiumBrowserServer.connect()
-- returns: <[Promise]<[Browser]>>
-
-Connects to the browser server and returns a <[Browser]> object.
-
-#### chromiumBrowserServer.connectOptions()
-- returns: <[Object]>
- - `browserWSEndpoint` <?[string]> a [browser websocket endpoint](#browserwsendpoint) to connect to.
- - `browserURL` <?[string]> a browser url to connect to, in format `http://${host}:${port}`. Use interchangeably with `browserWSEndpoint` to let Playwright fetch it from [metadata endpoint](https://chromedevtools.github.io/devtools-protocol/#how-do-i-access-the-browser-target).
- - `slowMo` <[number]>
- - `transport` <[ConnectionTransport]> **Experimental** A custom transport object which should be used to connect.
-
-This options object can be passed to [chromiumPlaywright.connect(options)](#chromiumplaywrightconnectoptions) to establish connection to the browser.
-
-#### chromiumBrowserServer.process()
-- returns: <?[ChildProcess]> Spawned browser server process.
-
-#### chromiumBrowserServer.wsEndpoint()
-- returns: <?[string]> Browser websocket url.
-
-Browser websocket endpoint which can be used as an argument to `playwright.connect`.
-
-Learn more about the [devtools protocol](https://chromedevtools.github.io/devtools-protocol) and the [browser endpoint](https://chromedevtools.github.io/devtools-protocol/#how-do-i-access-the-browser-target).
-
### class: ConsoleMessage
[ConsoleMessage] objects are dispatched by page via the ['console'](#event-console) event.
@@ -3132,90 +3184,6 @@ function findFocusedNode(node) {
}
```
-### class: ChromiumBrowser
-
-* extends: [Browser]
-
-Chromium-specific features including Tracing, service worker support, etc.
-You can use [`chromiumBrowser.startTracing`](#chromiumbrowserstarttracingpage-options) and [`chromiumBrowser.stopTracing`](#chromiumbrowserstoptracing) to create a trace file which can be opened in Chrome DevTools or [timeline viewer](https://chromedevtools.github.io/timeline-viewer/).
-
-```js
-await browser.startTracing(page, {path: 'trace.json'});
-await page.goto('https://www.google.com');
-await browser.stopTracing();
-```
-
-#### event: 'targetchanged'
-- <[Target]>
-
-Emitted when the url of a target changes.
-
-> **NOTE** This includes target changes in incognito browser contexts.
-
-
-#### event: 'targetcreated'
-- <[Target]>
-
-Emitted when a target is created, for example when a new page is opened by [`window.open`](https://developer.mozilla.org/en-US/docs/Web/API/Window/open) or [`browserContext.newPage`](#browsercontextnewpage).
-
-> **NOTE** This includes target creations in incognito browser contexts.
-
-#### event: 'targetdestroyed'
-- <[Target]>
-
-Emitted when a target is destroyed, for example when a page is closed.
-
-> **NOTE** This includes target destructions in incognito browser contexts.
-
-#### chromiumBrowser.browserTarget()
-- returns: <[Target]>
-
-Returns browser target.
-
-#### chromiumBrowser.pageTarget(page)
-- `page` <[Page]> Page to return target for.
-- returns: <[Target]> a target given page was created from.
-
-#### chromiumBrowser.serviceWorker(target)
-- `target` <[ChromiumTarget]> Target to treat as a service worker
-- returns: <[Promise]<[ChromiumWorker]>>
-
-Attaches to the service worker target.
-
-#### chromiumBrowser.startTracing(page, [options])
-- `page` <[Page]> Optional, if specified, tracing includes screenshots of the given page.
-- `options` <[Object]>
- - `path` <[string]> A path to write the trace file to.
- - `screenshots` <[boolean]> captures screenshots in the trace.
- - `categories` <[Array]<[string]>> specify custom categories to use instead of default.
-- returns: <[Promise]>
-
-Only one trace can be active at a time per browser.
-
-#### chromiumBrowser.stopTracing()
-- returns: <[Promise]<[Buffer]>> Promise which resolves to buffer with trace data.
-
-#### chromiumBrowser.targets(context)
-- `context` <[BrowserContext]> Optional, if specified, only targets from this context are returned.
-- returns: <[Array]<[Target]>>
-
-An array of all active targets inside the Browser. In case of multiple browser contexts,
-the method will return an array with all the targets in all browser contexts.
-
-#### chromiumBrowser.waitForTarget(predicate[, options])
-- `predicate` <[function]\([Target]\):[boolean]> A function to be run for every target
-- `options` <[Object]>
- - `timeout` <[number]> Maximum wait time in milliseconds. Pass `0` to disable the timeout. Defaults to 30 seconds.
-- returns: <[Promise]<[Target]>> Promise which resolves to the first target found that matches the `predicate` function.
-
-This searches for a target in all browser contexts.
-
-An example of finding a target for a page opened via `window.open`:
-```js
-await page.evaluate(() => window.open('https://www.example.com/'));
-const newWindowTarget = await browser.chromium.waitForTarget(target => target.url() === 'https://www.example.com/');
-```
-
### class: Coverage
Coverage gathers information about parts of JavaScript and CSS that were used by the page.
@@ -3284,43 +3252,58 @@ _To output coverage in a form consumable by [Istanbul](https://github.com/istanb
> **NOTE** JavaScript Coverage doesn't include anonymous scripts by default. However, scripts with sourceURLs are
reported.
-### class: ChromiumPlaywright
+### class: Worker
+
+The Worker class represents a [WebWorker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API).
+The events `workercreated` and `workerdestroyed` are emitted on the page object to signal the worker lifecycle.
-Playwright module provides a method to launch a Chromium instance.
-The following is a typical example of using Playwright to drive automation:
```js
-const playwright = require('playwright');
+page.on('workercreated', worker => console.log('Worker created: ' + worker.url()));
+page.on('workerdestroyed', worker => console.log('Worker destroyed: ' + worker.url()));
-(async () => {
- const browser = await playwright.launch();
- const context = await browser.newContext();
- const page = await context.newPage();
- await page.goto('https://www.google.com');
- // other actions...
- await browser.close();
-})();
+console.log('Current workers:');
+for (const worker of page.workers())
+ console.log(' ' + worker.url());
```
+#### worker.evaluate(pageFunction[, ...args])
+- `pageFunction` <[function]|[string]> Function to be evaluated in the worker context
+- `...args` <...[Serializable]|[JSHandle]> Arguments to pass to `pageFunction`
+- returns: <[Promise]<[Serializable]>> Promise which resolves to the return value of `pageFunction`
+
+If the function passed to the `worker.evaluate` returns a [Promise], then `worker.evaluate` would wait for the promise to resolve and return its value.
+
+If the function passed to the `worker.evaluate` returns a non-[Serializable] value, then `worker.evaluate` resolves to `undefined`. DevTools Protocol also supports transferring some additional values that are not serializable by `JSON`: `-0`, `NaN`, `Infinity`, `-Infinity`, and bigint literals.
+
+#### worker.evaluateHandle(pageFunction[, ...args])
+- `pageFunction` <[function]|[string]> Function to be evaluated in the page context
+- `...args` <...[Serializable]|[JSHandle]> Arguments to pass to `pageFunction`
+- returns: <[Promise]<[JSHandle]>> Promise which resolves to the return value of `pageFunction` as in-page object (JSHandle)
+
+The only difference between `worker.evaluate` and `worker.evaluateHandle` is that `worker.evaluateHandle` returns in-page object (JSHandle).
+
+If the function passed to the `worker.evaluateHandle` returns a [Promise], then `worker.evaluateHandle` would wait for the promise to resolve and return its value.
+
+#### worker.url()
+- returns: <[string]>
+
+### class: ChromiumPlaywright
+
+* extends: [Playwright]
+
#### chromiumPlaywright.connect(options)
- `options` <[Object]>
- `browserWSEndpoint` <?[string]> a [browser websocket endpoint](#browserwsendpoint) to connect to.
- `browserURL` <?[string]> a browser url to connect to, in format `http://${host}:${port}`. Use interchangeably with `browserWSEndpoint` to let Playwright fetch it from [metadata endpoint](https://chromedevtools.github.io/devtools-protocol/#how-do-i-access-the-browser-target).
- `slowMo` <[number]> Slows down Playwright operations by the specified amount of milliseconds. Useful so that you can see what is going on.
- `transport` <[ConnectionTransport]> **Experimental** Specify a custom transport object for Playwright to use.
-- returns: <[Promise]<[Browser]>>
+- returns: <[Promise]<[ChromiumBrowser]>>
This methods attaches Playwright to an existing Chromium instance.
-#### chromiumPlaywright.createBrowserFetcher([options])
-- `options` <[Object]>
- - `host` <[string]> A download host to be used. Defaults to `https://storage.googleapis.com`.
- - `path` <[string]> A path for the downloads folder. Defaults to `<root>/.local-chromium`, where `<root>` is playwright's package root.
- - `platform` <[string]> Possible values are: `mac`, `win32`, `win64`, `linux`. Defaults to the current platform.
-- returns: <[BrowserFetcher]>
-
#### chromiumPlaywright.defaultArgs([options])
- `options` <[Object]> Set of configurable options to set on the browser. Can have the following fields:
- - `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`.
+ - `headless` <[boolean]> Whether to run Chromium in [headless mode](https://developers.google.com/web/updates/2017/04/headless-chrome). Defaults to `true` unless the `devtools` option is `true`.
- `args` <[Array]<[string]>> Additional arguments to pass to the browser instance. The list of Chromium flags can be found [here](http://peter.sh/experiments/chromium-command-line-switches/).
- `userDataDir` <[string]> Path to a [User Data Directory](https://chromium.googlesource.com/chromium/src/+/master/docs/user_data_dir.md).
- `devtools` <[boolean]> Whether to auto-open a DevTools panel for each tab. If this option is `true`, the `headless` option will be set `false`.
@@ -3328,79 +3311,13 @@ This methods attaches Playwright to an existing Chromium instance.
The default flags that Chromium will be launched with.
-#### chromiumPlaywright.devices
-- returns: <[Object]>
-
-Returns a list of devices to be used with [`page.emulate(options)`](#pageemulateoptions). Actual list of
-devices can be found in [lib/DeviceDescriptors.js](https://github.com/Microsoft/playwright/blob/master/lib/DeviceDescriptors.js).
-
-```js
-const playwright = require('playwright');
-const iPhone = playwright.devices['iPhone 6'];
-
-(async () => {
- const browser = await playwright.launch();
- const context = await browser.newContext();
- const page = await context.newPage();
- await page.emulate(iPhone);
- await page.goto('https://www.google.com');
- // other actions...
- await browser.close();
-})();
-```
-
-> **NOTE** The old way (Playwright versions <= v1.14.0) devices can be obtained with `require('playwright/DeviceDescriptors')`.
-
-#### chromiumPlaywright.downloadBrowser([options])
-- `options` <[Object]>
- - `host` <[string]> A download host to be used. Defaults to `https://storage.googleapis.com`.
- - `path` <[string]> A path for the downloads folder. Defaults to `<root>/.local-chromium`, where `<root>` is playwright's package root.
- - `platform` <[string]> Possible values are: `mac`, `win32`, `win64`, `linux`. Defaults to the current platform.
- - `onProgress` <[function]([number], [number])> A function that will be called with two arguments:
- - `downloadedBytes` <[number]> how many bytes have been downloaded
- - `totalBytes` <[number]> how large is the total download.
-- returns: <[Promise]<[Object]>> Resolves with revision information when the revision is downloaded and extracted
- - `revision` <[string]> the revision the info was created from
- - `folderPath` <[string]> path to the extracted revision folder
- - `executablePath` <[string]> path to the revision executable
- - `url` <[string]> URL this revision can be downloaded from
- - `local` <[boolean]> whether the revision is locally available on disk
-
-Downloads the default browser that Playwright controls. The browser is usually around 100mb.
-
-#### chromiumPlaywright.errors
-- returns: <[Object]>
- - `TimeoutError` <[function]> A class of [TimeoutError].
-
-Playwright methods might throw errors if they are unable to fulfill a request. For example, [page.waitForSelector(selector[, options])](#pagewaitforselectorselector-options)
-might fail if the selector doesn't match any nodes during the given timeframe.
-
-For certain types of errors Playwright uses specific error classes.
-These classes are available via [`playwright.errors`](#playwrighterrors)
-
-An example of handling a timeout error:
-```js
-try {
- await page.waitForSelector('.foo');
-} catch (e) {
- if (e instanceof playwright.errors.TimeoutError) {
- // Do something if this is a timeout.
- }
-}
-```
-
-> **NOTE** The old way (Playwright versions <= v1.14.0) errors can be obtained with `require('playwright/Errors')`.
-
-#### chromiumPlaywright.executablePath()
-- returns: <[string]> A path where Playwright expects to find bundled Chromium.
-
#### chromiumPlaywright.launch([options])
- `options` <[Object]> Set of configurable options to set on the browser. Can have the following fields:
- - `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`.
+ - `headless` <[boolean]> Whether to run Chromium 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 Chromium or Chrome 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**: 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.
- `slowMo` <[number]> Slows down Playwright operations by the specified amount of milliseconds. Useful so that you can see what is going on.
- `args` <[Array]<[string]>> Additional arguments to pass to the browser instance. The list of Chromium flags can be found [here](http://peter.sh/experiments/chromium-command-line-switches/).
- - `ignoreDefaultArgs` <[boolean]|[Array]<[string]>> If `true`, then do not use [`playwright.defaultArgs()`](#playwrightdefaultargsoptions). If an array is given, then filter out the given default arguments. Dangerous option; use with care. Defaults to `false`.
+ - `ignoreDefaultArgs` <[boolean]|[Array]<[string]>> If `true`, then do not use [`chromiumPlaywright.defaultArgs()`](#chromiumplaywrightdefaultargsoptions). If an array is given, then filter out the given default arguments. Dangerous option; use with care. Defaults to `false`.
- `handleSIGINT` <[boolean]> Close the browser process on Ctrl-C. Defaults to `true`.
- `handleSIGTERM` <[boolean]> Close the browser process on SIGTERM. Defaults to `true`.
- `handleSIGHUP` <[boolean]> Close the browser process on SIGHUP. Defaults to `true`.
@@ -3410,7 +3327,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`.
-- returns: <[Promise]<[Browser]>> Promise which resolves to browser instance.
+- returns: <[Promise]<[ChromiumBrowser]>> Promise which resolves to browser instance.
You can use `ignoreDefaultArgs` to filter out `--mute-audio` from default arguments:
@@ -3424,17 +3341,17 @@ const browser = await playwright.launch({
>
> If Google Chrome (rather than Chromium) is preferred, a [Chrome Canary](https://www.google.com/chrome/browser/canary.html) or [Dev Channel](https://www.chromium.org/getting-involved/dev-channel) build is suggested.
>
-> In [playwright.launch([options])](#playwrightlaunchoptions) above, any mention of Chromium also applies to Chrome.
+> In [chromiumPlaywright.launch([options])](#chromiumplaywrightlaunchoptions) above, any mention of Chromium also applies to Chrome.
>
> See [`this article`](https://www.howtogeek.com/202825/what%E2%80%99s-the-difference-between-chromium-and-chrome/) for a description of the differences between Chromium and Chrome. [`This article`](https://chromium.googlesource.com/chromium/src/+/lkgr/docs/chromium_browser_vs_google_chrome.md) describes some differences for Linux users.
#### chromiumPlaywright.launchServer([options])
- `options` <[Object]> Set of configurable options to set on the browser. Can have the following fields:
- - `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`.
+ - `headless` <[boolean]> Whether to run Chromium 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 Chromium or Chrome 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**: 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.
- `slowMo` <[number]> Slows down Playwright operations by the specified amount of milliseconds. Useful so that you can see what is going on.
- `args` <[Array]<[string]>> Additional arguments to pass to the browser instance. The list of Chromium flags can be found [here](http://peter.sh/experiments/chromium-command-line-switches/).
- - `ignoreDefaultArgs` <[boolean]|[Array]<[string]>> If `true`, then do not use [`playwright.defaultArgs()`](#playwrightdefaultargsoptions). If an array is given, then filter out the given default arguments. Dangerous option; use with care. Defaults to `false`.
+ - `ignoreDefaultArgs` <[boolean]|[Array]<[string]>> If `true`, then do not use [`chromiumPlaywright.defaultArgs()`](#chromiumplaywrightdefaultargsoptions). If an array is given, then filter out the given default arguments. Dangerous option; use with care. Defaults to `false`.
- `handleSIGINT` <[boolean]> Close the browser process on Ctrl-C. Defaults to `true`.
- `handleSIGTERM` <[boolean]> Close the browser process on SIGTERM. Defaults to `true`.
- `handleSIGHUP` <[boolean]> Close the browser process on SIGHUP. Defaults to `true`.
@@ -3444,7 +3361,122 @@ const browser = await playwright.launch({
- `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`.
-- returns: <[Promise]<[BrowserServer]>> Promise which resolves to browser server instance.
+- returns: <[Promise]<[ChromiumBrowserServer]>> Promise which resolves to browser server instance.
+
+### class: ChromiumBrowser
+
+* extends: [Browser]
+
+Chromium-specific features including Tracing, service worker support, etc.
+You can use [`chromiumBrowser.startTracing`](#chromiumbrowserstarttracingpage-options) and [`chromiumBrowser.stopTracing`](#chromiumbrowserstoptracing) to create a trace file which can be opened in Chrome DevTools or [timeline viewer](https://chromedevtools.github.io/timeline-viewer/).
+
+```js
+await browser.startTracing(page, {path: 'trace.json'});
+await page.goto('https://www.google.com');
+await browser.stopTracing();
+```
+
+#### event: 'targetchanged'
+- <[Target]>
+
+Emitted when the url of a target changes.
+
+> **NOTE** This includes target changes in incognito browser contexts.
+
+
+#### event: 'targetcreated'
+- <[Target]>
+
+Emitted when a target is created, for example when a new page is opened by [`window.open`](https://developer.mozilla.org/en-US/docs/Web/API/Window/open) or [`browserContext.newPage`](#browsercontextnewpage).
+
+> **NOTE** This includes target creations in incognito browser contexts.
+
+#### event: 'targetdestroyed'
+- <[Target]>
+
+Emitted when a target is destroyed, for example when a page is closed.
+
+> **NOTE** This includes target destructions in incognito browser contexts.
+
+#### chromiumBrowser.browserTarget()
+- returns: <[Target]>
+
+Returns browser target.
+
+#### chromiumBrowser.pageTarget(page)
+- `page` <[Page]> Page to return target for.
+- returns: <[Target]> a target given page was created from.
+
+#### chromiumBrowser.serviceWorker(target)
+- `target` <[ChromiumTarget]> Target to treat as a service worker
+- returns: <[Promise]<[ChromiumWorker]>>
+
+Attaches to the service worker target.
+
+#### chromiumBrowser.startTracing(page, [options])
+- `page` <[Page]> Optional, if specified, tracing includes screenshots of the given page.
+- `options` <[Object]>
+ - `path` <[string]> A path to write the trace file to.
+ - `screenshots` <[boolean]> captures screenshots in the trace.
+ - `categories` <[Array]<[string]>> specify custom categories to use instead of default.
+- returns: <[Promise]>
+
+Only one trace can be active at a time per browser.
+
+#### chromiumBrowser.stopTracing()
+- returns: <[Promise]<[Buffer]>> Promise which resolves to buffer with trace data.
+
+#### chromiumBrowser.targets(context)
+- `context` <[BrowserContext]> Optional, if specified, only targets from this context are returned.
+- returns: <[Array]<[Target]>>
+
+An array of all active targets inside the Browser. In case of multiple browser contexts,
+the method will return an array with all the targets in all browser contexts.
+
+#### chromiumBrowser.waitForTarget(predicate[, options])
+- `predicate` <[function]\([Target]\):[boolean]> A function to be run for every target
+- `options` <[Object]>
+ - `timeout` <[number]> Maximum wait time in milliseconds. Pass `0` to disable the timeout. Defaults to 30 seconds.
+- returns: <[Promise]<[Target]>> Promise which resolves to the first target found that matches the `predicate` function.
+
+This searches for a target in all browser contexts.
+
+An example of finding a target for a page opened via `window.open`:
+```js
+await page.evaluate(() => window.open('https://www.example.com/'));
+const newWindowTarget = await browser.chromium.waitForTarget(target => target.url() === 'https://www.example.com/');
+```
+
+### class: ChromiumBrowserServer
+
+#### chromiumBrowserServer.close()
+- returns: <[Promise]>
+
+Closes the browser gracefully and makes sure the process is terminated.
+
+#### chromiumBrowserServer.connect()
+- returns: <[Promise]<[ChromiumBrowser]>>
+
+Connects to the browser server and returns a <[ChromiumBrowser]> object.
+
+#### chromiumBrowserServer.connectOptions()
+- returns: <[Object]>
+ - `browserWSEndpoint` <?[string]> a [browser websocket endpoint](#browserwsendpoint) to connect to.
+ - `browserURL` <?[string]> a browser url to connect to, in format `http://${host}:${port}`. Use interchangeably with `browserWSEndpoint` to let Playwright fetch it from [metadata endpoint](https://chromedevtools.github.io/devtools-protocol/#how-do-i-access-the-browser-target).
+ - `slowMo` <[number]>
+ - `transport` <[ConnectionTransport]> **Experimental** A custom transport object which should be used to connect.
+
+This options object can be passed to [chromiumPlaywright.connect(options)](#chromiumplaywrightconnectoptions) to establish connection to the browser.
+
+#### chromiumBrowserServer.process()
+- returns: <?[ChildProcess]> Spawned browser server process.
+
+#### chromiumBrowserServer.wsEndpoint()
+- returns: <?[string]> Browser websocket url.
+
+Browser websocket endpoint which can be used as an argument to [chromiumPlaywright.connect(options)](#chromiumplaywrightconnectoptions).
+
+Learn more about the [devtools protocol](https://chromedevtools.github.io/devtools-protocol) and the [browser endpoint](https://chromedevtools.github.io/devtools-protocol/#how-do-i-access-the-browser-target).
### class: ChromiumSession
@@ -3511,6 +3543,74 @@ Identifies what kind of target this is. Can be `"page"`, [`"background_page"`](h
#### chromiumTarget.url()
- returns: <[string]>
+### class: FirefoxPlaywright
+
+* extends: [Playwright]
+
+#### firefoxPlaywright.connect(options)
+- `options` <[Object]>
+ - `browserWSEndpoint` <?[string]> a [browser websocket endpoint](#browserwsendpoint) to connect to.
+ - `slowMo` <[number]> Slows down Playwright operations by the specified amount of milliseconds. Useful so that you can see what is going on.
+ - `transport` <[ConnectionTransport]> **Experimental** Specify a custom transport object for Playwright to use.
+- returns: <[Promise]<[FirefoxBrowser]>>
+
+This methods attaches Playwright to an existing Firefox instance.
+
+#### firefoxPlaywright.defaultArgs([options])
+- `options` <[Object]> Set of configurable options to set on the browser. Can have the following fields:
+ - `headless` <[boolean]> Whether to run Firefox in [headless mode](https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Headless_mode). Defaults to `true`.
+ - `args` <[Array]<[string]>> Additional arguments to pass to the browser instance. The list of Firefox flags can be found [here](https://developer.mozilla.org/en-US/docs/Mozilla/Command_Line_Options).
+ - `userDataDir` <[string]> Path to a [User Data Directory](https://developer.mozilla.org/en-US/docs/Mozilla/Command_Line_Options#User_Profile).
+- returns: <[Array]<[string]>>
+
+The default flags that Firefox will be launched with.
+
+#### firefoxPlaywright.launch([options])
+- `options` <[Object]> Set of configurable options to set on the browser. Can have the following fields:
+ - `headless` <[boolean]> Whether to run Firefox in [headless mode](https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Headless_mode). Defaults to `true`.
+ - `executablePath` <[string]> Path to a Firefox executable to run instead of the bundled Firefox. 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**: Playwright is only guaranteed to work with the bundled Firefox, use at your own risk.
+ - `slowMo` <[number]> Slows down Playwright operations by the specified amount of milliseconds. Useful so that you can see what is going on.
+ - `args` <[Array]<[string]>> Additional arguments to pass to the browser instance. The list of Firefox flags can be found [here](https://developer.mozilla.org/en-US/docs/Mozilla/Command_Line_Options).
+ - `ignoreDefaultArgs` <[boolean]|[Array]<[string]>> If `true`, then do not use [`firefoxPlaywright.defaultArgs()`](#firefoxplaywrightdefaultargsoptions). If an array is given, then filter out the given default arguments. Dangerous option; use with care. Defaults to `false`.
+ - `handleSIGINT` <[boolean]> Close the browser process on Ctrl-C. Defaults to `true`.
+ - `handleSIGTERM` <[boolean]> Close the browser process on SIGTERM. Defaults to `true`.
+ - `handleSIGHUP` <[boolean]> Close the browser process on SIGHUP. Defaults to `true`.
+ - `timeout` <[number]> Maximum time in milliseconds to wait for the browser instance to start. Defaults to `30000` (30 seconds). Pass `0` to disable timeout.
+ - `dumpio` <[boolean]> Whether to pipe the browser process stdout and stderr into `process.stdout` and `process.stderr`. Defaults to `false`.
+ - `userDataDir` <[string]> Path to a [User Data Directory](https://developer.mozilla.org/en-US/docs/Mozilla/Command_Line_Options#User_Profile).
+ - `env` <[Object]> Specify environment variables that will be visible to the browser. Defaults to `process.env`.
+- returns: <[Promise]<[FirefoxBrowser]>> Promise which resolves to browser instance.
+
+
+You can use `ignoreDefaultArgs` to filter out `--mute-audio` from default arguments:
+```js
+const browser = await playwright.launch({
+ ignoreDefaultArgs: ['--mute-audio']
+});
+```
+
+#### firefoxPlaywright.launchServer([options])
+- `options` <[Object]> Set of configurable options to set on the browser. Can have the following fields:
+ - `headless` <[boolean]> Whether to run Firefox in [headless mode](https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Headless_mode). Defaults to `true`.
+ - `executablePath` <[string]> Path to a Firefox executable to run instead of the bundled Firefox. 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**: Playwright is only guaranteed to work with the bundled Firefox, use at your own risk.
+ - `slowMo` <[number]> Slows down Playwright operations by the specified amount of milliseconds. Useful so that you can see what is going on.
+ - `args` <[Array]<[string]>> Additional arguments to pass to the browser instance. The list of Firefox flags can be found [here](https://developer.mozilla.org/en-US/docs/Mozilla/Command_Line_Options).
+ - `ignoreDefaultArgs` <[boolean]|[Array]<[string]>> If `true`, then do not use [`firefoxPlaywright.defaultArgs()`](#firefoxplaywrightdefaultargsoptions). If an array is given, then filter out the given default arguments. Dangerous option; use with care. Defaults to `false`.
+ - `handleSIGINT` <[boolean]> Close the browser process on Ctrl-C. Defaults to `true`.
+ - `handleSIGTERM` <[boolean]> Close the browser process on SIGTERM. Defaults to `true`.
+ - `handleSIGHUP` <[boolean]> Close the browser process on SIGHUP. Defaults to `true`.
+ - `timeout` <[number]> Maximum time in milliseconds to wait for the browser instance to start. Defaults to `30000` (30 seconds). Pass `0` to disable timeout.
+ - `dumpio` <[boolean]> Whether to pipe the browser process stdout and stderr into `process.stdout` and `process.stderr`. Defaults to `false`.
+ - `userDataDir` <[string]> Path to a [User Data Directory](https://developer.mozilla.org/en-US/docs/Mozilla/Command_Line_Options#User_Profile).
+ - `env` <[Object]> Specify environment variables that will be visible to the browser. Defaults to `process.env`.
+- returns: <[Promise]<[FirefoxBrowserServer]>> Promise which resolves to browser server instance.
+
+### class: FirefoxBrowser
+
+* extends: [Browser]
+
+Firefox browser instance does not expose Firefox-specific features.
+
### class: FirefoxBrowserServer
#### firefoxBrowserServer.close()
@@ -3519,9 +3619,9 @@ Identifies what kind of target this is. Can be `"page"`, [`"background_page"`](h
Closes the browser gracefully and makes sure the process is terminated.
#### firefoxBrowserServer.connect()
-- returns: <[Promise]<[Browser]>>
+- returns: <[Promise]<[FirefoxBrowser]>>
-Connects to the browser server and returns a <[Browser]> object.
+Connects to the browser server and returns a <[FirefoxBrowser]> object.
#### firefoxBrowserServer.connectOptions()
- returns: <[Object]>
@@ -3537,76 +3637,84 @@ This options object can be passed to [firefoxPlaywright.connect(options)](#firef
#### firefoxBrowserServer.wsEndpoint()
- returns: <?[string]> Browser websocket url.
-Browser websocket endpoint which can be used as an argument to `playwright.connect`.
-
-### class: WebKitBrowserServer
-
-#### webKitBrowserServer.close()
-- returns: <[Promise]>
+Browser websocket endpoint which can be used as an argument to [firefoxPlaywright.connect(options)](#firefoxplaywrightconnectoptions).
-Closes the browser gracefully and makes sure the process is terminated.
+### class: WebKitPlaywright
-#### webKitBrowserServer.connect()
-- returns: <[Promise]<[Browser]>>
+* extends: [Playwright]
-Connects to the browser server and returns a <[Browser]> object.
-
-#### webKitBrowserServer.connectOptions()
-- returns: <[Object]>
- - `slowMo` <[number]>
- - `transport` <[ConnectionTransport]> **Experimental** A custom transport object which should be used to connect.
+#### webkitPlaywright.defaultArgs([options])
+- `options` <[Object]> Set of configurable options to set on the browser. Can have the following fields:
+ - `args` <[Array]<[string]>> Additional arguments to pass to the browser instance.
+- returns: <[Array]<[string]>>
-This options object can be passed to [webKitPlaywright.connect(options)](#webkitplaywrightconnectoptions) to establish connection to the browser.
+The default flags that WebKit will be launched with.
-#### webKitBrowserServer.process()
-- returns: <?[ChildProcess]> Spawned browser server process.
-
-### class: Worker
+#### webkitPlaywright.launch([options])
+- `options` <[Object]> Set of configurable options to set on the browser. Can have the following fields:
+ - `headless` <[boolean]> Whether to run WebKit in headless mode. Defaults to `true`.
+ - `executablePath` <[string]> Path to a WebKit executable to run instead of the bundled WebKit. 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**: Playwright is only guaranteed to work with the bundled WebKit, use at your own risk.
+ - `slowMo` <[number]> Slows down Playwright operations by the specified amount of milliseconds. Useful so that you can see what is going on.
+ - `args` <[Array]<[string]>> Additional arguments to pass to the browser instance.
+ - `ignoreDefaultArgs` <[boolean]|[Array]<[string]>> If `true`, then do not use [`webKitPlaywright.defaultArgs()`](#webkitplaywrightdefaultargsoptions). If an array is given, then filter out the given default arguments. Dangerous option; use with care. Defaults to `false`.
+ - `handleSIGINT` <[boolean]> Close the browser process on Ctrl-C. Defaults to `true`.
+ - `handleSIGTERM` <[boolean]> Close the browser process on SIGTERM. Defaults to `true`.
+ - `handleSIGHUP` <[boolean]> Close the browser process on SIGHUP. Defaults to `true`.
+ - `timeout` <[number]> Maximum time in milliseconds to wait for the browser instance to start. Defaults to `30000` (30 seconds). Pass `0` to disable timeout.
+ - `dumpio` <[boolean]> Whether to pipe the browser process stdout and stderr into `process.stdout` and `process.stderr`. Defaults to `false`.
+ - `env` <[Object]> Specify environment variables that will be visible to the browser. Defaults to `process.env`.
+- returns: <[Promise]<[WebKitBrowser]>> Promise which resolves to browser instance.
-The Worker class represents a [WebWorker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API).
-The events `workercreated` and `workerdestroyed` are emitted on the page object to signal the worker lifecycle.
+You can use `ignoreDefaultArgs` to filter out `--mute-audio` from default arguments:
```js
-page.on('workercreated', worker => console.log('Worker created: ' + worker.url()));
-page.on('workerdestroyed', worker => console.log('Worker destroyed: ' + worker.url()));
-
-console.log('Current workers:');
-for (const worker of page.workers())
- console.log(' ' + worker.url());
+const browser = await playwright.launch({
+ ignoreDefaultArgs: ['--mute-audio']
+});
```
-#### worker.evaluate(pageFunction[, ...args])
-- `pageFunction` <[function]|[string]> Function to be evaluated in the worker context
-- `...args` <...[Serializable]|[JSHandle]> Arguments to pass to `pageFunction`
-- returns: <[Promise]<[Serializable]>> Promise which resolves to the return value of `pageFunction`
-
-If the function passed to the `worker.evaluate` returns a [Promise], then `worker.evaluate` would wait for the promise to resolve and return its value.
+#### webkitPlaywright.launchServer([options])
+- `options` <[Object]> Set of configurable options to set on the browser. Can have the following fields:
+ - `headless` <[boolean]> Whether to run WebKit in headless mode. Defaults to `true`.
+ - `executablePath` <[string]> Path to a WebKit executable to run instead of the bundled WebKit. 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**: Playwright is only guaranteed to work with the bundled WebKit, use at your own risk.
+ - `slowMo` <[number]> Slows down Playwright operations by the specified amount of milliseconds. Useful so that you can see what is going on.
+ - `args` <[Array]<[string]>> Additional arguments to pass to the browser instance.
+ - `ignoreDefaultArgs` <[boolean]|[Array]<[string]>> If `true`, then do not use [`webKitPlaywright.defaultArgs()`](#webkitplaywrightdefaultargsoptions). If an array is given, then filter out the given default arguments. Dangerous option; use with care. Defaults to `false`.
+ - `handleSIGINT` <[boolean]> Close the browser process on Ctrl-C. Defaults to `true`.
+ - `handleSIGTERM` <[boolean]> Close the browser process on SIGTERM. Defaults to `true`.
+ - `handleSIGHUP` <[boolean]> Close the browser process on SIGHUP. Defaults to `true`.
+ - `timeout` <[number]> Maximum time in milliseconds to wait for the browser instance to start. Defaults to `30000` (30 seconds). Pass `0` to disable timeout.
+ - `dumpio` <[boolean]> Whether to pipe the browser process stdout and stderr into `process.stdout` and `process.stderr`. Defaults to `false`.
+ - `env` <[Object]> Specify environment variables that will be visible to the browser. Defaults to `process.env`.
+- returns: <[Promise]<[WebKitBrowserServer]>> Promise which resolves to browser server instance.
-If the function passed to the `worker.evaluate` returns a non-[Serializable] value, then `worker.evaluate` resolves to `undefined`. DevTools Protocol also supports transferring some additional values that are not serializable by `JSON`: `-0`, `NaN`, `Infinity`, `-Infinity`, and bigint literals.
+### class: WebKitBrowser
-#### worker.evaluateHandle(pageFunction[, ...args])
-- `pageFunction` <[function]|[string]> Function to be evaluated in the page context
-- `...args` <...[Serializable]|[JSHandle]> Arguments to pass to `pageFunction`
-- returns: <[Promise]<[JSHandle]>> Promise which resolves to the return value of `pageFunction` as in-page object (JSHandle)
+* extends: [Browser]
-The only difference between `worker.evaluate` and `worker.evaluateHandle` is that `worker.evaluateHandle` returns in-page object (JSHandle).
+WebKit browser instance does not expose WebKit-specific features.
-If the function passed to the `worker.evaluateHandle` returns a [Promise], then `worker.evaluateHandle` would wait for the promise to resolve and return its value.
+### class: WebKitBrowserServer
-#### worker.url()
-- returns: <[string]>
+#### webKitBrowserServer.close()
+- returns: <[Promise]>
-### class: FirefoxBrowser
+Closes the browser gracefully and makes sure the process is terminated.
-* extends: [Browser]
+#### webKitBrowserServer.connect()
+- returns: <[Promise]<[WebKitBrowser]>>
-Firefox-specific features.
+Connects to the browser server and returns a <[WebKitBrowser]> object.
-### class: WebKitBrowser
+#### webKitBrowserServer.connectOptions()
+- returns: <[Object]>
+ - `slowMo` <[number]>
+ - `transport` <[ConnectionTransport]> **Experimental** A custom transport object which should be used to connect.
-* extends: [Browser]
+This options object can be passed to [webKitPlaywright.connect(options)](#webkitplaywrightconnectoptions) to establish connection to the browser.
-WebKit-specific features.
+#### webKitBrowserServer.process()
+- returns: <?[ChildProcess]> Spawned browser server process.
### Working with selectors
@@ -3674,6 +3782,17 @@ const playwright = require('playwright');
> **NOTE** It is not yet possible to test extension popups or content scripts.
+### Download defaults
+
+See [playwright.createBrowserFetcher([options])](#playwrightcreatebrowserfetcheroptions) for explanation. Below `<root>` is playwright's package root.
+
+| | Chromium | Firefox | WebKit |
+| --- | --- | --- | --- |
+| Download host | `https://storage.googleapis.com` | `https://playwrightaccount.blob.core.windows.net` | `https://playwrightaccount.blob.core.windows.net` |
+| Download path | `<root>/.local-chromium` | `<root>/.local-firefox` | `<root>/.local-webkit` |
+| Supported platforms | `mac`, `win32`, `win64`, `linux` | `mac`, `win32`, `win64`, `linux` | `mac`, `linux`; linux binaries are run with WSL on Windows |
+| Approximate download size | 120mb | 70mb | 50mb |
+
[AXNode]: #accessibilitysnapshotoptions "AXNode"
[Accessibility]: #class-accessibility "Accessibility"
[Array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array"
@@ -3682,9 +3801,11 @@ const playwright = require('playwright');
[BrowserFetcher]: #class-browserfetcher "BrowserFetcher"
[Browser]: #class-browser "Browser"
[Buffer]: https://nodejs.org/api/buffer.html#buffer_class_buffer "Buffer"
-[CDPSession]: #class-cdpsession "CDPSession"
[ChildProcess]: https://nodejs.org/api/child_process.html "ChildProcess"
-[Chromium]: #class-chromium "Chromium"
+[ChromiumBrowser]: #class-chromiumbrowser "ChromiumBrowser"
+[ChromiumBrowserServer]: #class-chromiumbrowserserver "ChromiumBrowserServer"
+[ChromiumPlaywright]: #class-chromiumplaywright "ChromiumPlaywright"
+[ChromiumSession]: #class-chromiumsession "ChromiumSession"
[ChromiumTarget]: #class-chromiumtarget "ChromiumTarget"
[ConnectionTransport]: ../lib/WebSocketTransport.js "ConnectionTransport"
[ConsoleMessage]: #class-consolemessage "ConsoleMessage"
@@ -3695,6 +3816,9 @@ const playwright = require('playwright');
[Error]: https://nodejs.org/api/errors.html#errors_class_error "Error"
[File]: #class-file "https://developer.mozilla.org/en-US/docs/Web/API/File"
[FileChooser]: #class-filechooser "FileChooser"
+[FirefoxBrowser]: #class-firefoxbrowser "FirefoxBrowser"
+[FirefoxBrowserServer]: #class-firefoxbrowserserver "FirefoxBrowserServer"
+[FirefoxPlaywright]: #class-firefoxplaywright "FirefoxPlaywright"
[Frame]: #class-frame "Frame"
[JSHandle]: #class-jshandle "JSHandle"
[Keyboard]: #class-keyboard "Keyboard"
@@ -3702,6 +3826,7 @@ const playwright = require('playwright');
[Mouse]: #class-mouse "Mouse"
[Object]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object"
[Page]: #class-page "Page"
+[Playwright]: #class-playwright "Playwright"
[Promise]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise"
[RegExp]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp
[Request]: #class-request "Request"
@@ -3713,6 +3838,9 @@ const playwright = require('playwright');
[URL]: https://nodejs.org/api/url.html
[USKeyboardLayout]: ../lib/USKeyboardLayout.js "USKeyboardLayout"
[UnixTime]: https://en.wikipedia.org/wiki/Unix_time "Unix Time"
+[WebKitBrowser]: #class-webkitbrowser "WebKitBrowser"
+[WebKitBrowserServer]: #class-webkitbrowserserver "WebKitBrowserServer"
+[WebKitPlaywright]: #class-webkitplaywright "WebKitPlaywright"
[Worker]: #class-worker "Worker"
[boolean]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean"
[function]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function "Function"
diff --git a/install.js b/install.js
index 2db4bd91ac..7aedbb6667 100644
--- a/install.js
+++ b/install.js
@@ -16,7 +16,7 @@
*/
// This file is only run when someone clones the github repo for development
-
+
try {
require('child_process').execSync('npm run build', {
stdio: 'ignore'
@@ -73,14 +73,16 @@ async function downloadBrowser(browser, playwright) {
progressBar.tick(delta);
}
- const revisionInfo = await playwright.downloadBrowser({onProgress});
+ const fetcher = playwright.createBrowserFetcher();
+ const revisionInfo = fetcher.revisionInfo();
// Do nothing if the revision is already downloaded.
if (revisionInfo.local)
return revisionInfo;
+ await fetcher.download(revisionInfo.revision, onProgress);
logPolitely(`${browser} downloaded to ${revisionInfo.folderPath}`);
const browserFetcher = playwright.createBrowserFetcher();
const localRevisions = await browserFetcher.localRevisions();
- // Remove previous chromium revisions.
+ // Remove previous revisions.
const cleanupOldVersions = localRevisions.filter(revision => revision !== revisionInfo.revision).map(revision => browserFetcher.remove(revision));
await Promise.all([...cleanupOldVersions]);
return revisionInfo;
diff --git a/src/api.ts b/src/api.ts
index 2b4d73d306..e85aba2f39 100644
--- a/src/api.ts
+++ b/src/api.ts
@@ -36,6 +36,7 @@ export { FFBrowser as FirefoxBrowser } from './firefox/ffBrowser';
export { WKBrowser as WebKitBrowser } from './webkit/wkBrowser';
export { BrowserFetcher } from './server/browserFetcher';
+export { Playwright } from './server/playwright';
export { CRPlaywright as ChromiumPlaywright, CRBrowserServer as ChromiumBrowserServer } from './server/crPlaywright';
export { FFPlaywright as FirefoxPlaywright, FFBrowserServer as FirefoxBrowserServer } from './server/ffPlaywright';
export { WKPlaywright as WebKitPlaywright, WKBrowserServer as WebKitBrowserServer } from './server/wkPlaywright';
diff --git a/src/firefox/ffBrowser.ts b/src/firefox/ffBrowser.ts
index c03fbf1840..7a5c3036d1 100644
--- a/src/firefox/ffBrowser.ts
+++ b/src/firefox/ffBrowser.ts
@@ -221,7 +221,7 @@ export class FFBrowser extends platform.EventEmitter implements Browser {
}
}
-export class Target {
+class Target {
_pagePromise?: Promise<Page>;
_ffPage: FFPage | null = null;
private readonly _browser: FFBrowser;
diff --git a/src/server/browserFetcher.ts b/src/server/browserFetcher.ts
index 322b8e155d..d424f02c89 100644
--- a/src/server/browserFetcher.ts
+++ b/src/server/browserFetcher.ts
@@ -44,15 +44,17 @@ export type OnProgressCallback = (downloadedBytes: number, totalBytes: number) =
export class BrowserFetcher {
private _downloadsFolder: string;
private _platform: string;
+ private _preferredRevision: string;
private _params: ParamsGetter;
- constructor(downloadsFolder: string, platform: string, params: ParamsGetter) {
+ constructor(downloadsFolder: string, platform: string, preferredRevision: string, params: ParamsGetter) {
this._downloadsFolder = downloadsFolder;
this._platform = platform;
+ this._preferredRevision = preferredRevision;
this._params = params;
}
- canDownload(revision: string): Promise<boolean> {
+ canDownload(revision: string = this._preferredRevision): Promise<boolean> {
const url = this._params(this._platform, revision).downloadUrl;
let resolve;
const promise = new Promise<boolean>(x => resolve = x);
@@ -66,7 +68,7 @@ export class BrowserFetcher {
return promise;
}
- async download(revision: string, progressCallback: OnProgressCallback | null): Promise<BrowserFetcherRevisionInfo> {
+ async download(revision: string = this._preferredRevision, progressCallback?: OnProgressCallback): Promise<BrowserFetcherRevisionInfo> {
const url = this._params(this._platform, revision).downloadUrl;
const zipPath = path.join(this._downloadsFolder, `download-${this._platform}-${revision}.zip`);
const folderPath = this._getFolderPath(revision);
@@ -94,13 +96,13 @@ export class BrowserFetcher {
return fileNames.map(fileName => parseFolderPath(fileName)).filter(entry => entry && entry.platform === this._platform).map(entry => entry.revision);
}
- async remove(revision: string) {
+ async remove(revision: string = this._preferredRevision) {
const folderPath = this._getFolderPath(revision);
assert(await existsAsync(folderPath), `Failed to remove: revision ${revision} is not downloaded`);
await new Promise(fulfill => removeRecursive(folderPath, fulfill));
}
- revisionInfo(revision: string): BrowserFetcherRevisionInfo {
+ revisionInfo(revision: string = this._preferredRevision): BrowserFetcherRevisionInfo {
const folderPath = this._getFolderPath(revision);
const params = this._params(this._platform, revision);
const local = fs.existsSync(folderPath);
diff --git a/src/server/crPlaywright.ts b/src/server/crPlaywright.ts
index 2095e29b68..f1de1bbfda 100644
--- a/src/server/crPlaywright.ts
+++ b/src/server/crPlaywright.ts
@@ -19,9 +19,8 @@ import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
import * as util from 'util';
-import { BrowserFetcher, BrowserFetcherOptions, BrowserFetcherRevisionInfo, OnProgressCallback } from '../server/browserFetcher';
+import { BrowserFetcher, BrowserFetcherOptions } from '../server/browserFetcher';
import { DeviceDescriptors } from '../deviceDescriptors';
-import * as Errors from '../errors';
import * as types from '../types';
import { assert } from '../helper';
import { CRBrowser, CRConnectOptions, createTransport } from '../chromium/crBrowser';
@@ -31,6 +30,7 @@ import { launchProcess, waitForLine } from '../server/processLauncher';
import { ChildProcess } from 'child_process';
import { CRConnection } from '../chromium/crConnection';
import { PipeTransport } from './pipeTransport';
+import { Playwright } from './playwright';
export type SlowMoOptions = {
slowMo?: number,
@@ -45,7 +45,7 @@ export type ChromeArgOptions = {
export type LaunchOptions = ChromeArgOptions & SlowMoOptions & {
executablePath?: string,
- ignoreDefaultArgs?: boolean|string[],
+ ignoreDefaultArgs?: boolean | string[],
handleSIGINT?: boolean,
handleSIGTERM?: boolean,
handleSIGHUP?: boolean,
@@ -87,7 +87,7 @@ export class CRBrowserServer {
}
}
-export class CRPlaywright {
+export class CRPlaywright implements Playwright {
private _projectRoot: string;
readonly _revision: string;
@@ -96,13 +96,6 @@ export class CRPlaywright {
this._revision = preferredRevision;
}
- async downloadBrowser(options?: BrowserFetcherOptions & { onProgress?: OnProgressCallback }): Promise<BrowserFetcherRevisionInfo> {
- const fetcher = this.createBrowserFetcher(options);
- const revisionInfo = fetcher.revisionInfo(this._revision);
- await fetcher.download(this._revision, options ? options.onProgress : undefined);
- return revisionInfo;
- }
-
async launch(options?: LaunchOptions): Promise<CRBrowser> {
const server = await this.launchServer(options);
return server.connect();
@@ -198,8 +191,8 @@ export class CRPlaywright {
return DeviceDescriptors;
}
- get errors(): any {
- return Errors;
+ get errors(): { TimeoutError: typeof TimeoutError } {
+ return { TimeoutError };
}
defaultArgs(options: ChromeArgOptions = {}): string[] {
@@ -255,7 +248,7 @@ export class CRPlaywright {
};
assert(!!(downloadURLs as any)[options.platform], 'Unsupported platform: ' + options.platform);
- return new BrowserFetcher(options.path, options.platform, (platform: string, revision: string) => {
+ return new BrowserFetcher(options.path, options.platform, this._revision, (platform: string, revision: string) => {
let archiveName = '';
let executablePath = '';
if (platform === 'linux') {
@@ -278,7 +271,7 @@ export class CRPlaywright {
_resolveExecutablePath(): { executablePath: string; missingText: string | null; } {
const browserFetcher = this.createBrowserFetcher();
- const revisionInfo = browserFetcher.revisionInfo(this._revision);
+ const revisionInfo = browserFetcher.revisionInfo();
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/server/ffPlaywright.ts b/src/server/ffPlaywright.ts
index 73a22353a8..5ac8614d71 100644
--- a/src/server/ffPlaywright.ts
+++ b/src/server/ffPlaywright.ts
@@ -16,10 +16,9 @@
*/
import { FFBrowser, FFConnectOptions, createTransport } from '../firefox/ffBrowser';
-import { BrowserFetcher, BrowserFetcherOptions, OnProgressCallback, BrowserFetcherRevisionInfo } from './browserFetcher';
+import { BrowserFetcher, BrowserFetcherOptions } from './browserFetcher';
import { DeviceDescriptors } from '../deviceDescriptors';
import { launchProcess, waitForLine } from './processLauncher';
-import * as Errors from '../errors';
import * as types from '../types';
import * as platform from '../platform';
import { FFConnection } from '../firefox/ffConnection';
@@ -30,6 +29,28 @@ import * as path from 'path';
import * as util from 'util';
import { TimeoutError } from '../errors';
import { assert } from '../helper';
+import { Playwright } from './playwright';
+
+export type SlowMoOptions = {
+ slowMo?: number,
+};
+
+export type FirefoxArgOptions = {
+ headless?: boolean,
+ args?: string[],
+ userDataDir?: string,
+};
+
+export type LaunchOptions = FirefoxArgOptions & SlowMoOptions & {
+ executablePath?: string,
+ ignoreDefaultArgs?: boolean | string[],
+ handleSIGINT?: boolean,
+ handleSIGTERM?: boolean,
+ handleSIGHUP?: boolean,
+ timeout?: number,
+ dumpio?: boolean,
+ env?: {[key: string]: string} | undefined,
+};
export class FFBrowserServer {
private _process: ChildProcess;
@@ -63,7 +84,7 @@ export class FFBrowserServer {
}
}
-export class FFPlaywright {
+export class FFPlaywright implements Playwright {
private _projectRoot: string;
readonly _revision: string;
@@ -72,19 +93,12 @@ export class FFPlaywright {
this._revision = preferredRevision;
}
- async downloadBrowser(options?: BrowserFetcherOptions & { onProgress?: OnProgressCallback }): Promise<BrowserFetcherRevisionInfo> {
- const fetcher = this.createBrowserFetcher(options);
- const revisionInfo = fetcher.revisionInfo(this._revision);
- await fetcher.download(this._revision, options ? options.onProgress : undefined);
- return revisionInfo;
- }
-
- async launch(options: any): Promise<FFBrowser> {
+ async launch(options: LaunchOptions): Promise<FFBrowser> {
const server = await this.launchServer(options);
return server.connect();
}
- async launchServer(options: any = {}): Promise<FFBrowserServer> {
+ async launchServer(options: LaunchOptions = {}): Promise<FFBrowserServer> {
const {
ignoreDefaultArgs = false,
args = [],
@@ -170,11 +184,12 @@ export class FFPlaywright {
return DeviceDescriptors;
}
- get errors(): any {
- return Errors;
+ get errors(): { TimeoutError: typeof TimeoutError } {
+ return { TimeoutError };
}
- defaultArgs(options: any = {}): string[] {
+ // TODO: rename userDataDir to profile?
+ defaultArgs(options: FirefoxArgOptions = {}): string[] {
const {
headless = true,
args = [],
@@ -219,7 +234,7 @@ export class FFPlaywright {
};
assert(!!downloadURLs[options.platform], 'Unsupported platform: ' + options.platform);
- return new BrowserFetcher(options.path, options.platform, (platform: string, revision: string) => {
+ return new BrowserFetcher(options.path, options.platform, this._revision, (platform: string, revision: string) => {
let executablePath = '';
if (platform === 'linux')
executablePath = path.join('firefox', 'firefox');
@@ -236,7 +251,7 @@ export class FFPlaywright {
_resolveExecutablePath() {
const browserFetcher = this.createBrowserFetcher();
- const revisionInfo = browserFetcher.revisionInfo(this._revision);
+ const revisionInfo = browserFetcher.revisionInfo();
const missingText = !revisionInfo.local ? `Firefox revision is not downloaded. Run "npm install" or "yarn install"` : null;
return { executablePath: revisionInfo.executablePath, missingText };
}
diff --git a/src/server/playwright.ts b/src/server/playwright.ts
new file mode 100644
index 0000000000..fa50ad6ae9
--- /dev/null
+++ b/src/server/playwright.ts
@@ -0,0 +1,26 @@
+/**
+ * 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.
+ * 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.
+ */
+
+import { BrowserFetcherOptions, BrowserFetcher } from './browserFetcher';
+import * as types from '../types';
+import { TimeoutError } from '../errors';
+
+export interface Playwright {
+ createBrowserFetcher(options?: BrowserFetcherOptions): BrowserFetcher;
+ executablePath(): string;
+ devices: types.Devices;
+ errors: { TimeoutError: typeof TimeoutError };
+}
diff --git a/src/server/wkPlaywright.ts b/src/server/wkPlaywright.ts
index cea3079161..b4b9a8b41b 100644
--- a/src/server/wkPlaywright.ts
+++ b/src/server/wkPlaywright.ts
@@ -15,9 +15,9 @@
* limitations under the License.
*/
-import { BrowserFetcher, BrowserFetcherOptions, OnProgressCallback, BrowserFetcherRevisionInfo } from './browserFetcher';
+import { BrowserFetcher, BrowserFetcherOptions } from './browserFetcher';
import { DeviceDescriptors } from '../deviceDescriptors';
-import * as Errors from '../errors';
+import { TimeoutError } from '../errors';
import * as types from '../types';
import { WKBrowser, createTransport } from '../webkit/wkBrowser';
import { WKConnectOptions } from '../webkit/wkBrowser';
@@ -29,9 +29,10 @@ import * as util from 'util';
import * as os from 'os';
import { assert } from '../helper';
import { kBrowserCloseMessageId } from '../webkit/wkConnection';
+import { Playwright } from './playwright';
export type LaunchOptions = {
- ignoreDefaultArgs?: boolean,
+ ignoreDefaultArgs?: boolean | string[],
args?: string[],
executablePath?: string,
handleSIGINT?: boolean,
@@ -72,7 +73,7 @@ export class WKBrowserServer {
}
}
-export class WKPlaywright {
+export class WKPlaywright implements Playwright {
private _projectRoot: string;
readonly _revision: string;
@@ -81,13 +82,6 @@ export class WKPlaywright {
this._revision = preferredRevision;
}
- async downloadBrowser(options?: BrowserFetcherOptions & { onProgress?: OnProgressCallback }): Promise<BrowserFetcherRevisionInfo> {
- const fetcher = this.createBrowserFetcher(options);
- const revisionInfo = fetcher.revisionInfo(this._revision);
- await fetcher.download(this._revision, options ? options.onProgress : undefined);
- return revisionInfo;
- }
-
async launch(options?: LaunchOptions): Promise<WKBrowser> {
const server = await this.launchServer(options);
return server.connect();
@@ -109,6 +103,8 @@ export class WKPlaywright {
const webkitArguments = [];
if (!ignoreDefaultArgs)
webkitArguments.push(...this.defaultArgs(options));
+ else if (Array.isArray(ignoreDefaultArgs))
+ webkitArguments.push(...this.defaultArgs(options).filter(arg => ignoreDefaultArgs.indexOf(arg) === -1));
else
webkitArguments.push(...args);
@@ -158,11 +154,11 @@ export class WKPlaywright {
return DeviceDescriptors;
}
- get errors(): any {
- return Errors;
+ get errors(): { TimeoutError: typeof TimeoutError } {
+ return { TimeoutError };
}
- defaultArgs(options: any = {}): string[] {
+ defaultArgs(options: { args?: string[] } = {}): string[] {
const {
args = [],
} = options;
@@ -197,7 +193,7 @@ export class WKPlaywright {
};
assert(!!downloadURLs[options.platform], 'Unsupported platform: ' + options.platform);
- return new BrowserFetcher(options.path, options.platform, (platform: string, revision: string) => {
+ return new BrowserFetcher(options.path, options.platform, this._revision, (platform: string, revision: string) => {
return {
downloadUrl: (platform === 'mac') ?
util.format(downloadURLs[platform], options.host, revision, getMacVersion()) :
@@ -209,7 +205,7 @@ export class WKPlaywright {
_resolveExecutablePath(): { executablePath: string; missingText: string | null; } {
const browserFetcher = this.createBrowserFetcher();
- const revisionInfo = browserFetcher.revisionInfo(this._revision);
+ const revisionInfo = browserFetcher.revisionInfo();
const missingText = !revisionInfo.local ? `WebKit revision is not downloaded. Run "npm install" or "yarn install"` : null;
return { executablePath: revisionInfo.executablePath, missingText };
}