refactor: extract Connect interfaces into common (#11392)
This commit is contained in:
parent
a9e959e8fe
commit
474d73fe1b
@ -14,66 +14,24 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type {
|
|
||||||
IsPageTargetCallback,
|
|
||||||
TargetFilterCallback,
|
|
||||||
} from '../api/Browser.js';
|
|
||||||
import type {BidiBrowser} from '../bidi/Browser.js';
|
import type {BidiBrowser} from '../bidi/Browser.js';
|
||||||
import type {ConnectionTransport} from '../common/ConnectionTransport.js';
|
import type {ConnectionTransport} from '../common/ConnectionTransport.js';
|
||||||
|
import type {
|
||||||
|
BrowserConnectOptions,
|
||||||
|
ConnectOptions,
|
||||||
|
} from '../common/ConnectOptions.js';
|
||||||
|
import {UnsupportedOperation} from '../common/Errors.js';
|
||||||
import {getFetch} from '../common/fetch.js';
|
import {getFetch} from '../common/fetch.js';
|
||||||
import {debugError} from '../common/util.js';
|
import {debugError} from '../common/util.js';
|
||||||
import type {Viewport} from '../common/Viewport.js';
|
|
||||||
import {isNode} from '../environment.js';
|
import {isNode} from '../environment.js';
|
||||||
import {assert} from '../util/assert.js';
|
import {assert} from '../util/assert.js';
|
||||||
import {isErrorLike} from '../util/ErrorLike.js';
|
import {isErrorLike} from '../util/ErrorLike.js';
|
||||||
|
|
||||||
import {CdpBrowser} from './Browser.js';
|
import {CdpBrowser} from './Browser.js';
|
||||||
import {Connection} from './Connection.js';
|
import {Connection} from './Connection.js';
|
||||||
import type {ConnectOptions} from './ConnectOptions.js';
|
|
||||||
|
|
||||||
const DEFAULT_VIEWPORT = Object.freeze({width: 800, height: 600});
|
const DEFAULT_VIEWPORT = Object.freeze({width: 800, height: 600});
|
||||||
|
|
||||||
/**
|
|
||||||
* Generic browser options that can be passed when launching any browser or when
|
|
||||||
* connecting to an existing browser instance.
|
|
||||||
* @public
|
|
||||||
*/
|
|
||||||
export interface BrowserConnectOptions {
|
|
||||||
/**
|
|
||||||
* Whether to ignore HTTPS errors during navigation.
|
|
||||||
* @defaultValue `false`
|
|
||||||
*/
|
|
||||||
ignoreHTTPSErrors?: boolean;
|
|
||||||
/**
|
|
||||||
* Sets the viewport for each page.
|
|
||||||
*/
|
|
||||||
defaultViewport?: Viewport | null;
|
|
||||||
/**
|
|
||||||
* Slows down Puppeteer operations by the specified amount of milliseconds to
|
|
||||||
* aid debugging.
|
|
||||||
*/
|
|
||||||
slowMo?: number;
|
|
||||||
/**
|
|
||||||
* Callback to decide if Puppeteer should connect to a given target or not.
|
|
||||||
*/
|
|
||||||
targetFilter?: TargetFilterCallback;
|
|
||||||
/**
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
_isPageTarget?: IsPageTargetCallback;
|
|
||||||
/**
|
|
||||||
* @defaultValue 'cdp'
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
protocol?: 'cdp' | 'webDriverBiDi';
|
|
||||||
/**
|
|
||||||
* Timeout setting for individual protocol (CDP) calls.
|
|
||||||
*
|
|
||||||
* @defaultValue `180_000`
|
|
||||||
*/
|
|
||||||
protocolTimeout?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
const getWebSocketTransportClass = async () => {
|
const getWebSocketTransportClass = async () => {
|
||||||
return isNode
|
return isNode
|
||||||
? (await import('../node/NodeWebSocketTransport.js')).NodeWebSocketTransport
|
? (await import('../node/NodeWebSocketTransport.js')).NodeWebSocketTransport
|
||||||
@ -139,7 +97,9 @@ export async function _connectToBiDiOverCdpBrowser(
|
|||||||
|
|
||||||
const version = await connection.send('Browser.getVersion');
|
const version = await connection.send('Browser.getVersion');
|
||||||
if (version.product.toLowerCase().includes('firefox')) {
|
if (version.product.toLowerCase().includes('firefox')) {
|
||||||
throw new Error('Firefox is not supported in BiDi over CDP mode.');
|
throw new UnsupportedOperation(
|
||||||
|
'Firefox is not supported in BiDi over CDP mode.'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: use other options too.
|
// TODO: use other options too.
|
||||||
|
@ -1,34 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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>;
|
|
||||||
}
|
|
@ -22,7 +22,6 @@ export * from './BrowserConnector.js';
|
|||||||
export * from './CDPSession.js';
|
export * from './CDPSession.js';
|
||||||
export * from './ChromeTargetManager.js';
|
export * from './ChromeTargetManager.js';
|
||||||
export * from './Connection.js';
|
export * from './Connection.js';
|
||||||
export * from './ConnectOptions.js';
|
|
||||||
export * from './Coverage.js';
|
export * from './Coverage.js';
|
||||||
export * from './DeviceRequestPrompt.js';
|
export * from './DeviceRequestPrompt.js';
|
||||||
export * from './Dialog.js';
|
export * from './Dialog.js';
|
||||||
|
79
packages/puppeteer-core/src/common/ConnectOptions.ts
Normal file
79
packages/puppeteer-core/src/common/ConnectOptions.ts
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
* 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 {
|
||||||
|
IsPageTargetCallback,
|
||||||
|
TargetFilterCallback,
|
||||||
|
} from '../api/Browser.js';
|
||||||
|
|
||||||
|
import type {ConnectionTransport} from './ConnectionTransport.js';
|
||||||
|
import type {Viewport} from './Viewport.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generic browser options that can be passed when launching any browser or when
|
||||||
|
* connecting to an existing browser instance.
|
||||||
|
* @public
|
||||||
|
*/
|
||||||
|
export interface BrowserConnectOptions {
|
||||||
|
/**
|
||||||
|
* Whether to ignore HTTPS errors during navigation.
|
||||||
|
* @defaultValue `false`
|
||||||
|
*/
|
||||||
|
ignoreHTTPSErrors?: boolean;
|
||||||
|
/**
|
||||||
|
* Sets the viewport for each page.
|
||||||
|
*/
|
||||||
|
defaultViewport?: Viewport | null;
|
||||||
|
/**
|
||||||
|
* Slows down Puppeteer operations by the specified amount of milliseconds to
|
||||||
|
* aid debugging.
|
||||||
|
*/
|
||||||
|
slowMo?: number;
|
||||||
|
/**
|
||||||
|
* Callback to decide if Puppeteer should connect to a given target or not.
|
||||||
|
*/
|
||||||
|
targetFilter?: TargetFilterCallback;
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
_isPageTarget?: IsPageTargetCallback;
|
||||||
|
/**
|
||||||
|
* @defaultValue 'cdp'
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
protocol?: 'cdp' | 'webDriverBiDi';
|
||||||
|
/**
|
||||||
|
* Timeout setting for individual protocol (CDP) calls.
|
||||||
|
*
|
||||||
|
* @defaultValue `180_000`
|
||||||
|
*/
|
||||||
|
protocolTimeout?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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>;
|
||||||
|
}
|
@ -19,8 +19,8 @@ import {
|
|||||||
_connectToBiDiOverCdpBrowser,
|
_connectToBiDiOverCdpBrowser,
|
||||||
_connectToCdpBrowser,
|
_connectToCdpBrowser,
|
||||||
} from '../cdp/BrowserConnector.js';
|
} from '../cdp/BrowserConnector.js';
|
||||||
import type {ConnectOptions} from '../cdp/ConnectOptions.js';
|
|
||||||
|
|
||||||
|
import type {ConnectOptions} from './ConnectOptions.js';
|
||||||
import {
|
import {
|
||||||
type CustomQueryHandler,
|
type CustomQueryHandler,
|
||||||
customQueryHandlers,
|
customQueryHandlers,
|
||||||
|
@ -15,9 +15,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export * from './BrowserWebSocketTransport.js';
|
export * from './BrowserWebSocketTransport.js';
|
||||||
export * from './common.js';
|
|
||||||
export * from './Configuration.js';
|
export * from './Configuration.js';
|
||||||
export * from './ConnectionTransport.js';
|
export * from './ConnectionTransport.js';
|
||||||
|
export * from './ConnectOptions.js';
|
||||||
export * from './ConsoleMessage.js';
|
export * from './ConsoleMessage.js';
|
||||||
export * from './CustomQueryHandler.js';
|
export * from './CustomQueryHandler.js';
|
||||||
export * from './Debug.js';
|
export * from './Debug.js';
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type {BrowserConnectOptions} from '../cdp/BrowserConnector.js';
|
import type {BrowserConnectOptions} from '../common/ConnectOptions.js';
|
||||||
import type {Product} from '../common/Product.js';
|
import type {Product} from '../common/Product.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -23,9 +23,11 @@ import {
|
|||||||
} from '@puppeteer/browsers';
|
} from '@puppeteer/browsers';
|
||||||
|
|
||||||
import type {Browser} from '../api/Browser.js';
|
import type {Browser} from '../api/Browser.js';
|
||||||
import type {BrowserConnectOptions} from '../cdp/BrowserConnector.js';
|
|
||||||
import type {ConnectOptions} from '../cdp/ConnectOptions.js';
|
|
||||||
import type {Configuration} from '../common/Configuration.js';
|
import type {Configuration} from '../common/Configuration.js';
|
||||||
|
import type {
|
||||||
|
ConnectOptions,
|
||||||
|
BrowserConnectOptions,
|
||||||
|
} from '../common/ConnectOptions.js';
|
||||||
import type {Product} from '../common/Product.js';
|
import type {Product} from '../common/Product.js';
|
||||||
import {type CommonPuppeteerSettings, Puppeteer} from '../common/Puppeteer.js';
|
import {type CommonPuppeteerSettings, Puppeteer} from '../common/Puppeteer.js';
|
||||||
import {PUPPETEER_REVISIONS} from '../revisions.js';
|
import {PUPPETEER_REVISIONS} from '../revisions.js';
|
||||||
|
Loading…
Reference in New Issue
Block a user