@extension-use/protocol 0.0.0-stage → 0.2.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.
@@ -0,0 +1,778 @@
1
+ // src/schemas.ts
2
+ import * as z from "zod";
3
+ var locatorSchema = z.object({
4
+ ref: z.string(),
5
+ role: z.string(),
6
+ name: z.string(),
7
+ text: z.string(),
8
+ testId: z.string(),
9
+ css: z.string(),
10
+ nth: z.number().int().min(0),
11
+ exact: z.boolean()
12
+ }).partial().refine((l) => Boolean(l.ref || l.role || l.text || l.testId || l.css), {
13
+ message: "A locator needs at least one of ref, role, text, testId or css"
14
+ });
15
+ var boxSchema = z.object({
16
+ x: z.number(),
17
+ y: z.number(),
18
+ width: z.number(),
19
+ height: z.number()
20
+ });
21
+ var elementInfoSchema = z.object({
22
+ ref: z.string(),
23
+ tag: z.string(),
24
+ role: z.string(),
25
+ name: z.string(),
26
+ text: z.string().optional(),
27
+ value: z.string().optional(),
28
+ checked: z.boolean().optional(),
29
+ disabled: z.boolean().optional(),
30
+ href: z.string().optional(),
31
+ attributes: z.record(z.string(), z.string()),
32
+ box: boxSchema,
33
+ visible: z.boolean()
34
+ });
35
+ var tabInfoSchema = z.object({
36
+ id: z.number(),
37
+ windowId: z.number(),
38
+ url: z.string(),
39
+ title: z.string(),
40
+ active: z.boolean(),
41
+ status: z.string(),
42
+ /** Chrome unloaded the tab to save memory. It reloads when it is activated or reloaded. */
43
+ discarded: z.boolean().optional(),
44
+ /** false: Chrome won't discard the tab when memory is low (see tabs.update). */
45
+ autoDiscardable: z.boolean().optional()
46
+ });
47
+ var windowInfoSchema = z.object({
48
+ id: z.number(),
49
+ focused: z.boolean(),
50
+ state: z.string(),
51
+ type: z.string(),
52
+ incognito: z.boolean(),
53
+ left: z.number().optional(),
54
+ top: z.number().optional(),
55
+ width: z.number().optional(),
56
+ height: z.number().optional(),
57
+ tabCount: z.number()
58
+ });
59
+ var downloadInfoSchema = z.object({
60
+ id: z.number(),
61
+ url: z.string(),
62
+ /** Full path on disk; empty until Chrome has picked it. */
63
+ filename: z.string(),
64
+ state: z.string(),
65
+ mime: z.string(),
66
+ bytesReceived: z.number(),
67
+ totalBytes: z.number(),
68
+ startTime: z.string(),
69
+ error: z.string().optional()
70
+ });
71
+ var bookmarkSchema = z.object({
72
+ id: z.string(),
73
+ title: z.string(),
74
+ url: z.string().optional(),
75
+ parentId: z.string().optional(),
76
+ index: z.number().optional(),
77
+ dateAdded: z.number().optional(),
78
+ folder: z.boolean()
79
+ });
80
+ var historyItemSchema = z.object({
81
+ url: z.string(),
82
+ title: z.string(),
83
+ lastVisitTime: z.number().optional(),
84
+ visitCount: z.number(),
85
+ typedCount: z.number()
86
+ });
87
+ var cookieSchema = z.object({
88
+ name: z.string(),
89
+ value: z.string(),
90
+ domain: z.string(),
91
+ path: z.string(),
92
+ secure: z.boolean(),
93
+ httpOnly: z.boolean(),
94
+ sameSite: z.string(),
95
+ session: z.boolean(),
96
+ hostOnly: z.boolean(),
97
+ expirationDate: z.number().optional()
98
+ });
99
+ var windowBoundsShape = {
100
+ left: z.number().int().optional(),
101
+ top: z.number().int().optional(),
102
+ width: z.number().int().min(100).optional(),
103
+ height: z.number().int().min(100).optional()
104
+ };
105
+ var snapshotNodeSchema = z.lazy(
106
+ () => z.object({
107
+ ref: z.string().optional(),
108
+ role: z.string(),
109
+ name: z.string().optional(),
110
+ value: z.string().optional(),
111
+ checked: z.boolean().optional(),
112
+ disabled: z.boolean().optional(),
113
+ level: z.number().optional(),
114
+ href: z.string().optional(),
115
+ children: z.array(snapshotNodeSchema).optional()
116
+ })
117
+ );
118
+ var empty = z.object({});
119
+ var refOut = z.object({ ref: z.string() });
120
+ var scrollBehavior = z.enum(["auto", "smooth", "instant"]);
121
+ function action(where, description, input, output, extra = {}) {
122
+ return {
123
+ input,
124
+ output,
125
+ where,
126
+ description,
127
+ version: extra.version ?? 1,
128
+ ...extra.timeoutMs ? { timeoutMs: extra.timeoutMs } : {},
129
+ ...extra.nestable === false ? { nestable: false } : {}
130
+ };
131
+ }
132
+ var jsonSchemaLike = z.record(z.string(), z.unknown());
133
+ var sequenceStepSchema = z.object({
134
+ action: z.string(),
135
+ input: z.unknown().optional(),
136
+ target: z.object({
137
+ tab: z.union([z.literal("active"), z.number(), z.object({ urlMatch: z.string() })]).optional(),
138
+ frame: z.union([z.literal("top"), z.number(), z.object({ urlMatch: z.string() })]).optional()
139
+ }).optional(),
140
+ timeoutMs: z.number().int().min(1).max(12e4).optional(),
141
+ /** What to do if this step fails. Default: the sequence's onError. */
142
+ onError: z.enum(["stop", "continue"]).optional(),
143
+ /** Wait this long after the step succeeds (for animations, debounced UIs). */
144
+ pauseMs: z.number().int().min(0).max(1e4).optional()
145
+ });
146
+ var coreActionSchemas = {
147
+ // runtime ----------------------------------------------------------------
148
+ "runtime.ping": action("background", "Check the connection.", empty, z.object({ pong: z.literal(true), ts: z.number() })),
149
+ "runtime.describe": action(
150
+ "background",
151
+ "List the actions this controller may call, with JSON schemas for their input and output. Includes host-defined actions.",
152
+ z.object({ actions: z.array(z.string()).optional() }),
153
+ z.object({
154
+ host: z.object({ id: z.string(), name: z.string().optional(), version: z.string().optional() }),
155
+ actions: z.array(
156
+ z.object({
157
+ name: z.string(),
158
+ description: z.string(),
159
+ where: z.enum(["background", "content", "bridge"]),
160
+ version: z.number(),
161
+ input: jsonSchemaLike,
162
+ output: jsonSchemaLike
163
+ })
164
+ )
165
+ })
166
+ ),
167
+ // run -------------------------------------------------------------------
168
+ "run.sequence": action(
169
+ "background",
170
+ "Run several actions in order in one round trip. Steps are plain data: no conditions or expressions. Each step is checked like a separate call.",
171
+ z.object({
172
+ steps: z.array(sequenceStepSchema).min(1).max(50),
173
+ onError: z.enum(["stop", "continue"]).default("stop")
174
+ }),
175
+ z.object({
176
+ completed: z.number(),
177
+ ok: z.boolean(),
178
+ results: z.array(
179
+ z.union([
180
+ z.object({ ok: z.literal(true), action: z.string(), output: z.unknown() }),
181
+ z.object({ ok: z.literal(false), action: z.string(), error: z.object({ code: z.string(), message: z.string() }) })
182
+ ])
183
+ )
184
+ }),
185
+ { timeoutMs: 12e4, nestable: false }
186
+ ),
187
+ // tabs ------------------------------------------------------------------
188
+ "tabs.list": action(
189
+ "background",
190
+ "List open tabs.",
191
+ z.object({ currentWindow: z.boolean().optional(), urlMatch: z.string().optional() }),
192
+ z.object({ tabs: z.array(tabInfoSchema) })
193
+ ),
194
+ "tabs.open": action(
195
+ "background",
196
+ "Open a URL in a new tab.",
197
+ z.object({ url: z.string(), active: z.boolean().default(true), waitForLoad: z.boolean().default(true) }),
198
+ tabInfoSchema,
199
+ { timeoutMs: 3e4 }
200
+ ),
201
+ "tabs.close": action("background", "Close a tab.", z.object({ tabId: z.number() }), empty),
202
+ "tabs.activate": action("background", "Focus a tab.", z.object({ tabId: z.number() }), tabInfoSchema),
203
+ "tabs.navigate": action(
204
+ "background",
205
+ "Navigate the target tab to a URL.",
206
+ z.object({ url: z.string(), waitForLoad: z.boolean().default(true) }),
207
+ tabInfoSchema,
208
+ { timeoutMs: 3e4 }
209
+ ),
210
+ "tabs.reload": action(
211
+ "background",
212
+ "Reload the target tab.",
213
+ z.object({ waitForLoad: z.boolean().default(true) }),
214
+ tabInfoSchema,
215
+ { timeoutMs: 3e4 }
216
+ ),
217
+ "tabs.waitForLoad": action("background", "Wait until the target tab has loaded.", empty, tabInfoSchema, { timeoutMs: 3e4 }),
218
+ "tabs.goBack": action(
219
+ "background",
220
+ "Go back one step in the target tab's history.",
221
+ z.object({ waitForLoad: z.boolean().default(true) }),
222
+ tabInfoSchema,
223
+ { timeoutMs: 3e4 }
224
+ ),
225
+ "tabs.goForward": action(
226
+ "background",
227
+ "Go forward one step in the target tab's history.",
228
+ z.object({ waitForLoad: z.boolean().default(true) }),
229
+ tabInfoSchema,
230
+ { timeoutMs: 3e4 }
231
+ ),
232
+ "tabs.update": action(
233
+ "background",
234
+ "Pin, mute or zoom the target tab, or keep Chrome from discarding it (autoDiscardable: false) while it works in the background.",
235
+ z.object({
236
+ pinned: z.boolean().optional(),
237
+ muted: z.boolean().optional(),
238
+ /** Page zoom factor; 1 is 100%. */
239
+ zoom: z.number().min(0.25).max(5).optional(),
240
+ /** false: Chrome won't unload the tab to save memory. */
241
+ autoDiscardable: z.boolean().optional()
242
+ }).refine((v) => Object.values(v).some((x) => x !== void 0), { message: "Give pinned, muted, zoom or autoDiscardable" }),
243
+ tabInfoSchema.extend({ pinned: z.boolean(), muted: z.boolean(), zoom: z.number(), autoDiscardable: z.boolean() })
244
+ ),
245
+ // windows ---------------------------------------------------------------
246
+ "windows.list": action(
247
+ "background",
248
+ "List browser windows.",
249
+ empty,
250
+ z.object({ windows: z.array(windowInfoSchema) })
251
+ ),
252
+ "windows.open": action(
253
+ "background",
254
+ "Open a new browser window, optionally at a URL.",
255
+ z.object({
256
+ url: z.string().optional(),
257
+ focused: z.boolean().default(true),
258
+ type: z.enum(["normal", "popup"]).default("normal"),
259
+ ...windowBoundsShape,
260
+ waitForLoad: z.boolean().default(true)
261
+ }),
262
+ windowInfoSchema.extend({ tab: tabInfoSchema.optional() }),
263
+ { timeoutMs: 3e4 }
264
+ ),
265
+ "windows.update": action(
266
+ "background",
267
+ "Focus, resize, move, minimize or maximize a window.",
268
+ z.object({
269
+ windowId: z.number(),
270
+ focused: z.boolean().optional(),
271
+ state: z.enum(["normal", "minimized", "maximized", "fullscreen"]).optional(),
272
+ ...windowBoundsShape
273
+ }),
274
+ windowInfoSchema
275
+ ),
276
+ "windows.close": action("background", "Close a window and all its tabs.", z.object({ windowId: z.number() }), empty),
277
+ // capture ---------------------------------------------------------------
278
+ "capture.screenshot": action(
279
+ "background",
280
+ "Capture the visible part of the target tab, or crop to one element. A tab in the background is captured through tab capture (the tabCapture group).",
281
+ z.object({
282
+ format: z.enum(["png", "jpeg"]).default("png"),
283
+ quality: z.number().int().min(0).max(100).optional(),
284
+ locator: locatorSchema.optional()
285
+ }),
286
+ z.object({ dataUrl: z.string(), width: z.number(), height: z.number() }),
287
+ { timeoutMs: 15e3 }
288
+ ),
289
+ "capture.fullPage": action(
290
+ "background",
291
+ "Capture the whole page by scrolling and stitching. A tab in the background is captured through tab capture (the tabCapture group). Fixed headers may show more than once.",
292
+ z.object({
293
+ format: z.enum(["png", "jpeg"]).default("png"),
294
+ quality: z.number().int().min(0).max(100).optional(),
295
+ /** Stop after this many CSS pixels of page height. */
296
+ maxHeight: z.number().int().min(100).max(3e4).default(15e3)
297
+ }),
298
+ z.object({ dataUrl: z.string(), width: z.number(), height: z.number(), truncated: z.boolean() }),
299
+ { timeoutMs: 9e4 }
300
+ ),
301
+ // tabCapture ------------------------------------------------------------
302
+ "tabCapture.start": action(
303
+ "background",
304
+ "Keep the target tab rendering in the background by capturing it: Chrome keeps painting it, runs its animation frames and timers at full speed, and doesn't discard it. Screenshots of it then work without bringing it to the front. The extension must have been invoked on the tab (toolbar button, side panel, shortcut or context menu) since it last navigated; otherwise this fails with NEEDS_USER_GESTURE.",
305
+ empty,
306
+ z.object({ tabId: z.number(), width: z.number(), height: z.number() }),
307
+ { timeoutMs: 15e3 }
308
+ ),
309
+ "tabCapture.stop": action("background", "Stop capturing the target tab, so Chrome can throttle it again.", empty, z.object({ stopped: z.boolean() })),
310
+ "tabCapture.list": action("background", "List the tabs being captured to keep them rendering.", empty, z.object({ tabIds: z.array(z.number()) })),
311
+ // frames ----------------------------------------------------------------
312
+ "frames.list": action(
313
+ "background",
314
+ "List the frames (iframes) in the target tab, to target one with { frame: frameId } or { frame: { urlMatch } }.",
315
+ empty,
316
+ z.object({ frames: z.array(z.object({ frameId: z.number(), parentFrameId: z.number(), url: z.string() })) })
317
+ ),
318
+ // page ------------------------------------------------------------------
319
+ "page.info": action(
320
+ "content",
321
+ "URL, title, viewport, scroll position and document size.",
322
+ empty,
323
+ z.object({
324
+ url: z.string(),
325
+ title: z.string(),
326
+ viewport: z.object({ width: z.number(), height: z.number(), devicePixelRatio: z.number() }),
327
+ scroll: z.object({ x: z.number(), y: z.number() }),
328
+ document: z.object({ width: z.number(), height: z.number() })
329
+ })
330
+ ),
331
+ "page.scroll": action(
332
+ "content",
333
+ "Scroll the page to a position, by an amount, or to the top or bottom.",
334
+ z.object({
335
+ x: z.number().optional(),
336
+ y: z.number().optional(),
337
+ by: z.boolean().default(false),
338
+ to: z.enum(["top", "bottom"]).optional(),
339
+ behavior: scrollBehavior.default("instant")
340
+ }),
341
+ z.object({ scroll: z.object({ x: z.number(), y: z.number() }) })
342
+ ),
343
+ // dom: reading ------------------------------------------------------------
344
+ "dom.query": action(
345
+ "content",
346
+ "Find elements and describe them.",
347
+ z.object({
348
+ locator: locatorSchema,
349
+ all: z.boolean().default(false),
350
+ limit: z.number().int().min(1).max(500).default(50),
351
+ textMaxLength: z.number().int().min(0).default(200),
352
+ wait: z.boolean().default(true)
353
+ }),
354
+ z.object({ elements: z.array(elementInfoSchema) })
355
+ ),
356
+ "dom.text": action(
357
+ "content",
358
+ "Readable text of the page or of one element.",
359
+ z.object({ locator: locatorSchema.optional(), maxLength: z.number().int().min(1).default(2e4) }),
360
+ z.object({ text: z.string(), truncated: z.boolean() })
361
+ ),
362
+ "dom.snapshot": action(
363
+ "content",
364
+ "Compact accessibility-style tree with refs for interactive elements.",
365
+ z.object({
366
+ locator: locatorSchema.optional(),
367
+ maxNodes: z.number().int().min(1).max(2e4).default(1500),
368
+ interactiveOnly: z.boolean().default(false),
369
+ /** Only elements at least partly inside the visible viewport. Keeps snapshots of long pages small. */
370
+ viewportOnly: z.boolean().default(false),
371
+ /** Cut text nodes longer than this. */
372
+ textMaxLength: z.number().int().min(10).max(5e3).default(300),
373
+ format: z.enum(["tree", "text", "both"]).default("both")
374
+ }),
375
+ z.object({
376
+ root: snapshotNodeSchema.optional(),
377
+ text: z.string().optional(),
378
+ nodeCount: z.number(),
379
+ truncated: z.boolean()
380
+ })
381
+ ),
382
+ "dom.html": action(
383
+ "content",
384
+ "HTML of the page or of one element. Password and payment field values are masked; shadow roots are not included.",
385
+ z.object({
386
+ locator: locatorSchema.optional(),
387
+ /** Include the element's own tag (outerHTML), or only its children (innerHTML). */
388
+ outer: z.boolean().default(true),
389
+ maxLength: z.number().int().min(1).max(5e6).default(5e5)
390
+ }),
391
+ z.object({ html: z.string(), length: z.number(), truncated: z.boolean() })
392
+ ),
393
+ // dom: interacting --------------------------------------------------------
394
+ "dom.click": action(
395
+ "content",
396
+ "Click an element.",
397
+ z.object({
398
+ locator: locatorSchema,
399
+ button: z.enum(["left", "middle", "right"]).default("left"),
400
+ clickCount: z.number().int().min(1).max(3).default(1),
401
+ modifiers: z.array(z.enum(["Alt", "Control", "Meta", "Shift"])).default([]),
402
+ /** Hold the button down this long before releasing (long press). */
403
+ holdMs: z.number().int().min(0).max(1e4).default(0)
404
+ }),
405
+ refOut
406
+ ),
407
+ "dom.hover": action("content", "Move the pointer over an element.", z.object({ locator: locatorSchema }), refOut),
408
+ "dom.focus": action("content", "Focus an element.", z.object({ locator: locatorSchema }), refOut),
409
+ "dom.type": action(
410
+ "content",
411
+ "Type text key by key into an element (or the focused element).",
412
+ z.object({
413
+ locator: locatorSchema.optional(),
414
+ text: z.string(),
415
+ delayMs: z.number().int().min(0).max(1e3).default(0),
416
+ clear: z.boolean().default(false)
417
+ }),
418
+ refOut,
419
+ { timeoutMs: 3e4 }
420
+ ),
421
+ "dom.fill": action("content", "Set the value of an input in one step.", z.object({ locator: locatorSchema, value: z.string() }), refOut),
422
+ "dom.select": action(
423
+ "content",
424
+ "Choose options in a <select> by value or label.",
425
+ z.object({ locator: locatorSchema, values: z.array(z.string()).min(1) }),
426
+ z.object({ ref: z.string(), selected: z.array(z.string()) })
427
+ ),
428
+ "dom.check": action(
429
+ "content",
430
+ "Check or uncheck a checkbox or radio.",
431
+ z.object({ locator: locatorSchema, checked: z.boolean().default(true) }),
432
+ z.object({ ref: z.string(), checked: z.boolean() })
433
+ ),
434
+ "dom.press": action(
435
+ "content",
436
+ "Press a key on an element (or the focused element).",
437
+ z.object({
438
+ locator: locatorSchema.optional(),
439
+ key: z.string(),
440
+ modifiers: z.array(z.enum(["Alt", "Control", "Meta", "Shift"])).default([])
441
+ }),
442
+ empty
443
+ ),
444
+ "dom.blur": action("content", "Take focus away from an element (or the focused element).", z.object({ locator: locatorSchema.optional() }), z.object({ ref: z.string().optional() })),
445
+ "dom.drag": action(
446
+ "content",
447
+ "Drag an element onto another element, or by an offset (sliders, sortable lists, HTML5 drag and drop).",
448
+ z.object({
449
+ from: locatorSchema,
450
+ to: locatorSchema.optional(),
451
+ /** Move by this many pixels from the source's center instead of onto an element. */
452
+ offset: z.object({ x: z.number(), y: z.number() }).optional(),
453
+ /** Pointer moves between start and end. */
454
+ steps: z.number().int().min(1).max(100).default(10)
455
+ }).refine((v) => Boolean(v.to) !== Boolean(v.offset), { message: "Give either to or offset" }),
456
+ z.object({ from: z.string(), to: z.string().optional(), html5: z.boolean() })
457
+ ),
458
+ "dom.upload": action(
459
+ "content",
460
+ "Give files to an <input type=file>, or drop them on a drop zone. Content is base64 (or text).",
461
+ z.object({
462
+ locator: locatorSchema,
463
+ files: z.array(
464
+ z.object({
465
+ name: z.string().min(1).max(255),
466
+ mimeType: z.string().default("application/octet-stream"),
467
+ base64: z.string().optional(),
468
+ text: z.string().optional()
469
+ }).refine((f) => f.base64 === void 0 !== (f.text === void 0), { message: "Give base64 or text" })
470
+ ).min(1).max(20)
471
+ }),
472
+ z.object({ ref: z.string(), files: z.number(), via: z.enum(["input", "drop"]) }),
473
+ { timeoutMs: 3e4 }
474
+ ),
475
+ "dom.scroll": action(
476
+ "content",
477
+ "Scroll inside a scrollable element (a list, a panel) by an amount, to a position, or to an edge.",
478
+ z.object({
479
+ locator: locatorSchema,
480
+ x: z.number().optional(),
481
+ y: z.number().optional(),
482
+ by: z.boolean().default(true),
483
+ to: z.enum(["top", "bottom", "left", "right"]).optional(),
484
+ behavior: scrollBehavior.default("instant")
485
+ }),
486
+ z.object({ ref: z.string(), scrollTop: z.number(), scrollLeft: z.number(), scrollHeight: z.number(), scrollWidth: z.number(), clientHeight: z.number(), clientWidth: z.number() })
487
+ ),
488
+ "dom.wheel": action(
489
+ "content",
490
+ "Turn the mouse wheel over an element (or the page). Fires wheel events, then scrolls if the page didn't cancel them.",
491
+ z.object({
492
+ locator: locatorSchema.optional(),
493
+ deltaX: z.number().default(0),
494
+ deltaY: z.number().default(100),
495
+ steps: z.number().int().min(1).max(50).default(1)
496
+ }),
497
+ z.object({ ref: z.string().optional(), scrolled: z.boolean(), scrollTop: z.number(), scrollLeft: z.number() })
498
+ ),
499
+ "dom.selectText": action(
500
+ "content",
501
+ "Select text: a range in an input, part of an element's text, or all of it.",
502
+ z.object({
503
+ locator: locatorSchema,
504
+ /** Character offsets (inputs and textareas, or within the element's text). */
505
+ start: z.number().int().min(0).optional(),
506
+ end: z.number().int().min(0).optional(),
507
+ /** Select the first occurrence of this text inside the element. */
508
+ text: z.string().optional()
509
+ }),
510
+ z.object({ ref: z.string(), selected: z.string() })
511
+ ),
512
+ "dom.paste": action(
513
+ "content",
514
+ "Paste text into an element (or the focused element): fires a paste event, then inserts the text unless the page handled it.",
515
+ z.object({ locator: locatorSchema.optional(), text: z.string() }),
516
+ z.object({ ref: z.string(), handledByPage: z.boolean() })
517
+ ),
518
+ "dom.pointer": action(
519
+ "content",
520
+ "Low-level pointer: press, move or release at an element (or viewport point). For custom gestures.",
521
+ z.object({
522
+ type: z.enum(["down", "move", "up"]),
523
+ locator: locatorSchema.optional(),
524
+ /** Viewport coordinates, instead of an element's center. */
525
+ x: z.number().optional(),
526
+ y: z.number().optional(),
527
+ button: z.enum(["left", "middle", "right"]).default("left")
528
+ }).refine((v) => v.locator || v.x !== void 0 && v.y !== void 0, { message: "Give a locator or x and y" }),
529
+ z.object({ ref: z.string().optional(), x: z.number(), y: z.number() })
530
+ ),
531
+ "dom.scrollTo": action(
532
+ "content",
533
+ "Scroll an element into view.",
534
+ z.object({
535
+ locator: locatorSchema,
536
+ block: z.enum(["start", "center", "end", "nearest"]).default("center"),
537
+ behavior: scrollBehavior.default("instant")
538
+ }),
539
+ refOut
540
+ ),
541
+ // edit: changing the page's DOM -----------------------------------------
542
+ "edit.setHtml": action(
543
+ "content",
544
+ "Replace or insert HTML at an element. The HTML is sanitized first: scripts, frames, plugins, event-handler attributes and javascript: URLs are removed.",
545
+ z.object({
546
+ locator: locatorSchema,
547
+ html: z.string().max(5e6),
548
+ /** inner: replace children; outer: replace the element; or insert next to it (insertAdjacentHTML positions). */
549
+ position: z.enum(["inner", "outer", "beforebegin", "afterbegin", "beforeend", "afterend"]).default("inner")
550
+ }),
551
+ z.object({
552
+ /** Refs of the top-level elements that were inserted. */
553
+ refs: z.array(z.string()),
554
+ /** Elements and attributes the sanitizer removed. */
555
+ removed: z.number()
556
+ })
557
+ ),
558
+ "edit.setText": action(
559
+ "content",
560
+ "Replace an element's text content (removes its children).",
561
+ z.object({ locator: locatorSchema, text: z.string().max(5e6) }),
562
+ refOut
563
+ ),
564
+ "edit.setAttributes": action(
565
+ "content",
566
+ "Set or remove attributes on an element (null removes). Event-handler attributes and javascript: URLs are refused.",
567
+ z.object({ locator: locatorSchema, attributes: z.record(z.string().min(1), z.string().nullable()) }),
568
+ z.object({ ref: z.string(), attributes: z.record(z.string(), z.string()) })
569
+ ),
570
+ "edit.remove": action(
571
+ "content",
572
+ "Remove elements from the page.",
573
+ z.object({ locator: locatorSchema, all: z.boolean().default(false) }),
574
+ z.object({ removed: z.number() })
575
+ ),
576
+ // wait ------------------------------------------------------------------
577
+ "wait.for": action(
578
+ "content",
579
+ "Wait for an element state or a URL.",
580
+ z.object({
581
+ locator: locatorSchema.optional(),
582
+ state: z.enum(["attached", "detached", "visible", "hidden"]).default("visible"),
583
+ urlMatch: z.string().optional()
584
+ }).refine((v) => v.locator || v.urlMatch, { message: "Give a locator or a urlMatch" }),
585
+ z.object({ ref: z.string().optional() }),
586
+ { timeoutMs: 15e3 }
587
+ ),
588
+ // overlay ---------------------------------------------------------------
589
+ "overlay.highlight": action(
590
+ "content",
591
+ "Outline elements on the page, with an optional label.",
592
+ z.object({
593
+ locator: locatorSchema,
594
+ all: z.boolean().default(false),
595
+ label: z.string().optional(),
596
+ color: z.string().default("#7c3aed"),
597
+ durationMs: z.number().int().min(0).default(0),
598
+ id: z.string().optional()
599
+ }),
600
+ z.object({ id: z.string(), count: z.number() })
601
+ ),
602
+ "overlay.clear": action("content", "Remove highlights (one id, or all).", z.object({ id: z.string().optional() }), empty),
603
+ "overlay.toast": action(
604
+ "content",
605
+ "Show a short message on the page.",
606
+ z.object({
607
+ message: z.string().max(500),
608
+ kind: z.enum(["info", "success", "error"]).default("info"),
609
+ durationMs: z.number().int().min(500).max(3e4).default(3e3)
610
+ }),
611
+ empty
612
+ ),
613
+ // picker ----------------------------------------------------------------
614
+ "picker.start": action(
615
+ "content",
616
+ "Let the person pick an element. Resolves with its locator; Esc cancels.",
617
+ z.object({ prompt: z.string().max(200).optional() }),
618
+ z.object({
619
+ ref: z.string(),
620
+ locator: z.object({
621
+ css: z.string(),
622
+ role: z.string().optional(),
623
+ name: z.string().optional(),
624
+ testId: z.string().optional(),
625
+ text: z.string().optional()
626
+ }),
627
+ element: elementInfoSchema
628
+ }),
629
+ { timeoutMs: 12e4 }
630
+ ),
631
+ "picker.cancel": action("content", "Stop an active picker.", empty, empty),
632
+ // downloads (opt-in) ----------------------------------------------------
633
+ "downloads.start": action(
634
+ "background",
635
+ "Download a URL to the person's Downloads folder, and by default wait until it finishes.",
636
+ z.object({
637
+ url: z.string(),
638
+ /** Path relative to the Downloads folder. */
639
+ filename: z.string().min(1).max(255).optional(),
640
+ conflictAction: z.enum(["uniquify", "overwrite", "prompt"]).default("uniquify"),
641
+ /** Show the Save As dialog. */
642
+ saveAs: z.boolean().default(false),
643
+ waitForComplete: z.boolean().default(true)
644
+ }),
645
+ downloadInfoSchema,
646
+ { timeoutMs: 12e4 }
647
+ ),
648
+ "downloads.list": action(
649
+ "background",
650
+ "List recent downloads, newest first.",
651
+ z.object({
652
+ query: z.string().optional(),
653
+ state: z.enum(["in_progress", "interrupted", "complete"]).optional(),
654
+ limit: z.number().int().min(1).max(1e3).default(50)
655
+ }),
656
+ z.object({ downloads: z.array(downloadInfoSchema) })
657
+ ),
658
+ "downloads.cancel": action("background", "Cancel a download that is in progress.", z.object({ id: z.number() }), empty),
659
+ // bookmarks (opt-in) ----------------------------------------------------
660
+ "bookmarks.search": action(
661
+ "background",
662
+ "Find bookmarks whose title or URL contains the text.",
663
+ z.object({ query: z.string().min(1), limit: z.number().int().min(1).max(1e3).default(100) }),
664
+ z.object({ bookmarks: z.array(bookmarkSchema) })
665
+ ),
666
+ "bookmarks.list": action(
667
+ "background",
668
+ "List the bookmarks and folders inside a folder (default: the top-level folders).",
669
+ z.object({ parentId: z.string().default("0") }),
670
+ z.object({ bookmarks: z.array(bookmarkSchema) })
671
+ ),
672
+ "bookmarks.create": action(
673
+ "background",
674
+ "Add a bookmark, or a folder when no url is given.",
675
+ z.object({ title: z.string(), url: z.string().optional(), parentId: z.string().optional(), index: z.number().int().min(0).optional() }),
676
+ bookmarkSchema
677
+ ),
678
+ "bookmarks.update": action(
679
+ "background",
680
+ "Rename a bookmark, change its URL, or move it to another folder or position.",
681
+ z.object({ id: z.string(), title: z.string().optional(), url: z.string().optional(), parentId: z.string().optional(), index: z.number().int().min(0).optional() }).refine((v) => v.title !== void 0 || v.url !== void 0 || v.parentId !== void 0 || v.index !== void 0, { message: "Give title, url, parentId or index" }),
682
+ bookmarkSchema
683
+ ),
684
+ "bookmarks.remove": action(
685
+ "background",
686
+ "Delete a bookmark, or a folder (a folder with contents needs recursive: true).",
687
+ z.object({ id: z.string(), recursive: z.boolean().default(false) }),
688
+ empty
689
+ ),
690
+ // history (opt-in) ------------------------------------------------------
691
+ "history.search": action(
692
+ "background",
693
+ "Search the browsing history, most recent first. Times are ms since the epoch.",
694
+ z.object({
695
+ text: z.string().default(""),
696
+ startTime: z.number().optional(),
697
+ endTime: z.number().optional(),
698
+ limit: z.number().int().min(1).max(1e3).default(100)
699
+ }),
700
+ z.object({ items: z.array(historyItemSchema) })
701
+ ),
702
+ "history.delete": action("background", "Remove every visit to a URL from the history.", z.object({ url: z.string() }), empty),
703
+ // cookies (opt-in) ------------------------------------------------------
704
+ "cookies.list": action(
705
+ "background",
706
+ "List cookies for a URL or a domain, optionally by name.",
707
+ z.object({ url: z.string().optional(), domain: z.string().optional(), name: z.string().optional() }).refine((v) => v.url || v.domain, { message: "Give a url or a domain" }),
708
+ z.object({ cookies: z.array(cookieSchema) })
709
+ ),
710
+ "cookies.set": action(
711
+ "background",
712
+ "Set a cookie. Without expirationDate (seconds since the epoch) it is a session cookie.",
713
+ z.object({
714
+ url: z.string(),
715
+ name: z.string(),
716
+ value: z.string(),
717
+ domain: z.string().optional(),
718
+ path: z.string().optional(),
719
+ secure: z.boolean().optional(),
720
+ httpOnly: z.boolean().optional(),
721
+ sameSite: z.enum(["no_restriction", "lax", "strict", "unspecified"]).optional(),
722
+ expirationDate: z.number().optional()
723
+ }),
724
+ cookieSchema
725
+ ),
726
+ "cookies.remove": action(
727
+ "background",
728
+ "Delete a cookie by URL and name.",
729
+ z.object({ url: z.string(), name: z.string() }),
730
+ z.object({ removed: z.boolean() })
731
+ ),
732
+ // permissions (run in the frame bridge, which has the person's click) ----
733
+ "permissions.contains": action(
734
+ "bridge",
735
+ "Check whether the extension has these permissions or host origins.",
736
+ permissionSetSchema(),
737
+ z.object({ granted: z.boolean() })
738
+ ),
739
+ "permissions.request": action(
740
+ "bridge",
741
+ "Ask the person for optional permissions or host origins. Needs a click in the frame within the last few seconds.",
742
+ permissionSetSchema(),
743
+ z.object({ granted: z.boolean() }),
744
+ { timeoutMs: 12e4 }
745
+ ),
746
+ "permissions.getAll": action(
747
+ "bridge",
748
+ "List the permissions and host origins the extension has now.",
749
+ empty,
750
+ z.object({ permissions: z.array(z.string()), origins: z.array(z.string()) })
751
+ )
752
+ };
753
+ function permissionSetSchema() {
754
+ return z.object({ permissions: z.array(z.string()).optional(), origins: z.array(z.string()).optional() }).refine((p) => (p.permissions?.length ?? 0) + (p.origins?.length ?? 0) > 0, { message: "Give permissions or origins" });
755
+ }
756
+ var coreEventSchemas = {
757
+ "tab.updated": z.object({ tab: tabInfoSchema, changes: z.record(z.string(), z.unknown()) }),
758
+ "tab.activated": z.object({ tabId: z.number(), windowId: z.number() }),
759
+ "tab.removed": z.object({ tabId: z.number() }),
760
+ "picker.selected": z.object({ ref: z.string(), locator: z.record(z.string(), z.string()), url: z.string() }),
761
+ "picker.hovered": z.object({ ref: z.string(), role: z.string(), name: z.string() })
762
+ };
763
+ export {
764
+ bookmarkSchema,
765
+ boxSchema,
766
+ cookieSchema,
767
+ coreActionSchemas,
768
+ coreEventSchemas,
769
+ downloadInfoSchema,
770
+ elementInfoSchema,
771
+ historyItemSchema,
772
+ locatorSchema,
773
+ sequenceStepSchema,
774
+ snapshotNodeSchema,
775
+ tabInfoSchema,
776
+ windowInfoSchema,
777
+ z
778
+ };