mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
db28203e64
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.
53 lines
1.1 KiB
TypeScript
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;
|
|
}
|