refactor: respect protocol option in Puppeteer.connect (#11338)

Co-authored-by: Maksim Sadym <sadym@google.com>
This commit is contained in:
Maksim Sadym 2023-11-09 18:12:23 +01:00 committed by GitHub
parent 0fe89b7da9
commit 3a11926bd8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 48 additions and 29 deletions

View File

@ -28,7 +28,7 @@ import {isErrorLike} from '../util/ErrorLike.js';
import {CdpBrowser} from './Browser.js';
import {Connection} from './Connection.js';
import type {ConnectOptions} from './Puppeteer.js';
import type {ConnectOptions} from './ConnectOptions.js';
/**
* Generic browser options that can be passed when launching any browser or when
* connecting to an existing browser instance.

View File

@ -0,0 +1,34 @@
/*
* Copyright 2023 Google Inc. All rights reserved.
*
* 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 type {ConnectionTransport} from '../common/ConnectionTransport.js';
import type {BrowserConnectOptions} from './BrowserConnector.js';
/**
* @public
*/
export interface ConnectOptions extends BrowserConnectOptions {
browserWSEndpoint?: string;
browserURL?: string;
transport?: ConnectionTransport;
/**
* Headers to use for the web socket connection.
* @remarks
* Only works in the Node.js environment.
*/
headers?: Record<string, string>;
}

View File

@ -22,6 +22,7 @@ export * from './BrowserConnector.js';
export * from './CDPSession.js';
export * from './ChromeTargetManager.js';
export * from './Connection.js';
export * from './ConnectOptions.js';
export * from './Coverage.js';
export * from './DeviceRequestPrompt.js';
export * from './Dialog.js';
@ -43,7 +44,6 @@ export * from './NetworkEventManager.js';
export * from './NetworkManager.js';
export * from './Page.js';
export * from './PredefinedNetworkConditions.js';
export * from './Puppeteer.js';
export * from './Target.js';
export * from './TargetManager.js';
export * from './Tracing.js';

View File

@ -15,16 +15,13 @@
*/
import type {Browser} from '../api/Browser.js';
import type {ConnectionTransport} from '../common/ConnectionTransport.js';
import {_connectToCdpBrowser} from '../cdp/BrowserConnector.js';
import type {ConnectOptions} from '../cdp/ConnectOptions.js';
import {
type CustomQueryHandler,
customQueryHandlers,
} from '../common/CustomQueryHandler.js';
import {
type BrowserConnectOptions,
_connectToCdpBrowser,
} from './BrowserConnector.js';
} from './CustomQueryHandler.js';
/**
* Settings that are common to the Puppeteer class, regardless of environment.
@ -34,20 +31,6 @@ import {
export interface CommonPuppeteerSettings {
isPuppeteerCore: boolean;
}
/**
* @public
*/
export interface ConnectOptions extends BrowserConnectOptions {
browserWSEndpoint?: string;
browserURL?: string;
transport?: ConnectionTransport;
/**
* Headers to use for the web socket connection.
* @remarks
* Only works in the Node.js environment.
*/
headers?: Record<string, string>;
}
/**
* The main Puppeteer class.
@ -145,6 +128,10 @@ export class Puppeteer {
* @returns Promise which resolves to browser instance.
*/
connect(options: ConnectOptions): Promise<Browser> {
return _connectToCdpBrowser(options);
if (options.protocol === 'webDriverBiDi') {
throw new Error('Not implemented');
} else {
return _connectToCdpBrowser(options);
}
}
}

View File

@ -34,6 +34,7 @@ export * from './PDFOptions.js';
export * from './PierceQueryHandler.js';
export * from './PQueryHandler.js';
export * from './Product.js';
export * from './Puppeteer.js';
export * from './QueryHandler.js';
export * from './ScriptInjector.js';
export * from './SecurityDetails.js';

View File

@ -24,13 +24,10 @@ import {
import type {Browser} from '../api/Browser.js';
import type {BrowserConnectOptions} from '../cdp/BrowserConnector.js';
import {
type CommonPuppeteerSettings,
type ConnectOptions,
Puppeteer,
} from '../cdp/Puppeteer.js';
import type {ConnectOptions} from '../cdp/ConnectOptions.js';
import type {Configuration} from '../common/Configuration.js';
import type {Product} from '../common/Product.js';
import {type CommonPuppeteerSettings, Puppeteer} from '../common/Puppeteer.js';
import {PUPPETEER_REVISIONS} from '../revisions.js';
import {ChromeLauncher} from './ChromeLauncher.js';