diff --git a/packages/playwright-core/src/browserServerImpl.ts b/packages/playwright-core/src/browserServerImpl.ts index 6db6a5608b..c594feb35e 100644 --- a/packages/playwright-core/src/browserServerImpl.ts +++ b/packages/playwright-core/src/browserServerImpl.ts @@ -100,7 +100,8 @@ export class BrowserServerLauncherImpl implements BrowserServerLauncher { } // This class implements multiplexing browser dispatchers over a single Browser instance. -class ConnectedBrowserDispatcher extends Dispatcher implements channels.BrowserChannel { +class ConnectedBrowserDispatcher extends Dispatcher implements channels.BrowserChannel { + _type_Browser = true; private _contexts = new Set(); private _selectors: Selectors; diff --git a/packages/playwright-core/src/client/android.ts b/packages/playwright-core/src/client/android.ts index 9364a0211c..b9dcfe886c 100644 --- a/packages/playwright-core/src/client/android.ts +++ b/packages/playwright-core/src/client/android.ts @@ -30,7 +30,7 @@ import { EventEmitter } from 'events'; type Direction = 'down' | 'up' | 'left' | 'right'; type SpeedOptions = { speed?: number }; -export class Android extends ChannelOwner implements api.Android { +export class Android extends ChannelOwner implements api.Android { readonly _timeoutSettings: TimeoutSettings; static from(android: channels.AndroidChannel): Android { @@ -55,7 +55,7 @@ export class Android extends ChannelOwner implements api.AndroidDevice { +export class AndroidDevice extends ChannelOwner implements api.AndroidDevice { readonly _timeoutSettings: TimeoutSettings; private _webViews = new Map(); @@ -249,7 +249,7 @@ export class AndroidDevice extends ChannelOwner implements api.AndroidSocket { +export class AndroidSocket extends ChannelOwner implements api.AndroidSocket { static from(androidDevice: channels.AndroidSocketChannel): AndroidSocket { return (androidDevice as any)._object; } diff --git a/packages/playwright-core/src/client/artifact.ts b/packages/playwright-core/src/client/artifact.ts index b719366d23..5aa31b5572 100644 --- a/packages/playwright-core/src/client/artifact.ts +++ b/packages/playwright-core/src/client/artifact.ts @@ -21,7 +21,7 @@ import { mkdirIfNeeded } from '../utils/utils'; import { ChannelOwner } from './channelOwner'; import { Readable } from 'stream'; -export class Artifact extends ChannelOwner { +export class Artifact extends ChannelOwner { static from(channel: channels.ArtifactChannel): Artifact { return (channel as any)._object; } diff --git a/packages/playwright-core/src/client/browser.ts b/packages/playwright-core/src/client/browser.ts index 8996519a5e..176fc03581 100644 --- a/packages/playwright-core/src/client/browser.ts +++ b/packages/playwright-core/src/client/browser.ts @@ -25,7 +25,7 @@ import * as api from '../../types/types'; import { CDPSession } from './cdpSession'; import type { BrowserType } from './browserType'; -export class Browser extends ChannelOwner implements api.Browser { +export class Browser extends ChannelOwner implements api.Browser { readonly _contexts = new Set(); private _isConnected = true; private _closedPromise: Promise; diff --git a/packages/playwright-core/src/client/browserContext.ts b/packages/playwright-core/src/client/browserContext.ts index 9cb7a4faa1..bafb4f9d5f 100644 --- a/packages/playwright-core/src/client/browserContext.ts +++ b/packages/playwright-core/src/client/browserContext.ts @@ -39,7 +39,7 @@ import { Artifact } from './artifact'; import { APIRequestContext } from './fetch'; import { createInstrumentation } from './clientInstrumentation'; -export class BrowserContext extends ChannelOwner implements api.BrowserContext { +export class BrowserContext extends ChannelOwner implements api.BrowserContext { _pages = new Set(); private _routes: network.RouteHandler[] = []; readonly _browser: Browser | null = null; diff --git a/packages/playwright-core/src/client/browserType.ts b/packages/playwright-core/src/client/browserType.ts index 3e0bfda3a9..1a2d39eab4 100644 --- a/packages/playwright-core/src/client/browserType.ts +++ b/packages/playwright-core/src/client/browserType.ts @@ -41,7 +41,7 @@ export interface BrowserServer extends api.BrowserServer { kill(): Promise; } -export class BrowserType extends ChannelOwner implements api.BrowserType { +export class BrowserType extends ChannelOwner implements api.BrowserType { _serverLauncher?: BrowserServerLauncher; _contexts = new Set(); _playwright!: Playwright; diff --git a/packages/playwright-core/src/client/cdpSession.ts b/packages/playwright-core/src/client/cdpSession.ts index 783d30be6a..1031f38220 100644 --- a/packages/playwright-core/src/client/cdpSession.ts +++ b/packages/playwright-core/src/client/cdpSession.ts @@ -19,7 +19,7 @@ import { ChannelOwner } from './channelOwner'; import { Protocol } from '../server/chromium/protocol'; import * as api from '../../types/types'; -export class CDPSession extends ChannelOwner implements api.CDPSession { +export class CDPSession extends ChannelOwner implements api.CDPSession { static from(cdpSession: channels.CDPSessionChannel): CDPSession { return (cdpSession as any)._object; } diff --git a/packages/playwright-core/src/client/channelOwner.ts b/packages/playwright-core/src/client/channelOwner.ts index 6a8c5bd7fd..b2dce54cd6 100644 --- a/packages/playwright-core/src/client/channelOwner.ts +++ b/packages/playwright-core/src/client/channelOwner.ts @@ -24,7 +24,7 @@ import { ClientInstrumentation } from './clientInstrumentation'; import type { Connection } from './connection'; import type { Logger } from './types'; -export abstract class ChannelOwner extends EventEmitter { +export abstract class ChannelOwner extends EventEmitter { readonly _connection: Connection; private _parent: ChannelOwner | undefined; private _objects = new Map(); @@ -32,11 +32,11 @@ export abstract class ChannelOwner; _logger: Logger | undefined; _instrumentation: ClientInstrumentation | undefined; - constructor(parent: ChannelOwner | Connection, type: string, guid: string, initializer: Initializer, instrumentation?: ClientInstrumentation) { + constructor(parent: ChannelOwner | Connection, type: string, guid: string, initializer: channels.InitializerTraits, instrumentation?: ClientInstrumentation) { super(); this.setMaxListeners(0); this._connection = parent instanceof ChannelOwner ? parent._connection : parent; diff --git a/packages/playwright-core/src/client/connection.ts b/packages/playwright-core/src/client/connection.ts index 1309aff374..eb02ecc8d2 100644 --- a/packages/playwright-core/src/client/connection.ts +++ b/packages/playwright-core/src/client/connection.ts @@ -41,7 +41,7 @@ import { EventEmitter } from 'events'; import { JsonPipe } from './jsonPipe'; import { APIRequestContext } from './fetch'; -class Root extends ChannelOwner { +class Root extends ChannelOwner { constructor(connection: Connection) { super(connection, 'Root', '', {}); } @@ -142,7 +142,7 @@ export class Connection extends EventEmitter { const object = this._objects.get(guid); if (!object) throw new Error(`Cannot find object to emit "${method}": ${guid}`); - object._channel.emit(method, object._type === 'JsonPipe' ? params : this._replaceGuidsWithChannels(params)); + (object._channel as any).emit(method, object._type === 'JsonPipe' ? params : this._replaceGuidsWithChannels(params)); } close(errorMessage: string = 'Connection closed') { @@ -173,7 +173,7 @@ export class Connection extends EventEmitter { const parent = this._objects.get(parentGuid); if (!parent) throw new Error(`Cannot find parent object ${parentGuid} to create ${guid}`); - let result: ChannelOwner; + let result: ChannelOwner; initializer = this._replaceGuidsWithChannels(initializer); switch (type) { case 'Android': diff --git a/packages/playwright-core/src/client/consoleMessage.ts b/packages/playwright-core/src/client/consoleMessage.ts index 58caf3e97c..ef4bad95c0 100644 --- a/packages/playwright-core/src/client/consoleMessage.ts +++ b/packages/playwright-core/src/client/consoleMessage.ts @@ -22,7 +22,7 @@ import * as api from '../../types/types'; type ConsoleMessageLocation = channels.ConsoleMessageInitializer['location']; -export class ConsoleMessage extends ChannelOwner implements api.ConsoleMessage { +export class ConsoleMessage extends ChannelOwner implements api.ConsoleMessage { static from(message: channels.ConsoleMessageChannel): ConsoleMessage { return (message as any)._object; } diff --git a/packages/playwright-core/src/client/dialog.ts b/packages/playwright-core/src/client/dialog.ts index 1fe6837d6f..2e3362d00f 100644 --- a/packages/playwright-core/src/client/dialog.ts +++ b/packages/playwright-core/src/client/dialog.ts @@ -18,7 +18,7 @@ import * as channels from '../protocol/channels'; import { ChannelOwner } from './channelOwner'; import * as api from '../../types/types'; -export class Dialog extends ChannelOwner implements api.Dialog { +export class Dialog extends ChannelOwner implements api.Dialog { static from(dialog: channels.DialogChannel): Dialog { return (dialog as any)._object; } diff --git a/packages/playwright-core/src/client/electron.ts b/packages/playwright-core/src/client/electron.ts index 0522fe7ad0..17c30012ab 100644 --- a/packages/playwright-core/src/client/electron.ts +++ b/packages/playwright-core/src/client/electron.ts @@ -36,7 +36,7 @@ type ElectronOptions = Omit implements api.Electron { +export class Electron extends ChannelOwner implements api.Electron { static from(electron: channels.ElectronChannel): Electron { return (electron as any)._object; } @@ -57,7 +57,7 @@ export class Electron extends ChannelOwner implements api.ElectronApplication { +export class ElectronApplication extends ChannelOwner implements api.ElectronApplication { private _context: BrowserContext; private _windows = new Set(); private _timeoutSettings = new TimeoutSettings(); diff --git a/packages/playwright-core/src/client/fetch.ts b/packages/playwright-core/src/client/fetch.ts index d794a079fc..a94ba2eedf 100644 --- a/packages/playwright-core/src/client/fetch.ts +++ b/packages/playwright-core/src/client/fetch.ts @@ -70,7 +70,7 @@ export class APIRequest implements api.APIRequest { } } -export class APIRequestContext extends ChannelOwner implements api.APIRequestContext { +export class APIRequestContext extends ChannelOwner implements api.APIRequestContext { static from(channel: channels.APIRequestContextChannel): APIRequestContext { return (channel as any)._object; } diff --git a/packages/playwright-core/src/client/frame.ts b/packages/playwright-core/src/client/frame.ts index 1f65634d14..cc053be23a 100644 --- a/packages/playwright-core/src/client/frame.ts +++ b/packages/playwright-core/src/client/frame.ts @@ -38,7 +38,7 @@ export type WaitForNavigationOptions = { url?: URLMatch, }; -export class Frame extends ChannelOwner implements api.Frame { +export class Frame extends ChannelOwner implements api.Frame { _eventEmitter: EventEmitter; _loadStates: Set; _parentFrame: Frame | null = null; diff --git a/packages/playwright-core/src/client/jsHandle.ts b/packages/playwright-core/src/client/jsHandle.ts index cc3da92691..d76ed16f6d 100644 --- a/packages/playwright-core/src/client/jsHandle.ts +++ b/packages/playwright-core/src/client/jsHandle.ts @@ -20,7 +20,7 @@ import { parseSerializedValue, serializeValue } from '../protocol/serializers'; import * as api from '../../types/types'; import * as structs from '../../types/structs'; -export class JSHandle extends ChannelOwner implements api.JSHandle { +export class JSHandle extends ChannelOwner implements api.JSHandle { private _preview: string; static from(handle: channels.JSHandleChannel): JSHandle { diff --git a/packages/playwright-core/src/client/jsonPipe.ts b/packages/playwright-core/src/client/jsonPipe.ts index 8f3a3e632a..32097605d0 100644 --- a/packages/playwright-core/src/client/jsonPipe.ts +++ b/packages/playwright-core/src/client/jsonPipe.ts @@ -17,7 +17,7 @@ import * as channels from '../protocol/channels'; import { ChannelOwner } from './channelOwner'; -export class JsonPipe extends ChannelOwner { +export class JsonPipe extends ChannelOwner { static from(jsonPipe: channels.JsonPipeChannel): JsonPipe { return (jsonPipe as any)._object; } diff --git a/packages/playwright-core/src/client/network.ts b/packages/playwright-core/src/client/network.ts index 98c942b896..8ceea26543 100644 --- a/packages/playwright-core/src/client/network.ts +++ b/packages/playwright-core/src/client/network.ts @@ -55,7 +55,7 @@ export type SetNetworkCookieParam = { sameSite?: 'Strict' | 'Lax' | 'None' }; -export class Request extends ChannelOwner implements api.Request { +export class Request extends ChannelOwner implements api.Request { private _redirectedFrom: Request | null = null; private _redirectedTo: Request | null = null; _failureText: string | null = null; @@ -215,7 +215,7 @@ export class Request extends ChannelOwner implements api.Route { +export class Route extends ChannelOwner implements api.Route { static from(route: channels.RouteChannel): Route { return (route as any)._object; } @@ -334,7 +334,7 @@ export type RequestSizes = { responseHeadersSize: number; }; -export class Response extends ChannelOwner implements api.Response { +export class Response extends ChannelOwner implements api.Response { private _provisionalHeaders: RawHeaders; private _actualHeadersPromise: Promise | undefined; private _request: Request; @@ -445,7 +445,7 @@ export class Response extends ChannelOwner implements api.WebSocket { +export class WebSocket extends ChannelOwner implements api.WebSocket { private _page: Page; private _isClosed: boolean; diff --git a/packages/playwright-core/src/client/page.ts b/packages/playwright-core/src/client/page.ts index 6c7caf4968..a3cfbc5f05 100644 --- a/packages/playwright-core/src/client/page.ts +++ b/packages/playwright-core/src/client/page.ts @@ -62,7 +62,7 @@ type PDFOptions = Omit & }; type Listener = (...args: any[]) => void; -export class Page extends ChannelOwner implements api.Page { +export class Page extends ChannelOwner implements api.Page { private _browserContext: BrowserContext; _ownedContext: BrowserContext | undefined; @@ -96,7 +96,7 @@ export class Page extends ChannelOwner { +export class BindingCall extends ChannelOwner { static from(channel: channels.BindingCallChannel): BindingCall { return (channel as any)._object; } diff --git a/packages/playwright-core/src/client/playwright.ts b/packages/playwright-core/src/client/playwright.ts index 9dac613020..b164873359 100644 --- a/packages/playwright-core/src/client/playwright.ts +++ b/packages/playwright-core/src/client/playwright.ts @@ -39,7 +39,7 @@ type DeviceDescriptor = { }; type Devices = { [name: string]: DeviceDescriptor }; -export class Playwright extends ChannelOwner { +export class Playwright extends ChannelOwner { readonly _android: Android; readonly _electron: Electron; readonly chromium: BrowserType; diff --git a/packages/playwright-core/src/client/selectors.ts b/packages/playwright-core/src/client/selectors.ts index 4ad07e8c34..3d42fdb3ba 100644 --- a/packages/playwright-core/src/client/selectors.ts +++ b/packages/playwright-core/src/client/selectors.ts @@ -45,7 +45,7 @@ export class Selectors implements api.Selectors { } } -export class SelectorsOwner extends ChannelOwner { +export class SelectorsOwner extends ChannelOwner { static from(browser: channels.SelectorsChannel): SelectorsOwner { return (browser as any)._object; } diff --git a/packages/playwright-core/src/client/stream.ts b/packages/playwright-core/src/client/stream.ts index 151d225cef..ff27f433fc 100644 --- a/packages/playwright-core/src/client/stream.ts +++ b/packages/playwright-core/src/client/stream.ts @@ -18,7 +18,7 @@ import { Readable } from 'stream'; import * as channels from '../protocol/channels'; import { ChannelOwner } from './channelOwner'; -export class Stream extends ChannelOwner { +export class Stream extends ChannelOwner { static from(Stream: channels.StreamChannel): Stream { return (Stream as any)._object; } diff --git a/packages/playwright-core/src/client/worker.ts b/packages/playwright-core/src/client/worker.ts index f8692b69c6..4a146a0c23 100644 --- a/packages/playwright-core/src/client/worker.ts +++ b/packages/playwright-core/src/client/worker.ts @@ -23,7 +23,7 @@ import { BrowserContext } from './browserContext'; import * as api from '../../types/types'; import * as structs from '../../types/structs'; -export class Worker extends ChannelOwner implements api.Worker { +export class Worker extends ChannelOwner implements api.Worker { _page: Page | undefined; // Set for web workers. _context: BrowserContext | undefined; // Set for service workers. diff --git a/packages/playwright-core/src/dispatchers/androidDispatcher.ts b/packages/playwright-core/src/dispatchers/androidDispatcher.ts index 5a8aa41e19..29ca1baa80 100644 --- a/packages/playwright-core/src/dispatchers/androidDispatcher.ts +++ b/packages/playwright-core/src/dispatchers/androidDispatcher.ts @@ -20,7 +20,8 @@ import * as channels from '../protocol/channels'; import { BrowserContextDispatcher } from './browserContextDispatcher'; import { CallMetadata } from '../server/instrumentation'; -export class AndroidDispatcher extends Dispatcher implements channels.AndroidChannel { +export class AndroidDispatcher extends Dispatcher implements channels.AndroidChannel { + _type_Android = true; constructor(scope: DispatcherScope, android: Android) { super(scope, android, 'Android', {}, true); } @@ -37,7 +38,9 @@ export class AndroidDispatcher extends Dispatcher implements channels.AndroidDeviceChannel { +export class AndroidDeviceDispatcher extends Dispatcher implements channels.AndroidDeviceChannel { + _type_EventTarget = true; + _type_AndroidDevice = true; static from(scope: DispatcherScope, device: AndroidDevice): AndroidDeviceDispatcher { const result = existingDispatcher(device); @@ -169,7 +172,9 @@ export class AndroidDeviceDispatcher extends Dispatcher implements channels.AndroidSocketChannel { +export class AndroidSocketDispatcher extends Dispatcher implements channels.AndroidSocketChannel { + _type_AndroidSocket = true; + constructor(scope: DispatcherScope, socket: SocketBackend) { super(scope, socket, 'AndroidSocket', {}, true); socket.on('data', (data: Buffer) => this._dispatchEvent('data', { data: data.toString('base64') })); diff --git a/packages/playwright-core/src/dispatchers/artifactDispatcher.ts b/packages/playwright-core/src/dispatchers/artifactDispatcher.ts index 07bb103986..742d2e2638 100644 --- a/packages/playwright-core/src/dispatchers/artifactDispatcher.ts +++ b/packages/playwright-core/src/dispatchers/artifactDispatcher.ts @@ -21,7 +21,8 @@ import fs from 'fs'; import { mkdirIfNeeded } from '../utils/utils'; import { Artifact } from '../server/artifact'; -export class ArtifactDispatcher extends Dispatcher implements channels.ArtifactChannel { +export class ArtifactDispatcher extends Dispatcher implements channels.ArtifactChannel { + _type_Artifact = true; constructor(scope: DispatcherScope, artifact: Artifact) { super(scope, artifact, 'Artifact', { absolutePath: artifact.localPath(), diff --git a/packages/playwright-core/src/dispatchers/browserContextDispatcher.ts b/packages/playwright-core/src/dispatchers/browserContextDispatcher.ts index dfc7aa42d0..babc02ea08 100644 --- a/packages/playwright-core/src/dispatchers/browserContextDispatcher.ts +++ b/packages/playwright-core/src/dispatchers/browserContextDispatcher.ts @@ -28,7 +28,9 @@ import { ArtifactDispatcher } from './artifactDispatcher'; import { Artifact } from '../server/artifact'; import { Request, Response } from '../server/network'; -export class BrowserContextDispatcher extends Dispatcher implements channels.BrowserContextChannel { +export class BrowserContextDispatcher extends Dispatcher implements channels.BrowserContextChannel { + _type_EventTarget = true; + _type_BrowserContext = true; private _context: BrowserContext; constructor(scope: DispatcherScope, context: BrowserContext) { diff --git a/packages/playwright-core/src/dispatchers/browserDispatcher.ts b/packages/playwright-core/src/dispatchers/browserDispatcher.ts index a744f1b1af..479947a745 100644 --- a/packages/playwright-core/src/dispatchers/browserDispatcher.ts +++ b/packages/playwright-core/src/dispatchers/browserDispatcher.ts @@ -23,7 +23,8 @@ import { CRBrowser } from '../server/chromium/crBrowser'; import { PageDispatcher } from './pageDispatcher'; import { CallMetadata } from '../server/instrumentation'; -export class BrowserDispatcher extends Dispatcher implements channels.BrowserChannel { +export class BrowserDispatcher extends Dispatcher implements channels.BrowserChannel { + _type_Browser = true; constructor(scope: DispatcherScope, browser: Browser) { super(scope, browser, 'Browser', { version: browser.version(), name: browser.options.name }, true); browser.on(Browser.Events.Disconnected, () => this._didClose()); diff --git a/packages/playwright-core/src/dispatchers/browserTypeDispatcher.ts b/packages/playwright-core/src/dispatchers/browserTypeDispatcher.ts index d4c8ee3af1..2bc759403c 100644 --- a/packages/playwright-core/src/dispatchers/browserTypeDispatcher.ts +++ b/packages/playwright-core/src/dispatchers/browserTypeDispatcher.ts @@ -25,7 +25,8 @@ import { JsonPipeDispatcher } from '../dispatchers/jsonPipeDispatcher'; import { getUserAgent, makeWaitForNextTask } from '../utils/utils'; import { ManualPromise } from '../utils/async'; -export class BrowserTypeDispatcher extends Dispatcher implements channels.BrowserTypeChannel { +export class BrowserTypeDispatcher extends Dispatcher implements channels.BrowserTypeChannel { + _type_BrowserType = true; constructor(scope: DispatcherScope, browserType: BrowserType) { super(scope, browserType, 'BrowserType', { executablePath: browserType.executablePath(), diff --git a/packages/playwright-core/src/dispatchers/cdpSessionDispatcher.ts b/packages/playwright-core/src/dispatchers/cdpSessionDispatcher.ts index a443a8aad3..ce967f829c 100644 --- a/packages/playwright-core/src/dispatchers/cdpSessionDispatcher.ts +++ b/packages/playwright-core/src/dispatchers/cdpSessionDispatcher.ts @@ -18,7 +18,9 @@ import { CRSession, CRSessionEvents } from '../server/chromium/crConnection'; import * as channels from '../protocol/channels'; import { Dispatcher, DispatcherScope } from './dispatcher'; -export class CDPSessionDispatcher extends Dispatcher implements channels.CDPSessionChannel { +export class CDPSessionDispatcher extends Dispatcher implements channels.CDPSessionChannel { + _type_CDPSession = true; + constructor(scope: DispatcherScope, crSession: CRSession) { super(scope, crSession, 'CDPSession', {}, true); crSession._eventListener = (method, params) => { diff --git a/packages/playwright-core/src/dispatchers/consoleMessageDispatcher.ts b/packages/playwright-core/src/dispatchers/consoleMessageDispatcher.ts index 7782eccf15..a83a0d61ca 100644 --- a/packages/playwright-core/src/dispatchers/consoleMessageDispatcher.ts +++ b/packages/playwright-core/src/dispatchers/consoleMessageDispatcher.ts @@ -19,7 +19,8 @@ import * as channels from '../protocol/channels'; import { Dispatcher, DispatcherScope } from './dispatcher'; import { ElementHandleDispatcher } from './elementHandlerDispatcher'; -export class ConsoleMessageDispatcher extends Dispatcher implements channels.ConsoleMessageChannel { +export class ConsoleMessageDispatcher extends Dispatcher implements channels.ConsoleMessageChannel { + _type_ConsoleMessage = true; constructor(scope: DispatcherScope, message: ConsoleMessage) { super(scope, message, 'ConsoleMessage', { type: message.type(), diff --git a/packages/playwright-core/src/dispatchers/dialogDispatcher.ts b/packages/playwright-core/src/dispatchers/dialogDispatcher.ts index 093fa53c67..0c9edd2d73 100644 --- a/packages/playwright-core/src/dispatchers/dialogDispatcher.ts +++ b/packages/playwright-core/src/dispatchers/dialogDispatcher.ts @@ -18,7 +18,8 @@ import { Dialog } from '../server/dialog'; import * as channels from '../protocol/channels'; import { Dispatcher, DispatcherScope } from './dispatcher'; -export class DialogDispatcher extends Dispatcher implements channels.DialogChannel { +export class DialogDispatcher extends Dispatcher implements channels.DialogChannel { + _type_Dialog = true; constructor(scope: DispatcherScope, dialog: Dialog) { super(scope, dialog, 'Dialog', { type: dialog.type(), diff --git a/packages/playwright-core/src/dispatchers/dispatcher.ts b/packages/playwright-core/src/dispatchers/dispatcher.ts index 285e8a429f..cda62fed61 100644 --- a/packages/playwright-core/src/dispatchers/dispatcher.ts +++ b/packages/playwright-core/src/dispatchers/dispatcher.ts @@ -41,21 +41,21 @@ export function lookupNullableDispatcher(object: any | null): Di return object ? lookupDispatcher(object) : undefined; } -export class Dispatcher extends EventEmitter implements channels.Channel { +export class Dispatcher extends EventEmitter implements channels.Channel { private _connection: DispatcherConnection; private _isScope: boolean; // Parent is always "isScope". - private _parent: Dispatcher | undefined; + private _parent: Dispatcher | undefined; // Only "isScope" channel owners have registered dispatchers inside. - private _dispatchers = new Map>(); + private _dispatchers = new Map>(); protected _disposed = false; readonly _guid: string; readonly _type: string; - readonly _scope: Dispatcher; + readonly _scope: Dispatcher; _object: Type; - constructor(parent: Dispatcher | DispatcherConnection, object: Type, type: string, initializer: Initializer, isScope?: boolean) { + constructor(parent: Dispatcher | DispatcherConnection, object: Type, type: string, initializer: channels.InitializerTraits, isScope?: boolean) { super(); this._connection = parent instanceof DispatcherConnection ? parent : parent._connection; @@ -80,7 +80,7 @@ export class Dispatcher exte this._connection.sendMessageToClient(this._parent._guid, type, '__create__', { type, initializer, guid }, this._parent._object); } - _dispatchEvent(method: T, params?: Events[T]) { + _dispatchEvent>(method: T, params?: channels.EventsTraits[T]) { if (this._disposed) { if (isUnderTest()) throw new Error(`${this._guid} is sending "${method}" event after being disposed`); @@ -121,8 +121,8 @@ export class Dispatcher exte } } -export type DispatcherScope = Dispatcher; -export class Root extends Dispatcher<{ guid: '' }, {}, {}> { +export type DispatcherScope = Dispatcher; +export class Root extends Dispatcher<{ guid: '' }, any> { private _initialized = false; constructor(connection: DispatcherConnection, private readonly createPlaywright?: (scope: DispatcherScope, options: channels.RootInitializeParams) => Promise) { @@ -140,7 +140,7 @@ export class Root extends Dispatcher<{ guid: '' }, {}, {}> { } export class DispatcherConnection { - readonly _dispatchers = new Map>(); + readonly _dispatchers = new Map>(); onmessage = (message: object) => {}; private _validateParams: (type: string, method: string, params: any) => any; private _validateMetadata: (metadata: any) => { stack?: channels.StackFrame[] }; diff --git a/packages/playwright-core/src/dispatchers/electronDispatcher.ts b/packages/playwright-core/src/dispatchers/electronDispatcher.ts index 4a6a39296a..31738fe1f0 100644 --- a/packages/playwright-core/src/dispatchers/electronDispatcher.ts +++ b/packages/playwright-core/src/dispatchers/electronDispatcher.ts @@ -22,7 +22,8 @@ import { PageDispatcher } from './pageDispatcher'; import { parseArgument, serializeResult } from './jsHandleDispatcher'; import { ElementHandleDispatcher } from './elementHandlerDispatcher'; -export class ElectronDispatcher extends Dispatcher implements channels.ElectronChannel { +export class ElectronDispatcher extends Dispatcher implements channels.ElectronChannel { + _type_Electron = true; constructor(scope: DispatcherScope, electron: Electron) { super(scope, electron, 'Electron', {}, true); } @@ -33,7 +34,10 @@ export class ElectronDispatcher extends Dispatcher implements channels.ElectronApplicationChannel { +export class ElectronApplicationDispatcher extends Dispatcher implements channels.ElectronApplicationChannel { + _type_EventTarget = true; + _type_ElectronApplication = true; + constructor(scope: DispatcherScope, electronApplication: ElectronApplication) { super(scope, electronApplication, 'ElectronApplication', { context: new BrowserContextDispatcher(scope, electronApplication.context()) diff --git a/packages/playwright-core/src/dispatchers/elementHandlerDispatcher.ts b/packages/playwright-core/src/dispatchers/elementHandlerDispatcher.ts index c05cc352bf..53209dd3cb 100644 --- a/packages/playwright-core/src/dispatchers/elementHandlerDispatcher.ts +++ b/packages/playwright-core/src/dispatchers/elementHandlerDispatcher.ts @@ -23,6 +23,8 @@ import { FrameDispatcher } from './frameDispatcher'; import { CallMetadata } from '../server/instrumentation'; export class ElementHandleDispatcher extends JSHandleDispatcher implements channels.ElementHandleChannel { + _type_ElementHandle = true; + readonly _elementHandle: ElementHandle; static from(scope: DispatcherScope, handle: ElementHandle): ElementHandleDispatcher { diff --git a/packages/playwright-core/src/dispatchers/frameDispatcher.ts b/packages/playwright-core/src/dispatchers/frameDispatcher.ts index 914cc7e9c1..b90c3dbf04 100644 --- a/packages/playwright-core/src/dispatchers/frameDispatcher.ts +++ b/packages/playwright-core/src/dispatchers/frameDispatcher.ts @@ -22,7 +22,8 @@ import { parseArgument, serializeResult } from './jsHandleDispatcher'; import { ResponseDispatcher, RequestDispatcher } from './networkDispatchers'; import { CallMetadata } from '../server/instrumentation'; -export class FrameDispatcher extends Dispatcher implements channels.FrameChannel { +export class FrameDispatcher extends Dispatcher implements channels.FrameChannel { + _type_Frame = true; private _frame: Frame; static from(scope: DispatcherScope, frame: Frame): FrameDispatcher { diff --git a/packages/playwright-core/src/dispatchers/jsHandleDispatcher.ts b/packages/playwright-core/src/dispatchers/jsHandleDispatcher.ts index f58f6182c8..70218bcf5d 100644 --- a/packages/playwright-core/src/dispatchers/jsHandleDispatcher.ts +++ b/packages/playwright-core/src/dispatchers/jsHandleDispatcher.ts @@ -20,7 +20,8 @@ import { Dispatcher, DispatcherScope } from './dispatcher'; import { ElementHandleDispatcher } from './elementHandlerDispatcher'; import { parseSerializedValue, serializeValue } from '../protocol/serializers'; -export class JSHandleDispatcher extends Dispatcher implements channels.JSHandleChannel { +export class JSHandleDispatcher extends Dispatcher implements channels.JSHandleChannel { + _type_JSHandle = true; protected constructor(scope: DispatcherScope, jsHandle: js.JSHandle) { // Do not call this directly, use createHandle() instead. diff --git a/packages/playwright-core/src/dispatchers/jsonPipeDispatcher.ts b/packages/playwright-core/src/dispatchers/jsonPipeDispatcher.ts index 540c93b752..f9d8f0a412 100644 --- a/packages/playwright-core/src/dispatchers/jsonPipeDispatcher.ts +++ b/packages/playwright-core/src/dispatchers/jsonPipeDispatcher.ts @@ -19,7 +19,8 @@ import { Dispatcher, DispatcherScope } from './dispatcher'; import { createGuid } from '../utils/utils'; import { serializeError } from '../protocol/serializers'; -export class JsonPipeDispatcher extends Dispatcher<{ guid: string }, channels.JsonPipeInitializer, channels.JsonPipeEvents> implements channels.JsonPipeChannel { +export class JsonPipeDispatcher extends Dispatcher<{ guid: string }, channels.JsonPipeChannel> implements channels.JsonPipeChannel { + _type_JsonPipe = true; constructor(scope: DispatcherScope) { super(scope, { guid: 'jsonPipe@' + createGuid() }, 'JsonPipe', {}); } diff --git a/packages/playwright-core/src/dispatchers/networkDispatchers.ts b/packages/playwright-core/src/dispatchers/networkDispatchers.ts index eda9f80736..2ac4701f5d 100644 --- a/packages/playwright-core/src/dispatchers/networkDispatchers.ts +++ b/packages/playwright-core/src/dispatchers/networkDispatchers.ts @@ -21,7 +21,8 @@ import { Request, Response, Route, WebSocket } from '../server/network'; import { Dispatcher, DispatcherScope, existingDispatcher, lookupNullableDispatcher } from './dispatcher'; import { FrameDispatcher } from './frameDispatcher'; -export class RequestDispatcher extends Dispatcher implements channels.RequestChannel { +export class RequestDispatcher extends Dispatcher implements channels.RequestChannel { + _type_Request: boolean; static from(scope: DispatcherScope, request: Request): RequestDispatcher { const result = existingDispatcher(request); @@ -44,6 +45,7 @@ export class RequestDispatcher extends Dispatcher { @@ -55,7 +57,8 @@ export class RequestDispatcher extends Dispatcher implements channels.ResponseChannel { +export class ResponseDispatcher extends Dispatcher implements channels.ResponseChannel { + _type_Response = true; static from(scope: DispatcherScope, response: Response): ResponseDispatcher { const result = existingDispatcher(response); @@ -99,7 +102,8 @@ export class ResponseDispatcher extends Dispatcher implements channels.RouteChannel { +export class RouteDispatcher extends Dispatcher implements channels.RouteChannel { + _type_Route = true; static from(scope: DispatcherScope, route: Route): RouteDispatcher { const result = existingDispatcher(route); @@ -131,7 +135,10 @@ export class RouteDispatcher extends Dispatcher implements channels.WebSocketChannel { +export class WebSocketDispatcher extends Dispatcher implements channels.WebSocketChannel { + _type_EventTarget = true; + _type_WebSocket = true; + constructor(scope: DispatcherScope, webSocket: WebSocket) { super(scope, webSocket, 'WebSocket', { url: webSocket.url(), @@ -143,7 +150,9 @@ export class WebSocketDispatcher extends Dispatcher implements channels.APIRequestContextChannel { +export class APIRequestContextDispatcher extends Dispatcher implements channels.APIRequestContextChannel { + _type_APIRequestContext = true; + static from(scope: DispatcherScope, request: APIRequestContext): APIRequestContextDispatcher { const result = existingDispatcher(request); return result || new APIRequestContextDispatcher(scope, request); diff --git a/packages/playwright-core/src/dispatchers/pageDispatcher.ts b/packages/playwright-core/src/dispatchers/pageDispatcher.ts index 141fa4bfd4..b0c18bed09 100644 --- a/packages/playwright-core/src/dispatchers/pageDispatcher.ts +++ b/packages/playwright-core/src/dispatchers/pageDispatcher.ts @@ -35,7 +35,9 @@ import { ArtifactDispatcher } from './artifactDispatcher'; import { Download } from '../server/download'; import { createGuid } from '../utils/utils'; -export class PageDispatcher extends Dispatcher implements channels.PageChannel { +export class PageDispatcher extends Dispatcher implements channels.PageChannel { + _type_EventTarget = true; + _type_Page = true; private _page: Page; static fromNullable(scope: DispatcherScope, page: Page | undefined): PageDispatcher | undefined { @@ -253,7 +255,8 @@ export class PageDispatcher extends Dispatcher implements channels.WorkerChannel { +export class WorkerDispatcher extends Dispatcher implements channels.WorkerChannel { + _type_Worker = true; constructor(scope: DispatcherScope, worker: Worker) { super(scope, worker, 'Worker', { url: worker.url() @@ -270,7 +273,8 @@ export class WorkerDispatcher extends Dispatcher implements channels.BindingCallChannel { +export class BindingCallDispatcher extends Dispatcher<{ guid: string }, channels.BindingCallChannel> implements channels.BindingCallChannel { + _type_BindingCall = true; private _resolve: ((arg: any) => void) | undefined; private _reject: ((error: any) => void) | undefined; private _promise: Promise; diff --git a/packages/playwright-core/src/dispatchers/playwrightDispatcher.ts b/packages/playwright-core/src/dispatchers/playwrightDispatcher.ts index d0c4374d76..8e7b7d2d62 100644 --- a/packages/playwright-core/src/dispatchers/playwrightDispatcher.ts +++ b/packages/playwright-core/src/dispatchers/playwrightDispatcher.ts @@ -29,7 +29,8 @@ import { ElectronDispatcher } from './electronDispatcher'; import { APIRequestContextDispatcher } from './networkDispatchers'; import { SelectorsDispatcher } from './selectorsDispatcher'; -export class PlaywrightDispatcher extends Dispatcher implements channels.PlaywrightChannel { +export class PlaywrightDispatcher extends Dispatcher implements channels.PlaywrightChannel { + _type_Playwright; private _socksProxy: SocksProxy | undefined; constructor(scope: DispatcherScope, playwright: Playwright, customSelectors?: channels.SelectorsChannel, preLaunchedBrowser?: channels.BrowserChannel) { @@ -46,6 +47,7 @@ export class PlaywrightDispatcher extends Dispatcher implements channels.SelectorsChannel { +export class SelectorsDispatcher extends Dispatcher implements channels.SelectorsChannel { + _type_Selectors = true; constructor(scope: DispatcherScope, selectors: Selectors) { super(scope, selectors, 'Selectors', {}); } diff --git a/packages/playwright-core/src/dispatchers/streamDispatcher.ts b/packages/playwright-core/src/dispatchers/streamDispatcher.ts index d20e8d0289..22a8c47107 100644 --- a/packages/playwright-core/src/dispatchers/streamDispatcher.ts +++ b/packages/playwright-core/src/dispatchers/streamDispatcher.ts @@ -19,7 +19,8 @@ import { Dispatcher, DispatcherScope } from './dispatcher'; import * as stream from 'stream'; import { createGuid } from '../utils/utils'; -export class StreamDispatcher extends Dispatcher<{ guid: string, stream: stream.Readable }, channels.StreamInitializer, channels.StreamEvents> implements channels.StreamChannel { +export class StreamDispatcher extends Dispatcher<{ guid: string, stream: stream.Readable }, channels.StreamChannel> implements channels.StreamChannel { + _type_Stream = true; private _ended: boolean = false; constructor(scope: DispatcherScope, stream: stream.Readable) { super(scope, { guid: 'stream@' + createGuid(), stream }, 'Stream', {}); diff --git a/packages/playwright-core/src/protocol/channels.ts b/packages/playwright-core/src/protocol/channels.ts index ef587cafc5..928e56e4f7 100644 --- a/packages/playwright-core/src/protocol/channels.ts +++ b/packages/playwright-core/src/protocol/channels.ts @@ -16,13 +16,110 @@ // This file is generated by generate_channels.js, do not edit manually. -import { EventEmitter } from 'events'; - export type Binary = string; -export interface Channel extends EventEmitter { +export interface Channel { } +// ----------- Initializer Traits ----------- +export type InitializerTraits = + T extends JsonPipeChannel ? JsonPipeInitializer : + T extends AndroidDeviceChannel ? AndroidDeviceInitializer : + T extends AndroidSocketChannel ? AndroidSocketInitializer : + T extends AndroidChannel ? AndroidInitializer : + T extends ElectronApplicationChannel ? ElectronApplicationInitializer : + T extends ElectronChannel ? ElectronInitializer : + T extends CDPSessionChannel ? CDPSessionInitializer : + T extends StreamChannel ? StreamInitializer : + T extends ArtifactChannel ? ArtifactInitializer : + T extends DialogChannel ? DialogInitializer : + T extends BindingCallChannel ? BindingCallInitializer : + T extends ConsoleMessageChannel ? ConsoleMessageInitializer : + T extends WebSocketChannel ? WebSocketInitializer : + T extends ResponseChannel ? ResponseInitializer : + T extends RouteChannel ? RouteInitializer : + T extends RequestChannel ? RequestInitializer : + T extends ElementHandleChannel ? ElementHandleInitializer : + T extends JSHandleChannel ? JSHandleInitializer : + T extends WorkerChannel ? WorkerInitializer : + T extends FrameChannel ? FrameInitializer : + T extends PageChannel ? PageInitializer : + T extends BrowserContextChannel ? BrowserContextInitializer : + T extends EventTargetChannel ? EventTargetInitializer : + T extends BrowserChannel ? BrowserInitializer : + T extends BrowserTypeChannel ? BrowserTypeInitializer : + T extends SelectorsChannel ? SelectorsInitializer : + T extends PlaywrightChannel ? PlaywrightInitializer : + T extends RootChannel ? RootInitializer : + T extends APIRequestContextChannel ? APIRequestContextInitializer : + object; + +// ----------- Event Traits ----------- +export type EventsTraits = + T extends JsonPipeChannel ? JsonPipeEvents : + T extends AndroidDeviceChannel ? AndroidDeviceEvents : + T extends AndroidSocketChannel ? AndroidSocketEvents : + T extends AndroidChannel ? AndroidEvents : + T extends ElectronApplicationChannel ? ElectronApplicationEvents : + T extends ElectronChannel ? ElectronEvents : + T extends CDPSessionChannel ? CDPSessionEvents : + T extends StreamChannel ? StreamEvents : + T extends ArtifactChannel ? ArtifactEvents : + T extends DialogChannel ? DialogEvents : + T extends BindingCallChannel ? BindingCallEvents : + T extends ConsoleMessageChannel ? ConsoleMessageEvents : + T extends WebSocketChannel ? WebSocketEvents : + T extends ResponseChannel ? ResponseEvents : + T extends RouteChannel ? RouteEvents : + T extends RequestChannel ? RequestEvents : + T extends ElementHandleChannel ? ElementHandleEvents : + T extends JSHandleChannel ? JSHandleEvents : + T extends WorkerChannel ? WorkerEvents : + T extends FrameChannel ? FrameEvents : + T extends PageChannel ? PageEvents : + T extends BrowserContextChannel ? BrowserContextEvents : + T extends EventTargetChannel ? EventTargetEvents : + T extends BrowserChannel ? BrowserEvents : + T extends BrowserTypeChannel ? BrowserTypeEvents : + T extends SelectorsChannel ? SelectorsEvents : + T extends PlaywrightChannel ? PlaywrightEvents : + T extends RootChannel ? RootEvents : + T extends APIRequestContextChannel ? APIRequestContextEvents : + undefined; + +// ----------- EventTarget Traits ----------- +export type EventTargetTraits = + T extends JsonPipeChannel ? JsonPipeEventTarget : + T extends AndroidDeviceChannel ? AndroidDeviceEventTarget : + T extends AndroidSocketChannel ? AndroidSocketEventTarget : + T extends AndroidChannel ? AndroidEventTarget : + T extends ElectronApplicationChannel ? ElectronApplicationEventTarget : + T extends ElectronChannel ? ElectronEventTarget : + T extends CDPSessionChannel ? CDPSessionEventTarget : + T extends StreamChannel ? StreamEventTarget : + T extends ArtifactChannel ? ArtifactEventTarget : + T extends DialogChannel ? DialogEventTarget : + T extends BindingCallChannel ? BindingCallEventTarget : + T extends ConsoleMessageChannel ? ConsoleMessageEventTarget : + T extends WebSocketChannel ? WebSocketEventTarget : + T extends ResponseChannel ? ResponseEventTarget : + T extends RouteChannel ? RouteEventTarget : + T extends RequestChannel ? RequestEventTarget : + T extends ElementHandleChannel ? ElementHandleEventTarget : + T extends JSHandleChannel ? JSHandleEventTarget : + T extends WorkerChannel ? WorkerEventTarget : + T extends FrameChannel ? FrameEventTarget : + T extends PageChannel ? PageEventTarget : + T extends BrowserContextChannel ? BrowserContextEventTarget : + T extends EventTargetChannel ? EventTargetEventTarget : + T extends BrowserChannel ? BrowserEventTarget : + T extends BrowserTypeChannel ? BrowserTypeEventTarget : + T extends SelectorsChannel ? SelectorsEventTarget : + T extends PlaywrightChannel ? PlaywrightEventTarget : + T extends RootChannel ? RootEventTarget : + T extends APIRequestContextChannel ? APIRequestContextEventTarget : + undefined; + export type StackFrame = { file: string, line?: number, @@ -163,7 +260,10 @@ export type FormField = { // ----------- APIRequestContext ----------- export type APIRequestContextInitializer = {}; -export interface APIRequestContextChannel extends Channel { +export interface APIRequestContextEventTarget { +} +export interface APIRequestContextChannel extends APIRequestContextEventTarget, Channel { + _type_APIRequestContext: boolean; fetch(params: APIRequestContextFetchParams, metadata?: Metadata): Promise; fetchResponseBody(params: APIRequestContextFetchResponseBodyParams, metadata?: Metadata): Promise; storageState(params?: APIRequestContextStorageStateParams, metadata?: Metadata): Promise; @@ -239,7 +339,10 @@ export type APIResponse = { export type LifecycleEvent = 'load' | 'domcontentloaded' | 'networkidle' | 'commit'; // ----------- Root ----------- export type RootInitializer = {}; -export interface RootChannel extends Channel { +export interface RootEventTarget { +} +export interface RootChannel extends RootEventTarget, Channel { + _type_Root: boolean; initialize(params: RootInitializeParams, metadata?: Metadata): Promise; } export type RootInitializeParams = { @@ -283,10 +386,13 @@ export type PlaywrightInitializer = { selectors: SelectorsChannel, preLaunchedBrowser?: BrowserChannel, }; -export interface PlaywrightChannel extends Channel { +export interface PlaywrightEventTarget { on(event: 'socksRequested', callback: (params: PlaywrightSocksRequestedEvent) => void): this; on(event: 'socksData', callback: (params: PlaywrightSocksDataEvent) => void): this; on(event: 'socksClosed', callback: (params: PlaywrightSocksClosedEvent) => void): this; +} +export interface PlaywrightChannel extends PlaywrightEventTarget, Channel { + _type_Playwright: boolean; socksConnected(params: PlaywrightSocksConnectedParams, metadata?: Metadata): Promise; socksFailed(params: PlaywrightSocksFailedParams, metadata?: Metadata): Promise; socksData(params: PlaywrightSocksDataParams, metadata?: Metadata): Promise; @@ -400,7 +506,10 @@ export interface PlaywrightEvents { // ----------- Selectors ----------- export type SelectorsInitializer = {}; -export interface SelectorsChannel extends Channel { +export interface SelectorsEventTarget { +} +export interface SelectorsChannel extends SelectorsEventTarget, Channel { + _type_Selectors: boolean; register(params: SelectorsRegisterParams, metadata?: Metadata): Promise; } export type SelectorsRegisterParams = { @@ -421,7 +530,10 @@ export type BrowserTypeInitializer = { executablePath: string, name: string, }; -export interface BrowserTypeChannel extends Channel { +export interface BrowserTypeEventTarget { +} +export interface BrowserTypeChannel extends BrowserTypeEventTarget, Channel { + _type_BrowserType: boolean; connect(params: BrowserTypeConnectParams, metadata?: Metadata): Promise; launch(params: BrowserTypeLaunchParams, metadata?: Metadata): Promise; launchPersistentContext(params: BrowserTypeLaunchPersistentContextParams, metadata?: Metadata): Promise; @@ -664,8 +776,11 @@ export type BrowserInitializer = { version: string, name: string, }; -export interface BrowserChannel extends Channel { +export interface BrowserEventTarget { on(event: 'close', callback: (params: BrowserCloseEvent) => void): this; +} +export interface BrowserChannel extends BrowserEventTarget, Channel { + _type_Browser: boolean; close(params?: BrowserCloseParams, metadata?: Metadata): Promise; killForTests(params?: BrowserKillForTestsParams, metadata?: Metadata): Promise; newContext(params: BrowserNewContextParams, metadata?: Metadata): Promise; @@ -831,7 +946,10 @@ export interface BrowserEvents { // ----------- EventTarget ----------- export type EventTargetInitializer = {}; -export interface EventTargetChannel extends Channel { +export interface EventTargetEventTarget { +} +export interface EventTargetChannel extends EventTargetEventTarget, Channel { + _type_EventTarget: boolean; waitForEventInfo(params: EventTargetWaitForEventInfoParams, metadata?: Metadata): Promise; } export type EventTargetWaitForEventInfoParams = { @@ -856,7 +974,7 @@ export type BrowserContextInitializer = { isChromium: boolean, APIRequestContext: APIRequestContextChannel, }; -export interface BrowserContextChannel extends EventTargetChannel { +export interface BrowserContextEventTarget { on(event: 'bindingCall', callback: (params: BrowserContextBindingCallEvent) => void): this; on(event: 'close', callback: (params: BrowserContextCloseEvent) => void): this; on(event: 'page', callback: (params: BrowserContextPageEvent) => void): this; @@ -868,6 +986,9 @@ export interface BrowserContextChannel extends EventTargetChannel { on(event: 'requestFailed', callback: (params: BrowserContextRequestFailedEvent) => void): this; on(event: 'requestFinished', callback: (params: BrowserContextRequestFinishedEvent) => void): this; on(event: 'response', callback: (params: BrowserContextResponseEvent) => void): this; +} +export interface BrowserContextChannel extends BrowserContextEventTarget, EventTargetChannel { + _type_BrowserContext: boolean; addCookies(params: BrowserContextAddCookiesParams, metadata?: Metadata): Promise; addInitScript(params: BrowserContextAddInitScriptParams, metadata?: Metadata): Promise; clearCookies(params?: BrowserContextClearCookiesParams, metadata?: Metadata): Promise; @@ -1153,7 +1274,7 @@ export type PageInitializer = { isClosed: boolean, opener?: PageChannel, }; -export interface PageChannel extends EventTargetChannel { +export interface PageEventTarget { on(event: 'bindingCall', callback: (params: PageBindingCallEvent) => void): this; on(event: 'close', callback: (params: PageCloseEvent) => void): this; on(event: 'console', callback: (params: PageConsoleEvent) => void): this; @@ -1170,6 +1291,9 @@ export interface PageChannel extends EventTargetChannel { on(event: 'video', callback: (params: PageVideoEvent) => void): this; on(event: 'webSocket', callback: (params: PageWebSocketEvent) => void): this; on(event: 'worker', callback: (params: PageWorkerEvent) => void): this; +} +export interface PageChannel extends PageEventTarget, EventTargetChannel { + _type_Page: boolean; setDefaultNavigationTimeoutNoReply(params: PageSetDefaultNavigationTimeoutNoReplyParams, metadata?: Metadata): Promise; setDefaultTimeoutNoReply(params: PageSetDefaultTimeoutNoReplyParams, metadata?: Metadata): Promise; setFileChooserInterceptedNoReply(params: PageSetFileChooserInterceptedNoReplyParams, metadata?: Metadata): Promise; @@ -1600,9 +1724,12 @@ export type FrameInitializer = { parentFrame?: FrameChannel, loadStates: LifecycleEvent[], }; -export interface FrameChannel extends Channel { +export interface FrameEventTarget { on(event: 'loadstate', callback: (params: FrameLoadstateEvent) => void): this; on(event: 'navigated', callback: (params: FrameNavigatedEvent) => void): this; +} +export interface FrameChannel extends FrameEventTarget, Channel { + _type_Frame: boolean; evalOnSelector(params: FrameEvalOnSelectorParams, metadata?: Metadata): Promise; evalOnSelectorAll(params: FrameEvalOnSelectorAllParams, metadata?: Metadata): Promise; addScriptTag(params: FrameAddScriptTagParams, metadata?: Metadata): Promise; @@ -2244,8 +2371,11 @@ export interface FrameEvents { export type WorkerInitializer = { url: string, }; -export interface WorkerChannel extends Channel { +export interface WorkerEventTarget { on(event: 'close', callback: (params: WorkerCloseEvent) => void): this; +} +export interface WorkerChannel extends WorkerEventTarget, Channel { + _type_Worker: boolean; evaluateExpression(params: WorkerEvaluateExpressionParams, metadata?: Metadata): Promise; evaluateExpressionHandle(params: WorkerEvaluateExpressionHandleParams, metadata?: Metadata): Promise; } @@ -2281,8 +2411,11 @@ export interface WorkerEvents { export type JSHandleInitializer = { preview: string, }; -export interface JSHandleChannel extends Channel { +export interface JSHandleEventTarget { on(event: 'previewUpdated', callback: (params: JSHandlePreviewUpdatedEvent) => void): this; +} +export interface JSHandleChannel extends JSHandleEventTarget, Channel { + _type_JSHandle: boolean; dispose(params?: JSHandleDisposeParams, metadata?: Metadata): Promise; evaluateExpression(params: JSHandleEvaluateExpressionParams, metadata?: Metadata): Promise; evaluateExpressionHandle(params: JSHandleEvaluateExpressionHandleParams, metadata?: Metadata): Promise; @@ -2347,7 +2480,10 @@ export interface JSHandleEvents { // ----------- ElementHandle ----------- export type ElementHandleInitializer = {}; -export interface ElementHandleChannel extends JSHandleChannel { +export interface ElementHandleEventTarget { +} +export interface ElementHandleChannel extends ElementHandleEventTarget, JSHandleChannel { + _type_ElementHandle: boolean; evalOnSelector(params: ElementHandleEvalOnSelectorParams, metadata?: Metadata): Promise; evalOnSelectorAll(params: ElementHandleEvalOnSelectorAllParams, metadata?: Metadata): Promise; boundingBox(params?: ElementHandleBoundingBoxParams, metadata?: Metadata): Promise; @@ -2764,7 +2900,10 @@ export type RequestInitializer = { isNavigationRequest: boolean, redirectedFrom?: RequestChannel, }; -export interface RequestChannel extends Channel { +export interface RequestEventTarget { +} +export interface RequestChannel extends RequestEventTarget, Channel { + _type_Request: boolean; response(params?: RequestResponseParams, metadata?: Metadata): Promise; rawRequestHeaders(params?: RequestRawRequestHeadersParams, metadata?: Metadata): Promise; } @@ -2786,7 +2925,10 @@ export interface RequestEvents { export type RouteInitializer = { request: RequestChannel, }; -export interface RouteChannel extends Channel { +export interface RouteEventTarget { +} +export interface RouteChannel extends RouteEventTarget, Channel { + _type_Route: boolean; abort(params: RouteAbortParams, metadata?: Metadata): Promise; continue(params: RouteContinueParams, metadata?: Metadata): Promise; fulfill(params: RouteFulfillParams, metadata?: Metadata): Promise; @@ -2850,7 +2992,10 @@ export type ResponseInitializer = { headers: NameValue[], timing: ResourceTiming, }; -export interface ResponseChannel extends Channel { +export interface ResponseEventTarget { +} +export interface ResponseChannel extends ResponseEventTarget, Channel { + _type_Response: boolean; body(params?: ResponseBodyParams, metadata?: Metadata): Promise; securityDetails(params?: ResponseSecurityDetailsParams, metadata?: Metadata): Promise; serverAddr(params?: ResponseServerAddrParams, metadata?: Metadata): Promise; @@ -2910,13 +3055,16 @@ export type RemoteAddr = { export type WebSocketInitializer = { url: string, }; -export interface WebSocketChannel extends EventTargetChannel { +export interface WebSocketEventTarget { on(event: 'open', callback: (params: WebSocketOpenEvent) => void): this; on(event: 'frameSent', callback: (params: WebSocketFrameSentEvent) => void): this; on(event: 'frameReceived', callback: (params: WebSocketFrameReceivedEvent) => void): this; on(event: 'socketError', callback: (params: WebSocketSocketErrorEvent) => void): this; on(event: 'close', callback: (params: WebSocketCloseEvent) => void): this; } +export interface WebSocketChannel extends WebSocketEventTarget, EventTargetChannel { + _type_WebSocket: boolean; +} export type WebSocketOpenEvent = {}; export type WebSocketFrameSentEvent = { opcode: number, @@ -2950,7 +3098,10 @@ export type ConsoleMessageInitializer = { columnNumber: number, }, }; -export interface ConsoleMessageChannel extends Channel { +export interface ConsoleMessageEventTarget { +} +export interface ConsoleMessageChannel extends ConsoleMessageEventTarget, Channel { + _type_ConsoleMessage: boolean; } export interface ConsoleMessageEvents { @@ -2963,7 +3114,10 @@ export type BindingCallInitializer = { args?: SerializedValue[], handle?: JSHandleChannel, }; -export interface BindingCallChannel extends Channel { +export interface BindingCallEventTarget { +} +export interface BindingCallChannel extends BindingCallEventTarget, Channel { + _type_BindingCall: boolean; reject(params: BindingCallRejectParams, metadata?: Metadata): Promise; resolve(params: BindingCallResolveParams, metadata?: Metadata): Promise; } @@ -2991,7 +3145,10 @@ export type DialogInitializer = { message: string, defaultValue: string, }; -export interface DialogChannel extends Channel { +export interface DialogEventTarget { +} +export interface DialogChannel extends DialogEventTarget, Channel { + _type_Dialog: boolean; accept(params: DialogAcceptParams, metadata?: Metadata): Promise; dismiss(params?: DialogDismissParams, metadata?: Metadata): Promise; } @@ -3013,7 +3170,10 @@ export interface DialogEvents { export type ArtifactInitializer = { absolutePath: string, }; -export interface ArtifactChannel extends Channel { +export interface ArtifactEventTarget { +} +export interface ArtifactChannel extends ArtifactEventTarget, Channel { + _type_Artifact: boolean; pathAfterFinished(params?: ArtifactPathAfterFinishedParams, metadata?: Metadata): Promise; saveAs(params: ArtifactSaveAsParams, metadata?: Metadata): Promise; saveAsStream(params?: ArtifactSaveAsStreamParams, metadata?: Metadata): Promise; @@ -3061,7 +3221,10 @@ export interface ArtifactEvents { // ----------- Stream ----------- export type StreamInitializer = {}; -export interface StreamChannel extends Channel { +export interface StreamEventTarget { +} +export interface StreamChannel extends StreamEventTarget, Channel { + _type_Stream: boolean; read(params: StreamReadParams, metadata?: Metadata): Promise; close(params?: StreamCloseParams, metadata?: Metadata): Promise; } @@ -3083,8 +3246,11 @@ export interface StreamEvents { // ----------- CDPSession ----------- export type CDPSessionInitializer = {}; -export interface CDPSessionChannel extends Channel { +export interface CDPSessionEventTarget { on(event: 'event', callback: (params: CDPSessionEventEvent) => void): this; +} +export interface CDPSessionChannel extends CDPSessionEventTarget, Channel { + _type_CDPSession: boolean; send(params: CDPSessionSendParams, metadata?: Metadata): Promise; detach(params?: CDPSessionDetachParams, metadata?: Metadata): Promise; } @@ -3112,7 +3278,10 @@ export interface CDPSessionEvents { // ----------- Electron ----------- export type ElectronInitializer = {}; -export interface ElectronChannel extends Channel { +export interface ElectronEventTarget { +} +export interface ElectronChannel extends ElectronEventTarget, Channel { + _type_Electron: boolean; launch(params: ElectronLaunchParams, metadata?: Metadata): Promise; } export type ElectronLaunchParams = { @@ -3198,8 +3367,11 @@ export interface ElectronEvents { export type ElectronApplicationInitializer = { context: BrowserContextChannel, }; -export interface ElectronApplicationChannel extends EventTargetChannel { +export interface ElectronApplicationEventTarget { on(event: 'close', callback: (params: ElectronApplicationCloseEvent) => void): this; +} +export interface ElectronApplicationChannel extends ElectronApplicationEventTarget, EventTargetChannel { + _type_ElectronApplication: boolean; browserWindow(params: ElectronApplicationBrowserWindowParams, metadata?: Metadata): Promise; evaluateExpression(params: ElectronApplicationEvaluateExpressionParams, metadata?: Metadata): Promise; evaluateExpressionHandle(params: ElectronApplicationEvaluateExpressionHandleParams, metadata?: Metadata): Promise; @@ -3247,7 +3419,10 @@ export interface ElectronApplicationEvents { // ----------- Android ----------- export type AndroidInitializer = {}; -export interface AndroidChannel extends Channel { +export interface AndroidEventTarget { +} +export interface AndroidChannel extends AndroidEventTarget, Channel { + _type_Android: boolean; devices(params?: AndroidDevicesParams, metadata?: Metadata): Promise; setDefaultTimeoutNoReply(params: AndroidSetDefaultTimeoutNoReplyParams, metadata?: Metadata): Promise; } @@ -3269,9 +3444,12 @@ export interface AndroidEvents { // ----------- AndroidSocket ----------- export type AndroidSocketInitializer = {}; -export interface AndroidSocketChannel extends Channel { +export interface AndroidSocketEventTarget { on(event: 'data', callback: (params: AndroidSocketDataEvent) => void): this; on(event: 'close', callback: (params: AndroidSocketCloseEvent) => void): this; +} +export interface AndroidSocketChannel extends AndroidSocketEventTarget, Channel { + _type_AndroidSocket: boolean; write(params: AndroidSocketWriteParams, metadata?: Metadata): Promise; close(params?: AndroidSocketCloseParams, metadata?: Metadata): Promise; } @@ -3300,9 +3478,12 @@ export type AndroidDeviceInitializer = { model: string, serial: string, }; -export interface AndroidDeviceChannel extends EventTargetChannel { +export interface AndroidDeviceEventTarget { on(event: 'webViewAdded', callback: (params: AndroidDeviceWebViewAddedEvent) => void): this; on(event: 'webViewRemoved', callback: (params: AndroidDeviceWebViewRemovedEvent) => void): this; +} +export interface AndroidDeviceChannel extends AndroidDeviceEventTarget, EventTargetChannel { + _type_AndroidDevice: boolean; wait(params: AndroidDeviceWaitParams, metadata?: Metadata): Promise; fill(params: AndroidDeviceFillParams, metadata?: Metadata): Promise; tap(params: AndroidDeviceTapParams, metadata?: Metadata): Promise; @@ -3698,9 +3879,12 @@ export type AndroidElementInfo = { // ----------- JsonPipe ----------- export type JsonPipeInitializer = {}; -export interface JsonPipeChannel extends Channel { +export interface JsonPipeEventTarget { on(event: 'message', callback: (params: JsonPipeMessageEvent) => void): this; on(event: 'closed', callback: (params: JsonPipeClosedEvent) => void): this; +} +export interface JsonPipeChannel extends JsonPipeEventTarget, Channel { + _type_JsonPipe: boolean; send(params: JsonPipeSendParams, metadata?: Metadata): Promise; close(params?: JsonPipeCloseParams, metadata?: Metadata): Promise; } diff --git a/utils/generate_channels.js b/utils/generate_channels.js index 39e6ef6eff..f03eda0c7a 100755 --- a/utils/generate_channels.js +++ b/utils/generate_channels.js @@ -124,11 +124,9 @@ const channels_ts = [ // This file is generated by ${path.basename(__filename).split(path.sep).join(path.posix.sep)}, do not edit manually. -import { EventEmitter } from 'events'; - export type Binary = string; -export interface Channel extends EventEmitter { +export interface Channel { } `]; @@ -202,6 +200,35 @@ for (const [name, item] of Object.entries(protocol)) { } } +channels_ts.push(`// ----------- Initializer Traits -----------`); +channels_ts.push(`export type InitializerTraits =`); +const entriesInReverse = Object.entries(protocol).reverse(); +for (const [name, item] of entriesInReverse) { + if (item.type !== 'interface') + continue; + channels_ts.push(` T extends ${name}Channel ? ${name}Initializer :`); +} +channels_ts.push(` object;`); +channels_ts.push(``); +channels_ts.push(`// ----------- Event Traits -----------`); +channels_ts.push(`export type EventsTraits =`); +for (const [name, item] of entriesInReverse) { + if (item.type !== 'interface') + continue; + channels_ts.push(` T extends ${name}Channel ? ${name}Events :`); +} +channels_ts.push(` undefined;`); +channels_ts.push(``); +channels_ts.push(`// ----------- EventTarget Traits -----------`); +channels_ts.push(`export type EventTargetTraits =`); +for (const [name, item] of entriesInReverse) { + if (item.type !== 'interface') + continue; + channels_ts.push(` T extends ${name}Channel ? ${name}EventTarget :`); +} +channels_ts.push(` undefined;`); +channels_ts.push(``); + for (const [name, item] of Object.entries(protocol)) { if (item.type === 'interface') { const channelName = name; @@ -210,7 +237,7 @@ for (const [name, item] of Object.entries(protocol)) { const initializerName = channelName + 'Initializer'; channels_ts.push(`export type ${initializerName} = ${init.ts};`); - channels_ts.push(`export interface ${channelName}Channel extends ${(item.extends || '') + 'Channel'} {`); + channels_ts.push(`export interface ${channelName}EventTarget {`); const ts_types = new Map(); /** @type{{eventName: string, eventType: string}[]} */ @@ -224,7 +251,10 @@ for (const [name, item] of Object.entries(protocol)) { channels_ts.push(` on(event: '${eventName}', callback: (params: ${paramsName}) => void): this;`); eventTypes.push({eventName, eventType: paramsName}); } + channels_ts.push(`}`); + channels_ts.push(`export interface ${channelName}Channel extends ${channelName}EventTarget, ${(item.extends || '') + 'Channel'} {`); + channels_ts.push(` _type_${channelName}: boolean;`); for (let [methodName, method] of Object.entries(item.commands || {})) { if (method === null) method = {};