agent-browser 0.0.0 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierrc +7 -0
- package/README.md +271 -1
- package/bin/agent-browser +2 -0
- package/dist/actions.d.ts +7 -0
- package/dist/actions.d.ts.map +1 -0
- package/dist/actions.js +1138 -0
- package/dist/actions.js.map +1 -0
- package/dist/browser.d.ts +232 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +477 -0
- package/dist/browser.js.map +1 -0
- package/dist/browser.test.d.ts +2 -0
- package/dist/browser.test.d.ts.map +1 -0
- package/dist/browser.test.js +136 -0
- package/dist/browser.test.js.map +1 -0
- package/dist/client.d.ts +17 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +133 -0
- package/dist/client.js.map +1 -0
- package/dist/daemon.d.ts +29 -0
- package/dist/daemon.d.ts.map +1 -0
- package/dist/daemon.js +165 -0
- package/dist/daemon.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +972 -0
- package/dist/index.js.map +1 -0
- package/dist/protocol.d.ts +26 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +717 -0
- package/dist/protocol.js.map +1 -0
- package/dist/protocol.test.d.ts +2 -0
- package/dist/protocol.test.d.ts.map +1 -0
- package/dist/protocol.test.js +176 -0
- package/dist/protocol.test.js.map +1 -0
- package/dist/types.d.ts +604 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +36 -7
- package/src/actions.ts +1658 -0
- package/src/browser.test.ts +157 -0
- package/src/browser.ts +586 -0
- package/src/client.ts +150 -0
- package/src/daemon.ts +187 -0
- package/src/index.ts +984 -0
- package/src/protocol.test.ts +216 -0
- package/src/protocol.ts +848 -0
- package/src/types.ts +913 -0
- package/tsconfig.json +19 -0
- package/vitest.config.ts +9 -0
- package/index.js +0 -2
package/dist/protocol.js
ADDED
|
@@ -0,0 +1,717 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
// Base schema for all commands
|
|
3
|
+
const baseCommandSchema = z.object({
|
|
4
|
+
id: z.string(),
|
|
5
|
+
action: z.string(),
|
|
6
|
+
});
|
|
7
|
+
// Individual action schemas
|
|
8
|
+
const launchSchema = baseCommandSchema.extend({
|
|
9
|
+
action: z.literal('launch'),
|
|
10
|
+
headless: z.boolean().optional(),
|
|
11
|
+
viewport: z
|
|
12
|
+
.object({
|
|
13
|
+
width: z.number().positive(),
|
|
14
|
+
height: z.number().positive(),
|
|
15
|
+
})
|
|
16
|
+
.optional(),
|
|
17
|
+
browser: z.enum(['chromium', 'firefox', 'webkit']).optional(),
|
|
18
|
+
});
|
|
19
|
+
const navigateSchema = baseCommandSchema.extend({
|
|
20
|
+
action: z.literal('navigate'),
|
|
21
|
+
url: z.string().min(1),
|
|
22
|
+
waitUntil: z.enum(['load', 'domcontentloaded', 'networkidle']).optional(),
|
|
23
|
+
});
|
|
24
|
+
const clickSchema = baseCommandSchema.extend({
|
|
25
|
+
action: z.literal('click'),
|
|
26
|
+
selector: z.string().min(1),
|
|
27
|
+
button: z.enum(['left', 'right', 'middle']).optional(),
|
|
28
|
+
clickCount: z.number().positive().optional(),
|
|
29
|
+
delay: z.number().nonnegative().optional(),
|
|
30
|
+
});
|
|
31
|
+
const typeSchema = baseCommandSchema.extend({
|
|
32
|
+
action: z.literal('type'),
|
|
33
|
+
selector: z.string().min(1),
|
|
34
|
+
text: z.string(),
|
|
35
|
+
delay: z.number().nonnegative().optional(),
|
|
36
|
+
clear: z.boolean().optional(),
|
|
37
|
+
});
|
|
38
|
+
const fillSchema = baseCommandSchema.extend({
|
|
39
|
+
action: z.literal('fill'),
|
|
40
|
+
selector: z.string().min(1),
|
|
41
|
+
value: z.string(),
|
|
42
|
+
});
|
|
43
|
+
const checkSchema = baseCommandSchema.extend({
|
|
44
|
+
action: z.literal('check'),
|
|
45
|
+
selector: z.string().min(1),
|
|
46
|
+
});
|
|
47
|
+
const uncheckSchema = baseCommandSchema.extend({
|
|
48
|
+
action: z.literal('uncheck'),
|
|
49
|
+
selector: z.string().min(1),
|
|
50
|
+
});
|
|
51
|
+
const uploadSchema = baseCommandSchema.extend({
|
|
52
|
+
action: z.literal('upload'),
|
|
53
|
+
selector: z.string().min(1),
|
|
54
|
+
files: z.union([z.string(), z.array(z.string())]),
|
|
55
|
+
});
|
|
56
|
+
const dblclickSchema = baseCommandSchema.extend({
|
|
57
|
+
action: z.literal('dblclick'),
|
|
58
|
+
selector: z.string().min(1),
|
|
59
|
+
});
|
|
60
|
+
const focusSchema = baseCommandSchema.extend({
|
|
61
|
+
action: z.literal('focus'),
|
|
62
|
+
selector: z.string().min(1),
|
|
63
|
+
});
|
|
64
|
+
const dragSchema = baseCommandSchema.extend({
|
|
65
|
+
action: z.literal('drag'),
|
|
66
|
+
source: z.string().min(1),
|
|
67
|
+
target: z.string().min(1),
|
|
68
|
+
});
|
|
69
|
+
const frameSchema = baseCommandSchema.extend({
|
|
70
|
+
action: z.literal('frame'),
|
|
71
|
+
selector: z.string().min(1).optional(),
|
|
72
|
+
name: z.string().optional(),
|
|
73
|
+
url: z.string().optional(),
|
|
74
|
+
});
|
|
75
|
+
const mainframeSchema = baseCommandSchema.extend({
|
|
76
|
+
action: z.literal('mainframe'),
|
|
77
|
+
});
|
|
78
|
+
const getByRoleSchema = baseCommandSchema.extend({
|
|
79
|
+
action: z.literal('getbyrole'),
|
|
80
|
+
role: z.string().min(1),
|
|
81
|
+
name: z.string().optional(),
|
|
82
|
+
subaction: z.enum(['click', 'fill', 'check', 'hover']),
|
|
83
|
+
value: z.string().optional(),
|
|
84
|
+
});
|
|
85
|
+
const getByTextSchema = baseCommandSchema.extend({
|
|
86
|
+
action: z.literal('getbytext'),
|
|
87
|
+
text: z.string().min(1),
|
|
88
|
+
exact: z.boolean().optional(),
|
|
89
|
+
subaction: z.enum(['click', 'hover']),
|
|
90
|
+
});
|
|
91
|
+
const getByLabelSchema = baseCommandSchema.extend({
|
|
92
|
+
action: z.literal('getbylabel'),
|
|
93
|
+
label: z.string().min(1),
|
|
94
|
+
subaction: z.enum(['click', 'fill', 'check']),
|
|
95
|
+
value: z.string().optional(),
|
|
96
|
+
});
|
|
97
|
+
const getByPlaceholderSchema = baseCommandSchema.extend({
|
|
98
|
+
action: z.literal('getbyplaceholder'),
|
|
99
|
+
placeholder: z.string().min(1),
|
|
100
|
+
subaction: z.enum(['click', 'fill']),
|
|
101
|
+
value: z.string().optional(),
|
|
102
|
+
});
|
|
103
|
+
const cookiesGetSchema = baseCommandSchema.extend({
|
|
104
|
+
action: z.literal('cookies_get'),
|
|
105
|
+
urls: z.array(z.string()).optional(),
|
|
106
|
+
});
|
|
107
|
+
const cookiesSetSchema = baseCommandSchema.extend({
|
|
108
|
+
action: z.literal('cookies_set'),
|
|
109
|
+
cookies: z.array(z.object({
|
|
110
|
+
name: z.string(),
|
|
111
|
+
value: z.string(),
|
|
112
|
+
url: z.string().optional(),
|
|
113
|
+
domain: z.string().optional(),
|
|
114
|
+
path: z.string().optional(),
|
|
115
|
+
expires: z.number().optional(),
|
|
116
|
+
httpOnly: z.boolean().optional(),
|
|
117
|
+
secure: z.boolean().optional(),
|
|
118
|
+
sameSite: z.enum(['Strict', 'Lax', 'None']).optional(),
|
|
119
|
+
})),
|
|
120
|
+
});
|
|
121
|
+
const cookiesClearSchema = baseCommandSchema.extend({
|
|
122
|
+
action: z.literal('cookies_clear'),
|
|
123
|
+
});
|
|
124
|
+
const storageGetSchema = baseCommandSchema.extend({
|
|
125
|
+
action: z.literal('storage_get'),
|
|
126
|
+
key: z.string().optional(),
|
|
127
|
+
type: z.enum(['local', 'session']),
|
|
128
|
+
});
|
|
129
|
+
const storageSetSchema = baseCommandSchema.extend({
|
|
130
|
+
action: z.literal('storage_set'),
|
|
131
|
+
key: z.string().min(1),
|
|
132
|
+
value: z.string(),
|
|
133
|
+
type: z.enum(['local', 'session']),
|
|
134
|
+
});
|
|
135
|
+
const storageClearSchema = baseCommandSchema.extend({
|
|
136
|
+
action: z.literal('storage_clear'),
|
|
137
|
+
type: z.enum(['local', 'session']),
|
|
138
|
+
});
|
|
139
|
+
const dialogSchema = baseCommandSchema.extend({
|
|
140
|
+
action: z.literal('dialog'),
|
|
141
|
+
response: z.enum(['accept', 'dismiss']),
|
|
142
|
+
promptText: z.string().optional(),
|
|
143
|
+
});
|
|
144
|
+
const pdfSchema = baseCommandSchema.extend({
|
|
145
|
+
action: z.literal('pdf'),
|
|
146
|
+
path: z.string().min(1),
|
|
147
|
+
format: z
|
|
148
|
+
.enum(['Letter', 'Legal', 'Tabloid', 'Ledger', 'A0', 'A1', 'A2', 'A3', 'A4', 'A5', 'A6'])
|
|
149
|
+
.optional(),
|
|
150
|
+
});
|
|
151
|
+
const routeSchema = baseCommandSchema.extend({
|
|
152
|
+
action: z.literal('route'),
|
|
153
|
+
url: z.string().min(1),
|
|
154
|
+
response: z
|
|
155
|
+
.object({
|
|
156
|
+
status: z.number().optional(),
|
|
157
|
+
body: z.string().optional(),
|
|
158
|
+
contentType: z.string().optional(),
|
|
159
|
+
headers: z.record(z.string()).optional(),
|
|
160
|
+
})
|
|
161
|
+
.optional(),
|
|
162
|
+
abort: z.boolean().optional(),
|
|
163
|
+
});
|
|
164
|
+
const unrouteSchema = baseCommandSchema.extend({
|
|
165
|
+
action: z.literal('unroute'),
|
|
166
|
+
url: z.string().optional(),
|
|
167
|
+
});
|
|
168
|
+
const requestsSchema = baseCommandSchema.extend({
|
|
169
|
+
action: z.literal('requests'),
|
|
170
|
+
filter: z.string().optional(),
|
|
171
|
+
clear: z.boolean().optional(),
|
|
172
|
+
});
|
|
173
|
+
const downloadSchema = baseCommandSchema.extend({
|
|
174
|
+
action: z.literal('download'),
|
|
175
|
+
selector: z.string().min(1),
|
|
176
|
+
path: z.string().min(1),
|
|
177
|
+
});
|
|
178
|
+
const geolocationSchema = baseCommandSchema.extend({
|
|
179
|
+
action: z.literal('geolocation'),
|
|
180
|
+
latitude: z.number(),
|
|
181
|
+
longitude: z.number(),
|
|
182
|
+
accuracy: z.number().optional(),
|
|
183
|
+
});
|
|
184
|
+
const permissionsSchema = baseCommandSchema.extend({
|
|
185
|
+
action: z.literal('permissions'),
|
|
186
|
+
permissions: z.array(z.string()),
|
|
187
|
+
grant: z.boolean(),
|
|
188
|
+
});
|
|
189
|
+
const viewportSchema = baseCommandSchema.extend({
|
|
190
|
+
action: z.literal('viewport'),
|
|
191
|
+
width: z.number().positive(),
|
|
192
|
+
height: z.number().positive(),
|
|
193
|
+
});
|
|
194
|
+
const userAgentSchema = baseCommandSchema.extend({
|
|
195
|
+
action: z.literal('useragent'),
|
|
196
|
+
userAgent: z.string().min(1),
|
|
197
|
+
});
|
|
198
|
+
const deviceSchema = baseCommandSchema.extend({
|
|
199
|
+
action: z.literal('device'),
|
|
200
|
+
device: z.string().min(1),
|
|
201
|
+
});
|
|
202
|
+
const backSchema = baseCommandSchema.extend({
|
|
203
|
+
action: z.literal('back'),
|
|
204
|
+
});
|
|
205
|
+
const forwardSchema = baseCommandSchema.extend({
|
|
206
|
+
action: z.literal('forward'),
|
|
207
|
+
});
|
|
208
|
+
const reloadSchema = baseCommandSchema.extend({
|
|
209
|
+
action: z.literal('reload'),
|
|
210
|
+
});
|
|
211
|
+
const urlSchema = baseCommandSchema.extend({
|
|
212
|
+
action: z.literal('url'),
|
|
213
|
+
});
|
|
214
|
+
const titleSchema = baseCommandSchema.extend({
|
|
215
|
+
action: z.literal('title'),
|
|
216
|
+
});
|
|
217
|
+
const getAttributeSchema = baseCommandSchema.extend({
|
|
218
|
+
action: z.literal('getattribute'),
|
|
219
|
+
selector: z.string().min(1),
|
|
220
|
+
attribute: z.string().min(1),
|
|
221
|
+
});
|
|
222
|
+
const getTextSchema = baseCommandSchema.extend({
|
|
223
|
+
action: z.literal('gettext'),
|
|
224
|
+
selector: z.string().min(1),
|
|
225
|
+
});
|
|
226
|
+
const isVisibleSchema = baseCommandSchema.extend({
|
|
227
|
+
action: z.literal('isvisible'),
|
|
228
|
+
selector: z.string().min(1),
|
|
229
|
+
});
|
|
230
|
+
const isEnabledSchema = baseCommandSchema.extend({
|
|
231
|
+
action: z.literal('isenabled'),
|
|
232
|
+
selector: z.string().min(1),
|
|
233
|
+
});
|
|
234
|
+
const isCheckedSchema = baseCommandSchema.extend({
|
|
235
|
+
action: z.literal('ischecked'),
|
|
236
|
+
selector: z.string().min(1),
|
|
237
|
+
});
|
|
238
|
+
const countSchema = baseCommandSchema.extend({
|
|
239
|
+
action: z.literal('count'),
|
|
240
|
+
selector: z.string().min(1),
|
|
241
|
+
});
|
|
242
|
+
const boundingBoxSchema = baseCommandSchema.extend({
|
|
243
|
+
action: z.literal('boundingbox'),
|
|
244
|
+
selector: z.string().min(1),
|
|
245
|
+
});
|
|
246
|
+
const videoStartSchema = baseCommandSchema.extend({
|
|
247
|
+
action: z.literal('video_start'),
|
|
248
|
+
path: z.string().min(1),
|
|
249
|
+
});
|
|
250
|
+
const videoStopSchema = baseCommandSchema.extend({
|
|
251
|
+
action: z.literal('video_stop'),
|
|
252
|
+
});
|
|
253
|
+
const traceStartSchema = baseCommandSchema.extend({
|
|
254
|
+
action: z.literal('trace_start'),
|
|
255
|
+
screenshots: z.boolean().optional(),
|
|
256
|
+
snapshots: z.boolean().optional(),
|
|
257
|
+
});
|
|
258
|
+
const traceStopSchema = baseCommandSchema.extend({
|
|
259
|
+
action: z.literal('trace_stop'),
|
|
260
|
+
path: z.string().min(1),
|
|
261
|
+
});
|
|
262
|
+
const harStartSchema = baseCommandSchema.extend({
|
|
263
|
+
action: z.literal('har_start'),
|
|
264
|
+
});
|
|
265
|
+
const harStopSchema = baseCommandSchema.extend({
|
|
266
|
+
action: z.literal('har_stop'),
|
|
267
|
+
path: z.string().min(1),
|
|
268
|
+
});
|
|
269
|
+
const stateSaveSchema = baseCommandSchema.extend({
|
|
270
|
+
action: z.literal('state_save'),
|
|
271
|
+
path: z.string().min(1),
|
|
272
|
+
});
|
|
273
|
+
const stateLoadSchema = baseCommandSchema.extend({
|
|
274
|
+
action: z.literal('state_load'),
|
|
275
|
+
path: z.string().min(1),
|
|
276
|
+
});
|
|
277
|
+
const consoleSchema = baseCommandSchema.extend({
|
|
278
|
+
action: z.literal('console'),
|
|
279
|
+
clear: z.boolean().optional(),
|
|
280
|
+
});
|
|
281
|
+
const errorsSchema = baseCommandSchema.extend({
|
|
282
|
+
action: z.literal('errors'),
|
|
283
|
+
clear: z.boolean().optional(),
|
|
284
|
+
});
|
|
285
|
+
const keyboardSchema = baseCommandSchema.extend({
|
|
286
|
+
action: z.literal('keyboard'),
|
|
287
|
+
keys: z.string().min(1),
|
|
288
|
+
});
|
|
289
|
+
const wheelSchema = baseCommandSchema.extend({
|
|
290
|
+
action: z.literal('wheel'),
|
|
291
|
+
deltaX: z.number().optional(),
|
|
292
|
+
deltaY: z.number().optional(),
|
|
293
|
+
selector: z.string().optional(),
|
|
294
|
+
});
|
|
295
|
+
const tapSchema = baseCommandSchema.extend({
|
|
296
|
+
action: z.literal('tap'),
|
|
297
|
+
selector: z.string().min(1),
|
|
298
|
+
});
|
|
299
|
+
const clipboardSchema = baseCommandSchema.extend({
|
|
300
|
+
action: z.literal('clipboard'),
|
|
301
|
+
operation: z.enum(['copy', 'paste', 'read']),
|
|
302
|
+
text: z.string().optional(),
|
|
303
|
+
});
|
|
304
|
+
const highlightSchema = baseCommandSchema.extend({
|
|
305
|
+
action: z.literal('highlight'),
|
|
306
|
+
selector: z.string().min(1),
|
|
307
|
+
});
|
|
308
|
+
const clearSchema = baseCommandSchema.extend({
|
|
309
|
+
action: z.literal('clear'),
|
|
310
|
+
selector: z.string().min(1),
|
|
311
|
+
});
|
|
312
|
+
const selectAllSchema = baseCommandSchema.extend({
|
|
313
|
+
action: z.literal('selectall'),
|
|
314
|
+
selector: z.string().min(1),
|
|
315
|
+
});
|
|
316
|
+
const innerTextSchema = baseCommandSchema.extend({
|
|
317
|
+
action: z.literal('innertext'),
|
|
318
|
+
selector: z.string().min(1),
|
|
319
|
+
});
|
|
320
|
+
const innerHtmlSchema = baseCommandSchema.extend({
|
|
321
|
+
action: z.literal('innerhtml'),
|
|
322
|
+
selector: z.string().min(1),
|
|
323
|
+
});
|
|
324
|
+
const inputValueSchema = baseCommandSchema.extend({
|
|
325
|
+
action: z.literal('inputvalue'),
|
|
326
|
+
selector: z.string().min(1),
|
|
327
|
+
});
|
|
328
|
+
const setValueSchema = baseCommandSchema.extend({
|
|
329
|
+
action: z.literal('setvalue'),
|
|
330
|
+
selector: z.string().min(1),
|
|
331
|
+
value: z.string(),
|
|
332
|
+
});
|
|
333
|
+
const dispatchSchema = baseCommandSchema.extend({
|
|
334
|
+
action: z.literal('dispatch'),
|
|
335
|
+
selector: z.string().min(1),
|
|
336
|
+
event: z.string().min(1),
|
|
337
|
+
eventInit: z.record(z.unknown()).optional(),
|
|
338
|
+
});
|
|
339
|
+
const evalHandleSchema = baseCommandSchema.extend({
|
|
340
|
+
action: z.literal('evalhandle'),
|
|
341
|
+
script: z.string().min(1),
|
|
342
|
+
});
|
|
343
|
+
const exposeSchema = baseCommandSchema.extend({
|
|
344
|
+
action: z.literal('expose'),
|
|
345
|
+
name: z.string().min(1),
|
|
346
|
+
});
|
|
347
|
+
const addScriptSchema = baseCommandSchema.extend({
|
|
348
|
+
action: z.literal('addscript'),
|
|
349
|
+
content: z.string().optional(),
|
|
350
|
+
url: z.string().optional(),
|
|
351
|
+
});
|
|
352
|
+
const addStyleSchema = baseCommandSchema.extend({
|
|
353
|
+
action: z.literal('addstyle'),
|
|
354
|
+
content: z.string().optional(),
|
|
355
|
+
url: z.string().optional(),
|
|
356
|
+
});
|
|
357
|
+
const emulateMediaSchema = baseCommandSchema.extend({
|
|
358
|
+
action: z.literal('emulatemedia'),
|
|
359
|
+
media: z.enum(['screen', 'print']).nullable().optional(),
|
|
360
|
+
colorScheme: z.enum(['light', 'dark', 'no-preference']).nullable().optional(),
|
|
361
|
+
reducedMotion: z.enum(['reduce', 'no-preference']).nullable().optional(),
|
|
362
|
+
forcedColors: z.enum(['active', 'none']).nullable().optional(),
|
|
363
|
+
});
|
|
364
|
+
const offlineSchema = baseCommandSchema.extend({
|
|
365
|
+
action: z.literal('offline'),
|
|
366
|
+
offline: z.boolean(),
|
|
367
|
+
});
|
|
368
|
+
const headersSchema = baseCommandSchema.extend({
|
|
369
|
+
action: z.literal('headers'),
|
|
370
|
+
headers: z.record(z.string()),
|
|
371
|
+
});
|
|
372
|
+
const pauseSchema = baseCommandSchema.extend({
|
|
373
|
+
action: z.literal('pause'),
|
|
374
|
+
});
|
|
375
|
+
const getByAltTextSchema = baseCommandSchema.extend({
|
|
376
|
+
action: z.literal('getbyalttext'),
|
|
377
|
+
text: z.string().min(1),
|
|
378
|
+
exact: z.boolean().optional(),
|
|
379
|
+
subaction: z.enum(['click', 'hover']),
|
|
380
|
+
});
|
|
381
|
+
const getByTitleSchema = baseCommandSchema.extend({
|
|
382
|
+
action: z.literal('getbytitle'),
|
|
383
|
+
text: z.string().min(1),
|
|
384
|
+
exact: z.boolean().optional(),
|
|
385
|
+
subaction: z.enum(['click', 'hover']),
|
|
386
|
+
});
|
|
387
|
+
const getByTestIdSchema = baseCommandSchema.extend({
|
|
388
|
+
action: z.literal('getbytestid'),
|
|
389
|
+
testId: z.string().min(1),
|
|
390
|
+
subaction: z.enum(['click', 'fill', 'check', 'hover']),
|
|
391
|
+
value: z.string().optional(),
|
|
392
|
+
});
|
|
393
|
+
const nthSchema = baseCommandSchema.extend({
|
|
394
|
+
action: z.literal('nth'),
|
|
395
|
+
selector: z.string().min(1),
|
|
396
|
+
index: z.number(),
|
|
397
|
+
subaction: z.enum(['click', 'fill', 'check', 'hover', 'text']),
|
|
398
|
+
value: z.string().optional(),
|
|
399
|
+
});
|
|
400
|
+
const waitForUrlSchema = baseCommandSchema.extend({
|
|
401
|
+
action: z.literal('waitforurl'),
|
|
402
|
+
url: z.string().min(1),
|
|
403
|
+
timeout: z.number().positive().optional(),
|
|
404
|
+
});
|
|
405
|
+
const waitForLoadStateSchema = baseCommandSchema.extend({
|
|
406
|
+
action: z.literal('waitforloadstate'),
|
|
407
|
+
state: z.enum(['load', 'domcontentloaded', 'networkidle']),
|
|
408
|
+
timeout: z.number().positive().optional(),
|
|
409
|
+
});
|
|
410
|
+
const setContentSchema = baseCommandSchema.extend({
|
|
411
|
+
action: z.literal('setcontent'),
|
|
412
|
+
html: z.string(),
|
|
413
|
+
});
|
|
414
|
+
const timezoneSchema = baseCommandSchema.extend({
|
|
415
|
+
action: z.literal('timezone'),
|
|
416
|
+
timezone: z.string().min(1),
|
|
417
|
+
});
|
|
418
|
+
const localeSchema = baseCommandSchema.extend({
|
|
419
|
+
action: z.literal('locale'),
|
|
420
|
+
locale: z.string().min(1),
|
|
421
|
+
});
|
|
422
|
+
const credentialsSchema = baseCommandSchema.extend({
|
|
423
|
+
action: z.literal('credentials'),
|
|
424
|
+
username: z.string(),
|
|
425
|
+
password: z.string(),
|
|
426
|
+
});
|
|
427
|
+
const mouseMoveSchema = baseCommandSchema.extend({
|
|
428
|
+
action: z.literal('mousemove'),
|
|
429
|
+
x: z.number(),
|
|
430
|
+
y: z.number(),
|
|
431
|
+
});
|
|
432
|
+
const mouseDownSchema = baseCommandSchema.extend({
|
|
433
|
+
action: z.literal('mousedown'),
|
|
434
|
+
button: z.enum(['left', 'right', 'middle']).optional(),
|
|
435
|
+
});
|
|
436
|
+
const mouseUpSchema = baseCommandSchema.extend({
|
|
437
|
+
action: z.literal('mouseup'),
|
|
438
|
+
button: z.enum(['left', 'right', 'middle']).optional(),
|
|
439
|
+
});
|
|
440
|
+
const bringToFrontSchema = baseCommandSchema.extend({
|
|
441
|
+
action: z.literal('bringtofront'),
|
|
442
|
+
});
|
|
443
|
+
const waitForFunctionSchema = baseCommandSchema.extend({
|
|
444
|
+
action: z.literal('waitforfunction'),
|
|
445
|
+
expression: z.string().min(1),
|
|
446
|
+
timeout: z.number().positive().optional(),
|
|
447
|
+
});
|
|
448
|
+
const scrollIntoViewSchema = baseCommandSchema.extend({
|
|
449
|
+
action: z.literal('scrollintoview'),
|
|
450
|
+
selector: z.string().min(1),
|
|
451
|
+
});
|
|
452
|
+
const addInitScriptSchema = baseCommandSchema.extend({
|
|
453
|
+
action: z.literal('addinitscript'),
|
|
454
|
+
script: z.string().min(1),
|
|
455
|
+
});
|
|
456
|
+
const keyDownSchema = baseCommandSchema.extend({
|
|
457
|
+
action: z.literal('keydown'),
|
|
458
|
+
key: z.string().min(1),
|
|
459
|
+
});
|
|
460
|
+
const keyUpSchema = baseCommandSchema.extend({
|
|
461
|
+
action: z.literal('keyup'),
|
|
462
|
+
key: z.string().min(1),
|
|
463
|
+
});
|
|
464
|
+
const insertTextSchema = baseCommandSchema.extend({
|
|
465
|
+
action: z.literal('inserttext'),
|
|
466
|
+
text: z.string(),
|
|
467
|
+
});
|
|
468
|
+
const multiSelectSchema = baseCommandSchema.extend({
|
|
469
|
+
action: z.literal('multiselect'),
|
|
470
|
+
selector: z.string().min(1),
|
|
471
|
+
values: z.array(z.string()),
|
|
472
|
+
});
|
|
473
|
+
const waitForDownloadSchema = baseCommandSchema.extend({
|
|
474
|
+
action: z.literal('waitfordownload'),
|
|
475
|
+
path: z.string().optional(),
|
|
476
|
+
timeout: z.number().positive().optional(),
|
|
477
|
+
});
|
|
478
|
+
const responseBodySchema = baseCommandSchema.extend({
|
|
479
|
+
action: z.literal('responsebody'),
|
|
480
|
+
url: z.string().min(1),
|
|
481
|
+
timeout: z.number().positive().optional(),
|
|
482
|
+
});
|
|
483
|
+
const pressSchema = baseCommandSchema.extend({
|
|
484
|
+
action: z.literal('press'),
|
|
485
|
+
key: z.string().min(1),
|
|
486
|
+
selector: z.string().min(1).optional(),
|
|
487
|
+
});
|
|
488
|
+
const screenshotSchema = baseCommandSchema.extend({
|
|
489
|
+
action: z.literal('screenshot'),
|
|
490
|
+
path: z.string().optional(),
|
|
491
|
+
fullPage: z.boolean().optional(),
|
|
492
|
+
selector: z.string().min(1).optional(),
|
|
493
|
+
format: z.enum(['png', 'jpeg']).optional(),
|
|
494
|
+
quality: z.number().min(0).max(100).optional(),
|
|
495
|
+
});
|
|
496
|
+
const snapshotSchema = baseCommandSchema.extend({
|
|
497
|
+
action: z.literal('snapshot'),
|
|
498
|
+
});
|
|
499
|
+
const evaluateSchema = baseCommandSchema.extend({
|
|
500
|
+
action: z.literal('evaluate'),
|
|
501
|
+
script: z.string().min(1),
|
|
502
|
+
args: z.array(z.unknown()).optional(),
|
|
503
|
+
});
|
|
504
|
+
const waitSchema = baseCommandSchema.extend({
|
|
505
|
+
action: z.literal('wait'),
|
|
506
|
+
selector: z.string().min(1).optional(),
|
|
507
|
+
timeout: z.number().positive().optional(),
|
|
508
|
+
state: z.enum(['attached', 'detached', 'visible', 'hidden']).optional(),
|
|
509
|
+
});
|
|
510
|
+
const scrollSchema = baseCommandSchema.extend({
|
|
511
|
+
action: z.literal('scroll'),
|
|
512
|
+
selector: z.string().min(1).optional(),
|
|
513
|
+
x: z.number().optional(),
|
|
514
|
+
y: z.number().optional(),
|
|
515
|
+
direction: z.enum(['up', 'down', 'left', 'right']).optional(),
|
|
516
|
+
amount: z.number().positive().optional(),
|
|
517
|
+
});
|
|
518
|
+
const selectSchema = baseCommandSchema.extend({
|
|
519
|
+
action: z.literal('select'),
|
|
520
|
+
selector: z.string().min(1),
|
|
521
|
+
values: z.union([z.string(), z.array(z.string())]),
|
|
522
|
+
});
|
|
523
|
+
const hoverSchema = baseCommandSchema.extend({
|
|
524
|
+
action: z.literal('hover'),
|
|
525
|
+
selector: z.string().min(1),
|
|
526
|
+
});
|
|
527
|
+
const contentSchema = baseCommandSchema.extend({
|
|
528
|
+
action: z.literal('content'),
|
|
529
|
+
selector: z.string().min(1).optional(),
|
|
530
|
+
});
|
|
531
|
+
const closeSchema = baseCommandSchema.extend({
|
|
532
|
+
action: z.literal('close'),
|
|
533
|
+
});
|
|
534
|
+
// Tab/Window schemas
|
|
535
|
+
const tabNewSchema = baseCommandSchema.extend({
|
|
536
|
+
action: z.literal('tab_new'),
|
|
537
|
+
});
|
|
538
|
+
const tabListSchema = baseCommandSchema.extend({
|
|
539
|
+
action: z.literal('tab_list'),
|
|
540
|
+
});
|
|
541
|
+
const tabSwitchSchema = baseCommandSchema.extend({
|
|
542
|
+
action: z.literal('tab_switch'),
|
|
543
|
+
index: z.number().nonnegative(),
|
|
544
|
+
});
|
|
545
|
+
const tabCloseSchema = baseCommandSchema.extend({
|
|
546
|
+
action: z.literal('tab_close'),
|
|
547
|
+
index: z.number().nonnegative().optional(),
|
|
548
|
+
});
|
|
549
|
+
const windowNewSchema = baseCommandSchema.extend({
|
|
550
|
+
action: z.literal('window_new'),
|
|
551
|
+
viewport: z
|
|
552
|
+
.object({
|
|
553
|
+
width: z.number().positive(),
|
|
554
|
+
height: z.number().positive(),
|
|
555
|
+
})
|
|
556
|
+
.optional(),
|
|
557
|
+
});
|
|
558
|
+
// Union schema for all commands
|
|
559
|
+
const commandSchema = z.discriminatedUnion('action', [
|
|
560
|
+
launchSchema,
|
|
561
|
+
navigateSchema,
|
|
562
|
+
clickSchema,
|
|
563
|
+
typeSchema,
|
|
564
|
+
fillSchema,
|
|
565
|
+
checkSchema,
|
|
566
|
+
uncheckSchema,
|
|
567
|
+
uploadSchema,
|
|
568
|
+
dblclickSchema,
|
|
569
|
+
focusSchema,
|
|
570
|
+
dragSchema,
|
|
571
|
+
frameSchema,
|
|
572
|
+
mainframeSchema,
|
|
573
|
+
getByRoleSchema,
|
|
574
|
+
getByTextSchema,
|
|
575
|
+
getByLabelSchema,
|
|
576
|
+
getByPlaceholderSchema,
|
|
577
|
+
pressSchema,
|
|
578
|
+
screenshotSchema,
|
|
579
|
+
snapshotSchema,
|
|
580
|
+
evaluateSchema,
|
|
581
|
+
waitSchema,
|
|
582
|
+
scrollSchema,
|
|
583
|
+
selectSchema,
|
|
584
|
+
hoverSchema,
|
|
585
|
+
contentSchema,
|
|
586
|
+
closeSchema,
|
|
587
|
+
tabNewSchema,
|
|
588
|
+
tabListSchema,
|
|
589
|
+
tabSwitchSchema,
|
|
590
|
+
tabCloseSchema,
|
|
591
|
+
windowNewSchema,
|
|
592
|
+
cookiesGetSchema,
|
|
593
|
+
cookiesSetSchema,
|
|
594
|
+
cookiesClearSchema,
|
|
595
|
+
storageGetSchema,
|
|
596
|
+
storageSetSchema,
|
|
597
|
+
storageClearSchema,
|
|
598
|
+
dialogSchema,
|
|
599
|
+
pdfSchema,
|
|
600
|
+
routeSchema,
|
|
601
|
+
unrouteSchema,
|
|
602
|
+
requestsSchema,
|
|
603
|
+
downloadSchema,
|
|
604
|
+
geolocationSchema,
|
|
605
|
+
permissionsSchema,
|
|
606
|
+
viewportSchema,
|
|
607
|
+
userAgentSchema,
|
|
608
|
+
deviceSchema,
|
|
609
|
+
backSchema,
|
|
610
|
+
forwardSchema,
|
|
611
|
+
reloadSchema,
|
|
612
|
+
urlSchema,
|
|
613
|
+
titleSchema,
|
|
614
|
+
getAttributeSchema,
|
|
615
|
+
getTextSchema,
|
|
616
|
+
isVisibleSchema,
|
|
617
|
+
isEnabledSchema,
|
|
618
|
+
isCheckedSchema,
|
|
619
|
+
countSchema,
|
|
620
|
+
boundingBoxSchema,
|
|
621
|
+
videoStartSchema,
|
|
622
|
+
videoStopSchema,
|
|
623
|
+
traceStartSchema,
|
|
624
|
+
traceStopSchema,
|
|
625
|
+
harStartSchema,
|
|
626
|
+
harStopSchema,
|
|
627
|
+
stateSaveSchema,
|
|
628
|
+
stateLoadSchema,
|
|
629
|
+
consoleSchema,
|
|
630
|
+
errorsSchema,
|
|
631
|
+
keyboardSchema,
|
|
632
|
+
wheelSchema,
|
|
633
|
+
tapSchema,
|
|
634
|
+
clipboardSchema,
|
|
635
|
+
highlightSchema,
|
|
636
|
+
clearSchema,
|
|
637
|
+
selectAllSchema,
|
|
638
|
+
innerTextSchema,
|
|
639
|
+
innerHtmlSchema,
|
|
640
|
+
inputValueSchema,
|
|
641
|
+
setValueSchema,
|
|
642
|
+
dispatchSchema,
|
|
643
|
+
evalHandleSchema,
|
|
644
|
+
exposeSchema,
|
|
645
|
+
addScriptSchema,
|
|
646
|
+
addStyleSchema,
|
|
647
|
+
emulateMediaSchema,
|
|
648
|
+
offlineSchema,
|
|
649
|
+
headersSchema,
|
|
650
|
+
pauseSchema,
|
|
651
|
+
getByAltTextSchema,
|
|
652
|
+
getByTitleSchema,
|
|
653
|
+
getByTestIdSchema,
|
|
654
|
+
nthSchema,
|
|
655
|
+
waitForUrlSchema,
|
|
656
|
+
waitForLoadStateSchema,
|
|
657
|
+
setContentSchema,
|
|
658
|
+
timezoneSchema,
|
|
659
|
+
localeSchema,
|
|
660
|
+
credentialsSchema,
|
|
661
|
+
mouseMoveSchema,
|
|
662
|
+
mouseDownSchema,
|
|
663
|
+
mouseUpSchema,
|
|
664
|
+
bringToFrontSchema,
|
|
665
|
+
waitForFunctionSchema,
|
|
666
|
+
scrollIntoViewSchema,
|
|
667
|
+
addInitScriptSchema,
|
|
668
|
+
keyDownSchema,
|
|
669
|
+
keyUpSchema,
|
|
670
|
+
insertTextSchema,
|
|
671
|
+
multiSelectSchema,
|
|
672
|
+
waitForDownloadSchema,
|
|
673
|
+
responseBodySchema,
|
|
674
|
+
]);
|
|
675
|
+
/**
|
|
676
|
+
* Parse a JSON string into a validated command
|
|
677
|
+
*/
|
|
678
|
+
export function parseCommand(input) {
|
|
679
|
+
// First, try to parse JSON
|
|
680
|
+
let json;
|
|
681
|
+
try {
|
|
682
|
+
json = JSON.parse(input);
|
|
683
|
+
}
|
|
684
|
+
catch {
|
|
685
|
+
return { success: false, error: 'Invalid JSON' };
|
|
686
|
+
}
|
|
687
|
+
// Extract id for error responses if possible
|
|
688
|
+
const id = typeof json === 'object' && json !== null && 'id' in json
|
|
689
|
+
? String(json.id)
|
|
690
|
+
: undefined;
|
|
691
|
+
// Validate against schema
|
|
692
|
+
const result = commandSchema.safeParse(json);
|
|
693
|
+
if (!result.success) {
|
|
694
|
+
const errors = result.error.errors.map((e) => `${e.path.join('.')}: ${e.message}`).join(', ');
|
|
695
|
+
return { success: false, error: `Validation error: ${errors}`, id };
|
|
696
|
+
}
|
|
697
|
+
return { success: true, command: result.data };
|
|
698
|
+
}
|
|
699
|
+
/**
|
|
700
|
+
* Create a success response
|
|
701
|
+
*/
|
|
702
|
+
export function successResponse(id, data) {
|
|
703
|
+
return { id, success: true, data };
|
|
704
|
+
}
|
|
705
|
+
/**
|
|
706
|
+
* Create an error response
|
|
707
|
+
*/
|
|
708
|
+
export function errorResponse(id, error) {
|
|
709
|
+
return { id, success: false, error };
|
|
710
|
+
}
|
|
711
|
+
/**
|
|
712
|
+
* Serialize a response to JSON string
|
|
713
|
+
*/
|
|
714
|
+
export function serializeResponse(response) {
|
|
715
|
+
return JSON.stringify(response);
|
|
716
|
+
}
|
|
717
|
+
//# sourceMappingURL=protocol.js.map
|