protocol.d.ts 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962
  1. /**
  2. * Copyright 2022 Google LLC.
  3. * Copyright (c) Microsoft Corporation.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /**
  18. * @fileoverview Provides TypeScript types for WebDriver BiDi protocol.
  19. *
  20. * Note: This file should not have any dependencies because it will be run in the browser.
  21. * Exception: Type dependencies are fine because they are compiled away.
  22. */
  23. import type { ProtocolMapping } from 'devtools-protocol/types/protocol-mapping.js';
  24. interface EventResponse<MethodType, ParamsType> {
  25. method: MethodType;
  26. params: ParamsType;
  27. }
  28. type BiDiCommand = BrowsingContext.Command | Cdp.Command | Input.Command | Network.Command | Script.Command | Session.Command;
  29. export declare namespace Message {
  30. type OutgoingMessage = CommandResponse | EventMessage | {
  31. launched: true;
  32. };
  33. type RawCommandRequest = {
  34. id: number;
  35. method: BiDiCommand['method'];
  36. params: BiDiCommand['params'];
  37. channel?: Script.Channel;
  38. };
  39. type CommandRequest = BiDiCommand & Pick<RawCommandRequest, 'id'>;
  40. type CommandResponse = ResultData & Pick<RawCommandRequest, 'id'>;
  41. type EmptyCommand = never;
  42. type EmptyMessage = Record<string, never>;
  43. type EmptyParams = Record<string, never>;
  44. type EmptyResult = {
  45. result: Record<string, never>;
  46. };
  47. type ResultData = EmptyResult | BrowsingContext.Result | Cdp.Result | ErrorResult | Network.Result | Script.Result | Session.Result;
  48. type EventMessage = BrowsingContext.Event | Cdp.Event | Log.Event | Network.Event | Script.Event;
  49. type EventNames = BrowsingContext.EventNames | Cdp.EventNames | Log.EventNames | Network.EventNames | Script.EventNames;
  50. type AllEvents = typeof BrowsingContext.AllEvents | typeof Log.AllEvents | typeof Network.AllEvents | typeof Script.AllEvents;
  51. enum ErrorCode {
  52. InvalidArgument = "invalid argument",
  53. InvalidSessionId = "invalid session id",
  54. MoveTargetOutOfBounds = "move target out of bounds",
  55. NoSuchAlert = "no such alert",
  56. NoSuchElement = "no such element",
  57. NoSuchFrame = "no such frame",
  58. NoSuchHandle = "no such handle",
  59. NoSuchNode = "no such node",
  60. NoSuchScript = "no such script",
  61. SessionNotCreated = "session not created",
  62. UnknownCommand = "unknown command",
  63. UnknownError = "unknown error",
  64. UnsupportedOperation = "unsupported operation"
  65. }
  66. type ErrorResult = {
  67. readonly error: ErrorCode;
  68. readonly message: string;
  69. readonly stacktrace?: string;
  70. };
  71. class ErrorResponse implements Message.ErrorResult {
  72. error: Message.ErrorCode;
  73. message: string;
  74. stacktrace?: string | undefined;
  75. constructor(error: Message.ErrorCode, message: string, stacktrace?: string | undefined);
  76. toErrorResponse(commandId: number): Message.CommandResponse;
  77. }
  78. class InvalidArgumentException extends ErrorResponse {
  79. constructor(message: string, stacktrace?: string);
  80. }
  81. class MoveTargetOutOfBoundsException extends ErrorResponse {
  82. constructor(message: string, stacktrace?: string);
  83. }
  84. class NoSuchHandleException extends ErrorResponse {
  85. constructor(message: string, stacktrace?: string);
  86. }
  87. class InvalidSessionIdException extends ErrorResponse {
  88. constructor(message: string, stacktrace?: string);
  89. }
  90. class NoSuchAlertException extends ErrorResponse {
  91. constructor(message: string, stacktrace?: string);
  92. }
  93. class NoSuchFrameException extends ErrorResponse {
  94. constructor(message: string);
  95. }
  96. class NoSuchNodeException extends ErrorResponse {
  97. constructor(message: string, stacktrace?: string);
  98. }
  99. class NoSuchElementException extends ErrorResponse {
  100. constructor(message: string, stacktrace?: string);
  101. }
  102. class NoSuchScriptException extends ErrorResponse {
  103. constructor(message: string, stacktrace?: string);
  104. }
  105. class SessionNotCreatedException extends ErrorResponse {
  106. constructor(message: string, stacktrace?: string);
  107. }
  108. class UnknownCommandException extends ErrorResponse {
  109. constructor(message: string, stacktrace?: string);
  110. }
  111. class UnknownErrorException extends ErrorResponse {
  112. constructor(message: string, stacktrace?: string);
  113. }
  114. class UnsupportedOperationException extends ErrorResponse {
  115. constructor(message: string, stacktrace?: string);
  116. }
  117. }
  118. export declare namespace CommonDataTypes {
  119. type Handle = string;
  120. type RemoteReference = {
  121. handle: Handle;
  122. };
  123. type SharedId = string;
  124. type SharedReference = {
  125. sharedId: SharedId;
  126. handle?: Handle;
  127. };
  128. type RemoteObjectReference = {
  129. handle: Handle;
  130. sharedId?: SharedId;
  131. };
  132. type UndefinedValue = {
  133. type: 'undefined';
  134. };
  135. type NullValue = {
  136. type: 'null';
  137. };
  138. type StringValue = {
  139. type: 'string';
  140. value: string;
  141. };
  142. type SpecialNumber = 'NaN' | '-0' | 'Infinity' | '-Infinity';
  143. type NumberValue = {
  144. type: 'number';
  145. value: number | SpecialNumber;
  146. };
  147. type BooleanValue = {
  148. type: 'boolean';
  149. value: boolean;
  150. };
  151. type BigIntValue = {
  152. type: 'bigint';
  153. value: string;
  154. };
  155. type PrimitiveProtocolValue = UndefinedValue | NullValue | StringValue | NumberValue | BooleanValue | BigIntValue;
  156. type LocalValue = PrimitiveProtocolValue | ArrayLocalValue | DateLocalValue | MapLocalValue | ObjectLocalValue | RegExpLocalValue | SetLocalValue;
  157. type ListLocalValue = LocalValue[];
  158. type ArrayLocalValue = {
  159. type: 'array';
  160. value: ListLocalValue;
  161. };
  162. type DateLocalValue = {
  163. type: 'date';
  164. value: string;
  165. };
  166. type MappingLocalValue = [string | LocalValue, LocalValue][];
  167. type MapLocalValue = {
  168. type: 'map';
  169. value: MappingLocalValue;
  170. };
  171. type ObjectLocalValue = {
  172. type: 'object';
  173. value: MappingLocalValue;
  174. };
  175. type RegExpValue = {
  176. pattern: string;
  177. flags?: string;
  178. };
  179. type RegExpLocalValue = {
  180. type: 'regexp';
  181. value: RegExpValue;
  182. };
  183. type SetLocalValue = {
  184. type: 'set';
  185. value: ListLocalValue;
  186. };
  187. type RemoteValue = PrimitiveProtocolValue | SymbolRemoteValue | ArrayRemoteValue | ObjectRemoteValue | FunctionRemoteValue | RegExpRemoteValue | DateRemoteValue | MapRemoteValue | SetRemoteValue | WeakMapRemoteValue | WeakSetRemoteValue | IteratorRemoteValue | GeneratorRemoteValue | ErrorRemoteValue | ProxyRemoteValue | PromiseRemoteValue | TypedArrayRemoteValue | ArrayBufferRemoteValue | NodeListRemoteValue | HTMLCollectionRemoteValue | NodeRemoteValue | WindowProxyRemoteValue;
  188. type InternalId = string;
  189. type ListRemoteValue = RemoteValue[];
  190. type MappingRemoteValue = [RemoteValue | string, RemoteValue][];
  191. type SymbolRemoteValue = RemoteReference & {
  192. type: 'symbol';
  193. };
  194. type ArrayRemoteValue = RemoteReference & {
  195. type: 'array';
  196. value?: ListRemoteValue;
  197. };
  198. type ObjectRemoteValue = RemoteReference & {
  199. type: 'object';
  200. value?: MappingRemoteValue;
  201. };
  202. type FunctionRemoteValue = RemoteReference & {
  203. type: 'function';
  204. };
  205. type RegExpRemoteValue = RemoteReference & RegExpLocalValue;
  206. type DateRemoteValue = RemoteReference & DateLocalValue;
  207. type MapRemoteValue = RemoteReference & {
  208. type: 'map';
  209. value: MappingRemoteValue;
  210. };
  211. type SetRemoteValue = RemoteReference & {
  212. type: 'set';
  213. value: ListRemoteValue;
  214. };
  215. type WeakMapRemoteValue = RemoteReference & {
  216. type: 'weakmap';
  217. };
  218. type WeakSetRemoteValue = RemoteReference & {
  219. type: 'weakset';
  220. };
  221. type IteratorRemoteValue = RemoteReference & {
  222. type: 'iterator';
  223. };
  224. type GeneratorRemoteValue = RemoteReference & {
  225. type: 'generator';
  226. };
  227. type ErrorRemoteValue = RemoteReference & {
  228. type: 'error';
  229. };
  230. type ProxyRemoteValue = RemoteReference & {
  231. type: 'proxy';
  232. };
  233. type PromiseRemoteValue = RemoteReference & {
  234. type: 'promise';
  235. };
  236. type TypedArrayRemoteValue = RemoteReference & {
  237. type: 'typedarray';
  238. };
  239. type ArrayBufferRemoteValue = RemoteReference & {
  240. type: 'arraybuffer';
  241. };
  242. type NodeListRemoteValue = RemoteReference & {
  243. type: 'nodelist';
  244. value?: ListRemoteValue;
  245. };
  246. type HTMLCollectionRemoteValue = RemoteReference & {
  247. type: 'htmlcollection';
  248. value?: ListRemoteValue;
  249. };
  250. type NodeRemoteValue = RemoteReference & {
  251. type: 'node';
  252. value?: NodeProperties;
  253. };
  254. type NodeProperties = {
  255. nodeType: number;
  256. childNodeCount: number;
  257. attributes?: Record<string, string>;
  258. children?: [NodeRemoteValue];
  259. localName?: string;
  260. mode?: 'open' | 'closed';
  261. namespaceURI?: string;
  262. nodeValue: string;
  263. shadowRoot?: NodeRemoteValue | null;
  264. };
  265. type WindowProxyRemoteValue = RemoteReference & {
  266. type: 'window';
  267. };
  268. type BrowsingContext = string;
  269. }
  270. /** @see https://w3c.github.io/webdriver-bidi/#module-script */
  271. export declare namespace Script {
  272. type Command = EvaluateCommand | CallFunctionCommand | GetRealmsCommand | DisownCommand | AddPreloadScriptCommand | RemovePreloadScriptCommand;
  273. type Result = EvaluateResult | CallFunctionResult | GetRealmsResult | DisownResult | AddPreloadScriptResult;
  274. type Event = MessageEvent | RealmCreatedEvent | RealmDestroyedEvent;
  275. type Realm = string;
  276. type ScriptResult = ScriptResultSuccess | ScriptResultException;
  277. type ScriptResultSuccess = {
  278. type: 'success';
  279. result: CommonDataTypes.RemoteValue;
  280. realm: Realm;
  281. };
  282. type ScriptResultException = {
  283. exceptionDetails: ExceptionDetails;
  284. type: 'exception';
  285. realm: Realm;
  286. };
  287. type ExceptionDetails = {
  288. columnNumber: number;
  289. exception: CommonDataTypes.RemoteValue;
  290. lineNumber: number;
  291. stackTrace: Script.StackTrace;
  292. text: string;
  293. };
  294. type RealmInfo = WindowRealmInfo | DedicatedWorkerRealmInfo | SharedWorkerRealmInfo | ServiceWorkerRealmInfo | WorkerRealmInfo | PaintWorkletRealmInfo | AudioWorkletRealmInfo | WorkletRealmInfo;
  295. type BaseRealmInfo = {
  296. realm: Realm;
  297. origin: string;
  298. };
  299. type WindowRealmInfo = BaseRealmInfo & {
  300. type: 'window';
  301. context: CommonDataTypes.BrowsingContext;
  302. sandbox?: string;
  303. };
  304. type DedicatedWorkerRealmInfo = BaseRealmInfo & {
  305. type: 'dedicated-worker';
  306. };
  307. type SharedWorkerRealmInfo = BaseRealmInfo & {
  308. type: 'shared-worker';
  309. };
  310. type ServiceWorkerRealmInfo = BaseRealmInfo & {
  311. type: 'service-worker';
  312. };
  313. type WorkerRealmInfo = BaseRealmInfo & {
  314. type: 'worker';
  315. };
  316. type PaintWorkletRealmInfo = BaseRealmInfo & {
  317. type: 'paint-worklet';
  318. };
  319. type AudioWorkletRealmInfo = BaseRealmInfo & {
  320. type: 'audio-worklet';
  321. };
  322. type WorkletRealmInfo = BaseRealmInfo & {
  323. type: 'worklet';
  324. };
  325. type RealmType = 'window' | 'dedicated-worker' | 'shared-worker' | 'service-worker' | 'worker' | 'paint-worklet' | 'audio-worklet' | 'worklet';
  326. type GetRealmsParameters = {
  327. context?: CommonDataTypes.BrowsingContext;
  328. type?: RealmType;
  329. };
  330. type GetRealmsCommand = {
  331. method: 'script.getRealms';
  332. params: GetRealmsParameters;
  333. };
  334. type GetRealmsResult = {
  335. result: {
  336. realms: RealmInfo[];
  337. };
  338. };
  339. type EvaluateCommand = {
  340. method: 'script.evaluate';
  341. params: EvaluateParameters;
  342. };
  343. type ContextTarget = {
  344. context: CommonDataTypes.BrowsingContext;
  345. sandbox?: string;
  346. };
  347. type RealmTarget = {
  348. realm: Realm;
  349. };
  350. type Target = RealmTarget | ContextTarget;
  351. type ResultOwnership = 'root' | 'none';
  352. type SerializationOptions = {
  353. maxDomDepth?: number | null;
  354. maxObjectDepth?: number | null;
  355. includeShadowTree?: 'none' | 'open' | 'all';
  356. };
  357. type EvaluateParameters = {
  358. expression: string;
  359. awaitPromise: boolean;
  360. target: Target;
  361. resultOwnership?: ResultOwnership;
  362. serializationOptions?: SerializationOptions;
  363. };
  364. type EvaluateResult = {
  365. result: ScriptResult;
  366. };
  367. type DisownCommand = {
  368. method: 'script.disown';
  369. params: EvaluateParameters;
  370. };
  371. type DisownParameters = {
  372. target: Target;
  373. handles: CommonDataTypes.Handle[];
  374. };
  375. type DisownResult = {
  376. result: Record<string, unknown>;
  377. };
  378. type CallFunctionCommand = {
  379. method: 'script.callFunction';
  380. params: CallFunctionParameters;
  381. };
  382. type ArgumentValue = CommonDataTypes.RemoteReference | CommonDataTypes.SharedReference | CommonDataTypes.LocalValue | Script.ChannelValue;
  383. type CallFunctionParameters = {
  384. functionDeclaration: string;
  385. awaitPromise: boolean;
  386. target: Target;
  387. arguments?: ArgumentValue[];
  388. this?: ArgumentValue;
  389. resultOwnership?: ResultOwnership;
  390. serializationOptions?: SerializationOptions;
  391. };
  392. type CallFunctionResult = {
  393. result: ScriptResult;
  394. };
  395. type Source = {
  396. realm: Realm;
  397. context?: CommonDataTypes.BrowsingContext;
  398. };
  399. type StackTrace = {
  400. callFrames: StackFrame[];
  401. };
  402. type StackFrame = {
  403. columnNumber: number;
  404. functionName: string;
  405. lineNumber: number;
  406. url: string;
  407. };
  408. /** The preload script identifier. */
  409. type PreloadScript = string;
  410. type AddPreloadScriptCommand = {
  411. method: 'script.addPreloadScript';
  412. params: AddPreloadScriptParameters;
  413. };
  414. type AddPreloadScriptParameters = {
  415. functionDeclaration: string;
  416. arguments?: ChannelValue[];
  417. sandbox?: string;
  418. context?: CommonDataTypes.BrowsingContext | null;
  419. };
  420. type AddPreloadScriptResult = {
  421. result: {
  422. script: PreloadScript;
  423. };
  424. };
  425. type RemovePreloadScriptCommand = {
  426. method: 'script.removePreloadScript';
  427. params: RemovePreloadScriptParameters;
  428. };
  429. type RemovePreloadScriptParameters = {
  430. script: PreloadScript;
  431. };
  432. type Channel = string;
  433. type ChannelProperties = {
  434. channel: Channel;
  435. serializationOptions?: SerializationOptions;
  436. ownership?: ResultOwnership;
  437. };
  438. type ChannelValue = {
  439. type: 'channel';
  440. value: ChannelProperties;
  441. };
  442. type Message = {
  443. method: 'script.message';
  444. params: MessageParameters;
  445. };
  446. type MessageParameters = {
  447. channel: Channel;
  448. data: CommonDataTypes.RemoteValue;
  449. source: Source;
  450. };
  451. type MessageEvent = EventResponse<EventNames.MessageEvent, Script.MessageParameters>;
  452. type RealmCreatedEvent = EventResponse<EventNames.RealmCreated, RealmInfo>;
  453. type RealmDestroyedParameters = {
  454. realm: Realm;
  455. };
  456. type RealmDestroyedEvent = EventResponse<EventNames.RealmDestroyed, RealmDestroyedParameters>;
  457. enum EventNames {
  458. MessageEvent = "script.message",
  459. RealmCreated = "script.realmCreated",
  460. RealmDestroyed = "script.realmDestroyed"
  461. }
  462. const AllEvents = "script";
  463. }
  464. export declare namespace BrowsingContext {
  465. type Command = CaptureScreenshotCommand | CloseCommand | CreateCommand | GetTreeCommand | NavigateCommand | PrintCommand | ReloadCommand | SetViewportCommand;
  466. type Result = CaptureScreenshotResult | CreateResult | GetTreeResult | NavigateResult | PrintResult;
  467. type Event = ContextCreatedEvent | ContextDestroyedEvent | DomContentLoadedEvent | FragmentNavigatedEvent | LoadEvent | NavigationStartedEvent;
  468. type Navigation = string;
  469. type GetTreeCommand = {
  470. method: 'browsingContext.getTree';
  471. params: GetTreeParameters;
  472. };
  473. type GetTreeParameters = {
  474. maxDepth?: number;
  475. root?: CommonDataTypes.BrowsingContext;
  476. };
  477. type GetTreeResult = {
  478. result: {
  479. contexts: InfoList;
  480. };
  481. };
  482. type InfoList = Info[];
  483. type Info = {
  484. context: CommonDataTypes.BrowsingContext;
  485. parent?: CommonDataTypes.BrowsingContext | null;
  486. url: string;
  487. children: InfoList | null;
  488. };
  489. type NavigateCommand = {
  490. method: 'browsingContext.navigate';
  491. params: NavigateParameters;
  492. };
  493. type ReadinessState = 'none' | 'interactive' | 'complete';
  494. type NavigateParameters = {
  495. context: CommonDataTypes.BrowsingContext;
  496. url: string;
  497. wait?: ReadinessState;
  498. };
  499. type NavigateResult = {
  500. result: {
  501. navigation: Navigation | null;
  502. url: string;
  503. };
  504. };
  505. type ReloadCommand = {
  506. method: 'browsingContext.reload';
  507. params: ReloadParameters;
  508. };
  509. type ReloadParameters = {
  510. context: CommonDataTypes.BrowsingContext;
  511. ignoreCache?: boolean;
  512. wait?: ReadinessState;
  513. };
  514. type CreateCommand = {
  515. method: 'browsingContext.create';
  516. params: CreateParameters;
  517. };
  518. type CreateParameters = {
  519. type: 'tab' | 'window';
  520. referenceContext?: CommonDataTypes.BrowsingContext;
  521. };
  522. type CreateResult = {
  523. result: {
  524. context: CommonDataTypes.BrowsingContext;
  525. };
  526. };
  527. type CloseCommand = {
  528. method: 'browsingContext.close';
  529. params: CloseParameters;
  530. };
  531. type CloseParameters = {
  532. context: CommonDataTypes.BrowsingContext;
  533. };
  534. type CaptureScreenshotCommand = {
  535. method: 'browsingContext.captureScreenshot';
  536. params: CaptureScreenshotParameters;
  537. };
  538. type CaptureScreenshotParameters = {
  539. context: CommonDataTypes.BrowsingContext;
  540. };
  541. type CaptureScreenshotResult = {
  542. result: {
  543. data: string;
  544. };
  545. };
  546. type PrintCommand = {
  547. method: 'browsingContext.print';
  548. params: PrintParameters;
  549. };
  550. type PrintParameters = {
  551. context: CommonDataTypes.BrowsingContext;
  552. background?: boolean;
  553. margin?: PrintMarginParameters;
  554. orientation?: 'portrait' | 'landscape';
  555. page?: PrintPageParams;
  556. pageRanges?: (string | number)[];
  557. scale?: number;
  558. shrinkToFit?: boolean;
  559. };
  560. type PrintMarginParameters = {
  561. bottom?: number;
  562. left?: number;
  563. right?: number;
  564. top?: number;
  565. };
  566. type PrintPageParams = {
  567. height?: number;
  568. width?: number;
  569. };
  570. type PrintResult = {
  571. result: {
  572. data: string;
  573. };
  574. };
  575. type Viewport = {
  576. width: number;
  577. height: number;
  578. };
  579. type SetViewportCommand = {
  580. method: 'browsingContext.setViewport';
  581. params: SetViewportParameters;
  582. };
  583. type SetViewportParameters = {
  584. context: CommonDataTypes.BrowsingContext;
  585. viewport: Viewport | null;
  586. };
  587. type LoadEvent = EventResponse<EventNames.LoadEvent, NavigationInfo>;
  588. type DomContentLoadedEvent = EventResponse<EventNames.DomContentLoadedEvent, NavigationInfo>;
  589. type NavigationInfo = {
  590. context: CommonDataTypes.BrowsingContext;
  591. navigation: Navigation | null;
  592. timestamp: number;
  593. url: string;
  594. };
  595. type ContextCreatedEvent = EventResponse<EventNames.ContextCreatedEvent, BrowsingContext.Info>;
  596. type ContextDestroyedEvent = EventResponse<EventNames.ContextDestroyedEvent, BrowsingContext.Info>;
  597. type FragmentNavigatedEvent = EventResponse<EventNames.FragmentNavigated, BrowsingContext.NavigationInfo>;
  598. type NavigationStartedEvent = EventResponse<EventNames.NavigationStarted, BrowsingContext.NavigationInfo>;
  599. enum EventNames {
  600. ContextCreatedEvent = "browsingContext.contextCreated",
  601. ContextDestroyedEvent = "browsingContext.contextDestroyed",
  602. DomContentLoadedEvent = "browsingContext.domContentLoaded",
  603. FragmentNavigated = "browsingContext.fragmentNavigated",
  604. LoadEvent = "browsingContext.load",
  605. NavigationStarted = "browsingContext.navigationStarted"
  606. }
  607. const AllEvents = "browsingContext";
  608. }
  609. /** @see https://w3c.github.io/webdriver-bidi/#module-log */
  610. export declare namespace Log {
  611. type LogEntry = GenericLogEntry | ConsoleLogEntry | JavascriptLogEntry;
  612. type Event = LogEntryAddedEvent;
  613. type LogLevel = 'debug' | 'info' | 'warn' | 'error';
  614. type BaseLogEntry = {
  615. level: LogLevel;
  616. source: Script.Source;
  617. text: string | null;
  618. timestamp: number;
  619. stackTrace?: Script.StackTrace;
  620. };
  621. type GenericLogEntry = BaseLogEntry & {
  622. type: string;
  623. };
  624. type ConsoleLogEntry = BaseLogEntry & {
  625. type: 'console';
  626. method: string;
  627. args: CommonDataTypes.RemoteValue[];
  628. };
  629. type JavascriptLogEntry = BaseLogEntry & {
  630. type: 'javascript';
  631. };
  632. type LogEntryAddedEvent = EventResponse<EventNames.LogEntryAddedEvent, LogEntry>;
  633. const AllEvents = "log";
  634. enum EventNames {
  635. LogEntryAddedEvent = "log.entryAdded"
  636. }
  637. }
  638. export declare namespace Network {
  639. export type Command = Message.EmptyCommand;
  640. export type Result = Message.EmptyResult;
  641. export type Event = BeforeRequestSentEvent | ResponseCompletedEvent | ResponseStartedEvent | FetchErrorEvent;
  642. export type BeforeRequestSentEvent = EventResponse<EventNames.BeforeRequestSentEvent, BeforeRequestSentParams>;
  643. export type ResponseCompletedEvent = EventResponse<EventNames.ResponseCompletedEvent, ResponseCompletedParams>;
  644. export type ResponseStartedEvent = EventResponse<EventNames.ResponseStartedEvent, ResponseStartedParams>;
  645. export type FetchErrorEvent = EventResponse<EventNames.FetchErrorEvent, FetchErrorParams>;
  646. export type Header = {
  647. name: string;
  648. value?: string;
  649. binaryValue?: number[];
  650. };
  651. export type Cookie = {
  652. name: string;
  653. value?: string;
  654. binaryValue?: number[];
  655. domain: string;
  656. path: string;
  657. expires?: number;
  658. size: number;
  659. httpOnly: boolean;
  660. secure: boolean;
  661. sameSite: 'strict' | 'lax' | 'none';
  662. };
  663. type FetchTimingInfo = {
  664. timeOrigin: number;
  665. requestTime: number;
  666. redirectStart: number;
  667. redirectEnd: number;
  668. fetchStart: number;
  669. dnsStart: number;
  670. dnsEnd: number;
  671. connectStart: number;
  672. connectEnd: number;
  673. tlsStart: number;
  674. requestStart: number;
  675. responseStart: number;
  676. responseEnd: number;
  677. };
  678. export type Request = string;
  679. export type RequestData = {
  680. request: string;
  681. url: string;
  682. method: string;
  683. headers: Header[];
  684. cookies: Cookie[];
  685. headersSize: number;
  686. bodySize: number | null;
  687. timings: FetchTimingInfo;
  688. };
  689. export type BaseParameters = {
  690. context: CommonDataTypes.BrowsingContext | null;
  691. navigation: BrowsingContext.Navigation | null;
  692. redirectCount: number;
  693. request: RequestData;
  694. timestamp: number;
  695. };
  696. export type Initiator = {
  697. type: 'parser' | 'script' | 'preflight' | 'other';
  698. columnNumber?: number;
  699. lineNumber?: number;
  700. stackTrace?: Script.StackTrace;
  701. request?: Request;
  702. };
  703. export type ResponseContent = {
  704. size: number;
  705. };
  706. export type ResponseData = {
  707. url: string;
  708. protocol: string;
  709. status: number;
  710. statusText: string;
  711. fromCache: boolean;
  712. headers: Header[];
  713. mimeType: string;
  714. bytesReceived: number;
  715. headersSize: number | null;
  716. bodySize: number | null;
  717. content: ResponseContent;
  718. };
  719. export type BeforeRequestSentParams = BaseParameters & {
  720. initiator: Initiator;
  721. };
  722. export type ResponseCompletedParams = BaseParameters & {
  723. response: ResponseData;
  724. };
  725. export type ResponseStartedParams = BaseParameters & {
  726. response: ResponseData;
  727. };
  728. export type FetchErrorParams = BaseParameters & {
  729. errorText: string;
  730. };
  731. export const AllEvents = "network";
  732. export enum EventNames {
  733. BeforeRequestSentEvent = "network.beforeRequestSent",
  734. FetchErrorEvent = "network.fetchError",
  735. ResponseStartedEvent = "network.responseStarted",
  736. ResponseCompletedEvent = "network.responseCompleted"
  737. }
  738. export {};
  739. }
  740. export declare namespace Cdp {
  741. type Command = SendCommandCommand | GetSessionCommand;
  742. type Result = SendCommandResult | GetSessionResult;
  743. type Event = EventReceivedEvent;
  744. type SendCommandCommand = {
  745. method: 'cdp.sendCommand';
  746. params: SendCommandParams;
  747. };
  748. type SendCommandParams<Command extends keyof ProtocolMapping.Commands = keyof ProtocolMapping.Commands> = {
  749. method: Command;
  750. params?: ProtocolMapping.Commands[Command]['paramsType'][0];
  751. session?: string;
  752. };
  753. type SendCommandResult = {
  754. result: ProtocolMapping.Commands[keyof ProtocolMapping.Commands]['returnType'];
  755. session?: string;
  756. };
  757. type GetSessionCommand = {
  758. method: 'cdp.getSession';
  759. params: GetSessionParams;
  760. };
  761. type GetSessionParams = {
  762. context: CommonDataTypes.BrowsingContext;
  763. };
  764. type GetSessionResult = {
  765. result: {
  766. session: string | null;
  767. };
  768. };
  769. type EventReceivedEvent = EventResponse<EventNames, EventParams>;
  770. type EventParams<EventName extends keyof ProtocolMapping.Events = keyof ProtocolMapping.Events> = {
  771. event: EventName;
  772. params: ProtocolMapping.Events[EventName];
  773. session: string;
  774. };
  775. type EventNames = `cdp.${keyof ProtocolMapping.Events}`;
  776. }
  777. /** @see https://w3c.github.io/webdriver-bidi/#module-session */
  778. export declare namespace Session {
  779. type Command = StatusCommand | SubscribeCommand | UnsubscribeCommand;
  780. type Result = StatusResult;
  781. type StatusCommand = {
  782. method: 'session.status';
  783. params: Message.EmptyParams;
  784. };
  785. type StatusResult = {
  786. result: {
  787. ready: boolean;
  788. message: string;
  789. };
  790. };
  791. type SubscribeCommand = {
  792. method: 'session.subscribe';
  793. params: SubscriptionRequest;
  794. };
  795. type SubscriptionRequestEvent = Cdp.EventNames | Message.EventNames | Message.AllEvents;
  796. type SubscriptionRequest = {
  797. events: SubscriptionRequestEvent[];
  798. contexts?: CommonDataTypes.BrowsingContext[];
  799. };
  800. type UnsubscribeCommand = {
  801. method: 'session.unsubscribe';
  802. params: SubscriptionRequest;
  803. };
  804. }
  805. /** @see https://w3c.github.io/webdriver-bidi/#module-input */
  806. export declare namespace Input {
  807. type Command = PerformActions | ReleaseActions;
  808. type ElementOrigin = {
  809. type: 'element';
  810. element: CommonDataTypes.SharedReference;
  811. };
  812. type PerformActions = {
  813. method: 'input.performActions';
  814. params: PerformActionsParameters;
  815. };
  816. type PerformActionsParameters = {
  817. context: CommonDataTypes.BrowsingContext;
  818. actions: SourceActions[];
  819. };
  820. type SourceActions = NoneSourceActions | KeySourceActions | PointerSourceActions | WheelSourceActions;
  821. enum SourceActionsType {
  822. None = "none",
  823. Key = "key",
  824. Pointer = "pointer",
  825. Wheel = "wheel"
  826. }
  827. type NoneSourceActions = {
  828. type: SourceActionsType.None;
  829. id: string;
  830. actions: NoneSourceAction[];
  831. };
  832. type NoneSourceAction = PauseAction;
  833. type KeySourceActions = {
  834. type: SourceActionsType.Key;
  835. id: string;
  836. actions: KeySourceAction[];
  837. };
  838. type KeySourceAction = PauseAction | KeyDownAction | KeyUpAction;
  839. type PointerSourceActions = {
  840. type: SourceActionsType.Pointer;
  841. id: string;
  842. parameters?: PointerParameters;
  843. actions: PointerSourceAction[];
  844. };
  845. enum PointerType {
  846. Mouse = "mouse",
  847. Pen = "pen",
  848. Touch = "touch"
  849. }
  850. type PointerParameters = {
  851. /**
  852. * @defaultValue `"mouse"`
  853. */
  854. pointerType?: PointerType;
  855. };
  856. type PointerSourceAction = PauseAction | PointerDownAction | PointerUpAction | PointerMoveAction;
  857. type WheelSourceActions = {
  858. type: SourceActionsType.Wheel;
  859. id: string;
  860. actions: WheelSourceAction[];
  861. };
  862. type WheelSourceAction = PauseAction | WheelScrollAction;
  863. enum ActionType {
  864. Pause = "pause",
  865. KeyDown = "keyDown",
  866. KeyUp = "keyUp",
  867. PointerUp = "pointerUp",
  868. PointerDown = "pointerDown",
  869. PointerMove = "pointerMove",
  870. Scroll = "scroll"
  871. }
  872. type PauseAction = {
  873. type: ActionType.Pause;
  874. duration?: number;
  875. };
  876. type KeyDownAction = {
  877. type: ActionType.KeyDown;
  878. value: string;
  879. };
  880. type KeyUpAction = {
  881. type: ActionType.KeyUp;
  882. value: string;
  883. };
  884. type PointerUpAction = PointerCommonProperties & {
  885. type: ActionType.PointerUp;
  886. button: number;
  887. };
  888. type PointerDownAction = PointerCommonProperties & {
  889. type: ActionType.PointerDown;
  890. button: number;
  891. };
  892. type PointerMoveAction = PointerCommonProperties & {
  893. type: ActionType.PointerMove;
  894. x: number;
  895. y: number;
  896. duration?: number;
  897. origin?: Origin;
  898. };
  899. type WheelScrollAction = {
  900. type: ActionType.Scroll;
  901. x: number;
  902. y: number;
  903. deltaX: number;
  904. deltaY: number;
  905. duration?: number;
  906. /**
  907. * @defaultValue `"viewport"`
  908. */
  909. origin?: Origin;
  910. };
  911. type PointerCommonProperties = {
  912. /**
  913. * @defaultValue `1`
  914. */
  915. width?: number;
  916. /**
  917. * @defaultValue `1`
  918. */
  919. height?: number;
  920. /**
  921. * @defaultValue `0.0`
  922. */
  923. pressure?: number;
  924. /**
  925. * @defaultValue `0.0`
  926. */
  927. tangentialPressure?: number;
  928. /**
  929. * @defaultValue `9`
  930. */
  931. twist?: number;
  932. } & (AngleProperties | TiltProperties);
  933. type AngleProperties = {
  934. /**
  935. * @defaultValue `0.0`
  936. */
  937. altitudeAngle?: number;
  938. /**
  939. * @defaultValue `0.0`
  940. */
  941. azimuthAngle?: number;
  942. };
  943. type TiltProperties = {
  944. /**
  945. * @defaultValue `0`
  946. */
  947. tiltX?: number;
  948. /**
  949. * @defaultValue `0`
  950. */
  951. tiltY?: number;
  952. };
  953. type Origin = 'viewport' | 'pointer' | ElementOrigin;
  954. type ReleaseActions = {
  955. method: 'input.releaseActions';
  956. params: ReleaseActionsParameters;
  957. };
  958. type ReleaseActionsParameters = {
  959. context: CommonDataTypes.BrowsingContext;
  960. };
  961. }
  962. export {};