agent-browser-stealth 0.17.0-fork.2 → 0.24.0-fork.2

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.
Files changed (122) hide show
  1. package/README.md +1256 -240
  2. package/bin/agent-browser-darwin-arm64 +0 -0
  3. package/bin/agent-browser-darwin-x64 +0 -0
  4. package/bin/agent-browser-linux-arm64 +0 -0
  5. package/bin/agent-browser-linux-x64 +0 -0
  6. package/bin/agent-browser-win32-x64.exe +0 -0
  7. package/bin/agent-browser.js +13 -2
  8. package/extensions/tab-group-cdp/content-script.js +425 -0
  9. package/extensions/tab-group-cdp/icons/icon.svg +7 -0
  10. package/extensions/tab-group-cdp/manifest.json +34 -0
  11. package/extensions/tab-group-cdp/page-bridge.js +133 -0
  12. package/extensions/tab-group-cdp/service-worker.js +2249 -0
  13. package/extensions/tab-group-cdp/sidepanel.css +258 -0
  14. package/extensions/tab-group-cdp/sidepanel.html +28 -0
  15. package/extensions/tab-group-cdp/sidepanel.js +1225 -0
  16. package/package.json +17 -69
  17. package/scripts/build-all-platforms.sh +6 -0
  18. package/scripts/check-version-sync.js +14 -2
  19. package/scripts/copy-native.js +8 -50
  20. package/scripts/postinstall.js +149 -165
  21. package/scripts/windows-debug/provision.sh +220 -0
  22. package/scripts/windows-debug/run.sh +92 -0
  23. package/scripts/windows-debug/start.sh +43 -0
  24. package/scripts/windows-debug/stop.sh +28 -0
  25. package/scripts/windows-debug/sync.sh +27 -0
  26. package/skills/agent-browser/SKILL.md +256 -159
  27. package/skills/agent-browser/references/authentication.md +101 -0
  28. package/skills/agent-browser/references/commands.md +34 -2
  29. package/skills/agent-browser/references/snapshot-refs.md +25 -0
  30. package/skills/agentcore/SKILL.md +115 -0
  31. package/skills/dogfood/SKILL.md +4 -2
  32. package/skills/electron/SKILL.md +26 -2
  33. package/skills/slack/SKILL.md +0 -9
  34. package/skills/slack/references/slack-tasks.md +2 -8
  35. package/skills/vercel-sandbox/SKILL.md +280 -0
  36. package/bin/agent-browser-local +0 -0
  37. package/bin/agent-browser-stealth +0 -0
  38. package/bin/agent-browser-stealth.d +0 -1
  39. package/dist/action-policy.d.ts +0 -14
  40. package/dist/action-policy.d.ts.map +0 -1
  41. package/dist/action-policy.js +0 -253
  42. package/dist/action-policy.js.map +0 -1
  43. package/dist/actions.d.ts +0 -21
  44. package/dist/actions.d.ts.map +0 -1
  45. package/dist/actions.js +0 -2139
  46. package/dist/actions.js.map +0 -1
  47. package/dist/auth-cli.d.ts +0 -2
  48. package/dist/auth-cli.d.ts.map +0 -1
  49. package/dist/auth-cli.js +0 -97
  50. package/dist/auth-cli.js.map +0 -1
  51. package/dist/auth-vault.d.ts +0 -36
  52. package/dist/auth-vault.d.ts.map +0 -1
  53. package/dist/auth-vault.js +0 -125
  54. package/dist/auth-vault.js.map +0 -1
  55. package/dist/browser.d.ts +0 -665
  56. package/dist/browser.d.ts.map +0 -1
  57. package/dist/browser.js +0 -3210
  58. package/dist/browser.js.map +0 -1
  59. package/dist/confirmation.d.ts +0 -8
  60. package/dist/confirmation.d.ts.map +0 -1
  61. package/dist/confirmation.js +0 -30
  62. package/dist/confirmation.js.map +0 -1
  63. package/dist/daemon.d.ts +0 -78
  64. package/dist/daemon.d.ts.map +0 -1
  65. package/dist/daemon.js +0 -744
  66. package/dist/daemon.js.map +0 -1
  67. package/dist/diff.d.ts +0 -18
  68. package/dist/diff.d.ts.map +0 -1
  69. package/dist/diff.js +0 -271
  70. package/dist/diff.js.map +0 -1
  71. package/dist/domain-filter.d.ts +0 -28
  72. package/dist/domain-filter.d.ts.map +0 -1
  73. package/dist/domain-filter.js +0 -149
  74. package/dist/domain-filter.js.map +0 -1
  75. package/dist/encryption.d.ts +0 -73
  76. package/dist/encryption.d.ts.map +0 -1
  77. package/dist/encryption.js +0 -171
  78. package/dist/encryption.js.map +0 -1
  79. package/dist/ios-actions.d.ts +0 -11
  80. package/dist/ios-actions.d.ts.map +0 -1
  81. package/dist/ios-actions.js +0 -228
  82. package/dist/ios-actions.js.map +0 -1
  83. package/dist/ios-manager.d.ts +0 -266
  84. package/dist/ios-manager.d.ts.map +0 -1
  85. package/dist/ios-manager.js +0 -1073
  86. package/dist/ios-manager.js.map +0 -1
  87. package/dist/protocol.d.ts +0 -26
  88. package/dist/protocol.d.ts.map +0 -1
  89. package/dist/protocol.js +0 -990
  90. package/dist/protocol.js.map +0 -1
  91. package/dist/snapshot.d.ts +0 -67
  92. package/dist/snapshot.d.ts.map +0 -1
  93. package/dist/snapshot.js +0 -514
  94. package/dist/snapshot.js.map +0 -1
  95. package/dist/state-utils.d.ts +0 -77
  96. package/dist/state-utils.d.ts.map +0 -1
  97. package/dist/state-utils.js +0 -178
  98. package/dist/state-utils.js.map +0 -1
  99. package/dist/stealth.d.ts +0 -41
  100. package/dist/stealth.d.ts.map +0 -1
  101. package/dist/stealth.js +0 -1743
  102. package/dist/stealth.js.map +0 -1
  103. package/dist/stream-server.d.ts +0 -117
  104. package/dist/stream-server.d.ts.map +0 -1
  105. package/dist/stream-server.js +0 -309
  106. package/dist/stream-server.js.map +0 -1
  107. package/dist/types.d.ts +0 -973
  108. package/dist/types.d.ts.map +0 -1
  109. package/dist/types.js +0 -2
  110. package/dist/types.js.map +0 -1
  111. package/scripts/check-creepjs-headless.js +0 -137
  112. package/scripts/check-daemon-pid-recovery.js +0 -148
  113. package/scripts/check-sannysoft-webdriver.js +0 -112
  114. package/scripts/check-stealth-regression.js +0 -199
  115. package/scripts/check-turnstile-testkey.ts +0 -125
  116. package/scripts/clawhub-sync.sh +0 -27
  117. package/scripts/sync-upstream.sh +0 -142
  118. package/scripts/verify-bundled-binaries.js +0 -71
  119. package/scripts/verify-native-version.js +0 -48
  120. package/scripts/verify-packed-host-binary.js +0 -88
  121. package/scripts/verify-registry-host-binary.js +0 -120
  122. package/skills/agent-browser-stealth/SKILL.md +0 -127
