protocol-parser.d.ts 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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 parsing and validator for WebDriver BiDi protocol.
  19. * Parser types should match the `../protocol` types.
  20. */
  21. import { type ZodType, z as zod } from 'zod';
  22. import { BrowsingContext as BrowsingContextTypes, Script as ScriptTypes, type Cdp as CdpTypes, type Session as SessionTypes, type CommonDataTypes as CommonDataTypesTypes, Input as InputTypes } from '../protocol/protocol.js';
  23. export declare function parseObject<T extends ZodType>(obj: object, schema: T): zod.infer<T>;
  24. export declare namespace CommonDataTypes {
  25. const SharedReferenceSchema: zod.ZodObject<{
  26. sharedId: zod.ZodString;
  27. handle: zod.ZodOptional<zod.ZodString>;
  28. }, "strip", zod.ZodTypeAny, {
  29. sharedId: string;
  30. handle?: string | undefined;
  31. }, {
  32. sharedId: string;
  33. handle?: string | undefined;
  34. }>;
  35. const RemoteReferenceSchema: zod.ZodObject<{
  36. handle: zod.ZodString;
  37. }, "strip", zod.ZodTypeAny, {
  38. handle: string;
  39. }, {
  40. handle: string;
  41. }>;
  42. const LocalValueSchema: zod.ZodType<CommonDataTypesTypes.LocalValue>;
  43. const BrowsingContextSchema: zod.ZodString;
  44. const MaxDepthSchema: zod.ZodNumber;
  45. }
  46. /** @see https://w3c.github.io/webdriver-bidi/#module-script */
  47. export declare namespace Script {
  48. const GetRealmsParametersSchema: zod.ZodObject<{
  49. context: zod.ZodOptional<zod.ZodString>;
  50. type: zod.ZodOptional<zod.ZodEnum<["window", "dedicated-worker", "shared-worker", "service-worker", "worker", "paint-worklet", "audio-worklet", "worklet"]>>;
  51. }, "strip", zod.ZodTypeAny, {
  52. context?: string | undefined;
  53. type?: "worker" | "window" | "dedicated-worker" | "shared-worker" | "service-worker" | "paint-worklet" | "audio-worklet" | "worklet" | undefined;
  54. }, {
  55. context?: string | undefined;
  56. type?: "worker" | "window" | "dedicated-worker" | "shared-worker" | "service-worker" | "paint-worklet" | "audio-worklet" | "worklet" | undefined;
  57. }>;
  58. function parseGetRealmsParams(params: object): ScriptTypes.GetRealmsParameters;
  59. function parseEvaluateParams(params: object): ScriptTypes.EvaluateParameters;
  60. function parseDisownParams(params: object): ScriptTypes.DisownParameters;
  61. const ChannelValueSchema: zod.ZodObject<{
  62. type: zod.ZodLiteral<"channel">;
  63. value: zod.ZodObject<{
  64. channel: zod.ZodString;
  65. serializationOptions: zod.ZodOptional<zod.ZodObject<{
  66. maxDomDepth: zod.ZodOptional<zod.ZodUnion<[zod.ZodNull, zod.ZodNumber]>>;
  67. maxObjectDepth: zod.ZodOptional<zod.ZodUnion<[zod.ZodNull, zod.ZodNumber]>>;
  68. includeShadowTree: zod.ZodOptional<zod.ZodEnum<["none", "open", "all"]>>;
  69. }, "strip", zod.ZodTypeAny, {
  70. maxDomDepth?: number | null | undefined;
  71. maxObjectDepth?: number | null | undefined;
  72. includeShadowTree?: "none" | "all" | "open" | undefined;
  73. }, {
  74. maxDomDepth?: number | null | undefined;
  75. maxObjectDepth?: number | null | undefined;
  76. includeShadowTree?: "none" | "all" | "open" | undefined;
  77. }>>;
  78. ownership: zod.ZodOptional<zod.ZodEnum<["root", "none"]>>;
  79. }, "strip", zod.ZodTypeAny, {
  80. channel: string;
  81. serializationOptions?: {
  82. maxDomDepth?: number | null | undefined;
  83. maxObjectDepth?: number | null | undefined;
  84. includeShadowTree?: "none" | "all" | "open" | undefined;
  85. } | undefined;
  86. ownership?: "none" | "root" | undefined;
  87. }, {
  88. channel: string;
  89. serializationOptions?: {
  90. maxDomDepth?: number | null | undefined;
  91. maxObjectDepth?: number | null | undefined;
  92. includeShadowTree?: "none" | "all" | "open" | undefined;
  93. } | undefined;
  94. ownership?: "none" | "root" | undefined;
  95. }>;
  96. }, "strip", zod.ZodTypeAny, {
  97. type: "channel";
  98. value: {
  99. channel: string;
  100. serializationOptions?: {
  101. maxDomDepth?: number | null | undefined;
  102. maxObjectDepth?: number | null | undefined;
  103. includeShadowTree?: "none" | "all" | "open" | undefined;
  104. } | undefined;
  105. ownership?: "none" | "root" | undefined;
  106. };
  107. }, {
  108. type: "channel";
  109. value: {
  110. channel: string;
  111. serializationOptions?: {
  112. maxDomDepth?: number | null | undefined;
  113. maxObjectDepth?: number | null | undefined;
  114. includeShadowTree?: "none" | "all" | "open" | undefined;
  115. } | undefined;
  116. ownership?: "none" | "root" | undefined;
  117. };
  118. }>;
  119. const PreloadScriptSchema: zod.ZodString;
  120. const AddPreloadScriptParametersSchema: zod.ZodObject<{
  121. functionDeclaration: zod.ZodString;
  122. arguments: zod.ZodOptional<zod.ZodArray<zod.ZodObject<{
  123. type: zod.ZodLiteral<"channel">;
  124. value: zod.ZodObject<{
  125. channel: zod.ZodString;
  126. serializationOptions: zod.ZodOptional<zod.ZodObject<{
  127. maxDomDepth: zod.ZodOptional<zod.ZodUnion<[zod.ZodNull, zod.ZodNumber]>>;
  128. maxObjectDepth: zod.ZodOptional<zod.ZodUnion<[zod.ZodNull, zod.ZodNumber]>>;
  129. includeShadowTree: zod.ZodOptional<zod.ZodEnum<["none", "open", "all"]>>;
  130. }, "strip", zod.ZodTypeAny, {
  131. maxDomDepth?: number | null | undefined;
  132. maxObjectDepth?: number | null | undefined;
  133. includeShadowTree?: "none" | "all" | "open" | undefined;
  134. }, {
  135. maxDomDepth?: number | null | undefined;
  136. maxObjectDepth?: number | null | undefined;
  137. includeShadowTree?: "none" | "all" | "open" | undefined;
  138. }>>;
  139. ownership: zod.ZodOptional<zod.ZodEnum<["root", "none"]>>;
  140. }, "strip", zod.ZodTypeAny, {
  141. channel: string;
  142. serializationOptions?: {
  143. maxDomDepth?: number | null | undefined;
  144. maxObjectDepth?: number | null | undefined;
  145. includeShadowTree?: "none" | "all" | "open" | undefined;
  146. } | undefined;
  147. ownership?: "none" | "root" | undefined;
  148. }, {
  149. channel: string;
  150. serializationOptions?: {
  151. maxDomDepth?: number | null | undefined;
  152. maxObjectDepth?: number | null | undefined;
  153. includeShadowTree?: "none" | "all" | "open" | undefined;
  154. } | undefined;
  155. ownership?: "none" | "root" | undefined;
  156. }>;
  157. }, "strip", zod.ZodTypeAny, {
  158. type: "channel";
  159. value: {
  160. channel: string;
  161. serializationOptions?: {
  162. maxDomDepth?: number | null | undefined;
  163. maxObjectDepth?: number | null | undefined;
  164. includeShadowTree?: "none" | "all" | "open" | undefined;
  165. } | undefined;
  166. ownership?: "none" | "root" | undefined;
  167. };
  168. }, {
  169. type: "channel";
  170. value: {
  171. channel: string;
  172. serializationOptions?: {
  173. maxDomDepth?: number | null | undefined;
  174. maxObjectDepth?: number | null | undefined;
  175. includeShadowTree?: "none" | "all" | "open" | undefined;
  176. } | undefined;
  177. ownership?: "none" | "root" | undefined;
  178. };
  179. }>, "many">>;
  180. sandbox: zod.ZodOptional<zod.ZodString>;
  181. context: zod.ZodOptional<zod.ZodString>;
  182. }, "strip", zod.ZodTypeAny, {
  183. functionDeclaration: string;
  184. arguments?: {
  185. type: "channel";
  186. value: {
  187. channel: string;
  188. serializationOptions?: {
  189. maxDomDepth?: number | null | undefined;
  190. maxObjectDepth?: number | null | undefined;
  191. includeShadowTree?: "none" | "all" | "open" | undefined;
  192. } | undefined;
  193. ownership?: "none" | "root" | undefined;
  194. };
  195. }[] | undefined;
  196. sandbox?: string | undefined;
  197. context?: string | undefined;
  198. }, {
  199. functionDeclaration: string;
  200. arguments?: {
  201. type: "channel";
  202. value: {
  203. channel: string;
  204. serializationOptions?: {
  205. maxDomDepth?: number | null | undefined;
  206. maxObjectDepth?: number | null | undefined;
  207. includeShadowTree?: "none" | "all" | "open" | undefined;
  208. } | undefined;
  209. ownership?: "none" | "root" | undefined;
  210. };
  211. }[] | undefined;
  212. sandbox?: string | undefined;
  213. context?: string | undefined;
  214. }>;
  215. function parseAddPreloadScriptParams(params: object): ScriptTypes.AddPreloadScriptParameters;
  216. const RemovePreloadScriptParametersSchema: zod.ZodObject<{
  217. script: zod.ZodString;
  218. }, "strip", zod.ZodTypeAny, {
  219. script: string;
  220. }, {
  221. script: string;
  222. }>;
  223. function parseRemovePreloadScriptParams(params: object): ScriptTypes.RemovePreloadScriptParameters;
  224. function parseCallFunctionParams(params: object): ScriptTypes.CallFunctionParameters;
  225. }
  226. /** @see https://w3c.github.io/webdriver-bidi/#module-browsingContext */
  227. export declare namespace BrowsingContext {
  228. function parseGetTreeParams(params: object): BrowsingContextTypes.GetTreeParameters;
  229. function parseNavigateParams(params: object): BrowsingContextTypes.NavigateParameters;
  230. function parseReloadParams(params: object): BrowsingContextTypes.ReloadParameters;
  231. function parseCreateParams(params: object): BrowsingContextTypes.CreateParameters;
  232. function parseCloseParams(params: object): BrowsingContextTypes.CloseParameters;
  233. function parseCaptureScreenshotParams(params: object): BrowsingContextTypes.CaptureScreenshotParameters;
  234. function parsePrintParams(params: object): BrowsingContextTypes.PrintParameters;
  235. function parseSetViewportParams(params: object): BrowsingContextTypes.SetViewportParameters;
  236. }
  237. export declare namespace Cdp {
  238. function parseSendCommandParams(params: object): CdpTypes.SendCommandParams;
  239. function parseGetSessionParams(params: object): CdpTypes.GetSessionParams;
  240. }
  241. /** @see https://w3c.github.io/webdriver-bidi/#module-session */
  242. export declare namespace Session {
  243. function parseSubscribeParams(params: object): SessionTypes.SubscriptionRequest;
  244. }
  245. /** @see https://w3c.github.io/webdriver-bidi/#module-input */
  246. export declare namespace Input {
  247. function parsePerformActionsParams(params: object): InputTypes.PerformActionsParameters;
  248. function parseReleaseActionsParams(params: object): InputTypes.ReleaseActionsParameters;
  249. }