puppeteer/src/common/bidi/Browser.ts
Alex Rudenko db28203e64 chore: support WebDriver BiDi browser instances (#8932)
This PR adds a basic support for WebDriver BiDi that currently includes only the ability to establish a connection and shutdown the browser. Therefore, the implementation is marked as internal and won't show up in the changelog as it's barely useful at the moment.

The API classes are kept as classes instead of interfaces so that clients relying on instanceof checks still work.
2022-09-15 02:15:15 +02:00

53 lines
1.1 KiB
TypeScript

import {
Browser as BrowserBase,
BrowserCloseCallback,
} from '../../api/Browser.js';
import {Connection} from './Connection.js';
import {ChildProcess} from 'child_process';
/**
* @internal
*/
export class Browser extends BrowserBase {
/**
* @internal
*/
static async create(opts: Options): Promise<Browser> {
// TODO: await until the connection is established.
return new Browser(opts);
}
#process?: ChildProcess;
#closeCallback?: BrowserCloseCallback;
#connection: Connection;
/**
* @internal
*/
constructor(opts: Options) {
super();
this.#process = opts.process;
this.#closeCallback = opts.closeCallback;
this.#connection = opts.connection;
}
override async close(): Promise<void> {
await this.#closeCallback?.call(null);
this.#connection.dispose();
}
override isConnected(): boolean {
return !this.#connection.closed;
}
override process(): ChildProcess | null {
return this.#process ?? null;
}
}
interface Options {
process?: ChildProcess;
closeCallback?: BrowserCloseCallback;
connection: Connection;
}