agentchrome 1.51.4

A CLI tool for browser automation via the Chrome DevTools Protocol
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
use serde::Serialize;

// =============================================================================
// Output types
// =============================================================================

#[derive(Serialize)]
pub struct CommandGroupSummary {
    pub command: String,
    pub description: String,
    pub examples: Vec<ExampleEntry>,
}

#[derive(Serialize, Clone)]
pub struct CommandGroupListing {
    pub command: String,
    pub description: String,
}

impl From<&CommandGroupSummary> for CommandGroupListing {
    fn from(s: &CommandGroupSummary) -> Self {
        Self {
            command: s.command.clone(),
            description: s.description.clone(),
        }
    }
}

#[derive(Serialize)]
pub struct ExampleEntry {
    pub cmd: String,
    pub description: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub flags: Option<Vec<String>>,
}

// =============================================================================
// Static example data
// =============================================================================

#[must_use]
#[allow(clippy::too_many_lines)]
pub fn all_examples() -> Vec<CommandGroupSummary> {
    vec![
        CommandGroupSummary {
            command: "connect".into(),
            description: "Connect to or launch a Chrome instance".into(),
            examples: vec![
                ExampleEntry {
                    cmd: "agentchrome connect".into(),
                    description: "Connect to Chrome on the default port (9222)".into(),
                    flags: None,
                },
                ExampleEntry {
                    cmd: "agentchrome connect --launch --headless".into(),
                    description: "Launch a new headless Chrome instance".into(),
                    flags: Some(vec!["--launch".into(), "--headless".into()]),
                },
                ExampleEntry {
                    cmd: "agentchrome connect --port 9333".into(),
                    description: "Connect to Chrome on a specific port".into(),
                    flags: Some(vec!["--port".into()]),
                },
                ExampleEntry {
                    cmd: "agentchrome connect --status".into(),
                    description: "Check current connection status".into(),
                    flags: Some(vec!["--status".into()]),
                },
                ExampleEntry {
                    cmd: "agentchrome connect --disconnect".into(),
                    description: "Disconnect and remove the session file".into(),
                    flags: Some(vec!["--disconnect".into()]),
                },
            ],
        },
        CommandGroupSummary {
            command: "tabs".into(),
            description: "Tab management (list, create, close, activate)".into(),
            examples: vec![
                ExampleEntry {
                    cmd: "agentchrome tabs list".into(),
                    description: "List all open tabs".into(),
                    flags: None,
                },
                ExampleEntry {
                    cmd: "agentchrome tabs create https://example.com".into(),
                    description: "Open a new tab with a URL".into(),
                    flags: None,
                },
                ExampleEntry {
                    cmd: "agentchrome tabs close ABC123".into(),
                    description: "Close a tab by its ID".into(),
                    flags: None,
                },
                ExampleEntry {
                    cmd: "agentchrome tabs activate ABC123".into(),
                    description: "Activate (focus) a tab by its ID".into(),
                    flags: None,
                },
                ExampleEntry {
                    cmd: "agentchrome tabs list --all".into(),
                    description: "List all tabs including internal Chrome pages".into(),
                    flags: Some(vec!["--all".into()]),
                },
            ],
        },
        CommandGroupSummary {
            command: "navigate".into(),
            description: "URL navigation and history".into(),
            examples: vec![
                ExampleEntry {
                    cmd: "agentchrome navigate https://example.com".into(),
                    description: "Navigate to a URL and wait for load".into(),
                    flags: None,
                },
                ExampleEntry {
                    cmd: "agentchrome navigate https://app.example.com --wait-until networkidle"
                        .into(),
                    description: "Navigate and wait for network idle (for SPAs)".into(),
                    flags: Some(vec!["--wait-until".into()]),
                },
                ExampleEntry {
                    cmd: "agentchrome navigate back".into(),
                    description: "Go back in browser history".into(),
                    flags: None,
                },
                ExampleEntry {
                    cmd: "agentchrome navigate reload --ignore-cache".into(),
                    description: "Reload the page without cache".into(),
                    flags: Some(vec!["--ignore-cache".into()]),
                },
            ],
        },
        CommandGroupSummary {
            command: "page".into(),
            description: "Page inspection (screenshot, text, accessibility tree, find)".into(),
            examples: vec![
                ExampleEntry {
                    cmd: "agentchrome page text".into(),
                    description: "Extract all visible text from the page".into(),
                    flags: None,
                },
                ExampleEntry {
                    cmd: "agentchrome page snapshot".into(),
                    description: "Capture the accessibility tree with element UIDs".into(),
                    flags: None,
                },
                ExampleEntry {
                    cmd: "agentchrome page snapshot --compact".into(),
                    description: "Compact snapshot with only interactive and landmark elements"
                        .into(),
                    flags: Some(vec!["--compact".into()]),
                },
                ExampleEntry {
                    cmd: "agentchrome page screenshot --full-page --file page.png".into(),
                    description: "Take a full-page screenshot".into(),
                    flags: Some(vec!["--full-page".into(), "--file".into()]),
                },
                ExampleEntry {
                    cmd: "agentchrome page find \"Sign in\"".into(),
                    description: "Find elements by text".into(),
                    flags: None,
                },
                ExampleEntry {
                    cmd: "agentchrome page resize 1280x720".into(),
                    description: "Resize the viewport to specific dimensions".into(),
                    flags: None,
                },
                ExampleEntry {
                    cmd: "agentchrome page frames".into(),
                    description: "List all iframes and frames in the page hierarchy".into(),
                    flags: None,
                },
                ExampleEntry {
                    cmd: "agentchrome page snapshot --frame 1".into(),
                    description: "Capture accessibility tree of a specific iframe".into(),
                    flags: Some(vec!["--frame".into()]),
                },
                ExampleEntry {
                    cmd: "agentchrome page snapshot --pierce-shadow".into(),
                    description: "Include shadow DOM elements in the accessibility tree".into(),
                    flags: Some(vec!["--pierce-shadow".into()]),
                },
                ExampleEntry {
                    cmd: "agentchrome page workers".into(),
                    description: "List service workers, shared workers, and web workers".into(),
                    flags: None,
                },
                ExampleEntry {
                    cmd: "agentchrome page hittest 100 200".into(),
                    description: "Hit test at viewport coordinates to identify click targets"
                        .into(),
                    flags: None,
                },
                ExampleEntry {
                    cmd: "agentchrome page hittest 50 50 --frame 1".into(),
                    description: "Hit test within a specific iframe".into(),
                    flags: Some(vec!["--frame".into()]),
                },
                ExampleEntry {
                    cmd: "agentchrome page coords --selector css:#submit".into(),
                    description: "Get frame-local and page-global bounding box for a CSS selector"
                        .into(),
                    flags: Some(vec!["--selector".into()]),
                },
                ExampleEntry {
                    cmd: "agentchrome page coords --selector s7".into(),
                    description: "Get bounding box for a snapshot UID".into(),
                    flags: Some(vec!["--selector".into()]),
                },
                ExampleEntry {
                    cmd: "agentchrome page --frame 1 coords --selector css:#inner".into(),
                    description: "Get bounding box for an element inside an iframe, reporting both frame-local and page-global coordinates".into(),
                    flags: Some(vec!["--frame".into(), "--selector".into()]),
                },
                ExampleEntry {
                    cmd: "agentchrome page analyze".into(),
                    description: "Analyze page structure: iframes, frameworks, overlays, media"
                        .into(),
                    flags: None,
                },
                ExampleEntry {
                    cmd: "agentchrome page analyze --frame 1".into(),
                    description: "Analyze structure within a specific iframe".into(),
                    flags: Some(vec!["--frame".into()]),
                },
            ],
        },
        CommandGroupSummary {
            command: "diagnose".into(),
            description: "Pre-automation challenge scan (iframes, overlays, media gates, frameworks, patterns)".into(),
            examples: vec![
                ExampleEntry {
                    cmd: "agentchrome diagnose https://example.com/course".into(),
                    description: "Navigate to a URL and diagnose it for automation challenges".into(),
                    flags: None,
                },
                ExampleEntry {
                    cmd: "agentchrome diagnose --current".into(),
                    description: "Diagnose the already-loaded page without navigating".into(),
                    flags: Some(vec!["--current".into()]),
                },
                ExampleEntry {
                    cmd: "agentchrome diagnose --current | jq -r '.patterns[].suggestion'".into(),
                    description: "Extract all pattern strategy suggestions via jq".into(),
                    flags: Some(vec!["--current".into()]),
                },
                ExampleEntry {
                    cmd: "agentchrome diagnose https://app.example.com --wait-until networkidle".into(),
                    description: "Diagnose after waiting for network idle (for SPAs)".into(),
                    flags: Some(vec!["--wait-until".into()]),
                },
                ExampleEntry {
                    cmd: "agentchrome diagnose --current | jq '.summary'".into(),
                    description: "Check if the page is straightforward to automate".into(),
                    flags: Some(vec!["--current".into()]),
                },
            ],
        },
        CommandGroupSummary {
            command: "dom".into(),
            description: "DOM inspection and manipulation".into(),
            examples: vec![
                ExampleEntry {
                    cmd: "agentchrome dom select \"h1\"".into(),
                    description: "Select elements by CSS selector".into(),
                    flags: None,
                },
                ExampleEntry {
                    cmd: "agentchrome dom select \"//a[@href]\" --xpath".into(),
                    description: "Select elements by XPath expression".into(),
                    flags: Some(vec!["--xpath".into()]),
                },
                ExampleEntry {
                    cmd: "agentchrome dom get-attribute s3 href".into(),
                    description: "Get an element's attribute by UID".into(),
                    flags: None,
                },
                ExampleEntry {
                    cmd: "agentchrome dom get-text css:h1".into(),
                    description: "Get the text content of an element".into(),
                    flags: None,
                },
                ExampleEntry {
                    cmd: "agentchrome dom tree --depth 3".into(),
                    description: "View the DOM tree with limited depth".into(),
                    flags: Some(vec!["--depth".into()]),
                },
                ExampleEntry {
                    cmd: "agentchrome dom tree css:table --depth 3".into(),
                    description: "View the DOM subtree rooted at an element (positional)".into(),
                    flags: Some(vec!["--depth".into()]),
                },
                ExampleEntry {
                    cmd: "agentchrome dom --frame 1 select \"css:button\"".into(),
                    description: "Query elements inside an iframe".into(),
                    flags: Some(vec!["--frame".into()]),
                },
                ExampleEntry {
                    cmd: "agentchrome dom --pierce-shadow select \"css:#shadow-btn\"".into(),
                    description: "Query elements inside shadow DOM".into(),
                    flags: Some(vec!["--pierce-shadow".into()]),
                },
                ExampleEntry {
                    cmd: "agentchrome dom events css:button".into(),
                    description: "List event listeners on an element".into(),
                    flags: None,
                },
            ],
        },
        CommandGroupSummary {
            command: "js".into(),
            description: "JavaScript execution in page context".into(),
            examples: vec![
                ExampleEntry {
                    cmd: "agentchrome js exec \"document.title\"".into(),
                    description: "Get the page title".into(),
                    flags: None,
                },
                ExampleEntry {
                    cmd: "agentchrome js exec --file script.js".into(),
                    description: "Execute a JavaScript file".into(),
                    flags: Some(vec!["--file".into()]),
                },
                ExampleEntry {
                    cmd: "agentchrome js exec --uid s3 \"(el) => el.textContent\"".into(),
                    description: "Run code on a specific element by UID".into(),
                    flags: Some(vec!["--uid".into()]),
                },
                ExampleEntry {
                    cmd: "echo 'document.URL' | agentchrome js exec -".into(),
                    description: "Read JavaScript from stdin".into(),
                    flags: None,
                },
                ExampleEntry {
                    cmd: "agentchrome js --frame 1 exec \"document.title\"".into(),
                    description: "Execute JavaScript inside an iframe".into(),
                    flags: Some(vec!["--frame".into()]),
                },
                ExampleEntry {
                    cmd: "agentchrome js exec --worker 0 \"self.registration.scope\"".into(),
                    description: "Execute JavaScript in a Service Worker".into(),
                    flags: Some(vec!["--worker".into()]),
                },
            ],
        },
        CommandGroupSummary {
            command: "console".into(),
            description: "Console message reading and monitoring".into(),
            examples: vec![
                ExampleEntry {
                    cmd: "agentchrome console read".into(),
                    description: "Read recent console messages".into(),
                    flags: None,
                },
                ExampleEntry {
                    cmd: "agentchrome console read --errors-only".into(),
                    description: "Show only error messages".into(),
                    flags: Some(vec!["--errors-only".into()]),
                },
                ExampleEntry {
                    cmd: "agentchrome console follow".into(),
                    description: "Stream console messages in real time".into(),
                    flags: None,
                },
                ExampleEntry {
                    cmd: "agentchrome console follow --errors-only --timeout 10000".into(),
                    description: "Stream errors for 10 seconds".into(),
                    flags: Some(vec!["--errors-only".into(), "--timeout".into()]),
                },
                ExampleEntry {
                    cmd: "agentchrome console follow --timeout 10000 --fail-on-error".into(),
                    description: "CI assertion: exit 1 if any console.error is seen within 10s"
                        .into(),
                    flags: Some(vec!["--timeout".into(), "--fail-on-error".into()]),
                },
            ],
        },
        CommandGroupSummary {
            command: "network".into(),
            description: "Network request monitoring and interception".into(),
            examples: vec![
                ExampleEntry {
                    cmd: "agentchrome network list".into(),
                    description: "List recent network requests".into(),
                    flags: None,
                },
                ExampleEntry {
                    cmd: "agentchrome network list --type xhr,fetch".into(),
                    description: "Filter requests by resource type".into(),
                    flags: Some(vec!["--type".into()]),
                },
                ExampleEntry {
                    cmd: "agentchrome network get 42".into(),
                    description: "Get details of a specific request by ID".into(),
                    flags: None,
                },
                ExampleEntry {
                    cmd: "agentchrome network follow --url api.example.com".into(),
                    description: "Stream network requests matching a URL pattern".into(),
                    flags: Some(vec!["--url".into()]),
                },
                ExampleEntry {
                    cmd: "agentchrome network list --frame 1".into(),
                    description: "List network requests from a specific frame".into(),
                    flags: Some(vec!["--frame".into()]),
                },
            ],
        },
        CommandGroupSummary {
            command: "interact".into(),
            description: "Mouse, keyboard, and scroll interactions".into(),
            examples: vec![
                ExampleEntry {
                    cmd: "agentchrome interact click s5".into(),
                    description: "Click an element by UID".into(),
                    flags: None,
                },
                ExampleEntry {
                    cmd: "agentchrome interact click css:#submit-btn".into(),
                    description: "Click an element by CSS selector".into(),
                    flags: None,
                },
                ExampleEntry {
                    cmd: "agentchrome interact click s12 --wait-until networkidle".into(),
                    description: "Click and wait for network idle (for SPA navigation)".into(),
                    flags: Some(vec!["--wait-until".into()]),
                },
                ExampleEntry {
                    cmd: "agentchrome interact type \"Hello, world!\"".into(),
                    description: "Type text into the focused element".into(),
                    flags: None,
                },
                ExampleEntry {
                    cmd: "agentchrome interact key Control+A".into(),
                    description: "Press a key combination".into(),
                    flags: None,
                },
                ExampleEntry {
                    cmd: "agentchrome interact scroll --to-bottom".into(),
                    description: "Scroll to the bottom of the page".into(),
                    flags: Some(vec!["--to-bottom".into()]),
                },
                ExampleEntry {
                    cmd: "agentchrome interact --frame 1 click s3".into(),
                    description: "Click an element inside an iframe".into(),
                    flags: Some(vec!["--frame".into()]),
                },
                ExampleEntry {
                    cmd: "agentchrome interact --frame 1 click-at 100 200".into(),
                    description: "Click at coordinates inside an iframe".into(),
                    flags: Some(vec!["--frame".into()]),
                },
                ExampleEntry {
                    cmd: "agentchrome interact drag-at 100 200 300 400".into(),
                    description: "Drag from coordinates to coordinates".into(),
                    flags: None,
                },
                ExampleEntry {
                    cmd: "agentchrome interact drag-at 0 0 500 500 --steps 10".into(),
                    description: "Drag with interpolated movement steps".into(),
                    flags: Some(vec!["--steps".into()]),
                },
                ExampleEntry {
                    cmd: "agentchrome interact mousedown-at 100 200".into(),
                    description: "Press mouse button at coordinates (no release)".into(),
                    flags: None,
                },
                ExampleEntry {
                    cmd: "agentchrome interact mouseup-at 300 400".into(),
                    description: "Release mouse button at coordinates".into(),
                    flags: None,
                },
                ExampleEntry {
                    cmd: "agentchrome interact click-at 50% 50% --relative-to css:#submit".into(),
                    description: "Click the center of an element using percentage coordinates"
                        .into(),
                    flags: Some(vec!["--relative-to".into()]),
                },
                ExampleEntry {
                    cmd: "agentchrome interact click-at 0% 0% --relative-to css:#submit".into(),
                    description: "Click the top-left corner of an element".into(),
                    flags: Some(vec!["--relative-to".into()]),
                },
                ExampleEntry {
                    cmd: "agentchrome interact click-at 100% 100% --relative-to s7".into(),
                    description: "Click the bottom-right pixel of an element by UID".into(),
                    flags: Some(vec!["--relative-to".into()]),
                },
                ExampleEntry {
                    cmd: "agentchrome interact drag-at 10% 50% 90% 50% --relative-to css:#track"
                        .into(),
                    description: "Drag a slider from 10% to 90% across an element".into(),
                    flags: Some(vec!["--relative-to".into()]),
                },
            ],
        },
        CommandGroupSummary {
            command: "form".into(),
            description: "Form input and submission".into(),
            examples: vec![
                ExampleEntry {
                    cmd: "agentchrome form fill s5 \"hello@example.com\"".into(),
                    description: "Fill a form field by UID".into(),
                    flags: None,
                },
                ExampleEntry {
                    cmd: "agentchrome form fill css:#email \"user@example.com\"".into(),
                    description: "Fill a form field by CSS selector".into(),
                    flags: None,
                },
                ExampleEntry {
                    cmd: "agentchrome form clear s5".into(),
                    description: "Clear a form field".into(),
                    flags: None,
                },
                ExampleEntry {
                    cmd: "agentchrome form upload s10 ./photo.jpg".into(),
                    description: "Upload a file to a file input element".into(),
                    flags: None,
                },
                ExampleEntry {
                    cmd: "agentchrome form fill s5 \"Acme Corp\"".into(),
                    description: "Fill an ARIA combobox field (auto click-type-confirm)".into(),
                    flags: None,
                },
                ExampleEntry {
                    cmd: "agentchrome form fill --confirm-key Tab s5 \"Acme Corp\"".into(),
                    description: "Fill combobox with custom confirmation key".into(),
                    flags: Some(vec!["--confirm-key".into()]),
                },
                ExampleEntry {
                    cmd: "agentchrome form --frame 1 fill s2 \"value\"".into(),
                    description: "Fill a form field inside an iframe".into(),
                    flags: Some(vec!["--frame".into()]),
                },
            ],
        },
        CommandGroupSummary {
            command: "emulate".into(),
            description: "Device and network emulation".into(),
            examples: vec![
                ExampleEntry {
                    cmd: "agentchrome emulate set --viewport 375x667 --device-scale 2 --mobile"
                        .into(),
                    description: "Emulate a mobile device".into(),
                    flags: Some(vec![
                        "--viewport".into(),
                        "--device-scale".into(),
                        "--mobile".into(),
                    ]),
                },
                ExampleEntry {
                    cmd: "agentchrome emulate set --network 3g".into(),
                    description: "Simulate slow 3G network".into(),
                    flags: Some(vec!["--network".into()]),
                },
                ExampleEntry {
                    cmd: "agentchrome emulate set --color-scheme dark".into(),
                    description: "Force dark mode".into(),
                    flags: Some(vec!["--color-scheme".into()]),
                },
                ExampleEntry {
                    cmd: "agentchrome emulate status".into(),
                    description: "Check current emulation settings".into(),
                    flags: None,
                },
                ExampleEntry {
                    cmd: "agentchrome emulate reset".into(),
                    description: "Clear all emulation overrides".into(),
                    flags: None,
                },
            ],
        },
        CommandGroupSummary {
            command: "perf".into(),
            description: "Performance tracing and metrics".into(),
            examples: vec![
                ExampleEntry {
                    cmd: "agentchrome perf vitals".into(),
                    description: "Quick Core Web Vitals measurement".into(),
                    flags: None,
                },
                ExampleEntry {
                    cmd: "agentchrome perf record --duration 5000".into(),
                    description: "Record a trace for 5 seconds".into(),
                    flags: Some(vec!["--duration".into()]),
                },
                ExampleEntry {
                    cmd: "agentchrome perf record --reload --duration 5000".into(),
                    description: "Record a trace with page reload".into(),
                    flags: Some(vec!["--reload".into(), "--duration".into()]),
                },
                ExampleEntry {
                    cmd: "agentchrome perf analyze RenderBlocking --trace-file trace.json".into(),
                    description: "Analyze render-blocking resources from a trace".into(),
                    flags: Some(vec!["--trace-file".into()]),
                },
            ],
        },
        CommandGroupSummary {
            command: "dialog".into(),
            description: "Browser dialog handling (alert, confirm, prompt, beforeunload)".into(),
            examples: vec![
                ExampleEntry {
                    cmd: "agentchrome dialog info".into(),
                    description: "Check if a dialog is currently open".into(),
                    flags: None,
                },
                ExampleEntry {
                    cmd: "agentchrome dialog handle accept".into(),
                    description: "Accept an alert or confirm dialog".into(),
                    flags: None,
                },
                ExampleEntry {
                    cmd: "agentchrome dialog handle dismiss".into(),
                    description: "Dismiss a dialog".into(),
                    flags: None,
                },
                ExampleEntry {
                    cmd: "agentchrome dialog handle accept --text \"my input\"".into(),
                    description: "Accept a prompt dialog with text".into(),
                    flags: Some(vec!["--text".into()]),
                },
            ],
        },
        CommandGroupSummary {
            command: "skill".into(),
            description: "Agentic tool skill installation and management".into(),
            examples: vec![
                ExampleEntry {
                    cmd: "agentchrome skill install".into(),
                    description: "Auto-detect agentic tool and install skill".into(),
                    flags: None,
                },
                ExampleEntry {
                    cmd: "agentchrome skill install --tool cursor".into(),
                    description: "Install skill for a specific tool".into(),
                    flags: Some(vec!["--tool".into()]),
                },
                ExampleEntry {
                    cmd: "agentchrome skill install --tool codex".into(),
                    description: "Install the AgentChrome skill for Codex".into(),
                    flags: Some(vec!["--tool".into()]),
                },
                ExampleEntry {
                    cmd: "agentchrome skill list".into(),
                    description: "List supported tools and installation status".into(),
                    flags: None,
                },
                ExampleEntry {
                    cmd: "agentchrome skill update --tool claude-code".into(),
                    description: "Update installed skill to current version".into(),
                    flags: Some(vec!["--tool".into()]),
                },
                ExampleEntry {
                    cmd: "agentchrome skill uninstall --tool aider".into(),
                    description: "Remove an installed skill".into(),
                    flags: Some(vec!["--tool".into()]),
                },
            ],
        },
        CommandGroupSummary {
            command: "media".into(),
            description: "Media element control (list, play, pause, seek audio/video)".into(),
            examples: vec![
                ExampleEntry {
                    cmd: "agentchrome media list".into(),
                    description: "List all audio and video elements on the page".into(),
                    flags: None,
                },
                ExampleEntry {
                    cmd: "agentchrome media play 0".into(),
                    description: "Play the first media element".into(),
                    flags: None,
                },
                ExampleEntry {
                    cmd: "agentchrome media pause 0".into(),
                    description: "Pause the first media element".into(),
                    flags: None,
                },
                ExampleEntry {
                    cmd: "agentchrome media seek 0 15.5".into(),
                    description: "Seek a media element to 15.5 seconds".into(),
                    flags: None,
                },
                ExampleEntry {
                    cmd: "agentchrome media seek-end --all".into(),
                    description: "Seek all media elements to end (skip narration gates)".into(),
                    flags: Some(vec!["--all".into()]),
                },
                ExampleEntry {
                    cmd: "agentchrome media --frame 0 list".into(),
                    description: "List media elements inside a specific iframe".into(),
                    flags: Some(vec!["--frame".into()]),
                },
                ExampleEntry {
                    cmd: "agentchrome media play css:audio.narration".into(),
                    description: "Play a media element by CSS selector".into(),
                    flags: None,
                },
            ],
        },
        CommandGroupSummary {
            command: "config".into(),
            description: "Configuration file management (show, init, path)".into(),
            examples: vec![
                ExampleEntry {
                    cmd: "agentchrome config show".into(),
                    description: "Show the resolved configuration from all sources".into(),
                    flags: None,
                },
                ExampleEntry {
                    cmd: "agentchrome config init".into(),
                    description: "Create a default config file".into(),
                    flags: None,
                },
                ExampleEntry {
                    cmd: "agentchrome config init --path ./my-config.toml".into(),
                    description: "Create a config at a custom path".into(),
                    flags: Some(vec!["--path".into()]),
                },
                ExampleEntry {
                    cmd: "agentchrome config path".into(),
                    description: "Show the active config file path".into(),
                    flags: None,
                },
            ],
        },
        CommandGroupSummary {
            command: "script".into(),
            description: "Execute a batch script of agentchrome commands from a JSON file".into(),
            examples: vec![
                ExampleEntry {
                    cmd: "agentchrome script run script.json".into(),
                    description: "Execute all commands in script.json sequentially".into(),
                    flags: None,
                },
                ExampleEntry {
                    cmd: "agentchrome script run script.json --fail-fast".into(),
                    description: "Stop on the first failing step and exit non-zero".into(),
                    flags: Some(vec!["--fail-fast".into()]),
                },
                ExampleEntry {
                    cmd: "agentchrome script run script.json --dry-run".into(),
                    description: "Validate the script schema without dispatching to Chrome".into(),
                    flags: Some(vec!["--dry-run".into()]),
                },
                ExampleEntry {
                    cmd: "agentchrome script run -".into(),
                    description: "Read the script from stdin instead of a file".into(),
                    flags: None,
                },
                ExampleEntry {
                    cmd: "echo '{\"commands\":[{\"cmd\":[\"page\",\"find\",\"Submit\"],\"bind\":\"match\"},{\"cmd\":[\"interact\",\"click\",\"$vars.match[0].uid\"]}]}' | agentchrome script run -"
                        .into(),
                    description:
                        "Discover an element via page find, bind the result, then click it"
                            .into(),
                    flags: None,
                },
                ExampleEntry {
                    cmd: "echo '{\"commands\":[{\"cmd\":[\"page\",\"screenshot\",\"--file\",\"out.png\"]}]}' | agentchrome script run -"
                        .into(),
                    description: "Capture a screenshot to a file from inside a script".into(),
                    flags: None,
                },
            ],
        },
    ]
}

