feat(firefox): implement browser.firefox.wsEndpoint() (#233)
This lets us pass the fixtures test for browser shutdown.
This commit is contained in:
parent
0675d8ec9a
commit
ee1f4784c6
13
docs/api.md
13
docs/api.md
|
|
@ -2286,6 +2286,15 @@ The `format` options are:
|
||||||
> 1. Script tags inside templates are not evaluated.
|
> 1. Script tags inside templates are not evaluated.
|
||||||
> 2. Page styles are not visible inside templates.
|
> 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
|
### 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/).
|
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
|
```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.goto('https://www.google.com');
|
||||||
await page.chromium.stopTracing();
|
await browser.chromium.stopTracing();
|
||||||
```
|
```
|
||||||
|
|
||||||
#### event: 'targetchanged'
|
#### event: 'targetchanged'
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ import { Permissions } from './features/permissions';
|
||||||
import { Page } from '../page';
|
import { Page } from '../page';
|
||||||
import * as types from '../types';
|
import * as types from '../types';
|
||||||
import { FrameManager } from './FrameManager';
|
import { FrameManager } from './FrameManager';
|
||||||
|
import { Firefox } from './features/firefox';
|
||||||
import * as network from '../network';
|
import * as network from '../network';
|
||||||
import { BrowserContext, BrowserInterface } from '../browserContext';
|
import { BrowserContext, BrowserInterface } from '../browserContext';
|
||||||
|
|
||||||
|
|
@ -36,6 +37,7 @@ export class Browser extends EventEmitter implements BrowserInterface {
|
||||||
private _defaultContext: BrowserContext;
|
private _defaultContext: BrowserContext;
|
||||||
private _contexts: Map<string, BrowserContext>;
|
private _contexts: Map<string, BrowserContext>;
|
||||||
private _eventListeners: RegisteredListener[];
|
private _eventListeners: RegisteredListener[];
|
||||||
|
readonly firefox: Firefox;
|
||||||
|
|
||||||
static async create(connection: Connection, defaultViewport: types.Viewport | null, process: import('child_process').ChildProcess | null, closeCallback: () => Promise<void>) {
|
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');
|
const {browserContextIds} = await connection.send('Target.getBrowserContexts');
|
||||||
|
|
@ -50,6 +52,7 @@ export class Browser extends EventEmitter implements BrowserInterface {
|
||||||
this._defaultViewport = defaultViewport;
|
this._defaultViewport = defaultViewport;
|
||||||
this._process = process;
|
this._process = process;
|
||||||
this._closeCallback = closeCallback;
|
this._closeCallback = closeCallback;
|
||||||
|
this.firefox = new Firefox(this);
|
||||||
|
|
||||||
this._targets = new Map();
|
this._targets = new Map();
|
||||||
|
|
||||||
|
|
|
||||||
17
src/firefox/features/firefox.ts
Normal file
17
src/firefox/features/firefox.ts
Normal file
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
5
test/fixtures/closeme.js
vendored
5
test/fixtures/closeme.js
vendored
|
|
@ -1,5 +1,8 @@
|
||||||
(async() => {
|
(async() => {
|
||||||
const [, , playwrightRoot, options] = process.argv;
|
const [, , playwrightRoot, options] = process.argv;
|
||||||
const browser = await require(playwrightRoot).launch(JSON.parse(options));
|
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());
|
||||||
})();
|
})();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue