Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
feat(rpc): use SerializedValue for CDPSession (#3076)
Dmitry Gozmandb4e856a572a
diff --git a/src/rpc/channels.ts b/src/rpc/channels.tsindex 9ee5fd81e9..ffa32805a0 100644--- a/src/rpc/channels.ts+++ b/src/rpc/channels.ts@@ -1571,21 +1571,15 @@ export interface CDPSessionChannel extends Channel {}export type CDPSessionEventEvent = {method: string,- params?: {-- },+ params?: SerializedValue,};export type CDPSessionDisconnectedEvent = {};export type CDPSessionSendParams = {method: string,- params?: {-- },+ params?: SerializedValue,};export type CDPSessionSendResult = {- result: {-- },+ result: SerializedValue,};export type CDPSessionDetachParams = {};export type CDPSessionDetachResult = void;diff --git a/src/rpc/client/cdpSession.ts b/src/rpc/client/cdpSession.tsindex 467aaa22d4..60c4a1000d 100644--- a/src/rpc/client/cdpSession.ts+++ b/src/rpc/client/cdpSession.ts@@ -17,6 +17,7 @@import { CDPSessionChannel, CDPSessionInitializer } from '../channels';import { ChannelOwner } from './channelOwner';import { Protocol } from '../../chromium/protocol';+import { parseResult, serializeArgument } from './jsHandle';export class CDPSession extends ChannelOwner<CDPSessionChannel, CDPSessionInitializer> {static from(cdpSession: CDPSessionChannel): CDPSession {@@ -32,7 +33,10 @@ export class CDPSession extends ChannelOwner<CDPSessionChannel, CDPSessionInitiaconstructor(parent: ChannelOwner, type: string, guid: string, initializer: CDPSessionInitializer) {super(parent, type, guid, initializer, true);- this._channel.on('event', ({ method, params }) => this.emit(method, params));+ this._channel.on('event', ({ method, params }) => {+ const cdpParams = params ? parseResult(params) : undefined;+ this.emit(method, cdpParams);+ });this._channel.on('disconnected', () => this._dispose());this.on = super.on;@@ -47,8 +51,9 @@ export class CDPSession extends ChannelOwner<CDPSessionChannel, CDPSessionInitiaparams?: Protocol.CommandParameters[T]): Promise<Protocol.CommandReturnValues[T]> {return this._wrapApiCall('cdpSession.send', async () => {- const result = await this._channel.send({ method, params });- return result.result as Protocol.CommandReturnValues[T];+ const protocolParams = params ? serializeArgument(params).value : undefined;+ const result = await this._channel.send({ method, params: protocolParams });+ return parseResult(result.result) as Protocol.CommandReturnValues[T];});}diff --git a/src/rpc/protocol.pdl b/src/rpc/protocol.pdlindex bc559cbf52..83e9d774b0 100644--- a/src/rpc/protocol.pdl+++ b/src/rpc/protocol.pdl@@ -1407,16 +1407,16 @@ interface CDPSessionevent eventparametersmethod: string- params?: object+ params?: SerializedValueevent disconnectedcommand sendparametersmethod: string- params?: object+ params?: SerializedValuereturns- result: object+ result: SerializedValuecommand detachdiff --git a/src/rpc/server/cdpSessionDispatcher.ts b/src/rpc/server/cdpSessionDispatcher.tsindex a7e1ad85d9..fd0d41af92 100644--- a/src/rpc/server/cdpSessionDispatcher.ts+++ b/src/rpc/server/cdpSessionDispatcher.ts@@ -15,21 +15,26 @@*/import { CRSession, CRSessionEvents } from '../../chromium/crConnection';-import { CDPSessionChannel, CDPSessionInitializer } from '../channels';+import { CDPSessionChannel, CDPSessionInitializer, SerializedValue } from '../channels';import { Dispatcher, DispatcherScope } from './dispatcher';+import { serializeResult, parseArgument } from './jsHandleDispatcher';export class CDPSessionDispatcher extends Dispatcher<CRSession, CDPSessionInitializer> implements CDPSessionChannel {constructor(scope: DispatcherScope, crSession: CRSession) {super(scope, crSession, 'cdpSession', {}, true);- crSession._eventListener = (method, params) => this._dispatchEvent('event', { method, params });+ crSession._eventListener = (method, cdpParams) => {+ const params = cdpParams ? serializeResult(cdpParams) : undefined;+ this._dispatchEvent('event', { method, params });+ };crSession.on(CRSessionEvents.Disconnected, () => {this._dispatchEvent('disconnected');this._dispose();});}- async send(params: { method: string, params?: Object }): Promise<{ result: Object }> {- return { result: await this._object.send(params.method as any, params.params) };+ async send(params: { method: string, params?: SerializedValue }): Promise<{ result: SerializedValue }> {+ const cdpParams = params.params ? parseArgument({ value: params.params, handles: [] }) : undefined;+ return { result: serializeResult(await this._object.send(params.method as any, cdpParams)) };}async detach(): Promise<void> {