Skip to content

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

feat(firefox): implement browser.firefox.wsEndpoint() (#233)

Andrey Lushnikovee1f4784c690
diff --git a/docs/api.md b/docs/api.md
index 4999242b6f..07d8e776f1 100644
--- a/docs/api.md
+++ b/docs/api.md
@@ -2286,6 +2286,15 @@ The `format` options are:
> 1. Script tags inside templates are not evaluated.
> 2. Page styles are not visible inside templates.
+### class: Firefox
+
+Firefox-specific features.
+
+#### firefox.wsEndpoint()
+- returns: <[string]> Browser websocket url.
+
+Browser websocket endpoint which can be used as an argument to [playwright.connect](#playwrightconnectoptions).
+
### class: Chromium
@@ -2293,9 +2302,9 @@ Chromium-specific features including Tracing, service worker support, etc.
You can use [`chromium.startTracing`](#chromiumstarttracingpage-options) and [`chromium.stopTracing`](#chromiumstoptracing) to create a trace file which can be opened in Chrome DevTools or [timeline viewer](https://chromedevtools.github.io/timeline-viewer/).
```js
-await page.chromium.startTracing({path: 'trace.json'});
+await browser.chromium.startTracing(page, {path: 'trace.json'});
await page.goto('https://www.google.com');
-await page.chromium.stopTracing();
+await browser.chromium.stopTracing();
```
#### event: 'targetchanged'
diff --git a/src/firefox/Browser.ts b/src/firefox/Browser.ts
index e7d904dff9..bf6bc3a5dc 100644
--- a/src/firefox/Browser.ts
+++ b/src/firefox/Browser.ts
@@ -24,6 +24,7 @@ import { Permissions } from './features/permissions';
import { Page } from '../page';
import * as types from '../types';
import { FrameManager } from './FrameManager';
+import { Firefox } from './features/firefox';
import * as network from '../network';
import { BrowserContext, BrowserInterface } from '../browserContext';
@@ -36,6 +37,7 @@ export class Browser extends EventEmitter implements BrowserInterface {
private _defaultContext: BrowserContext;
private _contexts: Map<string, BrowserContext>;
private _eventListeners: RegisteredListener[];
+ readonly firefox: Firefox;
static async create(connection: Connection, defaultViewport: types.Viewport | null, process: import('child_process').ChildProcess | null, closeCallback: () => Promise<void>) {
const {browserContextIds} = await connection.send('Target.getBrowserContexts');
@@ -50,6 +52,7 @@ export class Browser extends EventEmitter implements BrowserInterface {
this._defaultViewport = defaultViewport;
this._process = process;
this._closeCallback = closeCallback;
+ this.firefox = new Firefox(this);
this._targets = new Map();
diff --git a/src/firefox/features/firefox.ts b/src/firefox/features/firefox.ts
new file mode 100644
index 0000000000..3d5dc8df83
--- /dev/null
+++ b/src/firefox/features/firefox.ts
@@ -0,0 +1,17 @@
+// Copyright (c) Microsoft Corporation.
+// Licensed under the MIT license.
+
+import { Browser } from '../Browser';
+import { Connection } from '../Connection';
+
+export class Firefox {
+ private _connection: Connection;
+
+ constructor(browser: Browser) {
+ this._connection = browser._connection;
+ }
+
+ wsEndpoint(): string {
+ return this._connection.url();
+ }
+}
diff --git a/test/fixtures/closeme.js b/test/fixtures/closeme.js
index 094859db86..3e398ef388 100644
--- a/test/fixtures/closeme.js
+++ b/test/fixtures/closeme.js
@@ -1,5 +1,8 @@
(async() => {
const [, , playwrightRoot, options] = process.argv;
const browser = await require(playwrightRoot).launch(JSON.parse(options));
- console.log(browser.chromium.wsEndpoint());
+ if (browser.chromium)
+ console.log(browser.chromium.wsEndpoint());
+ else if (browser.firefox)
+ console.log(browser.firefox.wsEndpoint());
})();