Skip to content

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

chore(protocol): generate shared structs.d.ts for client and server channels (#41526)

Simon Knott912770bde311
diff --git a/packages/injected/src/injectedScript.ts b/packages/injected/src/injectedScript.ts
index 6c265ae8ff..17af70020b 100644
--- a/packages/injected/src/injectedScript.ts
+++ b/packages/injected/src/injectedScript.ts
@@ -43,20 +43,9 @@ import type { SelectorEngine, SelectorRoot } from './selectorEngine';
import type { GenerateSelectorOptions } from './selectorGenerator';
import type { ElementText, TextMatcher } from './selectorUtils';
import type { Builtins } from './utilityScript';
+import type { ExpectedTextValue, Point, Rect } from '@protocol/structs';
-type ExpectedTextValue = {
- string?: string,
- regexSource?: string,
- regexFlags?: string,
- matchSubstring?: boolean,
- ignoreCase?: boolean,
- normalizeWhiteSpace?: boolean,
-};
-
-type Point = { x: number, y: number };
-type Rect = Point & { width: number, height: number };
-
export type FrameExpectParams = {
selector?: string,
expression: string,
diff --git a/packages/injected/src/storageScript.ts b/packages/injected/src/storageScript.ts
index 13ec974c01..2583b2c3c3 100644
--- a/packages/injected/src/storageScript.ts
+++ b/packages/injected/src/storageScript.ts
@@ -16,42 +16,9 @@
import { parseEvaluationResultValue, serializeAsCallArgument } from '@isomorphic/utilityScriptSerializers';
-type NameValue = { name: string, value: string };
-
-type IndexedDBDatabase = {
- name: string,
- version: number,
- stores: {
- name: string,
- autoIncrement: boolean,
- keyPath?: string,
- keyPathArray?: string[],
- records: {
- key?: any,
- keyEncoded?: any,
- value?: any,
- valueEncoded?: any,
- }[],
- indexes: {
- name: string,
- keyPath?: string,
- keyPathArray?: string[],
- multiEntry: boolean,
- unique: boolean,
- }[],
- }[],
-};
-
-type SetOriginStorage = {
- origin: string,
- localStorage: NameValue[],
- indexedDB?: IndexedDBDatabase[],
-};
-
-export type SerializedStorage = {
- localStorage: NameValue[],
- indexedDB?: IndexedDBDatabase[],
-};
+import type { IndexedDBDatabase, OriginStorage, SetOriginStorage } from '@protocol/structs';
+
+export type SerializedStorage = Omit<OriginStorage, 'origin'>;
export class StorageScript {
private _isFirefox: boolean;
diff --git a/packages/isomorphic/trace/traceUtils.ts b/packages/isomorphic/trace/traceUtils.ts
index aa11c397ac..9873a63950 100644
--- a/packages/isomorphic/trace/traceUtils.ts
+++ b/packages/isomorphic/trace/traceUtils.ts
@@ -15,11 +15,7 @@
*/
import type { StackFrame } from '../stackTrace';
-
-type ClientSideCallMetadata = {
- id: number,
- stack?: StackFrame[],
-};
+import type { ClientSideCallMetadata } from '@protocol/structs';
export type SerializedStackFrame = [number, number, number, string];
export type SerializedStack = [number, SerializedStackFrame[]];
diff --git a/packages/playwright-core/src/client/channels.d.ts b/packages/playwright-core/src/client/channels.d.ts
index c66c5f2b5f..d797efe34a 100644
--- a/packages/playwright-core/src/client/channels.d.ts
+++ b/packages/playwright-core/src/client/channels.d.ts
@@ -15,10 +15,8 @@
*/
// This file is generated by generate_channels.js, do not edit manually.
-export type Binary = Buffer;
-
-export interface Channel {
-}
+import type { Binary, Channel, AndroidWebView, AndroidSelector, AndroidElementInfo, APIResponse, Metadata, ClientSideCallMetadata, SDKLanguage, WaitInfo, SetNetworkCookie, NetworkCookie, ResourceTiming, SecurityDetails, RequestSizes, RemoteAddr, ExpectedTextValue, SelectorEngine, FormField, LifecycleEvent, ConsoleMessagesFilter, RecorderSource, IndexedDBDatabase, SetOriginStorage, OriginStorage, RecordHarOptions, SerializedValue, SerializedArgument, SerializedError, StackFrame, VirtualCredential, Point, Rect, URLPattern, NameValue } from '@protocol/structs';
+export type { Binary, Channel, AndroidWebView, AndroidSelector, AndroidElementInfo, APIResponse, Metadata, ClientSideCallMetadata, SDKLanguage, WaitInfo, SetNetworkCookie, NetworkCookie, ResourceTiming, SecurityDetails, RequestSizes, RemoteAddr, ExpectedTextValue, SelectorEngine, FormField, LifecycleEvent, ConsoleMessagesFilter, RecorderSource, IndexedDBDatabase, SetOriginStorage, OriginStorage, RecordHarOptions, SerializedValue, SerializedArgument, SerializedError, StackFrame, VirtualCredential, Point, Rect, URLPattern, NameValue } from '@protocol/structs';
// ----------- Initializer Traits -----------
export type InitializerTraits<T> =
@@ -584,56 +582,6 @@ export interface AndroidDeviceEvents {
'webViewRemoved': AndroidDeviceWebViewRemovedEvent;
}
-export type AndroidWebView = {
- pid: number,
- pkg: string,
- socketName: string,
-};
-
-export type AndroidSelector = {
- checkable?: boolean,
- checked?: boolean,
- clazz?: string,
- clickable?: boolean,
- depth?: number,
- desc?: string,
- enabled?: boolean,
- focusable?: boolean,
- focused?: boolean,
- hasChild?: {
- androidSelector: AndroidSelector,
- },
- hasDescendant?: {
- androidSelector: AndroidSelector,
- maxDepth?: number,
- },
- longClickable?: boolean,
- pkg?: string,
- res?: string,
- scrollable?: boolean,
- selected?: boolean,
- text?: string,
-};
-
-export type AndroidElementInfo = {
- children?: AndroidElementInfo[],
- clazz: string,
- desc: string,
- res: string,
- pkg: string,
- text: string,
- bounds: Rect,
- checkable: boolean,
- checked: boolean,
- clickable: boolean,
- enabled: boolean,
- focusable: boolean,
- focused: boolean,
- longClickable: boolean,
- scrollable: boolean,
- selected: boolean,
-};
-
// ----------- APIRequestContext -----------
export type APIRequestContextInitializer = {
tracing: TracingChannel,
@@ -728,16 +676,6 @@ export type APIRequestContextDisposeResult = void;
export interface APIRequestContextEvents {
}
-export type APIResponse = {
- fetchUid: string,
- url: string,
- status: number,
- statusText: string,
- headers: NameValue[],
- securityDetails?: SecurityDetails,
- serverAddr?: RemoteAddr,
-};
-
// ----------- Artifact -----------
export type ArtifactInitializer = {
absolutePath: string,
@@ -2092,23 +2030,6 @@ export type BrowserTypeConnectToWorkerResult = {
export interface BrowserTypeEvents {
}
-export type Metadata = {
- location?: {
- file: string,
- line?: number,
- column?: number,
- },
- title?: string,
- internal?: boolean,
- stepId?: string,
-};
-
-export type ClientSideCallMetadata = {
- id: number,
- stack?: StackFrame[],
-};
-
-export type SDKLanguage = 'javascript' | 'python' | 'java' | 'csharp';
// ----------- Disposable -----------
export type DisposableInitializer = {};
export interface DisposableEventTarget {
@@ -2124,14 +2045,6 @@ export type DisposableDisposeResult = void;
export interface DisposableEvents {
}
-export type WaitInfo = {
- waitId: string,
- phase: 'before' | 'after' | 'log',
- event?: string,
- message?: string,
- error?: string,
-};
-
// ----------- Electron -----------
export type ElectronInitializer = {};
export interface ElectronEventTarget {
@@ -3713,33 +3626,6 @@ export type LocalUtilsGlobToRegexResult = {
export interface LocalUtilsEvents {
}
-export type SetNetworkCookie = {
- name: string,
- value: string,
- url?: string,
- domain?: string,
- path?: string,
- expires?: number,
- httpOnly?: boolean,
- secure?: boolean,
- sameSite?: 'Strict' | 'Lax' | 'None',
- partitionKey?: string,
- _crHasCrossSiteAncestor?: boolean,
-};
-
-export type NetworkCookie = {
- name: string,
- value: string,
- domain: string,
- path: string,
- expires: number,
- httpOnly: boolean,
- secure: boolean,
- sameSite: 'Strict' | 'Lax' | 'None',
- partitionKey?: string,
- _crHasCrossSiteAncestor?: boolean,
-};
-
// ----------- Request -----------
export type RequestInitializer = {
frame?: FrameChannel,
@@ -3921,17 +3807,6 @@ export interface WebSocketRouteEvents {
'closeServer': WebSocketRouteCloseServerEvent;
}
-export type ResourceTiming = {
- startTime: number,
- domainLookupStart: number,
- domainLookupEnd: number,
- connectStart: number,
- secureConnectionStart: number,
- connectEnd: number,
- requestStart: number,
- responseStart: number,
-};
-
// ----------- Response -----------
export type ResponseInitializer = {
request: RequestChannel,
@@ -3987,26 +3862,6 @@ export type ResponseSizesResult = {
export interface ResponseEvents {
}
-export type SecurityDetails = {
- issuer?: string,
- protocol?: string,
- subjectName?: string,
- validFrom?: number,
- validTo?: number,
-};
-
-export type RequestSizes = {
- requestBodySize: number,
- requestHeadersSize: number,
- responseBodySize: number,
- responseHeadersSize: number,
-};
-
-export type RemoteAddr = {
- ipAddress: string,
- port: number,
-};
-
// ----------- WebSocket -----------
export type WebSocketInitializer = {
url: string,
@@ -5110,93 +4965,6 @@ export interface JsonPipeEvents {
'closed': JsonPipeClosedEvent;
}
-export type ExpectedTextValue = {
- string?: string,
- regexSource?: string,
- regexFlags?: string,
- matchSubstring?: boolean,
- ignoreCase?: boolean,
- normalizeWhiteSpace?: boolean,
-};
-
-export type SelectorEngine = {
- name: string,
- source: string,
- contentScript?: boolean,
-};
-
-export type FormField = {
- name: string,
- value?: string,
- file?: {
- name: string,
- mimeType?: string,
- buffer: Binary,
- },
-};
-
-export type LifecycleEvent = 'load' | 'domcontentloaded' | 'networkidle' | 'commit';
-export type ConsoleMessagesFilter = 'all' | 'since-navigation';
-export type RecorderSource = {
- isRecorded: boolean,
- id: string,
- label: string,
- text: string,
- language: string,
- highlight: {
- line: number,
- type: string,
- }[],
- revealLine?: number,
- group?: string,
-};
-
-export type IndexedDBDatabase = {
- name: string,
- version: number,
- stores: {
- name: string,
- autoIncrement: boolean,
- keyPath?: string,
- keyPathArray?: string[],
- records: {
- key?: any,
- keyEncoded?: any,
- value?: any,
- valueEncoded?: any,
- }[],
- indexes: {
- name: string,
- keyPath?: string,
- keyPathArray?: string[],
- multiEntry: boolean,
- unique: boolean,
- }[],
- }[],
-};
-
-export type SetOriginStorage = {
- origin: string,
- localStorage: NameValue[],
- indexedDB?: IndexedDBDatabase[],
-};
-
-export type OriginStorage = {
- origin: string,
- localStorage: NameValue[],
- indexedDB?: IndexedDBDatabase[],
-};
-
-export type RecordHarOptions = {
- content?: 'embed' | 'attach' | 'omit',
- mode?: 'full' | 'minimal',
- urlGlob?: string,
- urlRegexSource?: string,
- urlRegexFlags?: string,
- harPath?: string,
- resourcesDir?: string,
-};
-
// ----------- CDPSession -----------
export type CDPSessionInitializer = {};
export interface CDPSessionEventTarget {
@@ -5339,94 +5107,6 @@ export type DialogDismissResult = void;
export interface DialogEvents {
}
-export type SerializedValue = {
- n?: number,
- b?: boolean,
- s?: string,
- v?: 'null' | 'undefined' | 'NaN' | 'Infinity' | '-Infinity' | '-0',
- d?: string,
- u?: string,
- bi?: string,
- ta?: {
- b: Binary,
- k: 'i8' | 'ui8' | 'ui8c' | 'i16' | 'ui16' | 'i32' | 'ui32' | 'f32' | 'f64' | 'bi64' | 'bui64',
- },
- e?: {
- m: string,
- n: string,
- s: string,
- },
- r?: {
- p: string,
- f: string,
- },
- a?: SerializedValue[],
- o?: {
- k: string,
- v: SerializedValue,
- }[],
- h?: number,
- id?: number,
- ref?: number,
-};
-
-export type SerializedArgument = {
- value: SerializedValue,
- handles: Channel[],
-};
-
-export type SerializedError = {
- error?: {
- message: string,
- name: string,
- stack?: string,
- },
- value?: SerializedValue,
-};
-
-export type StackFrame = {
- file: string,
- line: number,
- column: number,
- function?: string,
-};
-
-export type VirtualCredential = {
- id: string,
- rpId: string,
- userHandle: string,
- privateKey: string,
- publicKey: string,
-};
-
-export type Point = {
- x: number,
- y: number,
-};
-
-export type Rect = {
- x: number,
- y: number,
- width: number,
- height: number,
-};
-
-export type URLPattern = {
- hash: string,
- hostname: string,
- password: string,
- pathname: string,
- port: string,
- protocol: string,
- search: string,
- username: string,
-};
-
-export type NameValue = {
- name: string,
- value: string,
-};
-
// ----------- Tracing -----------
export type TracingInitializer = {};
export interface TracingEventTarget {
diff --git a/packages/playwright-core/src/protocol/serializers.ts b/packages/playwright-core/src/protocol/serializers.ts
index ccf795af15..020421c646 100644
--- a/packages/playwright-core/src/protocol/serializers.ts
+++ b/packages/playwright-core/src/protocol/serializers.ts
@@ -14,36 +14,7 @@
* limitations under the License.
*/
-export type SerializedValue = {
- n?: number,
- b?: boolean,
- s?: string,
- v?: 'null' | 'undefined' | 'NaN' | 'Infinity' | '-Infinity' | '-0',
- d?: string,
- u?: string,
- bi?: string,
- ta?: {
- b: Buffer,
- k: 'i8' | 'ui8' | 'ui8c' | 'i16' | 'ui16' | 'i32' | 'ui32' | 'f32' | 'f64' | 'bi64' | 'bui64',
- },
- e?: {
- m: string,
- n: string,
- s: string,
- },
- r?: {
- p: string,
- f: string,
- },
- a?: SerializedValue[],
- o?: {
- k: string,
- v: SerializedValue,
- }[],
- h?: number,
- id?: number,
- ref?: number,
-};
+import type { SerializedValue } from '@protocol/structs';
export function parseSerializedValue(value: SerializedValue, handles: any[] | undefined): any {
return innerParseSerializedValue(value, handles, new Map(), []);
diff --git a/packages/playwright-core/src/server/channels.d.ts b/packages/playwright-core/src/server/channels.d.ts
index 153920cac6..a28946f3b6 100644
--- a/packages/playwright-core/src/server/channels.d.ts
+++ b/packages/playwright-core/src/server/channels.d.ts
@@ -18,10 +18,8 @@
import type { Progress } from './progress';
-export type Binary = Buffer;
-
-export interface Channel {
-}
+import type { Binary, Channel, AndroidWebView, AndroidSelector, AndroidElementInfo, APIResponse, Metadata, ClientSideCallMetadata, SDKLanguage, WaitInfo, SetNetworkCookie, NetworkCookie, ResourceTiming, SecurityDetails, RequestSizes, RemoteAddr, ExpectedTextValue, SelectorEngine, FormField, LifecycleEvent, ConsoleMessagesFilter, RecorderSource, IndexedDBDatabase, SetOriginStorage, OriginStorage, RecordHarOptions, SerializedValue, SerializedArgument, SerializedError, StackFrame, VirtualCredential, Point, Rect, URLPattern, NameValue } from '@protocol/structs';
+export type { Binary, Channel, AndroidWebView, AndroidSelector, AndroidElementInfo, APIResponse, Metadata, ClientSideCallMetadata, SDKLanguage, WaitInfo, SetNetworkCookie, NetworkCookie, ResourceTiming, SecurityDetails, RequestSizes, RemoteAddr, ExpectedTextValue, SelectorEngine, FormField, LifecycleEvent, ConsoleMessagesFilter, RecorderSource, IndexedDBDatabase, SetOriginStorage, OriginStorage, RecordHarOptions, SerializedValue, SerializedArgument, SerializedError, StackFrame, VirtualCredential, Point, Rect, URLPattern, NameValue } from '@protocol/structs';
// ----------- Initializer Traits -----------
export type InitializerTraits<T> =
@@ -587,56 +585,6 @@ export interface AndroidDeviceEvents {
'webViewRemoved': AndroidDeviceWebViewRemovedEvent;
}
-export type AndroidWebView = {
- pid: number,
- pkg: string,
- socketName: string,
-};
-
-export type AndroidSelector = {
- checkable?: boolean,
- checked?: boolean,
- clazz?: string,
- clickable?: boolean,
- depth?: number,
- desc?: string,
- enabled?: boolean,
- focusable?: boolean,
- focused?: boolean,
- hasChild?: {
- androidSelector: AndroidSelector,
- },
- hasDescendant?: {
- androidSelector: AndroidSelector,
- maxDepth?: number,
- },
- longClickable?: boolean,
- pkg?: string,
- res?: string,
- scrollable?: boolean,
- selected?: boolean,
- text?: string,
-};
-
-export type AndroidElementInfo = {
- children?: AndroidElementInfo[],
- clazz: string,
- desc: string,
- res: string,
- pkg: string,
- text: string,
- bounds: Rect,
- checkable: boolean,
- checked: boolean,
- clickable: boolean,
- enabled: boolean,
- focusable: boolean,
- focused: boolean,
- longClickable: boolean,
- scrollable: boolean,
- selected: boolean,
-};
-
// ----------- APIRequestContext -----------
export type APIRequestContextInitializer = {
tracing: TracingChannel,
@@ -731,16 +679,6 @@ export type APIRequestContextDisposeResult = void;
export interface APIRequestContextEvents {
}
-export type APIResponse = {
- fetchUid: string,
- url: string,
- status: number,
- statusText: string,
- headers: NameValue[],
- securityDetails?: SecurityDetails,
- serverAddr?: RemoteAddr,
-};
-
// ----------- Artifact -----------
export type ArtifactInitializer = {
absolutePath: string,
@@ -2095,23 +2033,6 @@ export type BrowserTypeConnectToWorkerResult = {
export interface BrowserTypeEvents {
}
-export type Metadata = {
- location?: {
- file: string,
- line?: number,
- column?: number,
- },
- title?: string,
- internal?: boolean,
- stepId?: string,
-};
-
-export type ClientSideCallMetadata = {
- id: number,
- stack?: StackFrame[],
-};
-
-export type SDKLanguage = 'javascript' | 'python' | 'java' | 'csharp';
// ----------- Disposable -----------
export type DisposableInitializer = {};
export interface DisposableEventTarget {
@@ -2127,14 +2048,6 @@ export type DisposableDisposeResult = void;
export interface DisposableEvents {
}
-export type WaitInfo = {
- waitId: string,
- phase: 'before' | 'after' | 'log',
- event?: string,
- message?: string,
- error?: string,
-};
-
// ----------- Electron -----------
export type ElectronInitializer = {};
export interface ElectronEventTarget {
@@ -3716,33 +3629,6 @@ export type LocalUtilsGlobToRegexResult = {
export interface LocalUtilsEvents {
}
-export type SetNetworkCookie = {
- name: string,
- value: string,
- url?: string,
- domain?: string,
- path?: string,
- expires?: number,
- httpOnly?: boolean,
- secure?: boolean,
- sameSite?: 'Strict' | 'Lax' | 'None',
- partitionKey?: string,
- _crHasCrossSiteAncestor?: boolean,
-};
-
-export type NetworkCookie = {
- name: string,
- value: string,
- domain: string,
- path: string,
- expires: number,
- httpOnly: boolean,
- secure: boolean,
- sameSite: 'Strict' | 'Lax' | 'None',
- partitionKey?: string,
- _crHasCrossSiteAncestor?: boolean,
-};
-
// ----------- Request -----------
export type RequestInitializer = {
frame?: FrameChannel,
@@ -3924,17 +3810,6 @@ export interface WebSocketRouteEvents {
'closeServer': WebSocketRouteCloseServerEvent;
}
-export type ResourceTiming = {
- startTime: number,
- domainLookupStart: number,
- domainLookupEnd: number,
- connectStart: number,
- secureConnectionStart: number,
- connectEnd: number,
- requestStart: number,
- responseStart: number,
-};
-
// ----------- Response -----------
export type ResponseInitializer = {
request: RequestChannel,
@@ -3990,26 +3865,6 @@ export type ResponseSizesResult = {
export interface ResponseEvents {
}
-export type SecurityDetails = {
- issuer?: string,
- protocol?: string,
- subjectName?: string,
- validFrom?: number,
- validTo?: number,
-};
-
-export type RequestSizes = {
- requestBodySize: number,
- requestHeadersSize: number,
- responseBodySize: number,
- responseHeadersSize: number,
-};
-
-export type RemoteAddr = {
- ipAddress: string,
- port: number,
-};
-
// ----------- WebSocket -----------
export type WebSocketInitializer = {
url: string,
@@ -5113,93 +4968,6 @@ export interface JsonPipeEvents {
'closed': JsonPipeClosedEvent;
}
-export type ExpectedTextValue = {
- string?: string,
- regexSource?: string,
- regexFlags?: string,
- matchSubstring?: boolean,
- ignoreCase?: boolean,
- normalizeWhiteSpace?: boolean,
-};
-
-export type SelectorEngine = {
- name: string,
- source: string,
- contentScript?: boolean,
-};
-
-export type FormField = {
- name: string,
- value?: string,
- file?: {
- name: string,
- mimeType?: string,
- buffer: Binary,
- },
-};
-
-export type LifecycleEvent = 'load' | 'domcontentloaded' | 'networkidle' | 'commit';
-export type ConsoleMessagesFilter = 'all' | 'since-navigation';
-export type RecorderSource = {
- isRecorded: boolean,
- id: string,
- label: string,
- text: string,
- language: string,
- highlight: {
- line: number,
- type: string,
- }[],
- revealLine?: number,
- group?: string,
-};
-
-export type IndexedDBDatabase = {
- name: string,
- version: number,
- stores: {
- name: string,
- autoIncrement: boolean,
- keyPath?: string,
- keyPathArray?: string[],
- records: {
- key?: any,
- keyEncoded?: any,
- value?: any,
- valueEncoded?: any,
- }[],
- indexes: {
- name: string,
- keyPath?: string,
- keyPathArray?: string[],
- multiEntry: boolean,
- unique: boolean,
- }[],
- }[],
-};
-
-export type SetOriginStorage = {
- origin: string,
- localStorage: NameValue[],
- indexedDB?: IndexedDBDatabase[],
-};
-
-export type OriginStorage = {
- origin: string,
- localStorage: NameValue[],
- indexedDB?: IndexedDBDatabase[],
-};
-
-export type RecordHarOptions = {
- content?: 'embed' | 'attach' | 'omit',
- mode?: 'full' | 'minimal',
- urlGlob?: string,
- urlRegexSource?: string,
- urlRegexFlags?: string,
- harPath?: string,
- resourcesDir?: string,
-};
-
// ----------- CDPSession -----------
export type CDPSessionInitializer = {};
export interface CDPSessionEventTarget {
@@ -5342,94 +5110,6 @@ export type DialogDismissResult = void;
export interface DialogEvents {
}
-export type SerializedValue = {
- n?: number,
- b?: boolean,
- s?: string,
- v?: 'null' | 'undefined' | 'NaN' | 'Infinity' | '-Infinity' | '-0',
- d?: string,
- u?: string,
- bi?: string,
- ta?: {
- b: Binary,
- k: 'i8' | 'ui8' | 'ui8c' | 'i16' | 'ui16' | 'i32' | 'ui32' | 'f32' | 'f64' | 'bi64' | 'bui64',
- },
- e?: {
- m: string,
- n: string,
- s: string,
- },
- r?: {
- p: string,
- f: string,
- },
- a?: SerializedValue[],
- o?: {
- k: string,
- v: SerializedValue,
- }[],
- h?: number,
- id?: number,
- ref?: number,
-};
-
-export type SerializedArgument = {
- value: SerializedValue,
- handles: Channel[],
-};
-
-export type SerializedError = {
- error?: {
- message: string,
- name: string,
- stack?: string,
- },
- value?: SerializedValue,
-};
-
-export type StackFrame = {
- file: string,
- line: number,
- column: number,
- function?: string,
-};
-
-export type VirtualCredential = {
- id: string,
- rpId: string,
- userHandle: string,
- privateKey: string,
- publicKey: string,
-};
-
-export type Point = {
- x: number,
- y: number,
-};
-
-export type Rect = {
- x: number,
- y: number,
- width: number,
- height: number,
-};
-
-export type URLPattern = {
- hash: string,
- hostname: string,
- password: string,
- pathname: string,
- port: string,
- protocol: string,
- search: string,
- username: string,
-};
-
-export type NameValue = {
- name: string,
- value: string,
-};
-
// ----------- Tracing -----------
export type TracingInitializer = {};
export interface TracingEventTarget {
diff --git a/packages/protocol/src/structs.d.ts b/packages/protocol/src/structs.d.ts
new file mode 100644
index 0000000000..a44c990626
--- /dev/null
+++ b/packages/protocol/src/structs.d.ts
@@ -0,0 +1,344 @@
+/**
+ * Copyright (c) Microsoft Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// This file is generated by generate_channels.js, do not edit manually.
+
+export type Binary = Buffer;
+
+export interface Channel {
+}
+
+export type AndroidWebView = {
+ pid: number,
+ pkg: string,
+ socketName: string,
+};
+
+export type AndroidSelector = {
+ checkable?: boolean,
+ checked?: boolean,
+ clazz?: string,
+ clickable?: boolean,
+ depth?: number,
+ desc?: string,
+ enabled?: boolean,
+ focusable?: boolean,
+ focused?: boolean,
+ hasChild?: {
+ androidSelector: AndroidSelector,
+ },
+ hasDescendant?: {
+ androidSelector: AndroidSelector,
+ maxDepth?: number,
+ },
+ longClickable?: boolean,
+ pkg?: string,
+ res?: string,
+ scrollable?: boolean,
+ selected?: boolean,
+ text?: string,
+};
+
+export type AndroidElementInfo = {
+ children?: AndroidElementInfo[],
+ clazz: string,
+ desc: string,
+ res: string,
+ pkg: string,
+ text: string,
+ bounds: Rect,
+ checkable: boolean,
+ checked: boolean,
+ clickable: boolean,
+ enabled: boolean,
+ focusable: boolean,
+ focused: boolean,
+ longClickable: boolean,
+ scrollable: boolean,
+ selected: boolean,
+};
+
+export type APIResponse = {
+ fetchUid: string,
+ url: string,
+ status: number,
+ statusText: string,
+ headers: NameValue[],
+ securityDetails?: SecurityDetails,
+ serverAddr?: RemoteAddr,
+};
+
+export type Metadata = {
+ location?: {
+ file: string,
+ line?: number,
+ column?: number,
+ },
+ title?: string,
+ internal?: boolean,
+ stepId?: string,
+};
+
+export type ClientSideCallMetadata = {
+ id: number,
+ stack?: StackFrame[],
+};
+
+export type SDKLanguage = 'javascript' | 'python' | 'java' | 'csharp';
+
+export type WaitInfo = {
+ waitId: string,
+ phase: 'before' | 'after' | 'log',
+ event?: string,
+ message?: string,
+ error?: string,
+};
+
+export type SetNetworkCookie = {
+ name: string,
+ value: string,
+ url?: string,
+ domain?: string,
+ path?: string,
+ expires?: number,
+ httpOnly?: boolean,
+ secure?: boolean,
+ sameSite?: 'Strict' | 'Lax' | 'None',
+ partitionKey?: string,
+ _crHasCrossSiteAncestor?: boolean,
+};
+
+export type NetworkCookie = {
+ name: string,
+ value: string,
+ domain: string,
+ path: string,
+ expires: number,
+ httpOnly: boolean,
+ secure: boolean,
+ sameSite: 'Strict' | 'Lax' | 'None',
+ partitionKey?: string,
+ _crHasCrossSiteAncestor?: boolean,
+};
+
+export type ResourceTiming = {
+ startTime: number,
+ domainLookupStart: number,
+ domainLookupEnd: number,
+ connectStart: number,
+ secureConnectionStart: number,
+ connectEnd: number,
+ requestStart: number,
+ responseStart: number,
+};
+
+export type SecurityDetails = {
+ issuer?: string,
+ protocol?: string,
+ subjectName?: string,
+ validFrom?: number,
+ validTo?: number,
+};
+
+export type RequestSizes = {
+ requestBodySize: number,
+ requestHeadersSize: number,
+ responseBodySize: number,
+ responseHeadersSize: number,
+};
+
+export type RemoteAddr = {
+ ipAddress: string,
+ port: number,
+};
+
+export type ExpectedTextValue = {
+ string?: string,
+ regexSource?: string,
+ regexFlags?: string,
+ matchSubstring?: boolean,
+ ignoreCase?: boolean,
+ normalizeWhiteSpace?: boolean,
+};
+
+export type SelectorEngine = {
+ name: string,
+ source: string,
+ contentScript?: boolean,
+};
+
+export type FormField = {
+ name: string,
+ value?: string,
+ file?: {
+ name: string,
+ mimeType?: string,
+ buffer: Binary,
+ },
+};
+
+export type LifecycleEvent = 'load' | 'domcontentloaded' | 'networkidle' | 'commit';
+
+export type ConsoleMessagesFilter = 'all' | 'since-navigation';
+
+export type RecorderSource = {
+ isRecorded: boolean,
+ id: string,
+ label: string,
+ text: string,
+ language: string,
+ highlight: {
+ line: number,
+ type: string,
+ }[],
+ revealLine?: number,
+ group?: string,
+};
+
+export type IndexedDBDatabase = {
+ name: string,
+ version: number,
+ stores: {
+ name: string,
+ autoIncrement: boolean,
+ keyPath?: string,
+ keyPathArray?: string[],
+ records: {
+ key?: any,
+ keyEncoded?: any,
+ value?: any,
+ valueEncoded?: any,
+ }[],
+ indexes: {
+ name: string,
+ keyPath?: string,
+ keyPathArray?: string[],
+ multiEntry: boolean,
+ unique: boolean,
+ }[],
+ }[],
+};
+
+export type SetOriginStorage = {
+ origin: string,
+ localStorage: NameValue[],
+ indexedDB?: IndexedDBDatabase[],
+};
+
+export type OriginStorage = {
+ origin: string,
+ localStorage: NameValue[],
+ indexedDB?: IndexedDBDatabase[],
+};
+
+export type RecordHarOptions = {
+ content?: 'embed' | 'attach' | 'omit',
+ mode?: 'full' | 'minimal',
+ urlGlob?: string,
+ urlRegexSource?: string,
+ urlRegexFlags?: string,
+ harPath?: string,
+ resourcesDir?: string,
+};
+
+export type SerializedValue = {
+ n?: number,
+ b?: boolean,
+ s?: string,
+ v?: 'null' | 'undefined' | 'NaN' | 'Infinity' | '-Infinity' | '-0',
+ d?: string,
+ u?: string,
+ bi?: string,
+ ta?: {
+ b: Binary,
+ k: 'i8' | 'ui8' | 'ui8c' | 'i16' | 'ui16' | 'i32' | 'ui32' | 'f32' | 'f64' | 'bi64' | 'bui64',
+ },
+ e?: {
+ m: string,
+ n: string,
+ s: string,
+ },
+ r?: {
+ p: string,
+ f: string,
+ },
+ a?: SerializedValue[],
+ o?: {
+ k: string,
+ v: SerializedValue,
+ }[],
+ h?: number,
+ id?: number,
+ ref?: number,
+};
+
+export type SerializedArgument = {
+ value: SerializedValue,
+ handles: Channel[],
+};
+
+export type SerializedError = {
+ error?: {
+ message: string,
+ name: string,
+ stack?: string,
+ },
+ value?: SerializedValue,
+};
+
+export type StackFrame = {
+ file: string,
+ line: number,
+ column: number,
+ function?: string,
+};
+
+export type VirtualCredential = {
+ id: string,
+ rpId: string,
+ userHandle: string,
+ privateKey: string,
+ publicKey: string,
+};
+
+export type Point = {
+ x: number,
+ y: number,
+};
+
+export type Rect = {
+ x: number,
+ y: number,
+ width: number,
+ height: number,
+};
+
+export type URLPattern = {
+ hash: string,
+ hostname: string,
+ password: string,
+ pathname: string,
+ port: string,
+ protocol: string,
+ search: string,
+ username: string,
+};
+
+export type NameValue = {
+ name: string,
+ value: string,
+};
+
diff --git a/tsconfig.json b/tsconfig.json
index a027e586c8..c26c7fc9c6 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -16,6 +16,7 @@
"@injected/*": ["./packages/injected/src/*"],
"@isomorphic/*": ["./packages/isomorphic/*"],
"@utils/*": ["./packages/utils/*"],
+ "@protocol/*": ["./packages/protocol/src/*"],
"@recorder/*": ["./packages/recorder/src/*"],
"@testIsomorphic/*": ["./packages/playwright/src/isomorphic/*"],
"@trace/*": ["./packages/trace/src/*"],
diff --git a/utils/generate_channels.js b/utils/generate_channels.js
index cb03c6430a..374d334fa8 100755
--- a/utils/generate_channels.js
+++ b/utils/generate_channels.js
@@ -131,10 +131,8 @@ function channelsHeader(target) {
import type { Progress } from './progress';
` : '') + `
-export type Binary = Buffer;
-
-export interface Channel {
-}
+import type { Binary, Channel, ${structNames.join(', ')} } from '@protocol/structs';
+export type { Binary, Channel, ${structNames.join(', ')} } from '@protocol/structs';
`];
}
@@ -197,6 +195,13 @@ for (const [name, value] of Object.entries(protocol)) {
mixins.set(name, value);
}
+// Struct types (objects and enums) are identical for the client and the server,
+// so they are generated once into a shared structs.d.ts file that both the
+// client and the server channels.d.ts import and re-export.
+const structNames = Object.entries(protocol)
+ .filter(([, value]) => value.type === 'object' || value.type === 'enum')
+ .map(([name]) => name);
+
const derivedClasses = new Map();
for (const [name, item] of Object.entries(protocol)) {
if (item.type === 'interface' && item.extends) {
@@ -371,12 +376,8 @@ function generateChannels(target) {
} else if (item.type === 'object') {
const inner = objectType(item.properties, '');
- channels_ts.push(`export type ${name} = ${inner.ts};`);
- channels_ts.push(``);
addScheme(name, inner.scheme);
} else if (item.type === 'enum') {
- const ts = item.literals.map(literal => `'${literal}'`).join(' | ');
- channels_ts.push(`export type ${name} = ${ts};`)
addScheme(name, `tEnum([${item.literals.map(literal => `'${literal}'`).join(', ')}])`);
}
}
@@ -384,6 +385,50 @@ function generateChannels(target) {
return channels_ts;
}
+function structsHeader() {
+ return `/**
+ * Copyright (c) Microsoft Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// This file is generated by ${path.basename(__filename).split(path.sep).join(path.posix.sep)}, do not edit manually.
+
+export type Binary = Buffer;
+
+export interface Channel {
+}
+`;
+}
+
+function generateStructs() {
+ const structs_ts = [structsHeader()];
+ for (const [name, item] of Object.entries(protocol)) {
+ if (item.type === 'object') {
+ const inner = objectType(item.properties, '');
+ structs_ts.push(`export type ${name} = ${inner.ts};`);
+ structs_ts.push(``);
+ } else if (item.type === 'enum') {
+ const ts = item.literals.map(literal => `'${literal}'`).join(' | ');
+ structs_ts.push(`export type ${name} = ${ts};`);
+ structs_ts.push(``);
+ }
+ }
+ return structs_ts;
+}
+
+const structs_ts = generateStructs();
+
const client_channels_ts = generateChannels('Channel');
metainfo_ts.push(`export type MethodMetainfo = { internal?: boolean, title?: string, slowMo?: boolean, snapshot?: boolean, pause?: boolean, isAutoWaiting?: boolean, input?: boolean, group?: string };
@@ -416,6 +461,7 @@ function writeFile(filePath, content) {
fs.writeFileSync(filePath, content, 'utf8');
}
+writeFile(path.join(__dirname, '..', 'packages', 'protocol', 'src', 'structs.d.ts'), structs_ts.join('\n') + '\n');
writeFile(path.join(__dirname, '..', 'packages', 'playwright-core', 'src', 'client', 'channels.d.ts'), client_channels_ts.join('\n') + '\n');
writeFile(path.join(__dirname, '..', 'packages', 'playwright-core', 'src', 'server', 'channels.d.ts'), server_channels_ts.join('\n') + '\n');
writeFile(path.join(__dirname, '..', 'packages', 'isomorphic', 'protocolMetainfo.ts'), metainfoContent);