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): introduce JSON type in the protocol for arbitrary blobs (#3367)
Dmitry Gozmanef76f5b92265
diff --git a/src/rpc/channels.ts b/src/rpc/channels.tsindex a872fc22ea..232a813cd6 100644--- a/src/rpc/channels.ts+++ b/src/rpc/channels.ts@@ -180,7 +180,7 @@ export type BrowserTypeLaunchParams = {password?: string,},downloadsPath?: string,- firefoxUserPrefs?: SerializedValue,+ firefoxUserPrefs?: any,chromiumSandbox?: boolean,slowMo?: number,};@@ -206,7 +206,7 @@ export type BrowserTypeLaunchOptions = {password?: string,},downloadsPath?: string,- firefoxUserPrefs?: SerializedValue,+ firefoxUserPrefs?: any,chromiumSandbox?: boolean,slowMo?: number,};@@ -235,7 +235,7 @@ export type BrowserTypeLaunchServerParams = {password?: string,},downloadsPath?: string,- firefoxUserPrefs?: SerializedValue,+ firefoxUserPrefs?: any,chromiumSandbox?: boolean,port?: number,};@@ -261,7 +261,7 @@ export type BrowserTypeLaunchServerOptions = {password?: string,},downloadsPath?: string,- firefoxUserPrefs?: SerializedValue,+ firefoxUserPrefs?: any,chromiumSandbox?: boolean,port?: number,};@@ -2228,17 +2228,17 @@ export interface CDPSessionChannel extends Channel {}export type CDPSessionEventEvent = {method: string,- params?: SerializedValue,+ params?: any,};export type CDPSessionSendParams = {method: string,- params?: SerializedValue,+ params?: any,};export type CDPSessionSendOptions = {- params?: SerializedValue,+ params?: any,};export type CDPSessionSendResult = {- result: SerializedValue,+ result: any,};export type CDPSessionDetachParams = {};export type CDPSessionDetachOptions = {};diff --git a/src/rpc/client/browserType.ts b/src/rpc/client/browserType.tsindex 185816331e..c040c55907 100644--- a/src/rpc/client/browserType.ts+++ b/src/rpc/client/browserType.ts@@ -20,7 +20,6 @@ import { BrowserContext } from './browserContext';import { ChannelOwner } from './channelOwner';import { BrowserServer } from './browserServer';import { headersObjectToArray, envObjectToArray } from '../../converters';-import { serializeArgument } from './jsHandle';import { assert } from '../../helper';import { LaunchOptions, LaunchServerOptions, ConnectOptions, LaunchPersistentContextOptions } from './types';@@ -53,7 +52,6 @@ export class BrowserType extends ChannelOwner<BrowserTypeChannel, BrowserTypeIniignoreDefaultArgs: Array.isArray(options.ignoreDefaultArgs) ? options.ignoreDefaultArgs : undefined,ignoreAllDefaultArgs: !!options.ignoreDefaultArgs && !Array.isArray(options.ignoreDefaultArgs),env: options.env ? envObjectToArray(options.env) : undefined,- firefoxUserPrefs: options.firefoxUserPrefs ? serializeArgument(options.firefoxUserPrefs).value : undefined,};const browser = Browser.from((await this._channel.launch(launchOptions)).browser);browser._logger = logger;@@ -70,7 +68,6 @@ export class BrowserType extends ChannelOwner<BrowserTypeChannel, BrowserTypeIniignoreDefaultArgs: Array.isArray(options.ignoreDefaultArgs) ? options.ignoreDefaultArgs : undefined,ignoreAllDefaultArgs: !!options.ignoreDefaultArgs && !Array.isArray(options.ignoreDefaultArgs),env: options.env ? envObjectToArray(options.env) : undefined,- firefoxUserPrefs: options.firefoxUserPrefs ? serializeArgument(options.firefoxUserPrefs).value : undefined,};return BrowserServer.from((await this._channel.launchServer(launchServerOptions)).server);}, logger);diff --git a/src/rpc/client/cdpSession.ts b/src/rpc/client/cdpSession.tsindex a0d7574036..904ade04e1 100644--- a/src/rpc/client/cdpSession.ts+++ b/src/rpc/client/cdpSession.ts@@ -17,7 +17,6 @@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 {@@ -34,8 +33,7 @@ export class CDPSession extends ChannelOwner<CDPSessionChannel, CDPSessionInitiasuper(parent, type, guid, initializer);this._channel.on('event', ({ method, params }) => {- const cdpParams = params ? parseResult(params) : undefined;- this.emit(method, cdpParams);+ this.emit(method, params);});this.on = super.on;@@ -50,9 +48,8 @@ export class CDPSession extends ChannelOwner<CDPSessionChannel, CDPSessionInitiaparams?: Protocol.CommandParameters[T]): Promise<Protocol.CommandReturnValues[T]> {return this._wrapApiCall('cdpSession.send', async () => {- const protocolParams = params ? serializeArgument(params).value : undefined;- const result = await this._channel.send({ method, params: protocolParams });- return parseResult(result.result) as Protocol.CommandReturnValues[T];+ const result = await this._channel.send({ method, params });+ return result.result as Protocol.CommandReturnValues[T];});}diff --git a/src/rpc/protocol.yml b/src/rpc/protocol.ymlindex bada84e12e..9a862f3881 100644--- a/src/rpc/protocol.yml+++ b/src/rpc/protocol.yml@@ -215,7 +215,7 @@ BrowserType:username: string?password: string?downloadsPath: string?- firefoxUserPrefs: SerializedValue?+ firefoxUserPrefs: json?chromiumSandbox: boolean?slowMo: number?returns:@@ -252,7 +252,7 @@ BrowserType:username: string?password: string?downloadsPath: string?- firefoxUserPrefs: SerializedValue?+ firefoxUserPrefs: json?chromiumSandbox: boolean?port: number?returns:@@ -1849,9 +1849,9 @@ CDPSession:send:parameters:method: string- params: SerializedValue?+ params: json?returns:- result: SerializedValue+ result: jsondetach:@@ -1860,7 +1860,7 @@ CDPSession:event:parameters:method: string- params: SerializedValue?+ params: json?diff --git a/src/rpc/server/browserTypeDispatcher.ts b/src/rpc/server/browserTypeDispatcher.tsindex 87ee56c7f9..affdc082e1 100644--- a/src/rpc/server/browserTypeDispatcher.ts+++ b/src/rpc/server/browserTypeDispatcher.ts@@ -24,7 +24,6 @@ import { BrowserContextBase } from '../../browserContext';import { BrowserContextDispatcher } from './browserContextDispatcher';import { BrowserServerDispatcher } from './browserServerDispatcher';import { headersArrayToObject, envArrayToObject } from '../../converters';-import { parseValue } from './jsHandleDispatcher';export class BrowserTypeDispatcher extends Dispatcher<BrowserType, BrowserTypeInitializer> implements BrowserTypeChannel {constructor(scope: DispatcherScope, browserType: BrowserTypeBase) {@@ -39,7 +38,6 @@ export class BrowserTypeDispatcher extends Dispatcher<BrowserType, BrowserTypeIn...params,ignoreDefaultArgs: params.ignoreAllDefaultArgs ? true : params.ignoreDefaultArgs,env: params.env ? envArrayToObject(params.env) : undefined,- firefoxUserPrefs: params.firefoxUserPrefs ? parseValue(params.firefoxUserPrefs) : undefined,};const browser = await this._object.launch(options);return { browser: new BrowserDispatcher(this._scope, browser as BrowserBase) };@@ -61,7 +59,6 @@ export class BrowserTypeDispatcher extends Dispatcher<BrowserType, BrowserTypeInconst options = {...params,ignoreDefaultArgs: params.ignoreAllDefaultArgs ? true : params.ignoreDefaultArgs,- firefoxUserPrefs: params.firefoxUserPrefs ? parseValue(params.firefoxUserPrefs) : undefined,env: params.env ? envArrayToObject(params.env) : undefined,};return { server: new BrowserServerDispatcher(this._scope, await this._object.launchServer(options)) };diff --git a/src/rpc/server/cdpSessionDispatcher.ts b/src/rpc/server/cdpSessionDispatcher.tsindex 6f0d818294..a1f585d82d 100644--- a/src/rpc/server/cdpSessionDispatcher.ts+++ b/src/rpc/server/cdpSessionDispatcher.ts@@ -15,23 +15,20 @@*/import { CRSession, CRSessionEvents } from '../../chromium/crConnection';-import { CDPSessionChannel, CDPSessionInitializer, SerializedValue } from '../channels';+import { CDPSessionChannel, CDPSessionInitializer } from '../channels';import { Dispatcher, DispatcherScope } from './dispatcher';-import { serializeResult, parseValue } from './jsHandleDispatcher';export class CDPSessionDispatcher extends Dispatcher<CRSession, CDPSessionInitializer> implements CDPSessionChannel {constructor(scope: DispatcherScope, crSession: CRSession) {super(scope, crSession, 'CDPSession', {}, true);- crSession._eventListener = (method, cdpParams) => {- const params = cdpParams ? serializeResult(cdpParams) : undefined;+ crSession._eventListener = (method, params) => {this._dispatchEvent('event', { method, params });};crSession.on(CRSessionEvents.Disconnected, () => this._dispose());}- async send(params: { method: string, params?: SerializedValue }): Promise<{ result: SerializedValue }> {- const cdpParams = params.params ? parseValue(params.params) : undefined;- return { result: serializeResult(await this._object.send(params.method as any, cdpParams)) };+ async send(params: { method: string, params?: any }): Promise<{ result: any }> {+ return { result: await this._object.send(params.method as any, params.params) };}async detach(): Promise<void> {diff --git a/src/rpc/validator.ts b/src/rpc/validator.tsindex 9f46fa68aa..5a2a0d63c6 100644--- a/src/rpc/validator.ts+++ b/src/rpc/validator.ts@@ -16,7 +16,7 @@// This file is generated by generate_channels.js, do not edit manually.-import { Validator, ValidationError, tOptional, tObject, tBoolean, tNumber, tString, tEnum, tArray, tBinary } from './validatorPrimitives';+import { Validator, ValidationError, tOptional, tObject, tBoolean, tNumber, tString, tAny, tEnum, tArray, tBinary } from './validatorPrimitives';export { Validator, ValidationError } from './validatorPrimitives';type Scheme = { [key: string]: Validator };@@ -127,7 +127,7 @@ export function createScheme(tChannel: (name: string) => Validator): Scheme {password: tOptional(tString),})),downloadsPath: tOptional(tString),- firefoxUserPrefs: tOptional(tType('SerializedValue')),+ firefoxUserPrefs: tOptional(tAny),chromiumSandbox: tOptional(tBoolean),slowMo: tOptional(tNumber),});@@ -153,7 +153,7 @@ export function createScheme(tChannel: (name: string) => Validator): Scheme {password: tOptional(tString),})),downloadsPath: tOptional(tString),- firefoxUserPrefs: tOptional(tType('SerializedValue')),+ firefoxUserPrefs: tOptional(tAny),chromiumSandbox: tOptional(tBoolean),port: tOptional(tNumber),});@@ -837,7 +837,7 @@ export function createScheme(tChannel: (name: string) => Validator): Scheme {});scheme.CDPSessionSendParams = tObject({method: tString,- params: tOptional(tType('SerializedValue')),+ params: tOptional(tAny),});scheme.CDPSessionDetachParams = tOptional(tObject({}));scheme.ElectronLaunchParams = tObject({diff --git a/src/rpc/validatorPrimitives.ts b/src/rpc/validatorPrimitives.tsindex 818d29cbc7..215cb6e976 100644--- a/src/rpc/validatorPrimitives.ts+++ b/src/rpc/validatorPrimitives.ts@@ -52,6 +52,9 @@ export const tUndefined: Validator = (arg: any, path: string) => {return arg;throw new ValidationError(`${path}: expected undefined, got ${typeof arg}`);};+export const tAny: Validator = (arg: any, path: string) => {+ return arg;+};export const tOptional = (v: Validator): Validator => {return (arg: any, path: string) => {if (Object.is(arg, undefined))diff --git a/utils/generate_channels.js b/utils/generate_channels.jsindex d70dacad95..e9556df489 100755--- a/utils/generate_channels.js+++ b/utils/generate_channels.js@@ -36,6 +36,8 @@ function inlineType(type, indent, wrapEnums = false) {type = type.substring(0, type.length - 1);if (type === 'binary')return { ts: 'Binary', scheme: 'tBinary', optional };+ if (type === 'json')+ return { ts: 'any', scheme: 'tAny', optional };if (['string', 'boolean', 'number', 'undefined'].includes(type))return { ts: type, scheme: `t${titleCase(type)}`, optional };if (channels.has(type))@@ -137,7 +139,7 @@ const validator_ts = [// This file is generated by ${path.basename(__filename)}, do not edit manually.-import { Validator, ValidationError, tOptional, tObject, tBoolean, tNumber, tString, tEnum, tArray, tBinary } from './validatorPrimitives';+import { Validator, ValidationError, tOptional, tObject, tBoolean, tNumber, tString, tAny, tEnum, tArray, tBinary } from './validatorPrimitives';export { Validator, ValidationError } from './validatorPrimitives';type Scheme = { [key: string]: Validator };