browser-pilot 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.cjs +80 -111
- package/dist/cli.mjs +80 -111
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -3194,15 +3194,6 @@ function parseExecArgs(args) {
|
|
|
3194
3194
|
}
|
|
3195
3195
|
async function execCommand(args, globalOptions) {
|
|
3196
3196
|
const { actionsJson, options: execOptions } = parseExecArgs(args);
|
|
3197
|
-
let session;
|
|
3198
|
-
if (globalOptions.session) {
|
|
3199
|
-
session = await loadSession(globalOptions.session);
|
|
3200
|
-
} else {
|
|
3201
|
-
session = await getDefaultSession();
|
|
3202
|
-
if (!session) {
|
|
3203
|
-
throw new Error('No session found. Run "bp connect" first.');
|
|
3204
|
-
}
|
|
3205
|
-
}
|
|
3206
3197
|
if (!actionsJson) {
|
|
3207
3198
|
throw new Error(
|
|
3208
3199
|
`No actions provided. Usage: bp exec '{"action":"goto","url":"..."}'
|
|
@@ -3218,6 +3209,15 @@ Run 'bp actions' for complete action reference.`
|
|
|
3218
3209
|
"Invalid JSON. Actions must be valid JSON.\n\nRun 'bp actions' for complete action reference."
|
|
3219
3210
|
);
|
|
3220
3211
|
}
|
|
3212
|
+
let session;
|
|
3213
|
+
if (globalOptions.session) {
|
|
3214
|
+
session = await loadSession(globalOptions.session);
|
|
3215
|
+
} else {
|
|
3216
|
+
session = await getDefaultSession();
|
|
3217
|
+
if (!session) {
|
|
3218
|
+
throw new Error('No session found. Run "bp connect" first.');
|
|
3219
|
+
}
|
|
3220
|
+
}
|
|
3221
3221
|
const browser = await connect({
|
|
3222
3222
|
provider: session.provider,
|
|
3223
3223
|
wsUrl: session.wsUrl,
|
|
@@ -3317,67 +3317,62 @@ function getAge(date) {
|
|
|
3317
3317
|
|
|
3318
3318
|
// src/cli/commands/quickstart.ts
|
|
3319
3319
|
var QUICKSTART = `
|
|
3320
|
-
browser-pilot
|
|
3321
|
-
|
|
3322
|
-
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
|
|
3350
|
-
|
|
3351
|
-
|
|
3352
|
-
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
|
|
3362
|
-
|
|
3320
|
+
browser-pilot CLI - Quick Start Guide
|
|
3321
|
+
|
|
3322
|
+
STEP 1: CONNECT TO A BROWSER
|
|
3323
|
+
bp connect --provider generic --name mysite
|
|
3324
|
+
|
|
3325
|
+
This creates a session. The CLI remembers it for subsequent commands.
|
|
3326
|
+
|
|
3327
|
+
STEP 2: NAVIGATE
|
|
3328
|
+
bp exec '{"action":"goto","url":"https://example.com"}'
|
|
3329
|
+
|
|
3330
|
+
STEP 3: GET PAGE SNAPSHOT
|
|
3331
|
+
bp snapshot --format text
|
|
3332
|
+
|
|
3333
|
+
Output shows the page as an accessibility tree with element refs:
|
|
3334
|
+
- heading "Welcome" [ref=e1]
|
|
3335
|
+
- button "Sign In" [ref=e2]
|
|
3336
|
+
- textbox "Email" [ref=e3]
|
|
3337
|
+
|
|
3338
|
+
STEP 4: INTERACT USING REFS
|
|
3339
|
+
bp exec '{"action":"fill","selector":"ref:e3","value":"test@example.com"}'
|
|
3340
|
+
bp exec '{"action":"click","selector":"ref:e2"}'
|
|
3341
|
+
|
|
3342
|
+
STEP 5: BATCH MULTIPLE ACTIONS
|
|
3343
|
+
bp exec '[
|
|
3344
|
+
{"action":"fill","selector":"ref:e3","value":"user@test.com"},
|
|
3345
|
+
{"action":"click","selector":"ref:e2"},
|
|
3346
|
+
{"action":"snapshot"}
|
|
3347
|
+
]'
|
|
3348
|
+
|
|
3349
|
+
FOR AI AGENTS
|
|
3350
|
+
Use -o json for machine-readable output:
|
|
3351
|
+
bp snapshot --format text -o json
|
|
3352
|
+
bp exec '{"action":"click","selector":"ref:e3"}' -o json
|
|
3353
|
+
|
|
3354
|
+
TIPS
|
|
3355
|
+
\u2022 Refs (e1, e2...) are stable within a page - prefer them over CSS selectors
|
|
3356
|
+
\u2022 After navigation, take a new snapshot to get updated refs
|
|
3357
|
+
\u2022 Use multi-selectors for resilience: ["ref:e3", "#email", "input[type=email]"]
|
|
3358
|
+
\u2022 Add "optional":true to skip elements that may not exist
|
|
3359
|
+
|
|
3360
|
+
SELECTOR PRIORITY
|
|
3361
|
+
1. ref:e5 From snapshot - most reliable
|
|
3362
|
+
2. #id CSS ID selector
|
|
3363
|
+
3. [data-testid] Test attributes
|
|
3364
|
+
4. .class CSS class (less stable)
|
|
3363
3365
|
|
|
3364
3366
|
COMMON ACTIONS
|
|
3365
|
-
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
|
|
3373
|
-
|
|
3374
|
-
- Use snapshot() to get page state as accessibility tree
|
|
3375
|
-
- Refs (e1, e2...) identify elements without fragile selectors
|
|
3376
|
-
- Multi-selector arrays handle UI variations
|
|
3377
|
-
- optional: true prevents failures on transient elements
|
|
3378
|
-
|
|
3379
|
-
Ready to automate!
|
|
3380
|
-
Run: npx browser-pilot connect <wsUrl>
|
|
3367
|
+
goto {"action":"goto","url":"https://..."}
|
|
3368
|
+
click {"action":"click","selector":"ref:e3"}
|
|
3369
|
+
fill {"action":"fill","selector":"ref:e3","value":"text"}
|
|
3370
|
+
submit {"action":"submit","selector":"form"}
|
|
3371
|
+
select {"action":"select","selector":"ref:e5","value":"option"}
|
|
3372
|
+
snapshot {"action":"snapshot"}
|
|
3373
|
+
screenshot {"action":"screenshot"}
|
|
3374
|
+
|
|
3375
|
+
Run 'bp actions' for the complete action reference.
|
|
3381
3376
|
`;
|
|
3382
3377
|
async function quickstartCommand() {
|
|
3383
3378
|
console.log(QUICKSTART);
|
|
@@ -3553,56 +3548,30 @@ Usage:
|
|
|
3553
3548
|
bp <command> [options]
|
|
3554
3549
|
|
|
3555
3550
|
Commands:
|
|
3556
|
-
quickstart
|
|
3557
|
-
connect Create
|
|
3558
|
-
exec Execute actions
|
|
3559
|
-
snapshot Get page
|
|
3560
|
-
text Extract text content
|
|
3551
|
+
quickstart Getting started guide (start here!)
|
|
3552
|
+
connect Create browser session
|
|
3553
|
+
exec Execute actions
|
|
3554
|
+
snapshot Get page with element refs
|
|
3555
|
+
text Extract text content
|
|
3561
3556
|
screenshot Take screenshot
|
|
3562
3557
|
close Close session
|
|
3563
|
-
list List
|
|
3564
|
-
actions
|
|
3558
|
+
list List sessions
|
|
3559
|
+
actions Complete action reference
|
|
3565
3560
|
|
|
3566
|
-
|
|
3567
|
-
-s, --session <id> Session ID
|
|
3568
|
-
-o, --output <fmt>
|
|
3569
|
-
--trace Enable
|
|
3570
|
-
|
|
3571
|
-
|
|
3572
|
-
Exec Options:
|
|
3573
|
-
--dialog <mode> Auto-handle dialogs: accept | dismiss
|
|
3574
|
-
|
|
3575
|
-
Ref Selectors (Recommended for AI Agents):
|
|
3576
|
-
1. Navigate + snapshot: bp exec '[{"action":"goto","url":"..."},{"action":"snapshot"}]'
|
|
3577
|
-
Output shows: button "Submit" [ref=e4], textbox "Email" [ref=e5]
|
|
3578
|
-
2. Use refs (snapshot cached for same session+URL):
|
|
3579
|
-
bp exec '[{"action":"click","selector":"ref:e4"}]'
|
|
3580
|
-
|
|
3581
|
-
Refs are cached per session+URL after snapshot. Use new snapshot after navigation.
|
|
3582
|
-
Combine with CSS fallbacks:
|
|
3583
|
-
{"selector": ["ref:e4", "#submit", "button[type=submit]"]}
|
|
3561
|
+
Options:
|
|
3562
|
+
-s, --session <id> Session ID
|
|
3563
|
+
-o, --output <fmt> json | pretty (default: pretty)
|
|
3564
|
+
--trace Enable debug tracing
|
|
3565
|
+
--dialog <mode> Handle dialogs: accept | dismiss
|
|
3566
|
+
-h, --help Show help
|
|
3584
3567
|
|
|
3585
3568
|
Examples:
|
|
3586
|
-
# Connect to browser
|
|
3587
3569
|
bp connect --provider generic --name dev
|
|
3570
|
+
bp exec '{"action":"goto","url":"https://example.com"}'
|
|
3571
|
+
bp snapshot --format text
|
|
3572
|
+
bp exec '{"action":"click","selector":"ref:e3"}'
|
|
3588
3573
|
|
|
3589
|
-
|
|
3590
|
-
bp exec '[{"action":"goto","url":"https://example.com"},{"action":"snapshot"}]'
|
|
3591
|
-
|
|
3592
|
-
# Use refs (snapshot cached for same session+URL)
|
|
3593
|
-
bp exec '[{"action":"fill","selector":"ref:e5","value":"test@example.com"},{"action":"click","selector":"ref:e4"}]'
|
|
3594
|
-
|
|
3595
|
-
# Handle native dialogs (alert/confirm/prompt)
|
|
3596
|
-
bp exec --dialog accept '{"action":"click","selector":"#delete-btn"}'
|
|
3597
|
-
|
|
3598
|
-
# Batch multiple actions (snapshot optional if already cached)
|
|
3599
|
-
bp exec '[
|
|
3600
|
-
{"action":"snapshot"},
|
|
3601
|
-
{"action":"fill","selector":"ref:e5","value":"user@example.com"},
|
|
3602
|
-
{"action":"click","selector":"ref:e4"},
|
|
3603
|
-
{"action":"snapshot"}
|
|
3604
|
-
]'
|
|
3605
|
-
|
|
3574
|
+
Run 'bp quickstart' for CLI workflow guide.
|
|
3606
3575
|
Run 'bp actions' for complete action reference.
|
|
3607
3576
|
`;
|
|
3608
3577
|
function parseGlobalOptions(args) {
|
package/dist/cli.mjs
CHANGED
|
@@ -410,15 +410,6 @@ function parseExecArgs(args) {
|
|
|
410
410
|
}
|
|
411
411
|
async function execCommand(args, globalOptions) {
|
|
412
412
|
const { actionsJson, options: execOptions } = parseExecArgs(args);
|
|
413
|
-
let session;
|
|
414
|
-
if (globalOptions.session) {
|
|
415
|
-
session = await loadSession(globalOptions.session);
|
|
416
|
-
} else {
|
|
417
|
-
session = await getDefaultSession();
|
|
418
|
-
if (!session) {
|
|
419
|
-
throw new Error('No session found. Run "bp connect" first.');
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
413
|
if (!actionsJson) {
|
|
423
414
|
throw new Error(
|
|
424
415
|
`No actions provided. Usage: bp exec '{"action":"goto","url":"..."}'
|
|
@@ -434,6 +425,15 @@ Run 'bp actions' for complete action reference.`
|
|
|
434
425
|
"Invalid JSON. Actions must be valid JSON.\n\nRun 'bp actions' for complete action reference."
|
|
435
426
|
);
|
|
436
427
|
}
|
|
428
|
+
let session;
|
|
429
|
+
if (globalOptions.session) {
|
|
430
|
+
session = await loadSession(globalOptions.session);
|
|
431
|
+
} else {
|
|
432
|
+
session = await getDefaultSession();
|
|
433
|
+
if (!session) {
|
|
434
|
+
throw new Error('No session found. Run "bp connect" first.');
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
437
|
const browser = await connect({
|
|
438
438
|
provider: session.provider,
|
|
439
439
|
wsUrl: session.wsUrl,
|
|
@@ -533,67 +533,62 @@ function getAge(date) {
|
|
|
533
533
|
|
|
534
534
|
// src/cli/commands/quickstart.ts
|
|
535
535
|
var QUICKSTART = `
|
|
536
|
-
browser-pilot
|
|
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
|
-
|
|
536
|
+
browser-pilot CLI - Quick Start Guide
|
|
537
|
+
|
|
538
|
+
STEP 1: CONNECT TO A BROWSER
|
|
539
|
+
bp connect --provider generic --name mysite
|
|
540
|
+
|
|
541
|
+
This creates a session. The CLI remembers it for subsequent commands.
|
|
542
|
+
|
|
543
|
+
STEP 2: NAVIGATE
|
|
544
|
+
bp exec '{"action":"goto","url":"https://example.com"}'
|
|
545
|
+
|
|
546
|
+
STEP 3: GET PAGE SNAPSHOT
|
|
547
|
+
bp snapshot --format text
|
|
548
|
+
|
|
549
|
+
Output shows the page as an accessibility tree with element refs:
|
|
550
|
+
- heading "Welcome" [ref=e1]
|
|
551
|
+
- button "Sign In" [ref=e2]
|
|
552
|
+
- textbox "Email" [ref=e3]
|
|
553
|
+
|
|
554
|
+
STEP 4: INTERACT USING REFS
|
|
555
|
+
bp exec '{"action":"fill","selector":"ref:e3","value":"test@example.com"}'
|
|
556
|
+
bp exec '{"action":"click","selector":"ref:e2"}'
|
|
557
|
+
|
|
558
|
+
STEP 5: BATCH MULTIPLE ACTIONS
|
|
559
|
+
bp exec '[
|
|
560
|
+
{"action":"fill","selector":"ref:e3","value":"user@test.com"},
|
|
561
|
+
{"action":"click","selector":"ref:e2"},
|
|
562
|
+
{"action":"snapshot"}
|
|
563
|
+
]'
|
|
564
|
+
|
|
565
|
+
FOR AI AGENTS
|
|
566
|
+
Use -o json for machine-readable output:
|
|
567
|
+
bp snapshot --format text -o json
|
|
568
|
+
bp exec '{"action":"click","selector":"ref:e3"}' -o json
|
|
569
|
+
|
|
570
|
+
TIPS
|
|
571
|
+
\u2022 Refs (e1, e2...) are stable within a page - prefer them over CSS selectors
|
|
572
|
+
\u2022 After navigation, take a new snapshot to get updated refs
|
|
573
|
+
\u2022 Use multi-selectors for resilience: ["ref:e3", "#email", "input[type=email]"]
|
|
574
|
+
\u2022 Add "optional":true to skip elements that may not exist
|
|
575
|
+
|
|
576
|
+
SELECTOR PRIORITY
|
|
577
|
+
1. ref:e5 From snapshot - most reliable
|
|
578
|
+
2. #id CSS ID selector
|
|
579
|
+
3. [data-testid] Test attributes
|
|
580
|
+
4. .class CSS class (less stable)
|
|
579
581
|
|
|
580
582
|
COMMON ACTIONS
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
- Use snapshot() to get page state as accessibility tree
|
|
591
|
-
- Refs (e1, e2...) identify elements without fragile selectors
|
|
592
|
-
- Multi-selector arrays handle UI variations
|
|
593
|
-
- optional: true prevents failures on transient elements
|
|
594
|
-
|
|
595
|
-
Ready to automate!
|
|
596
|
-
Run: npx browser-pilot connect <wsUrl>
|
|
583
|
+
goto {"action":"goto","url":"https://..."}
|
|
584
|
+
click {"action":"click","selector":"ref:e3"}
|
|
585
|
+
fill {"action":"fill","selector":"ref:e3","value":"text"}
|
|
586
|
+
submit {"action":"submit","selector":"form"}
|
|
587
|
+
select {"action":"select","selector":"ref:e5","value":"option"}
|
|
588
|
+
snapshot {"action":"snapshot"}
|
|
589
|
+
screenshot {"action":"screenshot"}
|
|
590
|
+
|
|
591
|
+
Run 'bp actions' for the complete action reference.
|
|
597
592
|
`;
|
|
598
593
|
async function quickstartCommand() {
|
|
599
594
|
console.log(QUICKSTART);
|
|
@@ -769,56 +764,30 @@ Usage:
|
|
|
769
764
|
bp <command> [options]
|
|
770
765
|
|
|
771
766
|
Commands:
|
|
772
|
-
quickstart
|
|
773
|
-
connect Create
|
|
774
|
-
exec Execute actions
|
|
775
|
-
snapshot Get page
|
|
776
|
-
text Extract text content
|
|
767
|
+
quickstart Getting started guide (start here!)
|
|
768
|
+
connect Create browser session
|
|
769
|
+
exec Execute actions
|
|
770
|
+
snapshot Get page with element refs
|
|
771
|
+
text Extract text content
|
|
777
772
|
screenshot Take screenshot
|
|
778
773
|
close Close session
|
|
779
|
-
list List
|
|
780
|
-
actions
|
|
774
|
+
list List sessions
|
|
775
|
+
actions Complete action reference
|
|
781
776
|
|
|
782
|
-
|
|
783
|
-
-s, --session <id> Session ID
|
|
784
|
-
-o, --output <fmt>
|
|
785
|
-
--trace Enable
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
Exec Options:
|
|
789
|
-
--dialog <mode> Auto-handle dialogs: accept | dismiss
|
|
790
|
-
|
|
791
|
-
Ref Selectors (Recommended for AI Agents):
|
|
792
|
-
1. Navigate + snapshot: bp exec '[{"action":"goto","url":"..."},{"action":"snapshot"}]'
|
|
793
|
-
Output shows: button "Submit" [ref=e4], textbox "Email" [ref=e5]
|
|
794
|
-
2. Use refs (snapshot cached for same session+URL):
|
|
795
|
-
bp exec '[{"action":"click","selector":"ref:e4"}]'
|
|
796
|
-
|
|
797
|
-
Refs are cached per session+URL after snapshot. Use new snapshot after navigation.
|
|
798
|
-
Combine with CSS fallbacks:
|
|
799
|
-
{"selector": ["ref:e4", "#submit", "button[type=submit]"]}
|
|
777
|
+
Options:
|
|
778
|
+
-s, --session <id> Session ID
|
|
779
|
+
-o, --output <fmt> json | pretty (default: pretty)
|
|
780
|
+
--trace Enable debug tracing
|
|
781
|
+
--dialog <mode> Handle dialogs: accept | dismiss
|
|
782
|
+
-h, --help Show help
|
|
800
783
|
|
|
801
784
|
Examples:
|
|
802
|
-
# Connect to browser
|
|
803
785
|
bp connect --provider generic --name dev
|
|
786
|
+
bp exec '{"action":"goto","url":"https://example.com"}'
|
|
787
|
+
bp snapshot --format text
|
|
788
|
+
bp exec '{"action":"click","selector":"ref:e3"}'
|
|
804
789
|
|
|
805
|
-
|
|
806
|
-
bp exec '[{"action":"goto","url":"https://example.com"},{"action":"snapshot"}]'
|
|
807
|
-
|
|
808
|
-
# Use refs (snapshot cached for same session+URL)
|
|
809
|
-
bp exec '[{"action":"fill","selector":"ref:e5","value":"test@example.com"},{"action":"click","selector":"ref:e4"}]'
|
|
810
|
-
|
|
811
|
-
# Handle native dialogs (alert/confirm/prompt)
|
|
812
|
-
bp exec --dialog accept '{"action":"click","selector":"#delete-btn"}'
|
|
813
|
-
|
|
814
|
-
# Batch multiple actions (snapshot optional if already cached)
|
|
815
|
-
bp exec '[
|
|
816
|
-
{"action":"snapshot"},
|
|
817
|
-
{"action":"fill","selector":"ref:e5","value":"user@example.com"},
|
|
818
|
-
{"action":"click","selector":"ref:e4"},
|
|
819
|
-
{"action":"snapshot"}
|
|
820
|
-
]'
|
|
821
|
-
|
|
790
|
+
Run 'bp quickstart' for CLI workflow guide.
|
|
822
791
|
Run 'bp actions' for complete action reference.
|
|
823
792
|
`;
|
|
824
793
|
function parseGlobalOptions(args) {
|