From eab5ff4eaeaf39ed36eb770ba235a670e051db5a Mon Sep 17 00:00:00 2001 From: Dmitry Gozman Date: Thu, 20 Aug 2020 11:25:33 -0700 Subject: [PATCH] chore(rpc): use channels types in dispatchers (#3549) This ensures we actually implement channels as intended. For example, this change found an issue with Route.fulfill. --- src/network.ts | 9 ++- src/rpc/server/browserDispatcher.ts | 14 ++-- src/rpc/server/browserTypeDispatcher.ts | 8 +-- src/rpc/server/cdpSessionDispatcher.ts | 6 +- src/rpc/server/consoleMessageDispatcher.ts | 4 +- src/rpc/server/dialogDispatcher.ts | 4 +- src/rpc/server/dispatcher.ts | 4 +- src/rpc/server/downloadDispatcher.ts | 12 ++-- src/rpc/server/electronDispatcher.ts | 16 ++--- src/rpc/server/elementHandlerDispatcher.ts | 61 +++++++++-------- src/rpc/server/frameDispatcher.ts | 66 +++++++++---------- src/rpc/server/jsHandleDispatcher.ts | 21 +++--- src/rpc/server/networkDispatchers.ts | 21 +++--- src/rpc/server/pageDispatcher.ts | 77 +++++++++++----------- src/rpc/server/playwrightDispatcher.ts | 4 +- src/rpc/server/selectorsDispatcher.ts | 10 +-- src/rpc/server/streamDispatcher.ts | 6 +- 17 files changed, 173 insertions(+), 170 deletions(-) diff --git a/src/network.ts b/src/network.ts index c47fa5ae16..93448aac39 100644 --- a/src/network.ts +++ b/src/network.ts @@ -190,10 +190,15 @@ export class Route { await this._delegate.abort(errorCode); } - async fulfill(response: types.NormalizedFulfillResponse) { + async fulfill(response: { status?: number, headers?: types.HeadersArray, body?: string, isBase64?: boolean }) { assert(!this._handled, 'Route is already handled!'); this._handled = true; - await this._delegate.fulfill(response); + await this._delegate.fulfill({ + status: response.status === undefined ? 200 : response.status, + headers: response.headers || [], + body: response.body || '', + isBase64: response.isBase64 || false, + }); } async continue(overrides: types.NormalizedContinueOverrides = {}) { diff --git a/src/rpc/server/browserDispatcher.ts b/src/rpc/server/browserDispatcher.ts index 1c045b1092..1f686e3d85 100644 --- a/src/rpc/server/browserDispatcher.ts +++ b/src/rpc/server/browserDispatcher.ts @@ -16,14 +16,14 @@ import { Browser } from '../../browser'; import { Events } from '../../events'; -import { BrowserChannel, BrowserContextChannel, BrowserInitializer, CDPSessionChannel, Binary, BrowserNewContextParams } from '../channels'; +import * as channels from '../channels'; import { BrowserContextDispatcher } from './browserContextDispatcher'; import { CDPSessionDispatcher } from './cdpSessionDispatcher'; import { Dispatcher, DispatcherScope } from './dispatcher'; import { CRBrowser } from '../../chromium/crBrowser'; import { PageDispatcher } from './pageDispatcher'; -export class BrowserDispatcher extends Dispatcher implements BrowserChannel { +export class BrowserDispatcher extends Dispatcher implements channels.BrowserChannel { constructor(scope: DispatcherScope, browser: Browser, guid?: string) { super(scope, browser, 'Browser', { version: browser.version() }, true, guid); browser.on(Events.Browser.Disconnected, () => this._didClose()); @@ -34,7 +34,7 @@ export class BrowserDispatcher extends Dispatcher i this._dispose(); } - async newContext(params: BrowserNewContextParams): Promise<{ context: BrowserContextChannel }> { + async newContext(params: channels.BrowserNewContextParams): Promise { return { context: new BrowserContextDispatcher(this._scope, await this._object.newContext(params)) }; } @@ -42,17 +42,17 @@ export class BrowserDispatcher extends Dispatcher i await this._object.close(); } - async crNewBrowserCDPSession(): Promise<{ session: CDPSessionChannel }> { + async crNewBrowserCDPSession(): Promise { const crBrowser = this._object as CRBrowser; return { session: new CDPSessionDispatcher(this._scope, await crBrowser.newBrowserCDPSession()) }; } - async crStartTracing(params: { page?: PageDispatcher, path?: string, screenshots?: boolean, categories?: string[] }): Promise { + async crStartTracing(params: channels.BrowserCrStartTracingParams): Promise { const crBrowser = this._object as CRBrowser; - await crBrowser.startTracing(params.page ? params.page._object : undefined, params); + await crBrowser.startTracing(params.page ? (params.page as PageDispatcher)._object : undefined, params); } - async crStopTracing(): Promise<{ binary: Binary }> { + async crStopTracing(): Promise { const crBrowser = this._object as CRBrowser; const buffer = await crBrowser.stopTracing(); return { binary: buffer.toString('base64') }; diff --git a/src/rpc/server/browserTypeDispatcher.ts b/src/rpc/server/browserTypeDispatcher.ts index 7a9fd61eaa..1286400fb4 100644 --- a/src/rpc/server/browserTypeDispatcher.ts +++ b/src/rpc/server/browserTypeDispatcher.ts @@ -16,11 +16,11 @@ import { BrowserTypeBase, BrowserType } from '../../server/browserType'; import { BrowserDispatcher } from './browserDispatcher'; -import { BrowserChannel, BrowserTypeChannel, BrowserContextChannel, BrowserTypeInitializer, BrowserTypeLaunchParams, BrowserTypeLaunchPersistentContextParams } from '../channels'; +import * as channels from '../channels'; import { Dispatcher, DispatcherScope } from './dispatcher'; import { BrowserContextDispatcher } from './browserContextDispatcher'; -export class BrowserTypeDispatcher extends Dispatcher implements BrowserTypeChannel { +export class BrowserTypeDispatcher extends Dispatcher implements channels.BrowserTypeChannel { constructor(scope: DispatcherScope, browserType: BrowserTypeBase) { super(scope, browserType, 'BrowserType', { executablePath: browserType.executablePath(), @@ -28,12 +28,12 @@ export class BrowserTypeDispatcher extends Dispatcher { + async launch(params: channels.BrowserTypeLaunchParams): Promise { const browser = await this._object.launch(params); return { browser: new BrowserDispatcher(this._scope, browser) }; } - async launchPersistentContext(params: BrowserTypeLaunchPersistentContextParams): Promise<{ context: BrowserContextChannel }> { + async launchPersistentContext(params: channels.BrowserTypeLaunchPersistentContextParams): Promise { const browserContext = await this._object.launchPersistentContext(params.userDataDir, params); return { context: new BrowserContextDispatcher(this._scope, browserContext) }; } diff --git a/src/rpc/server/cdpSessionDispatcher.ts b/src/rpc/server/cdpSessionDispatcher.ts index a1f585d82d..0b9414c4e2 100644 --- a/src/rpc/server/cdpSessionDispatcher.ts +++ b/src/rpc/server/cdpSessionDispatcher.ts @@ -15,10 +15,10 @@ */ import { CRSession, CRSessionEvents } from '../../chromium/crConnection'; -import { CDPSessionChannel, CDPSessionInitializer } from '../channels'; +import * as channels from '../channels'; import { Dispatcher, DispatcherScope } from './dispatcher'; -export class CDPSessionDispatcher extends Dispatcher implements CDPSessionChannel { +export class CDPSessionDispatcher extends Dispatcher implements channels.CDPSessionChannel { constructor(scope: DispatcherScope, crSession: CRSession) { super(scope, crSession, 'CDPSession', {}, true); crSession._eventListener = (method, params) => { @@ -27,7 +27,7 @@ export class CDPSessionDispatcher extends Dispatcher this._dispose()); } - async send(params: { method: string, params?: any }): Promise<{ result: any }> { + async send(params: channels.CDPSessionSendParams): Promise { return { result: await this._object.send(params.method as any, params.params) }; } diff --git a/src/rpc/server/consoleMessageDispatcher.ts b/src/rpc/server/consoleMessageDispatcher.ts index 7051ae10f7..5ff601d636 100644 --- a/src/rpc/server/consoleMessageDispatcher.ts +++ b/src/rpc/server/consoleMessageDispatcher.ts @@ -15,11 +15,11 @@ */ import { ConsoleMessage } from '../../console'; -import { ConsoleMessageChannel, ConsoleMessageInitializer } from '../channels'; +import * as channels from '../channels'; import { Dispatcher, DispatcherScope } from './dispatcher'; import { createHandle } from './elementHandlerDispatcher'; -export class ConsoleMessageDispatcher extends Dispatcher implements ConsoleMessageChannel { +export class ConsoleMessageDispatcher extends Dispatcher implements channels.ConsoleMessageChannel { constructor(scope: DispatcherScope, message: ConsoleMessage) { super(scope, message, 'ConsoleMessage', { type: message.type(), diff --git a/src/rpc/server/dialogDispatcher.ts b/src/rpc/server/dialogDispatcher.ts index 202466ffdc..55b678efaf 100644 --- a/src/rpc/server/dialogDispatcher.ts +++ b/src/rpc/server/dialogDispatcher.ts @@ -15,10 +15,10 @@ */ import { Dialog } from '../../dialog'; -import { DialogChannel, DialogInitializer } from '../channels'; +import * as channels from '../channels'; import { Dispatcher, DispatcherScope } from './dispatcher'; -export class DialogDispatcher extends Dispatcher implements DialogChannel { +export class DialogDispatcher extends Dispatcher implements channels.DialogChannel { constructor(scope: DispatcherScope, dialog: Dialog) { super(scope, dialog, 'Dialog', { type: dialog.type(), diff --git a/src/rpc/server/dispatcher.ts b/src/rpc/server/dispatcher.ts index 57a76cbdbc..e122efc696 100644 --- a/src/rpc/server/dispatcher.ts +++ b/src/rpc/server/dispatcher.ts @@ -16,7 +16,7 @@ import { EventEmitter } from 'events'; import { helper, debugAssert, assert } from '../../helper'; -import { Channel } from '../channels'; +import * as channels from '../channels'; import { serializeError } from '../serializers'; import { createScheme, Validator, ValidationError } from '../validator'; @@ -36,7 +36,7 @@ export function lookupNullableDispatcher(object: any | null): Di return object ? lookupDispatcher(object) : undefined; } -export class Dispatcher extends EventEmitter implements Channel { +export class Dispatcher extends EventEmitter implements channels.Channel { private _connection: DispatcherConnection; private _isScope: boolean; // Parent is always "isScope". diff --git a/src/rpc/server/downloadDispatcher.ts b/src/rpc/server/downloadDispatcher.ts index fe0f961f0f..450b3c9768 100644 --- a/src/rpc/server/downloadDispatcher.ts +++ b/src/rpc/server/downloadDispatcher.ts @@ -15,11 +15,11 @@ */ import { Download } from '../../download'; -import { DownloadChannel, DownloadInitializer, StreamChannel } from '../channels'; +import * as channels from '../channels'; import { Dispatcher, DispatcherScope } from './dispatcher'; import { StreamDispatcher } from './streamDispatcher'; -export class DownloadDispatcher extends Dispatcher implements DownloadChannel { +export class DownloadDispatcher extends Dispatcher implements channels.DownloadChannel { constructor(scope: DispatcherScope, download: Download) { super(scope, download, 'Download', { url: download.url(), @@ -27,16 +27,16 @@ export class DownloadDispatcher extends Dispatcher { + async path(): Promise { const path = await this._object.path(); return { value: path || undefined }; } - async saveAs(params: { path: string }): Promise { + async saveAs(params: channels.DownloadSaveAsParams): Promise { await this._object.saveAs(params.path); } - async stream(): Promise<{ stream?: StreamChannel }> { + async stream(): Promise { const stream = await this._object.createReadStream(); if (!stream) return {}; @@ -44,7 +44,7 @@ export class DownloadDispatcher extends Dispatcher { + async failure(): Promise { const error = await this._object.failure(); return { error: error || undefined }; } diff --git a/src/rpc/server/electronDispatcher.ts b/src/rpc/server/electronDispatcher.ts index 5a5d9ee0fb..a046b53d9c 100644 --- a/src/rpc/server/electronDispatcher.ts +++ b/src/rpc/server/electronDispatcher.ts @@ -16,24 +16,24 @@ import { Dispatcher, DispatcherScope, lookupDispatcher } from './dispatcher'; import { Electron, ElectronApplication, ElectronEvents, ElectronPage } from '../../server/electron'; -import { ElectronApplicationChannel, ElectronApplicationInitializer, PageChannel, JSHandleChannel, ElectronInitializer, ElectronChannel, SerializedArgument, ElectronLaunchParams, SerializedValue } from '../channels'; +import * as channels from '../channels'; import { BrowserContextDispatcher } from './browserContextDispatcher'; import { PageDispatcher } from './pageDispatcher'; import { parseArgument, serializeResult } from './jsHandleDispatcher'; import { createHandle } from './elementHandlerDispatcher'; -export class ElectronDispatcher extends Dispatcher implements ElectronChannel { +export class ElectronDispatcher extends Dispatcher implements channels.ElectronChannel { constructor(scope: DispatcherScope, electron: Electron) { super(scope, electron, 'Electron', {}, true); } - async launch(params: ElectronLaunchParams): Promise<{ electronApplication: ElectronApplicationChannel }> { + async launch(params: channels.ElectronLaunchParams): Promise { const electronApplication = await this._object.launch(params.executablePath, params); return { electronApplication: new ElectronApplicationDispatcher(this._scope, electronApplication) }; } } -export class ElectronApplicationDispatcher extends Dispatcher implements ElectronApplicationChannel { +export class ElectronApplicationDispatcher extends Dispatcher implements channels.ElectronApplicationChannel { constructor(scope: DispatcherScope, electronApplication: ElectronApplication) { super(scope, electronApplication, 'ElectronApplication', {}, true); this._dispatchEvent('context', { context: new BrowserContextDispatcher(this._scope, electronApplication.context()) }); @@ -49,17 +49,17 @@ export class ElectronApplicationDispatcher extends Dispatcher { + async newBrowserWindow(params: channels.ElectronApplicationNewBrowserWindowParams): Promise { const page = await this._object.newBrowserWindow(parseArgument(params.arg)); - return { page: lookupDispatcher(page) }; + return { page: lookupDispatcher(page) }; } - async evaluateExpression(params: { expression: string, isFunction: boolean, arg: SerializedArgument }): Promise<{ value: SerializedValue }> { + async evaluateExpression(params: channels.ElectronApplicationEvaluateExpressionParams): Promise { const handle = this._object._nodeElectronHandle!; return { value: serializeResult(await handle._evaluateExpression(params.expression, params.isFunction, true /* returnByValue */, parseArgument(params.arg))) }; } - async evaluateExpressionHandle(params: { expression: string, isFunction: boolean, arg: SerializedArgument }): Promise<{ handle: JSHandleChannel }> { + async evaluateExpressionHandle(params: channels.ElectronApplicationEvaluateExpressionHandleParams): Promise { const handle = this._object._nodeElectronHandle!; const result = await handle._evaluateExpression(params.expression, params.isFunction, false /* returnByValue */, parseArgument(params.arg)); return { handle: createHandle(this._scope, result) }; diff --git a/src/rpc/server/elementHandlerDispatcher.ts b/src/rpc/server/elementHandlerDispatcher.ts index 8747025ff5..e76e3fb3ac 100644 --- a/src/rpc/server/elementHandlerDispatcher.ts +++ b/src/rpc/server/elementHandlerDispatcher.ts @@ -16,8 +16,7 @@ import { ElementHandle } from '../../dom'; import * as js from '../../javascript'; -import * as types from '../../types'; -import { ElementHandleChannel, FrameChannel, Binary, SerializedArgument, SerializedValue } from '../channels'; +import * as channels from '../channels'; import { DispatcherScope, lookupNullableDispatcher } from './dispatcher'; import { JSHandleDispatcher, serializeResult, parseArgument } from './jsHandleDispatcher'; import { FrameDispatcher } from './frameDispatcher'; @@ -26,7 +25,7 @@ export function createHandle(scope: DispatcherScope, handle: js.JSHandle): JSHan return handle.asElement() ? new ElementHandleDispatcher(scope, handle.asElement()!) : new JSHandleDispatcher(scope, handle); } -export class ElementHandleDispatcher extends JSHandleDispatcher implements ElementHandleChannel { +export class ElementHandleDispatcher extends JSHandleDispatcher implements channels.ElementHandleChannel { readonly _elementHandle: ElementHandle; static createNullable(scope: DispatcherScope, handle: ElementHandle | null): ElementHandleDispatcher | undefined { @@ -40,121 +39,121 @@ export class ElementHandleDispatcher extends JSHandleDispatcher implements Eleme this._elementHandle = elementHandle; } - async ownerFrame(): Promise<{ frame?: FrameChannel }> { + async ownerFrame(): Promise { return { frame: lookupNullableDispatcher(await this._elementHandle.ownerFrame()) }; } - async contentFrame(): Promise<{ frame?: FrameChannel }> { + async contentFrame(): Promise { return { frame: lookupNullableDispatcher(await this._elementHandle.contentFrame()) }; } - async getAttribute(params: { name: string }): Promise<{ value?: string }> { + async getAttribute(params: channels.ElementHandleGetAttributeParams): Promise { const value = await this._elementHandle.getAttribute(params.name); return { value: value === null ? undefined : value }; } - async textContent(): Promise<{ value?: string }> { + async textContent(): Promise { const value = await this._elementHandle.textContent(); return { value: value === null ? undefined : value }; } - async innerText(): Promise<{ value: string }> { + async innerText(): Promise { return { value: await this._elementHandle.innerText() }; } - async innerHTML(): Promise<{ value: string }> { + async innerHTML(): Promise { return { value: await this._elementHandle.innerHTML() }; } - async dispatchEvent(params: { type: string, eventInit: SerializedArgument }) { + async dispatchEvent(params: channels.ElementHandleDispatchEventParams): Promise { await this._elementHandle.dispatchEvent(params.type, parseArgument(params.eventInit)); } - async scrollIntoViewIfNeeded(params: types.TimeoutOptions) { + async scrollIntoViewIfNeeded(params: channels.ElementHandleScrollIntoViewIfNeededParams): Promise { await this._elementHandle.scrollIntoViewIfNeeded(params); } - async hover(params: types.PointerActionOptions & types.PointerActionWaitOptions) { + async hover(params: channels.ElementHandleHoverParams): Promise { await this._elementHandle.hover(params); } - async click(params: types.MouseClickOptions & types.PointerActionWaitOptions & types.NavigatingActionWaitOptions) { + async click(params: channels.ElementHandleClickParams): Promise { await this._elementHandle.click(params); } - async dblclick(params: types.MouseMultiClickOptions & types.PointerActionWaitOptions & types.NavigatingActionWaitOptions) { + async dblclick(params: channels.ElementHandleDblclickParams): Promise { await this._elementHandle.dblclick(params); } - async selectOption(params: { elements?: ElementHandleChannel[], options?: types.SelectOption[] } & types.NavigatingActionWaitOptions): Promise<{ values: string[] }> { + async selectOption(params: channels.ElementHandleSelectOptionParams): Promise { const elements = (params.elements || []).map(e => (e as ElementHandleDispatcher)._elementHandle); return { values: await this._elementHandle.selectOption(elements, params.options || [], params) }; } - async fill(params: { value: string } & types.NavigatingActionWaitOptions) { + async fill(params: channels.ElementHandleFillParams): Promise { await this._elementHandle.fill(params.value, params); } - async selectText(params: types.TimeoutOptions) { + async selectText(params: channels.ElementHandleSelectTextParams): Promise { await this._elementHandle.selectText(params); } - async setInputFiles(params: { files: { name: string, mimeType: string, buffer: string }[] } & types.NavigatingActionWaitOptions) { + async setInputFiles(params: channels.ElementHandleSetInputFilesParams): Promise { await this._elementHandle.setInputFiles(params.files, params); } - async focus() { + async focus(): Promise { await this._elementHandle.focus(); } - async type(params: { text: string } & { delay?: number } & types.NavigatingActionWaitOptions) { + async type(params: channels.ElementHandleTypeParams): Promise { await this._elementHandle.type(params.text, params); } - async press(params: { key: string } & { delay?: number } & types.NavigatingActionWaitOptions) { + async press(params: channels.ElementHandlePressParams): Promise { await this._elementHandle.press(params.key, params); } - async check(params: types.PointerActionWaitOptions & types.NavigatingActionWaitOptions) { + async check(params: channels.ElementHandleCheckParams): Promise { await this._elementHandle.check(params); } - async uncheck(params: types.PointerActionWaitOptions & types.NavigatingActionWaitOptions) { + async uncheck(params: channels.ElementHandleUncheckParams): Promise { await this._elementHandle.uncheck(params); } - async boundingBox(): Promise<{ value?: types.Rect }> { + async boundingBox(): Promise { const value = await this._elementHandle.boundingBox(); return { value: value || undefined }; } - async screenshot(params: types.ElementScreenshotOptions): Promise<{ binary: Binary }> { + async screenshot(params: channels.ElementHandleScreenshotParams): Promise { return { binary: (await this._elementHandle.screenshot(params)).toString('base64') }; } - async querySelector(params: { selector: string }): Promise<{ element?: ElementHandleChannel }> { + async querySelector(params: channels.ElementHandleQuerySelectorParams): Promise { const handle = await this._elementHandle.$(params.selector); return { element: handle ? new ElementHandleDispatcher(this._scope, handle) : undefined }; } - async querySelectorAll(params: { selector: string }): Promise<{ elements: ElementHandleChannel[] }> { + async querySelectorAll(params: channels.ElementHandleQuerySelectorAllParams): Promise { const elements = await this._elementHandle.$$(params.selector); return { elements: elements.map(e => new ElementHandleDispatcher(this._scope, e)) }; } - async evalOnSelector(params: { selector: string, expression: string, isFunction: boolean, arg: SerializedArgument }): Promise<{ value: SerializedValue }> { + async evalOnSelector(params: channels.ElementHandleEvalOnSelectorParams): Promise { return { value: serializeResult(await this._elementHandle._$evalExpression(params.selector, params.expression, params.isFunction, parseArgument(params.arg))) }; } - async evalOnSelectorAll(params: { selector: string, expression: string, isFunction: boolean, arg: SerializedArgument }): Promise<{ value: SerializedValue }> { + async evalOnSelectorAll(params: channels.ElementHandleEvalOnSelectorAllParams): Promise { return { value: serializeResult(await this._elementHandle._$$evalExpression(params.selector, params.expression, params.isFunction, parseArgument(params.arg))) }; } - async waitForElementState(params: { state: 'visible' | 'hidden' | 'stable' | 'enabled' | 'disabled' } & types.TimeoutOptions): Promise { + async waitForElementState(params: channels.ElementHandleWaitForElementStateParams): Promise { await this._elementHandle.waitForElementState(params.state, params); } - async waitForSelector(params: { selector: string } & types.WaitForElementOptions): Promise<{ element?: ElementHandleChannel }> { + async waitForSelector(params: channels.ElementHandleWaitForSelectorParams): Promise { return { element: ElementHandleDispatcher.createNullable(this._scope, await this._elementHandle.waitForSelector(params.selector, params)) }; } } diff --git a/src/rpc/server/frameDispatcher.ts b/src/rpc/server/frameDispatcher.ts index 19a6815e0e..fa0d04b4f9 100644 --- a/src/rpc/server/frameDispatcher.ts +++ b/src/rpc/server/frameDispatcher.ts @@ -16,13 +16,13 @@ import { Frame, kAddLifecycleEvent, kRemoveLifecycleEvent, kNavigationEvent, NavigationEvent } from '../../frames'; import * as types from '../../types'; -import { ElementHandleChannel, FrameChannel, FrameInitializer, JSHandleChannel, ResponseChannel, SerializedArgument, FrameWaitForFunctionParams, SerializedValue } from '../channels'; +import * as channels from '../channels'; import { Dispatcher, DispatcherScope, lookupNullableDispatcher, existingDispatcher } from './dispatcher'; import { ElementHandleDispatcher, createHandle } from './elementHandlerDispatcher'; import { parseArgument, serializeResult } from './jsHandleDispatcher'; import { ResponseDispatcher, RequestDispatcher } from './networkDispatchers'; -export class FrameDispatcher extends Dispatcher implements FrameChannel { +export class FrameDispatcher extends Dispatcher implements channels.FrameChannel { private _frame: Frame; static from(scope: DispatcherScope, frame: Frame): FrameDispatcher { @@ -52,127 +52,127 @@ export class FrameDispatcher extends Dispatcher impleme }); } - async goto(params: { url: string } & types.GotoOptions): Promise<{ response?: ResponseChannel }> { + async goto(params: channels.FrameGotoParams): Promise { return { response: lookupNullableDispatcher(await this._frame.goto(params.url, params)) }; } - async frameElement(): Promise<{ element: ElementHandleChannel }> { + async frameElement(): Promise { return { element: new ElementHandleDispatcher(this._scope, await this._frame.frameElement()) }; } - async evaluateExpression(params: { expression: string, isFunction: boolean, arg: SerializedArgument }): Promise<{ value: SerializedValue }> { + async evaluateExpression(params: channels.FrameEvaluateExpressionParams): Promise { return { value: serializeResult(await this._frame._evaluateExpression(params.expression, params.isFunction, parseArgument(params.arg))) }; } - async evaluateExpressionHandle(params: { expression: string, isFunction: boolean, arg: SerializedArgument }): Promise<{ handle: JSHandleChannel }> { + async evaluateExpressionHandle(params: channels.FrameEvaluateExpressionHandleParams): Promise { return { handle: createHandle(this._scope, await this._frame._evaluateExpressionHandle(params.expression, params.isFunction, parseArgument(params.arg))) }; } - async waitForSelector(params: { selector: string } & types.WaitForElementOptions): Promise<{ element?: ElementHandleChannel }> { + async waitForSelector(params: channels.FrameWaitForSelectorParams): Promise { return { element: ElementHandleDispatcher.createNullable(this._scope, await this._frame.waitForSelector(params.selector, params)) }; } - async dispatchEvent(params: { selector: string, type: string, eventInit: SerializedArgument } & types.TimeoutOptions): Promise { + async dispatchEvent(params: channels.FrameDispatchEventParams): Promise { return this._frame.dispatchEvent(params.selector, params.type, parseArgument(params.eventInit), params); } - async evalOnSelector(params: { selector: string, expression: string, isFunction: boolean, arg: SerializedArgument }): Promise<{ value: SerializedValue }> { + async evalOnSelector(params: channels.FrameEvalOnSelectorParams): Promise { return { value: serializeResult(await this._frame._$evalExpression(params.selector, params.expression, params.isFunction, parseArgument(params.arg))) }; } - async evalOnSelectorAll(params: { selector: string, expression: string, isFunction: boolean, arg: SerializedArgument }): Promise<{ value: SerializedValue }> { + async evalOnSelectorAll(params: channels.FrameEvalOnSelectorAllParams): Promise { return { value: serializeResult(await this._frame._$$evalExpression(params.selector, params.expression, params.isFunction, parseArgument(params.arg))) }; } - async querySelector(params: { selector: string }): Promise<{ element?: ElementHandleChannel }> { + async querySelector(params: channels.FrameQuerySelectorParams): Promise { return { element: ElementHandleDispatcher.createNullable(this._scope, await this._frame.$(params.selector)) }; } - async querySelectorAll(params: { selector: string }): Promise<{ elements: ElementHandleChannel[] }> { + async querySelectorAll(params: channels.FrameQuerySelectorAllParams): Promise { const elements = await this._frame.$$(params.selector); return { elements: elements.map(e => new ElementHandleDispatcher(this._scope, e)) }; } - async content(): Promise<{ value: string }> { + async content(): Promise { return { value: await this._frame.content() }; } - async setContent(params: { html: string } & types.NavigateOptions): Promise { + async setContent(params: channels.FrameSetContentParams): Promise { await this._frame.setContent(params.html, params); } - async addScriptTag(params: { url?: string, content?: string, type?: string }): Promise<{ element: ElementHandleChannel }> { + async addScriptTag(params: channels.FrameAddScriptTagParams): Promise { return { element: new ElementHandleDispatcher(this._scope, await this._frame.addScriptTag(params)) }; } - async addStyleTag(params: { url?: string, content?: string }): Promise<{ element: ElementHandleChannel }> { + async addStyleTag(params: channels.FrameAddStyleTagParams): Promise { return { element: new ElementHandleDispatcher(this._scope, await this._frame.addStyleTag(params)) }; } - async click(params: { selector: string } & types.PointerActionOptions & types.MouseClickOptions & types.TimeoutOptions & { force?: boolean } & { noWaitAfter?: boolean }): Promise { + async click(params: channels.FrameClickParams): Promise { await this._frame.click(params.selector, params); } - async dblclick(params: { selector: string } & types.PointerActionOptions & types.MouseMultiClickOptions & types.TimeoutOptions & { force?: boolean }): Promise { + async dblclick(params: channels.FrameDblclickParams): Promise { await this._frame.dblclick(params.selector, params); } - async fill(params: { selector: string, value: string } & types.NavigatingActionWaitOptions): Promise { + async fill(params: channels.FrameFillParams): Promise { await this._frame.fill(params.selector, params.value, params); } - async focus(params: { selector: string } & types.TimeoutOptions): Promise { + async focus(params: channels.FrameFocusParams): Promise { await this._frame.focus(params.selector, params); } - async textContent(params: { selector: string } & types.TimeoutOptions): Promise<{ value?: string }> { + async textContent(params: channels.FrameTextContentParams): Promise { const value = await this._frame.textContent(params.selector, params); return { value: value === null ? undefined : value }; } - async innerText(params: { selector: string } & types.TimeoutOptions): Promise<{ value: string }> { + async innerText(params: channels.FrameInnerTextParams): Promise { return { value: await this._frame.innerText(params.selector, params) }; } - async innerHTML(params: { selector: string } & types.TimeoutOptions): Promise<{ value: string }> { + async innerHTML(params: channels.FrameInnerHTMLParams): Promise { return { value: await this._frame.innerHTML(params.selector, params) }; } - async getAttribute(params: { selector: string, name: string } & types.TimeoutOptions): Promise<{ value?: string }> { + async getAttribute(params: channels.FrameGetAttributeParams): Promise { const value = await this._frame.getAttribute(params.selector, params.name, params); return { value: value === null ? undefined : value }; } - async hover(params: { selector: string } & types.PointerActionOptions & types.TimeoutOptions & { force?: boolean }): Promise { + async hover(params: channels.FrameHoverParams): Promise { await this._frame.hover(params.selector, params); } - async selectOption(params: { selector: string, elements?: ElementHandleChannel[], options?: types.SelectOption[] } & types.NavigatingActionWaitOptions): Promise<{ values: string[] }> { + async selectOption(params: channels.FrameSelectOptionParams): Promise { const elements = (params.elements || []).map(e => (e as ElementHandleDispatcher)._elementHandle); return { values: await this._frame.selectOption(params.selector, elements, params.options || [], params) }; } - async setInputFiles(params: { selector: string, files: { name: string, mimeType: string, buffer: string }[] } & types.NavigatingActionWaitOptions): Promise { + async setInputFiles(params: channels.FrameSetInputFilesParams): Promise { await this._frame.setInputFiles(params.selector, params.files, params); } - async type(params: { selector: string, text: string } & { delay?: number | undefined } & types.TimeoutOptions & { noWaitAfter?: boolean }): Promise { + async type(params: channels.FrameTypeParams): Promise { await this._frame.type(params.selector, params.text, params); } - async press(params: { selector: string, key: string } & { delay?: number | undefined } & types.TimeoutOptions & { noWaitAfter?: boolean }): Promise { + async press(params: channels.FramePressParams): Promise { await this._frame.press(params.selector, params.key, params); } - async check(params: { selector: string } & types.TimeoutOptions & { force?: boolean } & { noWaitAfter?: boolean }): Promise { + async check(params: channels.FrameCheckParams): Promise { await this._frame.check(params.selector, params); } - async uncheck(params: { selector: string } & types.TimeoutOptions & { force?: boolean } & { noWaitAfter?: boolean }): Promise { + async uncheck(params: channels.FrameUncheckParams): Promise { await this._frame.uncheck(params.selector, params); } - async waitForFunction(params: FrameWaitForFunctionParams): Promise<{ handle: JSHandleChannel }> { + async waitForFunction(params: channels.FrameWaitForFunctionParams): Promise { const options = { ...params, polling: params.pollingInterval === undefined ? 'raf' as const : params.pollingInterval @@ -180,7 +180,7 @@ export class FrameDispatcher extends Dispatcher impleme return { handle: createHandle(this._scope, await this._frame._waitForFunctionExpression(params.expression, params.isFunction, parseArgument(params.arg), options)) }; } - async title(): Promise<{ value: string }> { + async title(): Promise { return { value: await this._frame.title() }; } } diff --git a/src/rpc/server/jsHandleDispatcher.ts b/src/rpc/server/jsHandleDispatcher.ts index 0b9c72cd47..9fc363064f 100644 --- a/src/rpc/server/jsHandleDispatcher.ts +++ b/src/rpc/server/jsHandleDispatcher.ts @@ -15,12 +15,12 @@ */ import * as js from '../../javascript'; -import { JSHandleChannel, JSHandleInitializer, SerializedArgument, SerializedValue } from '../channels'; +import * as channels from '../channels'; import { Dispatcher, DispatcherScope } from './dispatcher'; import { createHandle } from './elementHandlerDispatcher'; import { parseSerializedValue, serializeValue } from '../serializers'; -export class JSHandleDispatcher extends Dispatcher implements JSHandleChannel { +export class JSHandleDispatcher extends Dispatcher implements channels.JSHandleChannel { constructor(scope: DispatcherScope, jsHandle: js.JSHandle) { super(scope, jsHandle, jsHandle.asElement() ? 'ElementHandle' : 'JSHandle', { @@ -29,21 +29,21 @@ export class JSHandleDispatcher extends Dispatcher this._dispatchEvent('previewUpdated', { preview })); } - async evaluateExpression(params: { expression: string, isFunction: boolean, arg: SerializedArgument }): Promise<{ value: SerializedValue }> { + async evaluateExpression(params: channels.JSHandleEvaluateExpressionParams): Promise { return { value: serializeResult(await this._object._evaluateExpression(params.expression, params.isFunction, true /* returnByValue */, parseArgument(params.arg))) }; } - async evaluateExpressionHandle(params: { expression: string, isFunction: boolean, arg: SerializedArgument}): Promise<{ handle: JSHandleChannel }> { + async evaluateExpressionHandle(params: channels.JSHandleEvaluateExpressionHandleParams): Promise { const jsHandle = await this._object._evaluateExpression(params.expression, params.isFunction, false /* returnByValue */, parseArgument(params.arg)); return { handle: createHandle(this._scope, jsHandle) }; } - async getProperty(params: { name: string }): Promise<{ handle: JSHandleChannel }> { + async getProperty(params: channels.JSHandleGetPropertyParams): Promise { const jsHandle = await this._object.getProperty(params.name); return { handle: createHandle(this._scope, jsHandle) }; } - async getPropertyList(): Promise<{ properties: { name: string, value: JSHandleChannel }[] }> { + async getPropertyList(): Promise { const map = await this._object.getProperties(); const properties = []; for (const [name, value] of map) @@ -51,7 +51,7 @@ export class JSHandleDispatcher extends Dispatcher { + async jsonValue(): Promise { return { value: serializeResult(await this._object.jsonValue()) }; } @@ -62,13 +62,14 @@ export class JSHandleDispatcher extends Dispatcher (a as JSHandleDispatcher)._object)); } -export function parseValue(v: SerializedValue): any { + +export function parseValue(v: channels.SerializedValue): any { return parseSerializedValue(v, []); } -export function serializeResult(arg: any): SerializedValue { +export function serializeResult(arg: any): channels.SerializedValue { return serializeValue(arg, value => ({ fallThrough: value }), new Set()); } diff --git a/src/rpc/server/networkDispatchers.ts b/src/rpc/server/networkDispatchers.ts index 881d2c32cd..be8c0d8caf 100644 --- a/src/rpc/server/networkDispatchers.ts +++ b/src/rpc/server/networkDispatchers.ts @@ -15,12 +15,11 @@ */ import { Request, Response, Route } from '../../network'; -import { RequestChannel, ResponseChannel, RouteChannel, ResponseInitializer, RequestInitializer, RouteInitializer, Binary } from '../channels'; +import * as channels from '../channels'; import { Dispatcher, DispatcherScope, lookupNullableDispatcher, existingDispatcher } from './dispatcher'; import { FrameDispatcher } from './frameDispatcher'; -import * as types from '../../types'; -export class RequestDispatcher extends Dispatcher implements RequestChannel { +export class RequestDispatcher extends Dispatcher implements channels.RequestChannel { static from(scope: DispatcherScope, request: Request): RequestDispatcher { const result = existingDispatcher(request); @@ -45,12 +44,12 @@ export class RequestDispatcher extends Dispatcher i }); } - async response(): Promise<{ response?: ResponseChannel }> { + async response(): Promise { return { response: lookupNullableDispatcher(await this._object.response()) }; } } -export class ResponseDispatcher extends Dispatcher implements ResponseChannel { +export class ResponseDispatcher extends Dispatcher implements channels.ResponseChannel { constructor(scope: DispatcherScope, response: Response) { super(scope, response, 'Response', { @@ -63,16 +62,16 @@ export class ResponseDispatcher extends Dispatcher { + async finished(): Promise { return await this._object._finishedPromise; } - async body(): Promise<{ binary: Binary }> { + async body(): Promise { return { binary: (await this._object.body()).toString('base64') }; } } -export class RouteDispatcher extends Dispatcher implements RouteChannel { +export class RouteDispatcher extends Dispatcher implements channels.RouteChannel { constructor(scope: DispatcherScope, route: Route) { super(scope, route, 'Route', { @@ -81,7 +80,7 @@ export class RouteDispatcher extends Dispatcher impleme }); } - async continue(params: { method?: string, headers?: types.HeadersArray, postData?: string }): Promise { + async continue(params: channels.RouteContinueParams): Promise { await this._object.continue({ method: params.method, headers: params.headers, @@ -89,11 +88,11 @@ export class RouteDispatcher extends Dispatcher impleme }); } - async fulfill(params: types.NormalizedFulfillResponse): Promise { + async fulfill(params: channels.RouteFulfillParams): Promise { await this._object.fulfill(params); } - async abort(params: { errorCode?: string }): Promise { + async abort(params: channels.RouteAbortParams): Promise { await this._object.abort(params.errorCode || 'failed'); } } diff --git a/src/rpc/server/pageDispatcher.ts b/src/rpc/server/pageDispatcher.ts index 39e19b17f5..d23a402e64 100644 --- a/src/rpc/server/pageDispatcher.ts +++ b/src/rpc/server/pageDispatcher.ts @@ -19,8 +19,7 @@ import { Events } from '../../events'; import { Frame } from '../../frames'; import { Request } from '../../network'; import { Page, Worker } from '../../page'; -import * as types from '../../types'; -import { BindingCallChannel, BindingCallInitializer, ElementHandleChannel, PageChannel, PageInitializer, ResponseChannel, WorkerInitializer, WorkerChannel, JSHandleChannel, Binary, SerializedArgument, PagePdfParams, SerializedError, PageAccessibilitySnapshotResult, SerializedValue, PageEmulateMediaParams } from '../channels'; +import * as channels from '../channels'; import { Dispatcher, DispatcherScope, lookupDispatcher, lookupNullableDispatcher } from './dispatcher'; import { parseError, serializeError } from '../serializers'; import { ConsoleMessageDispatcher } from './consoleMessageDispatcher'; @@ -33,7 +32,7 @@ import { ElementHandleDispatcher, createHandle } from './elementHandlerDispatche import { FileChooser } from '../../fileChooser'; import { CRCoverage } from '../../chromium/crCoverage'; -export class PageDispatcher extends Dispatcher implements PageChannel { +export class PageDispatcher extends Dispatcher implements channels.PageChannel { private _page: Page; constructor(scope: DispatcherScope, page: Page) { @@ -70,19 +69,19 @@ export class PageDispatcher extends Dispatcher implements page.on(Events.Page.Worker, worker => this._dispatchEvent('worker', { worker: new WorkerDispatcher(this._scope, worker) })); } - async setDefaultNavigationTimeoutNoReply(params: { timeout: number }) { + async setDefaultNavigationTimeoutNoReply(params: channels.PageSetDefaultNavigationTimeoutNoReplyParams): Promise { this._page.setDefaultNavigationTimeout(params.timeout); } - async setDefaultTimeoutNoReply(params: { timeout: number }) { + async setDefaultTimeoutNoReply(params: channels.PageSetDefaultTimeoutNoReplyParams): Promise { this._page.setDefaultTimeout(params.timeout); } - async opener(): Promise<{ page?: PageChannel }> { + async opener(): Promise { return { page: lookupNullableDispatcher(await this._page.opener()) }; } - async exposeBinding(params: { name: string }): Promise { + async exposeBinding(params: channels.PageExposeBindingParams): Promise { await this._page.exposeBinding(params.name, (source, ...args) => { const binding = new BindingCallDispatcher(this._scope, params.name, source, args); this._dispatchEvent('bindingCall', { binding }); @@ -90,38 +89,38 @@ export class PageDispatcher extends Dispatcher implements }); } - async setExtraHTTPHeaders(params: { headers: types.HeadersArray }): Promise { + async setExtraHTTPHeaders(params: channels.PageSetExtraHTTPHeadersParams): Promise { await this._page.setExtraHTTPHeaders(params.headers); } - async reload(params: types.NavigateOptions): Promise<{ response?: ResponseChannel }> { + async reload(params: channels.PageReloadParams): Promise { return { response: lookupNullableDispatcher(await this._page.reload(params)) }; } - async goBack(params: types.NavigateOptions): Promise<{ response?: ResponseChannel }> { + async goBack(params: channels.PageGoBackParams): Promise { return { response: lookupNullableDispatcher(await this._page.goBack(params)) }; } - async goForward(params: types.NavigateOptions): Promise<{ response?: ResponseChannel }> { + async goForward(params: channels.PageGoForwardParams): Promise { return { response: lookupNullableDispatcher(await this._page.goForward(params)) }; } - async emulateMedia(params: PageEmulateMediaParams): Promise { + async emulateMedia(params: channels.PageEmulateMediaParams): Promise { await this._page.emulateMedia({ media: params.media === 'null' ? null : params.media, colorScheme: params.colorScheme === 'null' ? null : params.colorScheme, }); } - async setViewportSize(params: { viewportSize: types.Size }): Promise { + async setViewportSize(params: channels.PageSetViewportSizeParams): Promise { await this._page.setViewportSize(params.viewportSize); } - async addInitScript(params: { source: string }): Promise { + async addInitScript(params: channels.PageAddInitScriptParams): Promise { await this._page._addInitScriptExpression(params.source); } - async setNetworkInterceptionEnabled(params: { enabled: boolean }): Promise { + async setNetworkInterceptionEnabled(params: channels.PageSetNetworkInterceptionEnabledParams): Promise { if (!params.enabled) { await this._page._setRequestInterceptor(undefined); return; @@ -131,55 +130,55 @@ export class PageDispatcher extends Dispatcher implements }); } - async screenshot(params: types.ScreenshotOptions): Promise<{ binary: Binary }> { + async screenshot(params: channels.PageScreenshotParams): Promise { return { binary: (await this._page.screenshot(params)).toString('base64') }; } - async close(params: { runBeforeUnload?: boolean }): Promise { + async close(params: channels.PageCloseParams): Promise { await this._page.close(params); } - async setFileChooserInterceptedNoReply(params: { intercepted: boolean }) { + async setFileChooserInterceptedNoReply(params: channels.PageSetFileChooserInterceptedNoReplyParams): Promise { await this._page._setFileChooserIntercepted(params.intercepted); } - async keyboardDown(params: { key: string }): Promise { + async keyboardDown(params: channels.PageKeyboardDownParams): Promise { await this._page.keyboard.down(params.key); } - async keyboardUp(params: { key: string }): Promise { + async keyboardUp(params: channels.PageKeyboardUpParams): Promise { await this._page.keyboard.up(params.key); } - async keyboardInsertText(params: { text: string }): Promise { + async keyboardInsertText(params: channels.PageKeyboardInsertTextParams): Promise { await this._page.keyboard.insertText(params.text); } - async keyboardType(params: { text: string, delay?: number }): Promise { + async keyboardType(params: channels.PageKeyboardTypeParams): Promise { await this._page.keyboard.type(params.text, params); } - async keyboardPress(params: { key: string, delay?: number }): Promise { + async keyboardPress(params: channels.PageKeyboardPressParams): Promise { await this._page.keyboard.press(params.key, params); } - async mouseMove(params: { x: number, y: number, steps?: number }): Promise { + async mouseMove(params: channels.PageMouseMoveParams): Promise { await this._page.mouse.move(params.x, params.y, params); } - async mouseDown(params: { button?: types.MouseButton, clickCount?: number }): Promise { + async mouseDown(params: channels.PageMouseDownParams): Promise { await this._page.mouse.down(params); } - async mouseUp(params: { button?: types.MouseButton, clickCount?: number }): Promise { + async mouseUp(params: channels.PageMouseUpParams): Promise { await this._page.mouse.up(params); } - async mouseClick(params: { x: number, y: number, delay?: number, button?: types.MouseButton, clickCount?: number }): Promise { + async mouseClick(params: channels.PageMouseClickParams): Promise { await this._page.mouse.click(params.x, params.y, params); } - async accessibilitySnapshot(params: { interestingOnly?: boolean, root?: ElementHandleChannel }): Promise { + async accessibilitySnapshot(params: channels.PageAccessibilitySnapshotParams): Promise { const rootAXNode = await this._page.accessibility.snapshot({ interestingOnly: params.interestingOnly, root: params.root ? (params.root as ElementHandleDispatcher)._elementHandle : undefined @@ -187,7 +186,7 @@ export class PageDispatcher extends Dispatcher implements return { rootAXNode: rootAXNode || undefined }; } - async pdf(params: PagePdfParams): Promise<{ pdf: Binary }> { + async pdf(params: channels.PagePdfParams): Promise { if (!this._page.pdf) throw new Error('PDF generation is only supported for Headless Chromium'); const buffer = await this._page.pdf(params); @@ -198,22 +197,22 @@ export class PageDispatcher extends Dispatcher implements await this._page.bringToFront(); } - async crStartJSCoverage(params: types.JSCoverageOptions): Promise { + async crStartJSCoverage(params: channels.PageCrStartJSCoverageParams): Promise { const coverage = this._page.coverage as CRCoverage; await coverage.startJSCoverage(params); } - async crStopJSCoverage(): Promise<{ entries: types.JSCoverageEntry[] }> { + async crStopJSCoverage(): Promise { const coverage = this._page.coverage as CRCoverage; return { entries: await coverage.stopJSCoverage() }; } - async crStartCSSCoverage(params: types.CSSCoverageOptions): Promise { + async crStartCSSCoverage(params: channels.PageCrStartCSSCoverageParams): Promise { const coverage = this._page.coverage as CRCoverage; await coverage.startCSSCoverage(params); } - async crStopCSSCoverage(): Promise<{ entries: types.CSSCoverageEntry[] }> { + async crStopCSSCoverage(): Promise { const coverage = this._page.coverage as CRCoverage; return { entries: await coverage.stopCSSCoverage() }; } @@ -228,7 +227,7 @@ export class PageDispatcher extends Dispatcher implements } -export class WorkerDispatcher extends Dispatcher implements WorkerChannel { +export class WorkerDispatcher extends Dispatcher implements channels.WorkerChannel { constructor(scope: DispatcherScope, worker: Worker) { super(scope, worker, 'Worker', { url: worker.url() @@ -236,16 +235,16 @@ export class WorkerDispatcher extends Dispatcher impl worker.on(Events.Worker.Close, () => this._dispatchEvent('close')); } - async evaluateExpression(params: { expression: string, isFunction: boolean, arg: SerializedArgument }): Promise<{ value: SerializedValue }> { + async evaluateExpression(params: channels.WorkerEvaluateExpressionParams): Promise { return { value: serializeResult(await this._object._evaluateExpression(params.expression, params.isFunction, parseArgument(params.arg))) }; } - async evaluateExpressionHandle(params: { expression: string, isFunction: boolean, arg: SerializedArgument }): Promise<{ handle: JSHandleChannel }> { + async evaluateExpressionHandle(params: channels.WorkerEvaluateExpressionHandleParams): Promise { return { handle: createHandle(this._scope, await this._object._evaluateExpressionHandle(params.expression, params.isFunction, parseArgument(params.arg))) }; } } -export class BindingCallDispatcher extends Dispatcher<{}, BindingCallInitializer> implements BindingCallChannel { +export class BindingCallDispatcher extends Dispatcher<{}, channels.BindingCallInitializer> implements channels.BindingCallChannel { private _resolve: ((arg: any) => void) | undefined; private _reject: ((error: any) => void) | undefined; private _promise: Promise; @@ -266,11 +265,11 @@ export class BindingCallDispatcher extends Dispatcher<{}, BindingCallInitializer return this._promise; } - async resolve(params: { result: SerializedArgument }) { + async resolve(params: channels.BindingCallResolveParams): Promise { this._resolve!(parseArgument(params.result)); } - async reject(params: { error: SerializedError }) { + async reject(params: channels.BindingCallRejectParams): Promise { this._reject!(parseError(params.error)); } } diff --git a/src/rpc/server/playwrightDispatcher.ts b/src/rpc/server/playwrightDispatcher.ts index 4b9b52b6f9..5d22da73f8 100644 --- a/src/rpc/server/playwrightDispatcher.ts +++ b/src/rpc/server/playwrightDispatcher.ts @@ -15,7 +15,7 @@ */ import { Playwright } from '../../server/playwright'; -import { PlaywrightChannel, PlaywrightInitializer } from '../channels'; +import * as channels from '../channels'; import { BrowserTypeDispatcher } from './browserTypeDispatcher'; import { Dispatcher, DispatcherScope } from './dispatcher'; import { SelectorsDispatcher } from './selectorsDispatcher'; @@ -23,7 +23,7 @@ import { Electron } from '../../server/electron'; import { ElectronDispatcher } from './electronDispatcher'; import { DeviceDescriptors } from '../../deviceDescriptors'; -export class PlaywrightDispatcher extends Dispatcher implements PlaywrightChannel { +export class PlaywrightDispatcher extends Dispatcher implements channels.PlaywrightChannel { constructor(scope: DispatcherScope, playwright: Playwright) { const electron = (playwright as any).electron as (Electron | undefined); const deviceDescriptors = Object.entries(DeviceDescriptors) diff --git a/src/rpc/server/selectorsDispatcher.ts b/src/rpc/server/selectorsDispatcher.ts index f15c2536cd..3d291b3c04 100644 --- a/src/rpc/server/selectorsDispatcher.ts +++ b/src/rpc/server/selectorsDispatcher.ts @@ -15,21 +15,21 @@ */ import { Dispatcher, DispatcherScope } from './dispatcher'; -import { SelectorsInitializer, SelectorsChannel } from '../channels'; +import * as channels from '../channels'; import { Selectors } from '../../selectors'; import { ElementHandleDispatcher } from './elementHandlerDispatcher'; import * as dom from '../../dom'; -export class SelectorsDispatcher extends Dispatcher implements SelectorsChannel { +export class SelectorsDispatcher extends Dispatcher implements channels.SelectorsChannel { constructor(scope: DispatcherScope, selectors: Selectors) { super(scope, selectors, 'Selectors', {}); } - async register(params: { name: string, source: string, contentScript?: boolean }): Promise { + async register(params: channels.SelectorsRegisterParams): Promise { await this._object.register(params.name, params.source, params.contentScript); } - async createSelector(params: { name: string, handle: ElementHandleDispatcher }): Promise<{ value?: string }> { - return { value: await this._object._createSelector(params.name, params.handle._object as dom.ElementHandle) }; + async createSelector(params: channels.SelectorsCreateSelectorParams): Promise { + return { value: await this._object._createSelector(params.name, (params.handle as ElementHandleDispatcher)._object as dom.ElementHandle) }; } } diff --git a/src/rpc/server/streamDispatcher.ts b/src/rpc/server/streamDispatcher.ts index dd9acc3a60..dc28f08abf 100644 --- a/src/rpc/server/streamDispatcher.ts +++ b/src/rpc/server/streamDispatcher.ts @@ -14,16 +14,16 @@ * limitations under the License. */ -import { StreamChannel, StreamInitializer, Binary } from '../channels'; +import * as channels from '../channels'; import { Dispatcher, DispatcherScope } from './dispatcher'; import * as stream from 'stream'; -export class StreamDispatcher extends Dispatcher implements StreamChannel { +export class StreamDispatcher extends Dispatcher implements channels.StreamChannel { constructor(scope: DispatcherScope, stream: stream.Readable) { super(scope, stream, 'Stream', {}); } - async read(params: { size?: number }): Promise<{ binary: Binary }> { + async read(params: channels.StreamReadParams): Promise { const buffer = this._object.read(Math.min(this._object.readableLength, params.size || this._object.readableLength)); return { binary: buffer ? buffer.toString('base64') : '' }; }