| /** |
| * Copyright 2022 Google LLC. |
| * 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. |
| */ |
| /** |
| * @file Provides TypeScript types for WebDriver BiDi protocol. |
| * This file should not have any dependencies. |
| */ |
| export interface EventResponse<MethodType, ParamsType> { |
| method: MethodType; |
| params: ParamsType; |
| } |
| export declare namespace Message { |
| type OutgoingMessage = CommandResponse | EventMessage | { |
| launched: true; |
| }; |
| type RawCommandRequest = { |
| id: number; |
| method: string; |
| params: object; |
| channel?: string; |
| }; |
| type CommandRequest = { |
| id: number; |
| } & (BrowsingContext.Command | Script.Command | Session.Command | CDP.Command); |
| type CommandResponse = { |
| id: number; |
| } & CommandResponseResult; |
| type CommandResponseResult = BrowsingContext.CommandResult | Script.CommandResult | Session.CommandResult | CDP.CommandResult | ErrorResult; |
| type EventMessage = BrowsingContext.Event | Log.Event | CDP.Event; |
| type ErrorCode = 'unknown error' | 'unknown command' | 'invalid argument' | 'no such frame' | 'no such node'; |
| type ErrorResult = { |
| readonly error: ErrorCode; |
| readonly message: string; |
| readonly stacktrace?: string; |
| }; |
| class ErrorResponseClass implements Message.ErrorResult { |
| protected constructor(error: Message.ErrorCode, message: string, stacktrace?: string); |
| readonly error: Message.ErrorCode; |
| readonly message: string; |
| readonly stacktrace?: string; |
| toErrorResponse(commandId: number): Message.CommandResponse; |
| } |
| class UnknownException extends ErrorResponseClass { |
| constructor(message: string, stacktrace?: string); |
| } |
| class UnknownCommandException extends ErrorResponseClass { |
| constructor(message: string, stacktrace?: string); |
| } |
| class InvalidArgumentException extends ErrorResponseClass { |
| constructor(message: string, stacktrace?: string); |
| } |
| class NoSuchNodeException extends ErrorResponseClass { |
| constructor(message: string, stacktrace?: string); |
| } |
| class NoSuchFrameException extends ErrorResponseClass { |
| constructor(message: string); |
| } |
| } |
| export declare namespace CommonDataTypes { |
| type RemoteReference = { |
| handle: string; |
| }; |
| type SharedReference = { |
| sharedId: string; |
| }; |
| type UndefinedValue = { |
| type: 'undefined'; |
| }; |
| type NullValue = { |
| type: 'null'; |
| }; |
| type StringValue = { |
| type: 'string'; |
| value: string; |
| }; |
| type SpecialNumber = 'NaN' | '-0' | 'Infinity' | '+Infinity' | '-Infinity'; |
| type NumberValue = { |
| type: 'number'; |
| value: SpecialNumber | number; |
| }; |
| type BooleanValue = { |
| type: 'boolean'; |
| value: boolean; |
| }; |
| type BigIntValue = { |
| type: 'bigint'; |
| value: string; |
| }; |
| type PrimitiveProtocolValue = UndefinedValue | NullValue | StringValue | NumberValue | BooleanValue | BigIntValue; |
| type LocalValue = PrimitiveProtocolValue | ArrayLocalValue | DateLocalValue | MapLocalValue | ObjectLocalValue | RegExpLocalValue | SetLocalValue; |
| type LocalOrRemoteValue = RemoteReference | LocalValue; |
| type ListLocalValue = LocalOrRemoteValue[]; |
| type ArrayLocalValue = { |
| type: 'array'; |
| value: ListLocalValue; |
| }; |
| type DateLocalValue = { |
| type: 'date'; |
| value: string; |
| }; |
| type MappingLocalValue = [ |
| string | LocalOrRemoteValue, |
| LocalOrRemoteValue |
| ][]; |
| type MapLocalValue = { |
| type: 'map'; |
| value: MappingLocalValue; |
| }; |
| type ObjectLocalValue = { |
| type: 'object'; |
| value: MappingLocalValue; |
| }; |
| type RegExpLocalValue = { |
| type: 'regexp'; |
| value: { |
| pattern: string; |
| flags?: string; |
| }; |
| }; |
| type SetLocalValue = { |
| type: 'set'; |
| value: ListLocalValue; |
| }; |
| type RemoteValue = PrimitiveProtocolValue | SymbolRemoteValue | ArrayRemoteValue | ObjectRemoteValue | FunctionRemoteValue | RegExpRemoteValue | DateRemoteValue | MapRemoteValue | SetRemoteValue | WeakMapRemoteValue | WeakSetRemoteValue | IteratorRemoteValue | GeneratorRemoteValue | ProxyRemoteValue | ErrorRemoteValue | PromiseRemoteValue | TypedArrayRemoteValue | ArrayBufferRemoteValue | NodeRemoteValue | WindowProxyRemoteValue; |
| type ListRemoteValue = RemoteValue[]; |
| type MappingRemoteValue = [RemoteValue | string, RemoteValue][]; |
| type SymbolRemoteValue = RemoteReference & { |
| type: 'symbol'; |
| }; |
| type ArrayRemoteValue = RemoteReference & { |
| type: 'array'; |
| value?: ListRemoteValue; |
| }; |
| type ObjectRemoteValue = RemoteReference & { |
| type: 'object'; |
| value?: MappingRemoteValue; |
| }; |
| type FunctionRemoteValue = RemoteReference & { |
| type: 'function'; |
| }; |
| type RegExpRemoteValue = RemoteReference & RegExpLocalValue; |
| type DateRemoteValue = RemoteReference & DateLocalValue; |
| type MapRemoteValue = RemoteReference & { |
| type: 'map'; |
| value: MappingRemoteValue; |
| }; |
| type SetRemoteValue = RemoteReference & { |
| type: 'set'; |
| value: ListRemoteValue; |
| }; |
| type WeakMapRemoteValue = RemoteReference & { |
| type: 'weakmap'; |
| }; |
| type WeakSetRemoteValue = RemoteReference & { |
| type: 'weakset'; |
| }; |
| type IteratorRemoteValue = RemoteReference & { |
| type: 'iterator'; |
| }; |
| type GeneratorRemoteValue = RemoteReference & { |
| type: 'generator'; |
| }; |
| type ProxyRemoteValue = RemoteReference & { |
| type: 'proxy'; |
| }; |
| type ErrorRemoteValue = RemoteReference & { |
| type: 'error'; |
| }; |
| type PromiseRemoteValue = RemoteReference & { |
| type: 'promise'; |
| }; |
| type TypedArrayRemoteValue = RemoteReference & { |
| type: 'typedarray'; |
| }; |
| type ArrayBufferRemoteValue = RemoteReference & { |
| type: 'arraybuffer'; |
| }; |
| type NodeRemoteValue = RemoteReference & { |
| type: 'node'; |
| value?: NodeProperties; |
| }; |
| type NodeProperties = RemoteReference & { |
| nodeType: number; |
| nodeValue: string; |
| localName?: string; |
| namespaceURI?: string; |
| childNodeCount: number; |
| children?: [NodeRemoteValue]; |
| attributes?: unknown; |
| shadowRoot?: NodeRemoteValue | null; |
| }; |
| type WindowProxyRemoteValue = RemoteReference & { |
| type: 'window'; |
| }; |
| type BrowsingContext = string; |
| } |
| export declare namespace Script { |
| type Command = EvaluateCommand | CallFunctionCommand | GetRealmsCommand | DisownCommand; |
| type CommandResult = EvaluateResult | CallFunctionResult | GetRealmsResult | DisownResult; |
| type Realm = string; |
| type ScriptResult = ScriptResultSuccess | ScriptResultException; |
| type ScriptResultSuccess = { |
| type: 'success'; |
| result: CommonDataTypes.RemoteValue; |
| realm: string; |
| }; |
| type ScriptResultException = { |
| exceptionDetails: ExceptionDetails; |
| type: 'exception'; |
| realm: string; |
| }; |
| type ExceptionDetails = { |
| columnNumber: number; |
| exception: CommonDataTypes.RemoteValue; |
| lineNumber: number; |
| stackTrace: Script.StackTrace; |
| text: string; |
| }; |
| type RealmInfo = WindowRealmInfo | DedicatedWorkerRealmInfo | SharedWorkerRealmInfo | ServiceWorkerRealmInfo | WorkerRealmInfo | PaintWorkletRealmInfo | AudioWorkletRealmInfo | WorkletRealmInfo; |
| type BaseRealmInfo = { |
| realm: Realm; |
| origin: string; |
| }; |
| type WindowRealmInfo = BaseRealmInfo & { |
| type: 'window'; |
| context: CommonDataTypes.BrowsingContext; |
| sandbox?: string; |
| }; |
| type DedicatedWorkerRealmInfo = BaseRealmInfo & { |
| type: 'dedicated-worker'; |
| }; |
| type SharedWorkerRealmInfo = BaseRealmInfo & { |
| type: 'shared-worker'; |
| }; |
| type ServiceWorkerRealmInfo = BaseRealmInfo & { |
| type: 'service-worker'; |
| }; |
| type WorkerRealmInfo = BaseRealmInfo & { |
| type: 'worker'; |
| }; |
| type PaintWorkletRealmInfo = BaseRealmInfo & { |
| type: 'paint-worklet'; |
| }; |
| type AudioWorkletRealmInfo = BaseRealmInfo & { |
| type: 'audio-worklet'; |
| }; |
| type WorkletRealmInfo = BaseRealmInfo & { |
| type: 'worklet'; |
| }; |
| type RealmType = 'window' | 'dedicated-worker' | 'shared-worker' | 'service-worker' | 'worker' | 'paint-worklet' | 'audio-worklet' | 'worklet'; |
| type GetRealmsParameters = { |
| context?: CommonDataTypes.BrowsingContext; |
| type?: RealmType; |
| }; |
| type GetRealmsCommand = { |
| method: 'script.getRealms'; |
| params: GetRealmsParameters; |
| }; |
| type GetRealmsResult = { |
| result: { |
| realms: RealmInfo[]; |
| }; |
| }; |
| type EvaluateCommand = { |
| method: 'script.evaluate'; |
| params: EvaluateParameters; |
| }; |
| type ContextTarget = { |
| context: CommonDataTypes.BrowsingContext; |
| sandbox?: string; |
| }; |
| type RealmTarget = { |
| realm: string; |
| }; |
| type Target = RealmTarget | ContextTarget; |
| type OwnershipModel = 'root' | 'none'; |
| type EvaluateParameters = { |
| expression: string; |
| awaitPromise: boolean; |
| target: Target; |
| resultOwnership?: OwnershipModel; |
| }; |
| type EvaluateResult = { |
| result: ScriptResult; |
| }; |
| type DisownCommand = { |
| method: 'script.disown'; |
| params: EvaluateParameters; |
| }; |
| type DisownParameters = { |
| target: Target; |
| handles: string[]; |
| }; |
| type DisownResult = { |
| result: {}; |
| }; |
| type CallFunctionCommand = { |
| method: 'script.callFunction'; |
| params: CallFunctionParameters; |
| }; |
| type ArgumentValue = CommonDataTypes.RemoteReference | CommonDataTypes.SharedReference | CommonDataTypes.LocalValue; |
| type CallFunctionParameters = { |
| functionDeclaration: string; |
| target: Target; |
| arguments?: ArgumentValue[]; |
| this?: ArgumentValue; |
| awaitPromise: boolean; |
| resultOwnership?: OwnershipModel; |
| }; |
| type CallFunctionResult = { |
| result: ScriptResult; |
| }; |
| type Source = { |
| realm: Realm; |
| context?: CommonDataTypes.BrowsingContext; |
| }; |
| type StackTrace = { |
| callFrames: StackFrame[]; |
| }; |
| type StackFrame = { |
| columnNumber: number; |
| functionName: string; |
| lineNumber: number; |
| url: string; |
| }; |
| } |
| export declare namespace BrowsingContext { |
| type Command = GetTreeCommand | NavigateCommand | CreateCommand | CloseCommand; |
| type CommandResult = GetTreeResult | NavigateResult | CreateResult | CloseResult; |
| type Event = LoadEvent | DomContentLoadedEvent | ContextCreatedEvent | ContextDestroyedEvent; |
| type Navigation = string; |
| type GetTreeCommand = { |
| method: 'browsingContext.getTree'; |
| params: GetTreeParameters; |
| }; |
| type GetTreeParameters = { |
| maxDepth?: number; |
| root?: CommonDataTypes.BrowsingContext; |
| }; |
| type GetTreeResult = { |
| result: { |
| contexts: InfoList; |
| }; |
| }; |
| type InfoList = Info[]; |
| type Info = { |
| context: CommonDataTypes.BrowsingContext; |
| parent?: CommonDataTypes.BrowsingContext | null; |
| url: string; |
| children: InfoList | null; |
| }; |
| type NavigateCommand = { |
| method: 'browsingContext.navigate'; |
| params: NavigateParameters; |
| }; |
| type ReadinessState = 'none' | 'interactive' | 'complete'; |
| type NavigateParameters = { |
| context: CommonDataTypes.BrowsingContext; |
| url: string; |
| wait?: ReadinessState; |
| }; |
| type NavigateResult = { |
| result: { |
| navigation: Navigation | null; |
| url: string; |
| }; |
| }; |
| type CreateCommand = { |
| method: 'browsingContext.create'; |
| params: CreateParameters; |
| }; |
| type CreateParameters = { |
| type: 'tab' | 'window'; |
| referenceContext?: CommonDataTypes.BrowsingContext; |
| }; |
| type CreateResult = { |
| result: Info; |
| }; |
| type CloseCommand = { |
| method: 'browsingContext.close'; |
| params: CloseParameters; |
| }; |
| type CloseParameters = { |
| context: CommonDataTypes.BrowsingContext; |
| }; |
| type CloseResult = { |
| result: {}; |
| }; |
| type LoadEvent = EventResponse<EventNames.LoadEvent, NavigationInfo>; |
| type DomContentLoadedEvent = EventResponse<EventNames.DomContentLoadedEvent, NavigationInfo>; |
| type NavigationInfo = { |
| context: CommonDataTypes.BrowsingContext; |
| navigation: Navigation | null; |
| url: string; |
| }; |
| type ContextCreatedEvent = EventResponse<EventNames.ContextCreatedEvent, BrowsingContext.Info>; |
| type ContextDestroyedEvent = EventResponse<EventNames.ContextDestroyedEvent, BrowsingContext.Info>; |
| enum EventNames { |
| LoadEvent = "browsingContext.load", |
| DomContentLoadedEvent = "browsingContext.domContentLoaded", |
| ContextCreatedEvent = "browsingContext.contextCreated", |
| ContextDestroyedEvent = "browsingContext.contextDestroyed" |
| } |
| const AllEvents = "browsingContext"; |
| } |
| export declare namespace Log { |
| type LogEntry = GenericLogEntry | ConsoleLogEntry | JavascriptLogEntry; |
| type Event = LogEntryAddedEvent; |
| type LogLevel = 'debug' | 'info' | 'warn' | 'error'; |
| type BaseLogEntry = { |
| level: LogLevel; |
| source: Script.Source; |
| text: string | null; |
| timestamp: number; |
| stackTrace?: Script.StackTrace; |
| }; |
| type GenericLogEntry = BaseLogEntry & { |
| type: string; |
| }; |
| type ConsoleLogEntry = BaseLogEntry & { |
| type: 'console'; |
| method: string; |
| args: CommonDataTypes.RemoteValue[]; |
| }; |
| type JavascriptLogEntry = BaseLogEntry & { |
| type: 'javascript'; |
| }; |
| type LogEntryAddedEvent = EventResponse<EventNames.LogEntryAddedEvent, LogEntry>; |
| const AllEvents = "log"; |
| enum EventNames { |
| LogEntryAddedEvent = "log.entryAdded" |
| } |
| } |
| export declare namespace CDP { |
| type Command = SendCommandCommand | GetSessionCommand; |
| type CommandResult = SendCommandResult | GetSessionResult; |
| type Event = EventReceivedEvent; |
| type SendCommandCommand = { |
| method: 'cdp.sendCommand'; |
| params: SendCommandParams; |
| }; |
| type SendCommandParams = { |
| cdpMethod: string; |
| cdpParams: object; |
| cdpSession?: any; |
| }; |
| type SendCommandResult = { |
| result: any; |
| }; |
| type GetSessionCommand = { |
| method: 'cdp.getSession'; |
| params: GetSessionParams; |
| }; |
| type GetSessionParams = { |
| context: CommonDataTypes.BrowsingContext; |
| }; |
| type GetSessionResult = { |
| result: { |
| session: string; |
| }; |
| }; |
| type EventReceivedEvent = EventResponse<EventNames.EventReceivedEvent, EventReceivedParams>; |
| type EventReceivedParams = { |
| cdpMethod: string; |
| cdpParams: object; |
| cdpSession: string; |
| }; |
| const AllEvents = "cdp"; |
| enum EventNames { |
| EventReceivedEvent = "cdp.eventReceived" |
| } |
| } |
| export declare namespace Session { |
| type Command = StatusCommand | SubscribeCommand | UnsubscribeCommand; |
| type CommandResult = StatusResult | SubscribeResult | UnsubscribeResult; |
| type StatusCommand = { |
| method: 'session.status'; |
| params: {}; |
| }; |
| type StatusResult = { |
| result: { |
| ready: boolean; |
| message: string; |
| }; |
| }; |
| type SubscribeCommand = { |
| method: 'session.subscribe'; |
| params: SubscribeParameters; |
| }; |
| type SubscribeParametersEvent = BrowsingContext.EventNames | typeof BrowsingContext.AllEvents | Log.EventNames | typeof Log.AllEvents | CDP.EventNames | typeof CDP.AllEvents; |
| type SubscribeParameters = { |
| events: SubscribeParametersEvent[]; |
| contexts?: CommonDataTypes.BrowsingContext[]; |
| }; |
| type SubscribeResult = { |
| result: {}; |
| }; |
| type UnsubscribeCommand = { |
| method: 'session.unsubscribe'; |
| params: SubscribeParameters; |
| }; |
| type UnsubscribeResult = { |
| result: {}; |
| }; |
| } |