package/dist/protocol.js DELETED
@@ -1,990 +0,0 @@
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
- .nullable()
17
- .optional(),
18
- browser: z.enum(['chromium', 'firefox', 'webkit']).optional(),
19
- cdpPort: z.number().positive().optional(),
20
- cdpUrl: z
21
- .string()
22
- .url()
23
- .refine((url) => url.startsWith('ws://') ||
24
- url.startsWith('wss://') ||
25
- url.startsWith('http://') ||
26
- url.startsWith('https://'), { message: 'CDP URL must start with ws://, wss://, http://, or https://' })
27
- .optional(),
28
- autoConnect: z.boolean().optional(),
29
- executablePath: z.string().optional(),
30
- extensions: z.array(z.string()).optional(),
31
- headers: z.record(z.string()).optional(),
32
- proxy: z
33
- .object({
34
- server: z.string().min(1),
35
- bypass: z.string().optional(),
36
- username: z.string().optional(),
37
- password: z.string().optional(),
38
- })
39
- .optional(),
40
- args: z.array(z.string()).optional(),
41
- userAgent: z.string().optional(),
42
- provider: z.string().optional(),
43
- ignoreHTTPSErrors: z.boolean().optional(),
44
- allowFileAccess: z.boolean().optional(),
45
- colorScheme: z.enum(['light', 'dark', 'no-preference']).optional(),
46
- downloadPath: z.string().optional(),
47
- tabGroup: z.string().min(1).optional(),
48
- tabGroupPluginId: z.string().min(1).optional(),
49
- storageState: z.string().optional(),
50
- allowedDomains: z.array(z.string()).optional(),
51
- actionPolicy: z.string().optional(),
52
- confirmActions: z.array(z.string()).optional(),
53
- engine: z.enum(['chrome', 'lightpanda']).optional(),
54
- });
55
- const navigateSchema = baseCommandSchema.extend({
56
- action: z.literal('navigate'),
57
- url: z.string().min(1),
58
- waitUntil: z.enum(['load', 'domcontentloaded', 'networkidle']).optional(),
59
- headers: z.record(z.string()).optional(),
60
- riskMode: z.enum(['off', 'warn', 'block']).optional(),
61
- });
62
- const clickSchema = baseCommandSchema.extend({
63
- action: z.literal('click'),
64
- selector: z.string().min(1),
65
- button: z.enum(['left', 'right', 'middle']).optional(),
66
- clickCount: z.number().positive().optional(),
67
- delay: z.number().nonnegative().optional(),
68
- newTab: z.boolean().optional(),
69
- });
70
- const typeSchema = baseCommandSchema.extend({
71
- action: z.literal('type'),
72
- selector: z.string().min(1),
73
- text: z.string(),
74
- delay: z.number().nonnegative().optional(),
75
- clear: z.boolean().optional(),
76
- });
77
- const fillSchema = baseCommandSchema.extend({
78
- action: z.literal('fill'),
79
- selector: z.string().min(1),
80
- value: z.string(),
81
- });
82
- const checkSchema = baseCommandSchema.extend({
83
- action: z.literal('check'),
84
- selector: z.string().min(1),
85
- });
86
- const uncheckSchema = baseCommandSchema.extend({
87
- action: z.literal('uncheck'),
88
- selector: z.string().min(1),
89
- });
90
- const uploadSchema = baseCommandSchema.extend({
91
- action: z.literal('upload'),
92
- selector: z.string().min(1),
93
- files: z.union([z.string(), z.array(z.string())]),
94
- });
95
- const dblclickSchema = baseCommandSchema.extend({
96
- action: z.literal('dblclick'),
97
- selector: z.string().min(1),
98
- });
99
- const focusSchema = baseCommandSchema.extend({
100
- action: z.literal('focus'),
101
- selector: z.string().min(1),
102
- });
103
- const dragSchema = baseCommandSchema.extend({
104
- action: z.literal('drag'),
105
- source: z.string().min(1),
106
- target: z.string().min(1),
107
- });
108
- const frameSchema = baseCommandSchema.extend({
109
- action: z.literal('frame'),
110
- selector: z.string().min(1).optional(),
111
- name: z.string().optional(),
112
- url: z.string().optional(),
113
- });
114
- const mainframeSchema = baseCommandSchema.extend({
115
- action: z.literal('mainframe'),
116
- });
117
- const getByRoleSchema = baseCommandSchema.extend({
118
- action: z.literal('getbyrole'),
119
- role: z.string().min(1),
120
- name: z.string().optional(),
121
- exact: z.boolean().optional(),
122
- subaction: z.enum(['click', 'fill', 'check', 'hover']),
123
- value: z.string().optional(),
124
- });
125
- const getByTextSchema = baseCommandSchema.extend({
126
- action: z.literal('getbytext'),
127
- text: z.string().min(1),
128
- exact: z.boolean().optional(),
129
- subaction: z.enum(['click', 'hover']),
130
- });
131
- const getByLabelSchema = baseCommandSchema.extend({
132
- action: z.literal('getbylabel'),
133
- label: z.string().min(1),
134
- exact: z.boolean().optional(),
135
- subaction: z.enum(['click', 'fill', 'check']),
136
- value: z.string().optional(),
137
- });
138
- const getByPlaceholderSchema = baseCommandSchema.extend({
139
- action: z.literal('getbyplaceholder'),
140
- placeholder: z.string().min(1),
141
- exact: z.boolean().optional(),
142
- subaction: z.enum(['click', 'fill']),
143
- value: z.string().optional(),
144
- });
145
- const cookiesGetSchema = baseCommandSchema.extend({
146
- action: z.literal('cookies_get'),
147
- urls: z.array(z.string()).optional(),
148
- });
149
- const cookiesSetSchema = baseCommandSchema.extend({
150
- action: z.literal('cookies_set'),
151
- cookies: z.array(z.object({
152
- name: z.string(),
153
- value: z.string(),
154
- url: z.string().optional(),
155
- domain: z.string().optional(),
156
- path: z.string().optional(),
157
- expires: z.number().optional(),
158
- httpOnly: z.boolean().optional(),
159
- secure: z.boolean().optional(),
160
- sameSite: z.enum(['Strict', 'Lax', 'None']).optional(),
161
- })),
162
- });
163
- const cookiesClearSchema = baseCommandSchema.extend({
164
- action: z.literal('cookies_clear'),
165
- });
166
- const storageGetSchema = baseCommandSchema.extend({
167
- action: z.literal('storage_get'),
168
- key: z.string().optional(),
169
- type: z.enum(['local', 'session']),
170
- });
171
- const storageSetSchema = baseCommandSchema.extend({
172
- action: z.literal('storage_set'),
173
- key: z.string().min(1),
174
- value: z.string(),
175
- type: z.enum(['local', 'session']),
176
- });
177
- const storageClearSchema = baseCommandSchema.extend({
178
- action: z.literal('storage_clear'),
179
- type: z.enum(['local', 'session']),
180
- });
181
- const dialogSchema = baseCommandSchema.extend({
182
- action: z.literal('dialog'),
183
- response: z.enum(['accept', 'dismiss']),
184
- promptText: z.string().optional(),
185
- });
186
- const pdfSchema = baseCommandSchema.extend({
187
- action: z.literal('pdf'),
188
- path: z.string().min(1),
189
- format: z
190
- .enum(['Letter', 'Legal', 'Tabloid', 'Ledger', 'A0', 'A1', 'A2', 'A3', 'A4', 'A5', 'A6'])
191
- .optional(),
192
- });
193
- const routeSchema = baseCommandSchema.extend({
194
- action: z.literal('route'),
195
- url: z.string().min(1),
196
- response: z
197
- .object({
198
- status: z.number().optional(),
199
- body: z.string().optional(),
200
- contentType: z.string().optional(),
201
- headers: z.record(z.string()).optional(),
202
- })
203
- .optional(),
204
- abort: z.boolean().optional(),
205
- });
206
- const unrouteSchema = baseCommandSchema.extend({
207
- action: z.literal('unroute'),
208
- url: z.string().optional(),
209
- });
210
- const requestsSchema = baseCommandSchema.extend({
211
- action: z.literal('requests'),
212
- filter: z.string().optional(),
213
- clear: z.boolean().optional(),
214
- });
215
- const downloadSchema = baseCommandSchema.extend({
216
- action: z.literal('download'),
217
- selector: z.string().min(1),
218
- path: z.string().min(1),
219
- });
220
- const geolocationSchema = baseCommandSchema.extend({
221
- action: z.literal('geolocation'),
222
- latitude: z.number(),
223
- longitude: z.number(),
224
- accuracy: z.number().optional(),
225
- });
226
- const permissionsSchema = baseCommandSchema.extend({
227
- action: z.literal('permissions'),
228
- permissions: z.array(z.string()),
229
- grant: z.boolean(),
230
- });
231
- const viewportSchema = baseCommandSchema.extend({
232
- action: z.literal('viewport'),
233
- width: z.number().positive(),
234
- height: z.number().positive(),
235
- });
236
- const userAgentSchema = baseCommandSchema.extend({
237
- action: z.literal('useragent'),
238
- userAgent: z.string().min(1),
239
- });
240
- const deviceSchema = baseCommandSchema.extend({
241
- action: z.literal('device'),
242
- device: z.string().min(1),
243
- });
244
- const backSchema = baseCommandSchema.extend({
245
- action: z.literal('back'),
246
- });
247
- const forwardSchema = baseCommandSchema.extend({
248
- action: z.literal('forward'),
249
- });
250
- const reloadSchema = baseCommandSchema.extend({
251
- action: z.literal('reload'),
252
- });
253
- const urlSchema = baseCommandSchema.extend({
254
- action: z.literal('url'),
255
- });
256
- const titleSchema = baseCommandSchema.extend({
257
- action: z.literal('title'),
258
- });
259
- const getAttributeSchema = baseCommandSchema.extend({
260
- action: z.literal('getattribute'),
261
- selector: z.string().min(1),
262
- attribute: z.string().min(1),
263
- });
264
- const getTextSchema = baseCommandSchema.extend({
265
- action: z.literal('gettext'),
266
- selector: z.string().min(1),
267
- });
268
- const isVisibleSchema = baseCommandSchema.extend({
269
- action: z.literal('isvisible'),
270
- selector: z.string().min(1),
271
- });
272
- const isEnabledSchema = baseCommandSchema.extend({
273
- action: z.literal('isenabled'),
274
- selector: z.string().min(1),
275
- });
276
- const isCheckedSchema = baseCommandSchema.extend({
277
- action: z.literal('ischecked'),
278
- selector: z.string().min(1),
279
- });
280
- const countSchema = baseCommandSchema.extend({
281
- action: z.literal('count'),
282
- selector: z.string().min(1),
283
- });
284
- const boundingBoxSchema = baseCommandSchema.extend({
285
- action: z.literal('boundingbox'),
286
- selector: z.string().min(1),
287
- });
288
- const stylesSchema = baseCommandSchema.extend({
289
- action: z.literal('styles'),
290
- selector: z.string().min(1),
291
- });
292
- const videoStartSchema = baseCommandSchema.extend({
293
- action: z.literal('video_start'),
294
- path: z.string().min(1),
295
- });
296
- const videoStopSchema = baseCommandSchema.extend({
297
- action: z.literal('video_stop'),
298
- });
299
- // Recording schemas (Playwright native video recording)
300
- const recordingStartSchema = baseCommandSchema.extend({
301
- action: z.literal('recording_start'),
302
- path: z.string().min(1),
303
- url: z.string().min(1).optional(),
304
- });
305
- const recordingStopSchema = baseCommandSchema.extend({
306
- action: z.literal('recording_stop'),
307
- });
308
- const recordingRestartSchema = baseCommandSchema.extend({
309
- action: z.literal('recording_restart'),
310
- path: z.string().min(1),
311
- url: z.string().min(1).optional(),
312
- });
313
- const traceStartSchema = baseCommandSchema.extend({
314
- action: z.literal('trace_start'),
315
- screenshots: z.boolean().optional(),
316
- snapshots: z.boolean().optional(),
317
- });
318
- const traceStopSchema = baseCommandSchema.extend({
319
- action: z.literal('trace_stop'),
320
- path: z.string().min(1).optional(),
321
- });
322
- const profilerStartSchema = baseCommandSchema.extend({
323
- action: z.literal('profiler_start'),
324
- categories: z.array(z.string()).optional(),
325
- });
326
- const profilerStopSchema = baseCommandSchema.extend({
327
- action: z.literal('profiler_stop'),
328
- path: z.string().min(1).optional(),
329
- });
330
- const harStartSchema = baseCommandSchema.extend({
331
- action: z.literal('har_start'),
332
- });
333
- const harStopSchema = baseCommandSchema.extend({
334
- action: z.literal('har_stop'),
335
- path: z.string().min(1),
336
- });
337
- const stateSaveSchema = baseCommandSchema.extend({
338
- action: z.literal('state_save'),
339
- path: z.string().min(1),
340
- });
341
- const stateLoadSchema = baseCommandSchema.extend({
342
- action: z.literal('state_load'),
343
- path: z.string().min(1),
344
- });
345
- const stateListSchema = baseCommandSchema.extend({
346
- action: z.literal('state_list'),
347
- });
348
- const stateClearSchema = baseCommandSchema.extend({
349
- action: z.literal('state_clear'),
350
- sessionName: z.string().optional(),
351
- all: z.boolean().optional(),
352
- });
353
- const stateShowSchema = baseCommandSchema.extend({
354
- action: z.literal('state_show'),
355
- filename: z.string().min(1),
356
- });
357
- const stateCleanSchema = baseCommandSchema.extend({
358
- action: z.literal('state_clean'),
359
- days: z.number().int().positive(),
360
- });
361
- const stateRenameSchema = baseCommandSchema.extend({
362
- action: z.literal('state_rename'),
363
- oldName: z.string().min(1),
364
- newName: z.string().min(1),
365
- });
366
- const consoleSchema = baseCommandSchema.extend({
367
- action: z.literal('console'),
368
- clear: z.boolean().optional(),
369
- });
370
- const errorsSchema = baseCommandSchema.extend({
371
- action: z.literal('errors'),
372
- clear: z.boolean().optional(),
373
- });
374
- const keyboardSchema = baseCommandSchema.extend({
375
- action: z.literal('keyboard'),
376
- subaction: z.enum(['type', 'press', 'insertText']).optional(),
377
- keys: z.string().min(1).optional(),
378
- text: z.string().min(1).optional(),
379
- delay: z.number().optional(),
380
- });
381
- const wheelSchema = baseCommandSchema.extend({
382
- action: z.literal('wheel'),
383
- deltaX: z.number().optional(),
384
- deltaY: z.number().optional(),
385
- selector: z.string().optional(),
386
- });
387
- const tapSchema = baseCommandSchema.extend({
388
- action: z.literal('tap'),
389
- selector: z.string().min(1),
390
- });
391
- const clipboardSchema = baseCommandSchema.extend({
392
- action: z.literal('clipboard'),
393
- operation: z.enum(['copy', 'paste', 'read']),
394
- text: z.string().optional(),
395
- });
396
- const highlightSchema = baseCommandSchema.extend({
397
- action: z.literal('highlight'),
398
- selector: z.string().min(1),
399
- });
400
- const clearSchema = baseCommandSchema.extend({
401
- action: z.literal('clear'),
402
- selector: z.string().min(1),
403
- });
404
- const selectAllSchema = baseCommandSchema.extend({
405
- action: z.literal('selectall'),
406
- selector: z.string().min(1),
407
- });
408
- const innerTextSchema = baseCommandSchema.extend({
409
- action: z.literal('innertext'),
410
- selector: z.string().min(1),
411
- });
412
- const innerHtmlSchema = baseCommandSchema.extend({
413
- action: z.literal('innerhtml'),
414
- selector: z.string().min(1),
415
- });
416
- const inputValueSchema = baseCommandSchema.extend({
417
- action: z.literal('inputvalue'),
418
- selector: z.string().min(1),
419
- });
420
- const setValueSchema = baseCommandSchema.extend({
421
- action: z.literal('setvalue'),
422
- selector: z.string().min(1),
423
- value: z.string(),
424
- });
425
- const dispatchSchema = baseCommandSchema.extend({
426
- action: z.literal('dispatch'),
427
- selector: z.string().min(1),
428
- event: z.string().min(1),
429
- eventInit: z.record(z.unknown()).optional(),
430
- });
431
- const evalHandleSchema = baseCommandSchema.extend({
432
- action: z.literal('evalhandle'),
433
- script: z.string().min(1),
434
- });
435
- const exposeSchema = baseCommandSchema.extend({
436
- action: z.literal('expose'),
437
- name: z.string().min(1),
438
- });
439
- const addScriptSchema = baseCommandSchema.extend({
440
- action: z.literal('addscript'),
441
- content: z.string().optional(),
442
- url: z.string().optional(),
443
- });
444
- const addStyleSchema = baseCommandSchema.extend({
445
- action: z.literal('addstyle'),
446
- content: z.string().optional(),
447
- url: z.string().optional(),
448
- });
449
- const emulateMediaSchema = baseCommandSchema.extend({
450
- action: z.literal('emulatemedia'),
451
- media: z.enum(['screen', 'print']).nullable().optional(),
452
- colorScheme: z.enum(['light', 'dark', 'no-preference']).nullable().optional(),
453
- reducedMotion: z.enum(['reduce', 'no-preference']).nullable().optional(),
454
- forcedColors: z.enum(['active', 'none']).nullable().optional(),
455
- });
456
- const offlineSchema = baseCommandSchema.extend({
457
- action: z.literal('offline'),
458
- offline: z.boolean(),
459
- });
460
- const headersSchema = baseCommandSchema.extend({
461
- action: z.literal('headers'),
462
- headers: z.record(z.string()),
463
- });
464
- const pauseSchema = baseCommandSchema.extend({
465
- action: z.literal('pause'),
466
- });
467
- const getByAltTextSchema = baseCommandSchema.extend({
468
- action: z.literal('getbyalttext'),
469
- text: z.string().min(1),
470
- exact: z.boolean().optional(),
471
- subaction: z.enum(['click', 'hover']),
472
- });
473
- const getByTitleSchema = baseCommandSchema.extend({
474
- action: z.literal('getbytitle'),
475
- text: z.string().min(1),
476
- exact: z.boolean().optional(),
477
- subaction: z.enum(['click', 'hover']),
478
- });
479
- const getByTestIdSchema = baseCommandSchema.extend({
480
- action: z.literal('getbytestid'),
481
- testId: z.string().min(1),
482
- subaction: z.enum(['click', 'fill', 'check', 'hover']),
483
- value: z.string().optional(),
484
- });
485
- const nthSchema = baseCommandSchema.extend({
486
- action: z.literal('nth'),
487
- selector: z.string().min(1),
488
- index: z.number(),
489
- subaction: z.enum(['click', 'fill', 'check', 'hover', 'text']),
490
- value: z.string().optional(),
491
- });
492
- const waitForUrlSchema = baseCommandSchema.extend({
493
- action: z.literal('waitforurl'),
494
- url: z.string().min(1),
495
- timeout: z.number().positive().optional(),
496
- });
497
- const waitForLoadStateSchema = baseCommandSchema.extend({
498
- action: z.literal('waitforloadstate'),
499
- state: z.enum(['load', 'domcontentloaded', 'networkidle']),
500
- timeout: z.number().positive().optional(),
501
- });
502
- const setContentSchema = baseCommandSchema.extend({
503
- action: z.literal('setcontent'),
504
- html: z.string(),
505
- });
506
- const timezoneSchema = baseCommandSchema.extend({
507
- action: z.literal('timezone'),
508
- timezone: z.string().min(1),
509
- });
510
- const localeSchema = baseCommandSchema.extend({
511
- action: z.literal('locale'),
512
- locale: z.string().min(1),
513
- });
514
- const credentialsSchema = baseCommandSchema.extend({
515
- action: z.literal('credentials'),
516
- username: z.string(),
517
- password: z.string(),
518
- });
519
- const mouseMoveSchema = baseCommandSchema.extend({
520
- action: z.literal('mousemove'),
521
- x: z.number(),
522
- y: z.number(),
523
- });
524
- const mouseDownSchema = baseCommandSchema.extend({
525
- action: z.literal('mousedown'),
526
- button: z.enum(['left', 'right', 'middle']).optional(),
527
- });
528
- const mouseUpSchema = baseCommandSchema.extend({
529
- action: z.literal('mouseup'),
530
- button: z.enum(['left', 'right', 'middle']).optional(),
531
- });
532
- const bringToFrontSchema = baseCommandSchema.extend({
533
- action: z.literal('bringtofront'),
534
- });
535
- const waitForFunctionSchema = baseCommandSchema.extend({
536
- action: z.literal('waitforfunction'),
537
- expression: z.string().min(1),
538
- timeout: z.number().positive().optional(),
539
- });
540
- const scrollIntoViewSchema = baseCommandSchema.extend({
541
- action: z.literal('scrollintoview'),
542
- selector: z.string().min(1),
543
- });
544
- const addInitScriptSchema = baseCommandSchema.extend({
545
- action: z.literal('addinitscript'),
546
- script: z.string().min(1),
547
- });
548
- const keyDownSchema = baseCommandSchema.extend({
549
- action: z.literal('keydown'),
550
- key: z.string().min(1),
551
- });
552
- const keyUpSchema = baseCommandSchema.extend({
553
- action: z.literal('keyup'),
554
- key: z.string().min(1),
555
- });
556
- const insertTextSchema = baseCommandSchema.extend({
557
- action: z.literal('inserttext'),
558
- text: z.string(),
559
- });
560
- const multiSelectSchema = baseCommandSchema.extend({
561
- action: z.literal('multiselect'),
562
- selector: z.string().min(1),
563
- values: z.array(z.string()),
564
- });
565
- const waitForDownloadSchema = baseCommandSchema.extend({
566
- action: z.literal('waitfordownload'),
567
- path: z.string().optional(),
568
- timeout: z.number().positive().optional(),
569
- });
570
- const responseBodySchema = baseCommandSchema.extend({
571
- action: z.literal('responsebody'),
572
- url: z.string().min(1),
573
- timeout: z.number().positive().optional(),
574
- });
575
- // Screencast schemas for streaming browser viewport
576
- const screencastStartSchema = baseCommandSchema.extend({
577
- action: z.literal('screencast_start'),
578
- format: z.enum(['jpeg', 'png']).optional(),
579
- quality: z.number().min(0).max(100).optional(),
580
- maxWidth: z.number().positive().optional(),
581
- maxHeight: z.number().positive().optional(),
582
- everyNthFrame: z.number().positive().optional(),
583
- });
584
- const screencastStopSchema = baseCommandSchema.extend({
585
- action: z.literal('screencast_stop'),
586
- });
587
- // Input injection schemas for pair browsing
588
- const inputMouseSchema = baseCommandSchema.extend({
589
- action: z.literal('input_mouse'),
590
- type: z.enum(['mousePressed', 'mouseReleased', 'mouseMoved', 'mouseWheel']),
591
- x: z.number(),
592
- y: z.number(),
593
- button: z.enum(['left', 'right', 'middle', 'none']).optional(),
594
- clickCount: z.number().positive().optional(),
595
- deltaX: z.number().optional(),
596
- deltaY: z.number().optional(),
597
- modifiers: z.number().optional(),
598
- });
599
- const inputKeyboardSchema = baseCommandSchema.extend({
600
- action: z.literal('input_keyboard'),
601
- type: z.enum(['keyDown', 'keyUp', 'char']),
602
- key: z.string().optional(),
603
- code: z.string().optional(),
604
- text: z.string().optional(),
605
- modifiers: z.number().optional(),
606
- });
607
- const inputTouchSchema = baseCommandSchema.extend({
608
- action: z.literal('input_touch'),
609
- type: z.enum(['touchStart', 'touchEnd', 'touchMove', 'touchCancel']),
610
- touchPoints: z.array(z.object({
611
- x: z.number(),
612
- y: z.number(),
613
- id: z.number().optional(),
614
- })),
615
- modifiers: z.number().optional(),
616
- });
617
- // iOS-specific schemas
618
- const swipeSchema = baseCommandSchema.extend({
619
- action: z.literal('swipe'),
620
- direction: z.enum(['up', 'down', 'left', 'right']),
621
- distance: z.number().positive().optional(),
622
- });
623
- const deviceListSchema = baseCommandSchema.extend({
624
- action: z.literal('device_list'),
625
- });
626
- // Diff schemas
627
- const diffSnapshotSchema = baseCommandSchema.extend({
628
- action: z.literal('diff_snapshot'),
629
- baseline: z.string().optional(),
630
- selector: z.string().optional(),
631
- compact: z.boolean().optional(),
632
- maxDepth: z.number().nonnegative().optional(),
633
- });
634
- const diffScreenshotSchema = baseCommandSchema.extend({
635
- action: z.literal('diff_screenshot'),
636
- baseline: z.string().min(1),
637
- output: z.string().optional(),
638
- threshold: z.number().min(0).max(1).optional(),
639
- selector: z.string().min(1).optional(),
640
- fullPage: z.boolean().optional(),
641
- });
642
- const diffUrlSchema = baseCommandSchema.extend({
643
- action: z.literal('diff_url'),
644
- url1: z.string().min(1),
645
- url2: z.string().min(1),
646
- screenshot: z.boolean().optional(),
647
- fullPage: z.boolean().optional(),
648
- waitUntil: z.enum(['load', 'domcontentloaded', 'networkidle']).optional(),
649
- selector: z.string().optional(),
650
- compact: z.boolean().optional(),
651
- maxDepth: z.number().nonnegative().optional(),
652
- });
653
- const pressSchema = baseCommandSchema.extend({
654
- action: z.literal('press'),
655
- key: z.string().min(1),
656
- selector: z.string().min(1).optional(),
657
- });
658
- const screenshotSchema = baseCommandSchema.extend({
659
- action: z.literal('screenshot'),
660
- path: z.string().nullable().optional(),
661
- fullPage: z.boolean().optional(),
662
- selector: z.string().min(1).nullish(),
663
- format: z.enum(['png', 'jpeg']).optional(),
664
- quality: z.number().min(0).max(100).optional(),
665
- annotate: z.boolean().optional(),
666
- });
667
- const snapshotSchema = baseCommandSchema.extend({
668
- action: z.literal('snapshot'),
669
- interactive: z.boolean().optional(),
670
- cursor: z.boolean().optional(),
671
- maxDepth: z.number().nonnegative().optional(),
672
- compact: z.boolean().optional(),
673
- selector: z.string().optional(),
674
- });
675
- const evaluateSchema = baseCommandSchema.extend({
676
- action: z.literal('evaluate'),
677
- script: z.string().min(1),
678
- args: z.array(z.unknown()).optional(),
679
- });
680
- const waitSchema = baseCommandSchema.extend({
681
- action: z.literal('wait'),
682
- selector: z.string().min(1).optional(),
683
- timeout: z.number().positive().optional(),
684
- timeoutMax: z.number().positive().optional(),
685
- state: z.enum(['attached', 'detached', 'visible', 'hidden']).optional(),
686
- });
687
- const scrollSchema = baseCommandSchema.extend({
688
- action: z.literal('scroll'),
689
- selector: z.string().min(1).optional(),
690
- x: z.number().optional(),
691
- y: z.number().optional(),
692
- direction: z.enum(['up', 'down', 'left', 'right']).optional(),
693
- amount: z.number().positive().optional(),
694
- });
695
- const selectSchema = baseCommandSchema.extend({
696
- action: z.literal('select'),
697
- selector: z.string().min(1),
698
- values: z.union([z.string(), z.array(z.string())]),
699
- });
700
- const hoverSchema = baseCommandSchema.extend({
701
- action: z.literal('hover'),
702
- selector: z.string().min(1),
703
- });
704
- const contentSchema = baseCommandSchema.extend({
705
- action: z.literal('content'),
706
- selector: z.string().min(1).optional(),
707
- });
708
- const closeSchema = baseCommandSchema.extend({
709
- action: z.literal('close'),
710
- });
711
- const doctorSchema = baseCommandSchema.extend({
712
- action: z.literal('doctor'),
713
- });
714
- // Tab/Window schemas
715
- const tabNewSchema = baseCommandSchema.extend({
716
- action: z.literal('tab_new'),
717
- url: z.string().min(1).optional(),
718
- });
719
- const tabListSchema = baseCommandSchema.extend({
720
- action: z.literal('tab_list'),
721
- });
722
- const tabSwitchSchema = baseCommandSchema.extend({
723
- action: z.literal('tab_switch'),
724
- index: z.number().nonnegative(),
725
- });
726
- const tabCloseSchema = baseCommandSchema.extend({
727
- action: z.literal('tab_close'),
728
- index: z.number().nonnegative().optional(),
729
- });
730
- const windowNewSchema = baseCommandSchema.extend({
731
- action: z.literal('window_new'),
732
- viewport: z
733
- .object({
734
- width: z.number().positive(),
735
- height: z.number().positive(),
736
- })
737
- .nullable()
738
- .optional(),
739
- });
740
- const authProfileName = z
741
- .string()
742
- .min(1)
743
- .regex(/^[a-zA-Z0-9_-]+$/, {
744
- message: 'Profile name must contain only alphanumeric characters, hyphens, and underscores',
745
- });
746
- const authSaveSchema = baseCommandSchema.extend({
747
- action: z.literal('auth_save'),
748
- name: authProfileName,
749
- url: z.string().min(1),
750
- username: z.string().min(1),
751
- password: z.string().min(1),
752
- usernameSelector: z.string().optional(),
753
- passwordSelector: z.string().optional(),
754
- submitSelector: z.string().optional(),
755
- });
756
- const authLoginSchema = baseCommandSchema.extend({
757
- action: z.literal('auth_login'),
758
- name: authProfileName,
759
- });
760
- const authListSchema = baseCommandSchema.extend({
761
- action: z.literal('auth_list'),
762
- });
763
- const authDeleteSchema = baseCommandSchema.extend({
764
- action: z.literal('auth_delete'),
765
- name: authProfileName,
766
- });
767
- const authShowSchema = baseCommandSchema.extend({
768
- action: z.literal('auth_show'),
769
- name: authProfileName,
770
- });
771
- const confirmSchema = baseCommandSchema.extend({
772
- action: z.literal('confirm'),
773
- confirmationId: z.string().min(1),
774
- });
775
- const denySchema = baseCommandSchema.extend({
776
- action: z.literal('deny'),
777
- confirmationId: z.string().min(1),
778
- });
779
- // Union schema for all commands
780
- const commandSchema = z.discriminatedUnion('action', [
781
- launchSchema,
782
- navigateSchema,
783
- clickSchema,
784
- typeSchema,
785
- fillSchema,
786
- checkSchema,
787
- uncheckSchema,
788
- uploadSchema,
789
- dblclickSchema,
790
- focusSchema,
791
- dragSchema,
792
- frameSchema,
793
- mainframeSchema,
794
- getByRoleSchema,
795
- getByTextSchema,
796
- getByLabelSchema,
797
- getByPlaceholderSchema,
798
- pressSchema,
799
- screenshotSchema,
800
- snapshotSchema,
801
- evaluateSchema,
802
- waitSchema,
803
- scrollSchema,
804
- selectSchema,
805
- hoverSchema,
806
- contentSchema,
807
- closeSchema,
808
- doctorSchema,
809
- tabNewSchema,
810
- tabListSchema,
811
- tabSwitchSchema,
812
- tabCloseSchema,
813
- windowNewSchema,
814
- cookiesGetSchema,
815
- cookiesSetSchema,
816
- cookiesClearSchema,
817
- storageGetSchema,
818
- storageSetSchema,
819
- storageClearSchema,
820
- dialogSchema,
821
- pdfSchema,
822
- routeSchema,
823
- unrouteSchema,
824
- requestsSchema,
825
- downloadSchema,
826
- geolocationSchema,
827
- permissionsSchema,
828
- viewportSchema,
829
- userAgentSchema,
830
- deviceSchema,
831
- backSchema,
832
- forwardSchema,
833
- reloadSchema,
834
- urlSchema,
835
- titleSchema,
836
- getAttributeSchema,
837
- getTextSchema,
838
- isVisibleSchema,
839
- isEnabledSchema,
840
- isCheckedSchema,
841
- countSchema,
842
- boundingBoxSchema,
843
- stylesSchema,
844
- videoStartSchema,
845
- videoStopSchema,
846
- recordingStartSchema,
847
- recordingStopSchema,
848
- recordingRestartSchema,
849
- traceStartSchema,
850
- traceStopSchema,
851
- profilerStartSchema,
852
- profilerStopSchema,
853
- harStartSchema,
854
- harStopSchema,
855
- stateSaveSchema,
856
- stateLoadSchema,
857
- stateListSchema,
858
- stateClearSchema,
859
- stateShowSchema,
860
- stateCleanSchema,
861
- stateRenameSchema,
862
- consoleSchema,
863
- errorsSchema,
864
- keyboardSchema,
865
- wheelSchema,
866
- tapSchema,
867
- clipboardSchema,
868
- highlightSchema,
869
- clearSchema,
870
- selectAllSchema,
871
- innerTextSchema,
872
- innerHtmlSchema,
873
- inputValueSchema,
874
- setValueSchema,
875
- dispatchSchema,
876
- evalHandleSchema,
877
- exposeSchema,
878
- addScriptSchema,
879
- addStyleSchema,
880
- emulateMediaSchema,
881
- offlineSchema,
882
- headersSchema,
883
- pauseSchema,
884
- getByAltTextSchema,
885
- getByTitleSchema,
886
- getByTestIdSchema,
887
- nthSchema,
888
- waitForUrlSchema,
889
- waitForLoadStateSchema,
890
- setContentSchema,
891
- timezoneSchema,
892
- localeSchema,
893
- credentialsSchema,
894
- mouseMoveSchema,
895
- mouseDownSchema,
896
- mouseUpSchema,
897
- bringToFrontSchema,
898
- waitForFunctionSchema,
899
- scrollIntoViewSchema,
900
- addInitScriptSchema,
901
- keyDownSchema,
902
- keyUpSchema,
903
- insertTextSchema,
904
- multiSelectSchema,
905
- waitForDownloadSchema,
906
- responseBodySchema,
907
- screencastStartSchema,
908
- screencastStopSchema,
909
- inputMouseSchema,
910
- inputKeyboardSchema,
911
- inputTouchSchema,
912
- swipeSchema,
913
- deviceListSchema,
914
- diffSnapshotSchema,
915
- diffScreenshotSchema,
916
- diffUrlSchema,
917
- confirmSchema,
918
- denySchema,
919
- authSaveSchema,
920
- authLoginSchema,
921
- authListSchema,
922
- authDeleteSchema,
923
- authShowSchema,
924
- ]);
925
- /**
926
- * Parse a JSON string into a validated command
927
- */
928
- export function parseCommand(input) {
929
- // First, try to parse JSON
930
- let json;
931
- try {
932
- json = JSON.parse(input);
933
- }
934
- catch {
935
- return { success: false, error: 'Invalid JSON' };
936
- }
937
- // Extract id for error responses if possible
938
- const id = typeof json === 'object' && json !== null && 'id' in json
939
- ? String(json.id)
940
- : undefined;
941
- // Validate against schema
942
- const result = commandSchema.safeParse(json);
943
- if (!result.success) {
944
- const errors = result.error.errors.map((e) => `${e.path.join('.')}: ${e.message}`).join(', ');
945
- return { success: false, error: `Validation error: ${errors}`, id };
946
- }
947
- const command = result.data;
948
- // Post-parse validation for commands that need cross-field checks
949
- if ((command.action === 'addscript' || command.action === 'addstyle') &&
950
- !command.content &&
951
- !command.url) {
952
- return { success: false, error: 'Either content or url must be provided', id };
953
- }
954
- if (command.action === 'frame' && !command.selector && !command.name && !command.url) {
955
- return {
956
- success: false,
957
- error: 'frame command requires at least one of: selector, name, or url',
958
- id,
959
- };
960
- }
961
- if (command.action === 'keyboard') {
962
- const sub = command.subaction ?? 'press';
963
- if ((sub === 'type' || sub === 'insertText') && !command.text) {
964
- return { success: false, error: `keyboard ${sub} requires text`, id };
965
- }
966
- if (sub === 'press' && !command.keys) {
967
- return { success: false, error: 'keyboard press requires keys', id };
968
- }
969
- }
970
- return { success: true, command };
971
- }
972
- /**
973
- * Create a success response
974
- */
975
- export function successResponse(id, data) {
976
- return { id, success: true, data };
977
- }
978
- /**
979
- * Create an error response
980
- */
981
- export function errorResponse(id, error) {
982
- return { id, success: false, error };
983
- }
984
- /**
985
- * Serialize a response to JSON string
986
- */
987
- export function serializeResponse(response) {
988
- return JSON.stringify(response);
989
- }
990
- //# sourceMappingURL=protocol.js.map