// =============================================================================
// Tests
// =============================================================================

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn all_examples_returns_expected_groups() {
        let groups = all_examples();
        let names: Vec<&str> = groups.iter().map(|g| g.command.as_str()).collect();
        assert!(names.contains(&"connect"));
        assert!(names.contains(&"tabs"));
        assert!(names.contains(&"navigate"));
        assert!(names.contains(&"page"));
        assert!(names.contains(&"dom"));
        assert!(names.contains(&"js"));
        assert!(names.contains(&"console"));
        assert!(names.contains(&"network"));
        assert!(names.contains(&"interact"));
        assert!(names.contains(&"form"));
        assert!(names.contains(&"emulate"));
        assert!(names.contains(&"perf"));
        assert!(names.contains(&"dialog"));
        assert!(names.contains(&"media"));
        assert!(names.contains(&"skill"));
        assert!(names.contains(&"config"));
    }

    #[test]
    fn each_group_has_at_least_3_examples() {
        for group in all_examples() {
            assert!(
                group.examples.len() >= 3,
                "Group '{}' has only {} examples, expected at least 3",
                group.command,
                group.examples.len()
            );
        }
    }

    #[test]
    fn no_empty_fields() {
        for group in all_examples() {
            assert!(!group.command.is_empty());
            assert!(!group.description.is_empty());
            for example in &group.examples {
                assert!(
                    !example.cmd.is_empty(),
                    "Empty cmd in group '{}'",
                    group.command
                );
                assert!(
                    !example.description.is_empty(),
                    "Empty description in group '{}'",
                    group.command
                );
            }
        }
    }

    #[test]
    fn json_serialization_has_expected_fields() {
        let groups = all_examples();
        let json = serde_json::to_string(&groups).unwrap();
        let parsed: serde_json::Value = serde_json::from_str(&json).unwrap();
        let arr = parsed.as_array().unwrap();
        assert!(!arr.is_empty());
        for entry in arr {
            assert!(entry.get("command").is_some(), "missing 'command' field");
            assert!(
                entry.get("description").is_some(),
                "missing 'description' field"
            );
            let examples = entry.get("examples").unwrap().as_array().unwrap();
            assert!(!examples.is_empty());
            for ex in examples {
                assert!(ex.get("cmd").is_some(), "missing 'cmd' field");
                assert!(
                    ex.get("description").is_some(),
                    "missing 'description' field"
                );
            }
        }
    }
}