Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

feat(rpc): use SerializedValue for CDPSession (#3076)

Dmitry Gozmandb4e856a572a
diff --git a/src/rpc/channels.ts b/src/rpc/channels.ts
index 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.ts
index 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, CDPSessionInitia
constructor(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, CDPSessionInitia
params?: 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.pdl
index bc559cbf52..83e9d774b0 100644
--- a/src/rpc/protocol.pdl
+++ b/src/rpc/protocol.pdl
@@ -1407,16 +1407,16 @@ interface CDPSession
event event
parameters
method: string
- params?: object
+ params?: SerializedValue
event disconnected
command send
parameters
method: string
- params?: object
+ params?: SerializedValue
returns
- result: object
+ result: SerializedValue
command detach
diff --git a/src/rpc/server/cdpSessionDispatcher.ts b/src/rpc/server/cdpSessionDispatcher.ts
index 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> {