diff --git a/src/client/accessibility.ts b/src/client/accessibility.ts index 15e39dde24..63c938a316 100644 --- a/src/client/accessibility.ts +++ b/src/client/accessibility.ts @@ -15,17 +15,17 @@ * limitations under the License. */ -import { PageChannel, AXNode } from '../protocol/channels'; +import * as channels from '../protocol/channels'; import { ElementHandle } from './elementHandle'; -type SerializedAXNode = Omit & { +type SerializedAXNode = Omit & { value?: string|number, checked?: boolean | 'mixed', pressed?: boolean | 'mixed', children?: SerializedAXNode[] }; -function axNodeFromProtocol(axNode: AXNode): SerializedAXNode { +function axNodeFromProtocol(axNode: channels.AXNode): SerializedAXNode { const result: SerializedAXNode = { ...axNode, value: axNode.valueNumber !== undefined ? axNode.valueNumber : axNode.valueString, @@ -39,9 +39,9 @@ function axNodeFromProtocol(axNode: AXNode): SerializedAXNode { } export class Accessibility { - private _channel: PageChannel; + private _channel: channels.PageChannel; - constructor(channel: PageChannel) { + constructor(channel: channels.PageChannel) { this._channel = channel; } diff --git a/src/client/browser.ts b/src/client/browser.ts index 221ff93bb4..0d58c38f82 100644 --- a/src/client/browser.ts +++ b/src/client/browser.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { BrowserChannel, BrowserInitializer, BrowserNewContextParams } from '../protocol/channels'; +import * as channels from '../protocol/channels'; import { BrowserContext } from './browserContext'; import { Page } from './page'; import { ChannelOwner } from './channelOwner'; @@ -24,22 +24,22 @@ import { BrowserContextOptions } from './types'; import { validateHeaders } from './network'; import { headersObjectToArray } from '../utils/utils'; -export class Browser extends ChannelOwner { +export class Browser extends ChannelOwner { readonly _contexts = new Set(); private _isConnected = true; private _isClosedOrClosing = false; private _closedPromise: Promise; readonly _browserType: BrowserType; - static from(browser: BrowserChannel): Browser { + static from(browser: channels.BrowserChannel): Browser { return (browser as any)._object; } - static fromNullable(browser: BrowserChannel | null): Browser | null { + static fromNullable(browser: channels.BrowserChannel | null): Browser | null { return browser ? Browser.from(browser) : null; } - constructor(parent: ChannelOwner, type: string, guid: string, initializer: BrowserInitializer) { + constructor(parent: ChannelOwner, type: string, guid: string, initializer: channels.BrowserInitializer) { super(parent, type, guid, initializer); this._browserType = parent as BrowserType; this._channel.on('close', () => this._didClose()); @@ -51,7 +51,7 @@ export class Browser extends ChannelOwner { return this._wrapApiCall('browser.newContext', async () => { if (options.extraHTTPHeaders) validateHeaders(options.extraHTTPHeaders); - const contextOptions: BrowserNewContextParams = { + const contextOptions: channels.BrowserNewContextParams = { ...options, viewport: options.viewport === null ? undefined : options.viewport, noDefaultViewport: options.viewport === null, diff --git a/src/client/browserContext.ts b/src/client/browserContext.ts index a4101e8ebe..bddc1b8205 100644 --- a/src/client/browserContext.ts +++ b/src/client/browserContext.ts @@ -18,7 +18,7 @@ import * as frames from './frame'; import { Page, BindingCall } from './page'; import * as network from './network'; -import { BrowserContextChannel, BrowserContextInitializer } from '../protocol/channels'; +import * as channels from '../protocol/channels'; import { ChannelOwner } from './channelOwner'; import { deprecate, evaluationScript, urlMatches } from './clientHelper'; import { Browser } from './browser'; @@ -28,7 +28,7 @@ import { Waiter } from './waiter'; import { URLMatch, Headers, WaitForEventOptions } from './types'; import { isUnderTest, headersObjectToArray } from '../utils/utils'; -export class BrowserContext extends ChannelOwner { +export class BrowserContext extends ChannelOwner { _pages = new Set(); private _routes: { url: URLMatch, handler: network.RouteHandler }[] = []; readonly _browser: Browser | undefined; @@ -39,15 +39,15 @@ export class BrowserContext extends ChannelOwner; - static from(context: BrowserContextChannel): BrowserContext { + static from(context: channels.BrowserContextChannel): BrowserContext { return (context as any)._object; } - static fromNullable(context: BrowserContextChannel | null): BrowserContext | null { + static fromNullable(context: channels.BrowserContextChannel | null): BrowserContext | null { return context ? BrowserContext.from(context) : null; } - constructor(parent: ChannelOwner, type: string, guid: string, initializer: BrowserContextInitializer, browserName: string) { + constructor(parent: ChannelOwner, type: string, guid: string, initializer: channels.BrowserContextInitializer, browserName: string) { super(parent, type, guid, initializer); if (parent instanceof Browser) this._browser = parent; diff --git a/src/client/browserType.ts b/src/client/browserType.ts index 97395d527e..9de1dc70d2 100644 --- a/src/client/browserType.ts +++ b/src/client/browserType.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { BrowserTypeChannel, BrowserTypeInitializer, BrowserTypeLaunchParams, BrowserTypeLaunchPersistentContextParams } from '../protocol/channels'; +import * as channels from '../protocol/channels'; import { Browser } from './browser'; import { BrowserContext } from './browserContext'; import { ChannelOwner } from './channelOwner'; @@ -40,15 +40,15 @@ export interface BrowserServer { kill(): Promise; } -export class BrowserType extends ChannelOwner { +export class BrowserType extends ChannelOwner { private _timeoutSettings = new TimeoutSettings(); _serverLauncher?: BrowserServerLauncher; - static from(browserType: BrowserTypeChannel): BrowserType { + static from(browserType: channels.BrowserTypeChannel): BrowserType { return (browserType as any)._object; } - constructor(parent: ChannelOwner, type: string, guid: string, initializer: BrowserTypeInitializer) { + constructor(parent: ChannelOwner, type: string, guid: string, initializer: channels.BrowserTypeInitializer) { super(parent, type, guid, initializer); } @@ -66,7 +66,7 @@ export class BrowserType extends ChannelOwner { assert(!(options as any).userDataDir, 'userDataDir option is not supported in `browserType.launch`. Use `browserType.launchPersistentContext` instead'); assert(!(options as any).port, 'Cannot specify a port without launching as a server.'); - const launchOptions: BrowserTypeLaunchParams = { + const launchOptions: channels.BrowserTypeLaunchParams = { ...options, ignoreDefaultArgs: Array.isArray(options.ignoreDefaultArgs) ? options.ignoreDefaultArgs : undefined, ignoreAllDefaultArgs: !!options.ignoreDefaultArgs && !Array.isArray(options.ignoreDefaultArgs), @@ -90,7 +90,7 @@ export class BrowserType extends ChannelOwner { if (options.extraHTTPHeaders) validateHeaders(options.extraHTTPHeaders); - const persistentOptions: BrowserTypeLaunchPersistentContextParams = { + const persistentOptions: channels.BrowserTypeLaunchPersistentContextParams = { ...options, viewport: options.viewport === null ? undefined : options.viewport, noDefaultViewport: options.viewport === null, diff --git a/src/client/cdpSession.ts b/src/client/cdpSession.ts index e71a3b0eda..c3b7923950 100644 --- a/src/client/cdpSession.ts +++ b/src/client/cdpSession.ts @@ -14,12 +14,12 @@ * limitations under the License. */ -import { CDPSessionChannel, CDPSessionInitializer } from '../protocol/channels'; +import * as channels from '../protocol/channels'; import { ChannelOwner } from './channelOwner'; import { Protocol } from '../server/chromium/protocol'; -export class CDPSession extends ChannelOwner { - static from(cdpSession: CDPSessionChannel): CDPSession { +export class CDPSession extends ChannelOwner { + static from(cdpSession: channels.CDPSessionChannel): CDPSession { return (cdpSession as any)._object; } @@ -29,7 +29,7 @@ export class CDPSession extends ChannelOwner(event: T, listener: (payload: T extends symbol ? any : Protocol.Events[T extends keyof Protocol.Events ? T : never]) => void) => this; once: (event: T, listener: (payload: T extends symbol ? any : Protocol.Events[T extends keyof Protocol.Events ? T : never]) => void) => this; - constructor(parent: ChannelOwner, type: string, guid: string, initializer: CDPSessionInitializer) { + constructor(parent: ChannelOwner, type: string, guid: string, initializer: channels.CDPSessionInitializer) { super(parent, type, guid, initializer); this._channel.on('event', ({ method, params }) => { diff --git a/src/client/channelOwner.ts b/src/client/channelOwner.ts index 5deba14825..f8f4d4896b 100644 --- a/src/client/channelOwner.ts +++ b/src/client/channelOwner.ts @@ -15,12 +15,12 @@ */ import { EventEmitter } from 'events'; -import type { Channel } from '../protocol/channels'; +import * as channels from '../protocol/channels'; import type { Connection } from './connection'; -import type { LoggerSink } from './types'; +import type { Logger } from './types'; import { debugLogger } from '../utils/debugLogger'; -export abstract class ChannelOwner extends EventEmitter { +export abstract class ChannelOwner extends EventEmitter { private _connection: Connection; private _parent: ChannelOwner | undefined; private _objects = new Map(); @@ -29,7 +29,7 @@ export abstract class ChannelOwner(apiName: string, func: () => Promise, logger?: LoggerSink): Promise { + protected async _wrapApiCall(apiName: string, func: () => Promise, logger?: Logger): Promise { const stackObject: any = {}; Error.captureStackTrace(stackObject); const stack = stackObject.stack.startsWith('Error') ? stackObject.stack.substring(5) : stackObject.stack; @@ -119,7 +119,7 @@ export abstract class ChannelOwner(); _serviceWorkers = new Set(); - constructor(parent: ChannelOwner, type: string, guid: string, initializer: BrowserContextInitializer) { + constructor(parent: ChannelOwner, type: string, guid: string, initializer: channels.BrowserContextInitializer) { super(parent, type, guid, initializer, 'chromium'); this._channel.on('crBackgroundPage', ({ page }) => { const backgroundPage = Page.from(page); diff --git a/src/client/chromiumCoverage.ts b/src/client/chromiumCoverage.ts index ed9ed12ec6..472e0ac6d1 100644 --- a/src/client/chromiumCoverage.ts +++ b/src/client/chromiumCoverage.ts @@ -14,28 +14,28 @@ * limitations under the License. */ -import { PageChannel, PageCrStartJSCoverageOptions, PageCrStopJSCoverageResult, PageCrStartCSSCoverageOptions, PageCrStopCSSCoverageResult } from '../protocol/channels'; +import * as channels from '../protocol/channels'; export class ChromiumCoverage { - private _channel: PageChannel; + private _channel: channels.PageChannel; - constructor(channel: PageChannel) { + constructor(channel: channels.PageChannel) { this._channel = channel; } - async startJSCoverage(options: PageCrStartJSCoverageOptions = {}) { + async startJSCoverage(options: channels.PageCrStartJSCoverageOptions = {}) { await this._channel.crStartJSCoverage(options); } - async stopJSCoverage(): Promise { + async stopJSCoverage(): Promise { return (await this._channel.crStopJSCoverage()).entries; } - async startCSSCoverage(options: PageCrStartCSSCoverageOptions = {}) { + async startCSSCoverage(options: channels.PageCrStartCSSCoverageOptions = {}) { await this._channel.crStartCSSCoverage(options); } - async stopCSSCoverage(): Promise { + async stopCSSCoverage(): Promise { return (await this._channel.crStopCSSCoverage()).entries; } } diff --git a/src/client/connection.ts b/src/client/connection.ts index 2b18b0db22..11bab69ea4 100644 --- a/src/client/connection.ts +++ b/src/client/connection.ts @@ -31,7 +31,7 @@ import { parseError } from '../protocol/serializers'; import { CDPSession } from './cdpSession'; import { Playwright } from './playwright'; import { Electron, ElectronApplication } from './electron'; -import { Channel } from '../protocol/channels'; +import * as channels from '../protocol/channels'; import { ChromiumBrowser } from './chromiumBrowser'; import { ChromiumBrowserContext } from './chromiumBrowserContext'; import { Selectors } from './selectors'; @@ -41,7 +41,7 @@ import { WebKitBrowser } from './webkitBrowser'; import { FirefoxBrowser } from './firefoxBrowser'; import { debugLogger } from '../utils/debugLogger'; -class Root extends ChannelOwner { +class Root extends ChannelOwner { constructor(connection: Connection) { super(connection, '', '', {}); } diff --git a/src/client/consoleMessage.ts b/src/client/consoleMessage.ts index e3cad9e591..e8948c2500 100644 --- a/src/client/consoleMessage.ts +++ b/src/client/consoleMessage.ts @@ -16,17 +16,17 @@ import * as util from 'util'; import { JSHandle } from './jsHandle'; -import { ConsoleMessageChannel, ConsoleMessageInitializer } from '../protocol/channels'; +import * as channels from '../protocol/channels'; import { ChannelOwner } from './channelOwner'; -type ConsoleMessageLocation = ConsoleMessageInitializer['location']; +type ConsoleMessageLocation = channels.ConsoleMessageInitializer['location']; -export class ConsoleMessage extends ChannelOwner { - static from(message: ConsoleMessageChannel): ConsoleMessage { +export class ConsoleMessage extends ChannelOwner { + static from(message: channels.ConsoleMessageChannel): ConsoleMessage { return (message as any)._object; } - constructor(parent: ChannelOwner, type: string, guid: string, initializer: ConsoleMessageInitializer) { + constructor(parent: ChannelOwner, type: string, guid: string, initializer: channels.ConsoleMessageInitializer) { super(parent, type, guid, initializer); } diff --git a/src/client/dialog.ts b/src/client/dialog.ts index 8fc6775ebe..458fcfd4e8 100644 --- a/src/client/dialog.ts +++ b/src/client/dialog.ts @@ -14,15 +14,15 @@ * limitations under the License. */ -import { DialogChannel, DialogInitializer } from '../protocol/channels'; +import * as channels from '../protocol/channels'; import { ChannelOwner } from './channelOwner'; -export class Dialog extends ChannelOwner { - static from(dialog: DialogChannel): Dialog { +export class Dialog extends ChannelOwner { + static from(dialog: channels.DialogChannel): Dialog { return (dialog as any)._object; } - constructor(parent: ChannelOwner, type: string, guid: string, initializer: DialogInitializer) { + constructor(parent: ChannelOwner, type: string, guid: string, initializer: channels.DialogInitializer) { super(parent, type, guid, initializer); } diff --git a/src/client/download.ts b/src/client/download.ts index 0231d0522f..cf3768d6b1 100644 --- a/src/client/download.ts +++ b/src/client/download.ts @@ -14,17 +14,17 @@ * limitations under the License. */ -import { DownloadChannel, DownloadInitializer } from '../protocol/channels'; +import * as channels from '../protocol/channels'; import { ChannelOwner } from './channelOwner'; import { Readable } from 'stream'; import { Stream } from './stream'; -export class Download extends ChannelOwner { - static from(download: DownloadChannel): Download { +export class Download extends ChannelOwner { + static from(download: channels.DownloadChannel): Download { return (download as any)._object; } - constructor(parent: ChannelOwner, type: string, guid: string, initializer: DownloadInitializer) { + constructor(parent: ChannelOwner, type: string, guid: string, initializer: channels.DownloadInitializer) { super(parent, type, guid, initializer); } diff --git a/src/client/electron.ts b/src/client/electron.ts index b1f5ecfa3b..73689adfd8 100644 --- a/src/client/electron.ts +++ b/src/client/electron.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { ElectronChannel, ElectronInitializer, ElectronApplicationChannel, ElectronApplicationInitializer, ElectronLaunchParams, ElectronLaunchOptions } from '../protocol/channels'; +import * as channels from '../protocol/channels'; import { BrowserContext } from './browserContext'; import { ChannelOwner } from './channelOwner'; import { Page } from './page'; @@ -22,20 +22,20 @@ import { serializeArgument, FuncOn, parseResult, SmartHandle, JSHandle } from '. import { TimeoutSettings } from '../utils/timeoutSettings'; import { Waiter } from './waiter'; import { Events } from './events'; -import { WaitForEventOptions, Env, LoggerSink } from './types'; +import { WaitForEventOptions, Env, Logger } from './types'; import { envObjectToArray } from './clientHelper'; -type ElectronOptions = Omit & { +type ElectronOptions = Omit & { env?: Env, - logger?: LoggerSink, + logger?: Logger, }; -export class Electron extends ChannelOwner { - static from(electron: ElectronChannel): Electron { +export class Electron extends ChannelOwner { + static from(electron: channels.ElectronChannel): Electron { return (electron as any)._object; } - constructor(parent: ChannelOwner, type: string, guid: string, initializer: ElectronInitializer) { + constructor(parent: ChannelOwner, type: string, guid: string, initializer: channels.ElectronInitializer) { super(parent, type, guid, initializer); } @@ -43,7 +43,7 @@ export class Electron extends ChannelOwner const logger = options.logger; options = { ...options, logger: undefined }; return this._wrapApiCall('electron.launch', async () => { - const params: ElectronLaunchParams = { + const params: channels.ElectronLaunchParams = { ...options, env: options.env ? envObjectToArray(options.env) : undefined, executablePath, @@ -53,16 +53,16 @@ export class Electron extends ChannelOwner } } -export class ElectronApplication extends ChannelOwner { +export class ElectronApplication extends ChannelOwner { private _context?: BrowserContext; private _windows = new Set(); private _timeoutSettings = new TimeoutSettings(); - static from(electronApplication: ElectronApplicationChannel): ElectronApplication { + static from(electronApplication: channels.ElectronApplicationChannel): ElectronApplication { return (electronApplication as any)._object; } - constructor(parent: ChannelOwner, type: string, guid: string, initializer: ElectronApplicationInitializer) { + constructor(parent: ChannelOwner, type: string, guid: string, initializer: channels.ElectronApplicationInitializer) { super(parent, type, guid, initializer); this._channel.on('context', ({ context }) => this._context = BrowserContext.from(context)); this._channel.on('window', ({ page, browserWindow }) => { diff --git a/src/client/elementHandle.ts b/src/client/elementHandle.ts index 63f9135f96..cf0971b636 100644 --- a/src/client/elementHandle.ts +++ b/src/client/elementHandle.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { ElementHandleChannel, JSHandleInitializer, ElementHandleScrollIntoViewIfNeededOptions, ElementHandleHoverOptions, ElementHandleClickOptions, ElementHandleDblclickOptions, ElementHandleFillOptions, ElementHandleSetInputFilesOptions, ElementHandlePressOptions, ElementHandleCheckOptions, ElementHandleUncheckOptions, ElementHandleScreenshotOptions, ElementHandleTypeOptions, ElementHandleSelectTextOptions, ElementHandleWaitForSelectorOptions, ElementHandleWaitForElementStateOptions, ElementHandleSetInputFilesParams } from '../protocol/channels'; +import * as channels from '../protocol/channels'; import { Frame } from './frame'; import { FuncOn, JSHandle, serializeArgument, parseResult } from './jsHandle'; import { ChannelOwner } from './channelOwner'; @@ -28,19 +28,19 @@ import { assert, isString, mkdirIfNeeded } from '../utils/utils'; const fsWriteFileAsync = util.promisify(fs.writeFile.bind(fs)); export class ElementHandle extends JSHandle { - readonly _elementChannel: ElementHandleChannel; + readonly _elementChannel: channels.ElementHandleChannel; - static from(handle: ElementHandleChannel): ElementHandle { + static from(handle: channels.ElementHandleChannel): ElementHandle { return (handle as any)._object; } - static fromNullable(handle: ElementHandleChannel | undefined): ElementHandle | null { + static fromNullable(handle: channels.ElementHandleChannel | undefined): ElementHandle | null { return handle ? ElementHandle.from(handle) : null; } - constructor(parent: ChannelOwner, type: string, guid: string, initializer: JSHandleInitializer) { + constructor(parent: ChannelOwner, type: string, guid: string, initializer: channels.JSHandleInitializer) { super(parent, type, guid, initializer); - this._elementChannel = this._channel as ElementHandleChannel; + this._elementChannel = this._channel as channels.ElementHandleChannel; } asElement(): ElementHandle | null { @@ -91,25 +91,25 @@ export class ElementHandle extends JSHandle { }); } - async scrollIntoViewIfNeeded(options: ElementHandleScrollIntoViewIfNeededOptions = {}) { + async scrollIntoViewIfNeeded(options: channels.ElementHandleScrollIntoViewIfNeededOptions = {}) { return this._wrapApiCall('elementHandle.scrollIntoViewIfNeeded', async () => { await this._elementChannel.scrollIntoViewIfNeeded(options); }); } - async hover(options: ElementHandleHoverOptions = {}): Promise { + async hover(options: channels.ElementHandleHoverOptions = {}): Promise { return this._wrapApiCall('elementHandle.hover', async () => { await this._elementChannel.hover(options); }); } - async click(options: ElementHandleClickOptions = {}): Promise { + async click(options: channels.ElementHandleClickOptions = {}): Promise { return this._wrapApiCall('elementHandle.click', async () => { return await this._elementChannel.click(options); }); } - async dblclick(options: ElementHandleDblclickOptions = {}): Promise { + async dblclick(options: channels.ElementHandleDblclickOptions = {}): Promise { return this._wrapApiCall('elementHandle.dblclick', async () => { return await this._elementChannel.dblclick(options); }); @@ -122,19 +122,19 @@ export class ElementHandle extends JSHandle { }); } - async fill(value: string, options: ElementHandleFillOptions = {}): Promise { + async fill(value: string, options: channels.ElementHandleFillOptions = {}): Promise { return this._wrapApiCall('elementHandle.fill', async () => { return await this._elementChannel.fill({ value, ...options }); }); } - async selectText(options: ElementHandleSelectTextOptions = {}): Promise { + async selectText(options: channels.ElementHandleSelectTextOptions = {}): Promise { return this._wrapApiCall('elementHandle.selectText', async () => { await this._elementChannel.selectText(options); }); } - async setInputFiles(files: string | FilePayload | string[] | FilePayload[], options: ElementHandleSetInputFilesOptions = {}) { + async setInputFiles(files: string | FilePayload | string[] | FilePayload[], options: channels.ElementHandleSetInputFilesOptions = {}) { return this._wrapApiCall('elementHandle.setInputFiles', async () => { await this._elementChannel.setInputFiles({ files: await convertInputFiles(files), ...options }); }); @@ -146,25 +146,25 @@ export class ElementHandle extends JSHandle { }); } - async type(text: string, options: ElementHandleTypeOptions = {}): Promise { + async type(text: string, options: channels.ElementHandleTypeOptions = {}): Promise { return this._wrapApiCall('elementHandle.type', async () => { await this._elementChannel.type({ text, ...options }); }); } - async press(key: string, options: ElementHandlePressOptions = {}): Promise { + async press(key: string, options: channels.ElementHandlePressOptions = {}): Promise { return this._wrapApiCall('elementHandle.press', async () => { await this._elementChannel.press({ key, ...options }); }); } - async check(options: ElementHandleCheckOptions = {}) { + async check(options: channels.ElementHandleCheckOptions = {}) { return this._wrapApiCall('elementHandle.check', async () => { return await this._elementChannel.check(options); }); } - async uncheck(options: ElementHandleUncheckOptions = {}) { + async uncheck(options: channels.ElementHandleUncheckOptions = {}) { return this._wrapApiCall('elementHandle.uncheck', async () => { return await this._elementChannel.uncheck(options); }); @@ -177,7 +177,7 @@ export class ElementHandle extends JSHandle { }); } - async screenshot(options: ElementHandleScreenshotOptions & { path?: string } = {}): Promise { + async screenshot(options: channels.ElementHandleScreenshotOptions & { path?: string } = {}): Promise { return this._wrapApiCall('elementHandle.screenshot', async () => { const type = determineScreenshotType(options); const result = await this._elementChannel.screenshot({ ...options, type }); @@ -221,13 +221,13 @@ export class ElementHandle extends JSHandle { }); } - async waitForElementState(state: 'visible' | 'hidden' | 'stable' | 'enabled' | 'disabled', options: ElementHandleWaitForElementStateOptions = {}): Promise { + async waitForElementState(state: 'visible' | 'hidden' | 'stable' | 'enabled' | 'disabled', options: channels.ElementHandleWaitForElementStateOptions = {}): Promise { return this._wrapApiCall('elementHandle.waitForElementState', async () => { return await this._elementChannel.waitForElementState({ state, ...options }); }); } - async waitForSelector(selector: string, options: ElementHandleWaitForSelectorOptions = {}): Promise | null> { + async waitForSelector(selector: string, options: channels.ElementHandleWaitForSelectorOptions = {}): Promise | null> { return this._wrapApiCall('elementHandle.waitForSelector', async () => { const result = await this._elementChannel.waitForSelector({ selector, ...options }); return ElementHandle.fromNullable(result.element) as ElementHandle | null; @@ -235,7 +235,7 @@ export class ElementHandle extends JSHandle { } } -export function convertSelectOptionValues(values: string | ElementHandle | SelectOption | string[] | ElementHandle[] | SelectOption[] | null): { elements?: ElementHandleChannel[], options?: SelectOption[] } { +export function convertSelectOptionValues(values: string | ElementHandle | SelectOption | string[] | ElementHandle[] | SelectOption[] | null): { elements?: channels.ElementHandleChannel[], options?: SelectOption[] } { if (values === null) return {}; if (!Array.isArray(values)) @@ -251,7 +251,7 @@ export function convertSelectOptionValues(values: string | ElementHandle | Selec return { options: values as SelectOption[] }; } -type SetInputFilesFiles = ElementHandleSetInputFilesParams['files']; +type SetInputFilesFiles = channels.ElementHandleSetInputFilesParams['files']; export async function convertInputFiles(files: string | FilePayload | string[] | FilePayload[]): Promise { const items: (string | FilePayload)[] = Array.isArray(files) ? files : [ files ]; const filePayloads: SetInputFilesFiles = await Promise.all(items.map(async item => { diff --git a/src/client/fileChooser.ts b/src/client/fileChooser.ts index 1d3bc5d414..923c39e02d 100644 --- a/src/client/fileChooser.ts +++ b/src/client/fileChooser.ts @@ -17,7 +17,7 @@ import { ElementHandle } from './elementHandle'; import { Page } from './page'; import { FilePayload } from './types'; -import { ElementHandleSetInputFilesOptions } from '../protocol/channels'; +import * as channels from '../protocol/channels'; export class FileChooser { private _page: Page; @@ -42,7 +42,7 @@ export class FileChooser { return this._page; } - async setFiles(files: string | FilePayload | string[] | FilePayload[], options?: ElementHandleSetInputFilesOptions) { + async setFiles(files: string | FilePayload | string[] | FilePayload[], options?: channels.ElementHandleSetInputFilesOptions) { return this._elementHandle.setInputFiles(files, options); } } diff --git a/src/client/frame.ts b/src/client/frame.ts index f46753027b..e8e43f70ad 100644 --- a/src/client/frame.ts +++ b/src/client/frame.ts @@ -16,7 +16,7 @@ */ import { assert } from '../utils/utils'; -import { FrameChannel, FrameInitializer, FrameNavigatedEvent, FrameGotoOptions, FrameWaitForSelectorOptions, FrameDispatchEventOptions, FrameSetContentOptions, FrameClickOptions, FrameDblclickOptions, FrameFillOptions, FrameFocusOptions, FrameTextContentOptions, FrameInnerTextOptions, FrameInnerHTMLOptions, FrameGetAttributeOptions, FrameHoverOptions, FrameSetInputFilesOptions, FrameTypeOptions, FramePressOptions, FrameCheckOptions, FrameUncheckOptions } from '../protocol/channels'; +import * as channels from '../protocol/channels'; import { BrowserContext } from './browserContext'; import { ChannelOwner } from './channelOwner'; import { ElementHandle, convertSelectOptionValues, convertInputFiles } from './elementHandle'; @@ -40,7 +40,7 @@ export type WaitForNavigationOptions = { url?: URLMatch, }; -export class Frame extends ChannelOwner { +export class Frame extends ChannelOwner { _eventEmitter: EventEmitter; _loadStates: Set; _parentFrame: Frame | null = null; @@ -50,15 +50,15 @@ export class Frame extends ChannelOwner { _childFrames = new Set(); _page: Page | undefined; - static from(frame: FrameChannel): Frame { + static from(frame: channels.FrameChannel): Frame { return (frame as any)._object; } - static fromNullable(frame: FrameChannel | undefined): Frame | null { + static fromNullable(frame: channels.FrameChannel | undefined): Frame | null { return frame ? Frame.from(frame) : null; } - constructor(parent: ChannelOwner, type: string, guid: string, initializer: FrameInitializer) { + constructor(parent: ChannelOwner, type: string, guid: string, initializer: channels.FrameInitializer) { super(parent, type, guid, initializer); this._eventEmitter = new EventEmitter(); this._eventEmitter.setMaxListeners(0); @@ -93,7 +93,7 @@ export class Frame extends ChannelOwner { return this._page!; } - async goto(url: string, options: FrameGotoOptions = {}): Promise { + async goto(url: string, options: channels.FrameGotoOptions = {}): Promise { return this._wrapApiCall(this._apiName('goto'), async () => { const waitUntil = verifyLoadState('waitUntil', options.waitUntil === undefined ? 'load' : options.waitUntil); return network.Response.fromNullable((await this._channel.goto({ url, ...options, waitUntil })).response); @@ -119,7 +119,7 @@ export class Frame extends ChannelOwner { const toUrl = typeof options.url === 'string' ? ` to "${options.url}"` : ''; waiter.log(`waiting for navigation${toUrl} until "${waitUntil}"`); - const navigatedEvent = await waiter.waitForEvent(this._eventEmitter, 'navigated', event => { + const navigatedEvent = await waiter.waitForEvent(this._eventEmitter, 'navigated', event => { // Any failed navigation results in a rejection. if (event.error) return true; @@ -193,7 +193,7 @@ export class Frame extends ChannelOwner { }); } - async waitForSelector(selector: string, options: FrameWaitForSelectorOptions = {}): Promise | null> { + async waitForSelector(selector: string, options: channels.FrameWaitForSelectorOptions = {}): Promise | null> { return this._wrapApiCall(this._apiName('waitForSelector'), async () => { if ((options as any).visibility) throw new Error('options.visibility is not supported, did you mean options.state?'); @@ -204,7 +204,7 @@ export class Frame extends ChannelOwner { }); } - async dispatchEvent(selector: string, type: string, eventInit?: any, options: FrameDispatchEventOptions = {}): Promise { + async dispatchEvent(selector: string, type: string, eventInit?: any, options: channels.FrameDispatchEventOptions = {}): Promise { return this._wrapApiCall(this._apiName('dispatchEvent'), async () => { await this._channel.dispatchEvent({ selector, type, eventInit: serializeArgument(eventInit), ...options }); }); @@ -243,7 +243,7 @@ export class Frame extends ChannelOwner { }); } - async setContent(html: string, options: FrameSetContentOptions = {}): Promise { + async setContent(html: string, options: channels.FrameSetContentOptions = {}): Promise { return this._wrapApiCall(this._apiName('setContent'), async () => { const waitUntil = verifyLoadState('waitUntil', options.waitUntil === undefined ? 'load' : options.waitUntil); await this._channel.setContent({ html, ...options, waitUntil }); @@ -292,57 +292,57 @@ export class Frame extends ChannelOwner { }); } - async click(selector: string, options: FrameClickOptions = {}) { + async click(selector: string, options: channels.FrameClickOptions = {}) { return this._wrapApiCall(this._apiName('click'), async () => { return await this._channel.click({ selector, ...options }); }); } - async dblclick(selector: string, options: FrameDblclickOptions = {}) { + async dblclick(selector: string, options: channels.FrameDblclickOptions = {}) { return this._wrapApiCall(this._apiName('dblclick'), async () => { return await this._channel.dblclick({ selector, ...options }); }); } - async fill(selector: string, value: string, options: FrameFillOptions = {}) { + async fill(selector: string, value: string, options: channels.FrameFillOptions = {}) { return this._wrapApiCall(this._apiName('fill'), async () => { return await this._channel.fill({ selector, value, ...options }); }); } - async focus(selector: string, options: FrameFocusOptions = {}) { + async focus(selector: string, options: channels.FrameFocusOptions = {}) { return this._wrapApiCall(this._apiName('focus'), async () => { await this._channel.focus({ selector, ...options }); }); } - async textContent(selector: string, options: FrameTextContentOptions = {}): Promise { + async textContent(selector: string, options: channels.FrameTextContentOptions = {}): Promise { return this._wrapApiCall(this._apiName('textContent'), async () => { const value = (await this._channel.textContent({ selector, ...options })).value; return value === undefined ? null : value; }); } - async innerText(selector: string, options: FrameInnerTextOptions = {}): Promise { + async innerText(selector: string, options: channels.FrameInnerTextOptions = {}): Promise { return this._wrapApiCall(this._apiName('innerText'), async () => { return (await this._channel.innerText({ selector, ...options })).value; }); } - async innerHTML(selector: string, options: FrameInnerHTMLOptions = {}): Promise { + async innerHTML(selector: string, options: channels.FrameInnerHTMLOptions = {}): Promise { return this._wrapApiCall(this._apiName('innerHTML'), async () => { return (await this._channel.innerHTML({ selector, ...options })).value; }); } - async getAttribute(selector: string, name: string, options: FrameGetAttributeOptions = {}): Promise { + async getAttribute(selector: string, name: string, options: channels.FrameGetAttributeOptions = {}): Promise { return this._wrapApiCall(this._apiName('getAttribute'), async () => { const value = (await this._channel.getAttribute({ selector, name, ...options })).value; return value === undefined ? null : value; }); } - async hover(selector: string, options: FrameHoverOptions = {}) { + async hover(selector: string, options: channels.FrameHoverOptions = {}) { return this._wrapApiCall(this._apiName('hover'), async () => { await this._channel.hover({ selector, ...options }); }); @@ -354,31 +354,31 @@ export class Frame extends ChannelOwner { }); } - async setInputFiles(selector: string, files: string | FilePayload | string[] | FilePayload[], options: FrameSetInputFilesOptions = {}): Promise { + async setInputFiles(selector: string, files: string | FilePayload | string[] | FilePayload[], options: channels.FrameSetInputFilesOptions = {}): Promise { return this._wrapApiCall(this._apiName('setInputFiles'), async () => { await this._channel.setInputFiles({ selector, files: await convertInputFiles(files), ...options }); }); } - async type(selector: string, text: string, options: FrameTypeOptions = {}) { + async type(selector: string, text: string, options: channels.FrameTypeOptions = {}) { return this._wrapApiCall(this._apiName('type'), async () => { await this._channel.type({ selector, text, ...options }); }); } - async press(selector: string, key: string, options: FramePressOptions = {}) { + async press(selector: string, key: string, options: channels.FramePressOptions = {}) { return this._wrapApiCall(this._apiName('press'), async () => { await this._channel.press({ selector, key, ...options }); }); } - async check(selector: string, options: FrameCheckOptions = {}) { + async check(selector: string, options: channels.FrameCheckOptions = {}) { return this._wrapApiCall(this._apiName('check'), async () => { await this._channel.check({ selector, ...options }); }); } - async uncheck(selector: string, options: FrameUncheckOptions = {}) { + async uncheck(selector: string, options: channels.FrameUncheckOptions = {}) { return this._wrapApiCall(this._apiName('uncheck'), async () => { await this._channel.uncheck({ selector, ...options }); }); diff --git a/src/client/input.ts b/src/client/input.ts index 957a8e1510..668b08a5b4 100644 --- a/src/client/input.ts +++ b/src/client/input.ts @@ -15,12 +15,12 @@ * limitations under the License. */ -import { PageChannel, PageKeyboardTypeOptions, PageKeyboardPressOptions, PageMouseDownOptions, PageMouseUpOptions, PageMouseClickOptions } from '../protocol/channels'; +import * as channels from '../protocol/channels'; export class Keyboard { - private _channel: PageChannel; + private _channel: channels.PageChannel; - constructor(channel: PageChannel) { + constructor(channel: channels.PageChannel) { this._channel = channel; } @@ -36,19 +36,19 @@ export class Keyboard { await this._channel.keyboardInsertText({ text }); } - async type(text: string, options: PageKeyboardTypeOptions = {}) { + async type(text: string, options: channels.PageKeyboardTypeOptions = {}) { await this._channel.keyboardType({ text, ...options }); } - async press(key: string, options: PageKeyboardPressOptions = {}) { + async press(key: string, options: channels.PageKeyboardPressOptions = {}) { await this._channel.keyboardPress({ key, ...options }); } } export class Mouse { - private _channel: PageChannel; + private _channel: channels.PageChannel; - constructor(channel: PageChannel) { + constructor(channel: channels.PageChannel) { this._channel = channel; } @@ -56,19 +56,19 @@ export class Mouse { await this._channel.mouseMove({ x, y, ...options }); } - async down(options: PageMouseDownOptions = {}) { + async down(options: channels.PageMouseDownOptions = {}) { await this._channel.mouseDown({ ...options }); } - async up(options: PageMouseUpOptions = {}) { + async up(options: channels.PageMouseUpOptions = {}) { await this._channel.mouseUp(options); } - async click(x: number, y: number, options: PageMouseClickOptions = {}) { + async click(x: number, y: number, options: channels.PageMouseClickOptions = {}) { await this._channel.mouseClick({ x, y, ...options }); } - async dblclick(x: number, y: number, options: Omit = {}) { + async dblclick(x: number, y: number, options: Omit = {}) { await this.click(x, y, { ...options, clickCount: 2 }); } } diff --git a/src/client/jsHandle.ts b/src/client/jsHandle.ts index d4696d7ee9..55ff3e7c36 100644 --- a/src/client/jsHandle.ts +++ b/src/client/jsHandle.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { JSHandleChannel, JSHandleInitializer, SerializedArgument, SerializedValue, Channel } from '../protocol/channels'; +import * as channels from '../protocol/channels'; import { ElementHandle } from './elementHandle'; import { ChannelOwner } from './channelOwner'; import { parseSerializedValue, serializeValue } from '../protocol/serializers'; @@ -35,14 +35,14 @@ export type Func1 = string | ((arg: Unboxed) => R | Promise); export type FuncOn = string | ((on: On, arg2: Unboxed) => R | Promise); export type SmartHandle = T extends Node ? ElementHandle : JSHandle; -export class JSHandle extends ChannelOwner { +export class JSHandle extends ChannelOwner { private _preview: string; - static from(handle: JSHandleChannel): JSHandle { + static from(handle: channels.JSHandleChannel): JSHandle { return (handle as any)._object; } - constructor(parent: ChannelOwner, type: string, guid: string, initializer: JSHandleInitializer) { + constructor(parent: ChannelOwner, type: string, guid: string, initializer: channels.JSHandleInitializer) { super(parent, type, guid, initializer); this._preview = this._initializer.preview; this._channel.on('previewUpdated', ({preview}) => this._preview = preview); @@ -93,9 +93,9 @@ export class JSHandle extends ChannelOwner { +export function serializeArgument(arg: any): channels.SerializedArgument { + const handles: channels.Channel[] = []; + const pushHandle = (channel: channels.Channel): number => { handles.push(channel); return handles.length - 1; }; @@ -107,7 +107,7 @@ export function serializeArgument(arg: any): SerializedArgument { return { value, handles }; } -export function parseResult(value: SerializedValue): any { +export function parseResult(value: channels.SerializedValue): any { return parseSerializedValue(value, undefined); } diff --git a/src/client/network.ts b/src/client/network.ts index 72618e3b61..67593a9fa0 100644 --- a/src/client/network.ts +++ b/src/client/network.ts @@ -15,7 +15,7 @@ */ import { URLSearchParams } from 'url'; -import { RequestChannel, ResponseChannel, RouteChannel, RequestInitializer, ResponseInitializer, RouteInitializer } from '../protocol/channels'; +import * as channels from '../protocol/channels'; import { ChannelOwner } from './channelOwner'; import { Frame } from './frame'; import { Headers } from './types'; @@ -47,22 +47,22 @@ export type SetNetworkCookieParam = { sameSite?: 'Strict' | 'Lax' | 'None' }; -export class Request extends ChannelOwner { +export class Request extends ChannelOwner { private _redirectedFrom: Request | null = null; private _redirectedTo: Request | null = null; _failureText: string | null = null; private _headers: Headers; private _postData: Buffer | null; - static from(request: RequestChannel): Request { + static from(request: channels.RequestChannel): Request { return (request as any)._object; } - static fromNullable(request: RequestChannel | undefined): Request | null { + static fromNullable(request: channels.RequestChannel | undefined): Request | null { return request ? Request.from(request) : null; } - constructor(parent: ChannelOwner, type: string, guid: string, initializer: RequestInitializer) { + constructor(parent: ChannelOwner, type: string, guid: string, initializer: channels.RequestInitializer) { super(parent, type, guid, initializer); this._redirectedFrom = Request.fromNullable(initializer.redirectedFrom); if (this._redirectedFrom) @@ -148,12 +148,12 @@ export class Request extends ChannelOwner { } } -export class Route extends ChannelOwner { - static from(route: RouteChannel): Route { +export class Route extends ChannelOwner { + static from(route: channels.RouteChannel): Route { return (route as any)._object; } - constructor(parent: ChannelOwner, type: string, guid: string, initializer: RouteInitializer) { + constructor(parent: ChannelOwner, type: string, guid: string, initializer: channels.RouteInitializer) { super(parent, type, guid, initializer); } @@ -214,18 +214,18 @@ export class Route extends ChannelOwner { export type RouteHandler = (route: Route, request: Request) => void; -export class Response extends ChannelOwner { +export class Response extends ChannelOwner { private _headers: Headers; - static from(response: ResponseChannel): Response { + static from(response: channels.ResponseChannel): Response { return (response as any)._object; } - static fromNullable(response: ResponseChannel | undefined): Response | null { + static fromNullable(response: channels.ResponseChannel | undefined): Response | null { return response ? Response.from(response) : null; } - constructor(parent: ChannelOwner, type: string, guid: string, initializer: ResponseInitializer) { + constructor(parent: ChannelOwner, type: string, guid: string, initializer: channels.ResponseInitializer) { super(parent, type, guid, initializer); this._headers = headersArrayToObject(initializer.headers, true /* lowerCase */); } diff --git a/src/client/page.ts b/src/client/page.ts index bcd49e45cc..fd0bed3493 100644 --- a/src/client/page.ts +++ b/src/client/page.ts @@ -18,7 +18,7 @@ import { Events } from './events'; import { assert } from '../utils/utils'; import { TimeoutSettings } from '../utils/timeoutSettings'; -import { BindingCallChannel, BindingCallInitializer, PageChannel, PageInitializer, PagePdfParams, FrameWaitForSelectorOptions, FrameDispatchEventOptions, FrameSetContentOptions, FrameGotoOptions, PageReloadOptions, PageGoBackOptions, PageGoForwardOptions, PageScreenshotOptions, FrameClickOptions, FrameDblclickOptions, FrameFillOptions, FrameFocusOptions, FrameTextContentOptions, FrameInnerTextOptions, FrameInnerHTMLOptions, FrameGetAttributeOptions, FrameHoverOptions, FrameSetInputFilesOptions, FrameTypeOptions, FramePressOptions, FrameCheckOptions, FrameUncheckOptions } from '../protocol/channels'; +import * as channels from '../protocol/channels'; import { parseError, serializeError } from '../protocol/serializers'; import { Accessibility } from './accessibility'; import { BrowserContext } from './browserContext'; @@ -43,7 +43,7 @@ import { Size, URLMatch, Headers, LifecycleEvent, WaitForEventOptions, SelectOpt import { evaluationScript, urlMatches } from './clientHelper'; import { isString, isRegExp, isObject, mkdirIfNeeded, headersObjectToArray } from '../utils/utils'; -type PDFOptions = Omit & { +type PDFOptions = Omit & { width?: string | number, height?: string | number, margin?: { @@ -58,7 +58,7 @@ type Listener = (...args: any[]) => void; const fsWriteFileAsync = util.promisify(fs.writeFile.bind(fs)); -export class Page extends ChannelOwner { +export class Page extends ChannelOwner { private _browserContext: BrowserContext; _ownedContext: BrowserContext | undefined; @@ -79,15 +79,15 @@ export class Page extends ChannelOwner { readonly _timeoutSettings: TimeoutSettings; _isPageCall = false; - static from(page: PageChannel): Page { + static from(page: channels.PageChannel): Page { return (page as any)._object; } - static fromNullable(page: PageChannel | undefined): Page | null { + static fromNullable(page: channels.PageChannel | undefined): Page | null { return page ? Page.from(page) : null; } - constructor(parent: ChannelOwner, type: string, guid: string, initializer: PageInitializer) { + constructor(parent: ChannelOwner, type: string, guid: string, initializer: channels.PageInitializer) { super(parent, type, guid, initializer); this.setMaxListeners(0); this._browserContext = parent as BrowserContext; @@ -235,11 +235,11 @@ export class Page extends ChannelOwner { return this._attributeToPage(() => this._mainFrame.$(selector)); } - async waitForSelector(selector: string, options?: FrameWaitForSelectorOptions): Promise | null> { + async waitForSelector(selector: string, options?: channels.FrameWaitForSelectorOptions): Promise | null> { return this._attributeToPage(() => this._mainFrame.waitForSelector(selector, options)); } - async dispatchEvent(selector: string, type: string, eventInit?: any, options?: FrameDispatchEventOptions): Promise { + async dispatchEvent(selector: string, type: string, eventInit?: any, options?: channels.FrameDispatchEventOptions): Promise { return this._attributeToPage(() => this._mainFrame.dispatchEvent(selector, type, eventInit, options)); } @@ -306,15 +306,15 @@ export class Page extends ChannelOwner { return this._attributeToPage(() => this._mainFrame.content()); } - async setContent(html: string, options?: FrameSetContentOptions): Promise { + async setContent(html: string, options?: channels.FrameSetContentOptions): Promise { return this._attributeToPage(() => this._mainFrame.setContent(html, options)); } - async goto(url: string, options?: FrameGotoOptions): Promise { + async goto(url: string, options?: channels.FrameGotoOptions): Promise { return this._attributeToPage(() => this._mainFrame.goto(url, options)); } - async reload(options: PageReloadOptions = {}): Promise { + async reload(options: channels.PageReloadOptions = {}): Promise { return this._wrapApiCall('page.reload', async () => { const waitUntil = verifyLoadState('waitUntil', options.waitUntil === undefined ? 'load' : options.waitUntil); return Response.fromNullable((await this._channel.reload({ ...options, waitUntil })).response); @@ -361,14 +361,14 @@ export class Page extends ChannelOwner { return result; } - async goBack(options: PageGoBackOptions = {}): Promise { + async goBack(options: channels.PageGoBackOptions = {}): Promise { return this._wrapApiCall('page.goBack', async () => { const waitUntil = verifyLoadState('waitUntil', options.waitUntil === undefined ? 'load' : options.waitUntil); return Response.fromNullable((await this._channel.goBack({ ...options, waitUntil })).response); }); } - async goForward(options: PageGoForwardOptions = {}): Promise { + async goForward(options: channels.PageGoForwardOptions = {}): Promise { return this._wrapApiCall('page.goForward', async () => { const waitUntil = verifyLoadState('waitUntil', options.waitUntil === undefined ? 'load' : options.waitUntil); return Response.fromNullable((await this._channel.goForward({ ...options, waitUntil })).response); @@ -425,7 +425,7 @@ export class Page extends ChannelOwner { }); } - async screenshot(options: PageScreenshotOptions & { path?: string } = {}): Promise { + async screenshot(options: channels.PageScreenshotOptions & { path?: string } = {}): Promise { return this._wrapApiCall('page.screenshot', async () => { const type = determineScreenshotType(options); const result = await this._channel.screenshot({ ...options, type }); @@ -460,39 +460,39 @@ export class Page extends ChannelOwner { return this._closed; } - async click(selector: string, options?: FrameClickOptions) { + async click(selector: string, options?: channels.FrameClickOptions) { return this._attributeToPage(() => this._mainFrame.click(selector, options)); } - async dblclick(selector: string, options?: FrameDblclickOptions) { + async dblclick(selector: string, options?: channels.FrameDblclickOptions) { return this._attributeToPage(() => this._mainFrame.dblclick(selector, options)); } - async fill(selector: string, value: string, options?: FrameFillOptions) { + async fill(selector: string, value: string, options?: channels.FrameFillOptions) { return this._attributeToPage(() => this._mainFrame.fill(selector, value, options)); } - async focus(selector: string, options?: FrameFocusOptions) { + async focus(selector: string, options?: channels.FrameFocusOptions) { return this._attributeToPage(() => this._mainFrame.focus(selector, options)); } - async textContent(selector: string, options?: FrameTextContentOptions): Promise { + async textContent(selector: string, options?: channels.FrameTextContentOptions): Promise { return this._attributeToPage(() => this._mainFrame.textContent(selector, options)); } - async innerText(selector: string, options?: FrameInnerTextOptions): Promise { + async innerText(selector: string, options?: channels.FrameInnerTextOptions): Promise { return this._attributeToPage(() => this._mainFrame.innerText(selector, options)); } - async innerHTML(selector: string, options?: FrameInnerHTMLOptions): Promise { + async innerHTML(selector: string, options?: channels.FrameInnerHTMLOptions): Promise { return this._attributeToPage(() => this._mainFrame.innerHTML(selector, options)); } - async getAttribute(selector: string, name: string, options?: FrameGetAttributeOptions): Promise { + async getAttribute(selector: string, name: string, options?: channels.FrameGetAttributeOptions): Promise { return this._attributeToPage(() => this._mainFrame.getAttribute(selector, name, options)); } - async hover(selector: string, options?: FrameHoverOptions) { + async hover(selector: string, options?: channels.FrameHoverOptions) { return this._attributeToPage(() => this._mainFrame.hover(selector, options)); } @@ -500,23 +500,23 @@ export class Page extends ChannelOwner { return this._attributeToPage(() => this._mainFrame.selectOption(selector, values, options)); } - async setInputFiles(selector: string, files: string | FilePayload | string[] | FilePayload[], options?: FrameSetInputFilesOptions): Promise { + async setInputFiles(selector: string, files: string | FilePayload | string[] | FilePayload[], options?: channels.FrameSetInputFilesOptions): Promise { return this._attributeToPage(() => this._mainFrame.setInputFiles(selector, files, options)); } - async type(selector: string, text: string, options?: FrameTypeOptions) { + async type(selector: string, text: string, options?: channels.FrameTypeOptions) { return this._attributeToPage(() => this._mainFrame.type(selector, text, options)); } - async press(selector: string, key: string, options?: FramePressOptions) { + async press(selector: string, key: string, options?: channels.FramePressOptions) { return this._attributeToPage(() => this._mainFrame.press(selector, key, options)); } - async check(selector: string, options?: FrameCheckOptions) { + async check(selector: string, options?: channels.FrameCheckOptions) { return this._attributeToPage(() => this._mainFrame.check(selector, options)); } - async uncheck(selector: string, options?: FrameUncheckOptions) { + async uncheck(selector: string, options?: channels.FrameUncheckOptions) { return this._attributeToPage(() => this._mainFrame.uncheck(selector, options)); } @@ -567,7 +567,7 @@ export class Page extends ChannelOwner { } async _pdf(options: PDFOptions = {}): Promise { - const transportOptions: PagePdfParams = { ...options } as PagePdfParams; + const transportOptions: channels.PagePdfParams = { ...options } as channels.PagePdfParams; if (transportOptions.margin) transportOptions.margin = { ...transportOptions.margin }; if (typeof options.width === 'number') @@ -587,12 +587,12 @@ export class Page extends ChannelOwner { } } -export class BindingCall extends ChannelOwner { - static from(channel: BindingCallChannel): BindingCall { +export class BindingCall extends ChannelOwner { + static from(channel: channels.BindingCallChannel): BindingCall { return (channel as any)._object; } - constructor(parent: ChannelOwner, type: string, guid: string, initializer: BindingCallInitializer) { + constructor(parent: ChannelOwner, type: string, guid: string, initializer: channels.BindingCallInitializer) { super(parent, type, guid, initializer); } diff --git a/src/client/playwright.ts b/src/client/playwright.ts index d93e9bb7c2..159256ed80 100644 --- a/src/client/playwright.ts +++ b/src/client/playwright.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { PlaywrightChannel, PlaywrightInitializer } from '../protocol/channels'; +import * as channels from '../protocol/channels'; import { BrowserType } from './browserType'; import { ChannelOwner } from './channelOwner'; import { Selectors } from './selectors'; @@ -31,7 +31,7 @@ type DeviceDescriptor = { }; type Devices = { [name: string]: DeviceDescriptor }; -export class Playwright extends ChannelOwner { +export class Playwright extends ChannelOwner { readonly chromium: BrowserType; readonly firefox: BrowserType; readonly webkit: BrowserType; @@ -39,7 +39,7 @@ export class Playwright extends ChannelOwner { - static from(selectors: SelectorsChannel): Selectors { +export class Selectors extends ChannelOwner { + static from(selectors: channels.SelectorsChannel): Selectors { return (selectors as any)._object; } - constructor(parent: ChannelOwner, type: string, guid: string, initializer: SelectorsInitializer) { + constructor(parent: ChannelOwner, type: string, guid: string, initializer: channels.SelectorsInitializer) { super(parent, type, guid, initializer); } diff --git a/src/client/stream.ts b/src/client/stream.ts index dcc671ce32..5e030fb2a3 100644 --- a/src/client/stream.ts +++ b/src/client/stream.ts @@ -15,15 +15,15 @@ */ import { Readable } from 'stream'; -import { StreamChannel, StreamInitializer } from '../protocol/channels'; +import * as channels from '../protocol/channels'; import { ChannelOwner } from './channelOwner'; -export class Stream extends ChannelOwner { - static from(Stream: StreamChannel): Stream { +export class Stream extends ChannelOwner { + static from(Stream: channels.StreamChannel): Stream { return (Stream as any)._object; } - constructor(parent: ChannelOwner, type: string, guid: string, initializer: StreamInitializer) { + constructor(parent: ChannelOwner, type: string, guid: string, initializer: channels.StreamInitializer) { super(parent, type, guid, initializer); } @@ -33,9 +33,9 @@ export class Stream extends ChannelOwner { } class StreamImpl extends Readable { - private _channel: StreamChannel; + private _channel: channels.StreamChannel; - constructor(channel: StreamChannel) { + constructor(channel: channels.StreamChannel) { super(); this._channel = channel; } diff --git a/src/client/types.ts b/src/client/types.ts index 24b625697d..9891da5ef5 100644 --- a/src/client/types.ts +++ b/src/client/types.ts @@ -15,15 +15,13 @@ * limitations under the License. */ -import { BrowserNewContextOptions, BrowserTypeLaunchOptions } from '../protocol/channels'; +import * as channels from '../protocol/channels'; type LoggerSeverity = 'verbose' | 'info' | 'warning' | 'error'; -export interface LoggerSink { +export interface Logger { isEnabled(name: string, severity: LoggerSeverity): boolean; log(name: string, severity: LoggerSeverity, message: string | Error, args: any[], hints: { color?: string }): void; } -// This is a workaround for the documentation generation. -export interface Logger extends LoggerSink {} export type Size = { width: number, height: number }; export type Point = { x: number, y: number }; @@ -42,21 +40,21 @@ export type FilePayload = { name: string, mimeType: string, buffer: Buffer }; export type LifecycleEvent = 'load' | 'domcontentloaded' | 'networkidle'; export const kLifecycleEvents: Set = new Set(['load', 'domcontentloaded', 'networkidle']); -export type BrowserContextOptions = Omit & { +export type BrowserContextOptions = Omit & { viewport?: Size | null, extraHTTPHeaders?: Headers, - logger?: LoggerSink, + logger?: Logger, }; type LaunchOverrides = { ignoreDefaultArgs?: boolean | string[], env?: Env, - logger?: LoggerSink, + logger?: Logger, }; type FirefoxUserPrefs = { firefoxUserPrefs?: { [key: string]: string | number | boolean }, }; -type LaunchOptionsBase = Omit & LaunchOverrides; +type LaunchOptionsBase = Omit & LaunchOverrides; export type LaunchOptions = LaunchOptionsBase & FirefoxUserPrefs; export type LaunchPersistentContextOptions = LaunchOptionsBase & BrowserContextOptions; @@ -64,7 +62,7 @@ export type ConnectOptions = { wsEndpoint: string, slowMo?: number, timeout?: number, - logger?: LoggerSink, + logger?: Logger, }; export type LaunchServerOptions = { executablePath?: string, @@ -86,5 +84,5 @@ export type LaunchServerOptions = { downloadsPath?: string, chromiumSandbox?: boolean, port?: number, - logger?: LoggerSink, + logger?: Logger, } & FirefoxUserPrefs; diff --git a/src/client/worker.ts b/src/client/worker.ts index a6e3c9260e..cbd14378b6 100644 --- a/src/client/worker.ts +++ b/src/client/worker.ts @@ -15,22 +15,22 @@ */ import { Events } from './events'; -import { WorkerChannel, WorkerInitializer } from '../protocol/channels'; +import * as channels from '../protocol/channels'; import { ChannelOwner } from './channelOwner'; import { assertMaxArguments, Func1, JSHandle, parseResult, serializeArgument, SmartHandle } from './jsHandle'; import { Page } from './page'; import { BrowserContext } from './browserContext'; import { ChromiumBrowserContext } from './chromiumBrowserContext'; -export class Worker extends ChannelOwner { +export class Worker extends ChannelOwner { _page: Page | undefined; // Set for web workers. _context: BrowserContext | undefined; // Set for service workers. - static from(worker: WorkerChannel): Worker { + static from(worker: channels.WorkerChannel): Worker { return (worker as any)._object; } - constructor(parent: ChannelOwner, type: string, guid: string, initializer: WorkerInitializer) { + constructor(parent: ChannelOwner, type: string, guid: string, initializer: channels.WorkerInitializer) { super(parent, type, guid, initializer); this._channel.on('close', () => { if (this._page)