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.
Files changed (3) hide show
  1. package/dist/cli.cjs +80 -111
  2. package/dist/cli.mjs +80 -111
  3. 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 - CDP-based browser automation for AI agents
3321
-
3322
- Zero production dependencies. Works in Node.js, Bun, and Cloudflare Workers.
3323
-
3324
- RUNNING
3325
- npx browser-pilot ... # Node.js projects
3326
- bunx browser-pilot ... # Bun projects (faster)
3327
-
3328
- CONNECTING
3329
- npx browser-pilot connect <wsUrl> Connect to existing browser
3330
- npx browser-pilot connect --provider browserbase --api-key <key>
3331
-
3332
- BASIC USAGE (Code)
3333
- import { Browser } from 'browser-pilot';
3334
-
3335
- const browser = await Browser.connect({ wsUrl: '...' });
3336
- const page = await browser.newPage();
3337
- await page.goto('https://example.com');
3338
- await page.click('#button');
3339
- await page.fill('#input', 'text');
3340
- await browser.close();
3341
-
3342
- KEY PATTERNS
3343
- Multi-Selector await page.click(['#primary', '.fallback', 'button']);
3344
- Smart Waiting Every action waits for visibility automatically
3345
- Optional Actions await page.click('#banner', { optional: true });
3346
-
3347
- BATCH EXECUTION
3348
- await page.batch([
3349
- { action: 'goto', url: 'https://example.com' },
3350
- { action: 'fill', selector: '#email', value: 'test@test.com' },
3351
- { action: 'submit', selector: 'form' },
3352
- ]);
3353
-
3354
- SNAPSHOTS (FOR AI AGENTS)
3355
- const snapshot = await page.snapshot();
3356
- // Returns accessibility tree with refs: e1, e2, e3...
3357
- await page.click({ ref: 'e5' });
3358
-
3359
- PROVIDERS
3360
- BrowserBase Browser.connect({ provider: 'browserbase', apiKey })
3361
- Browserless Browser.connect({ provider: 'browserless', apiKey })
3362
- Generic Browser.connect({ wsUrl: 'ws://...' })
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
- page.goto(url) Navigate to URL
3366
- page.click(selector) Click element
3367
- page.fill(selector, value) Fill input field
3368
- page.submit(selector) Submit form
3369
- page.select(selector, val) Select dropdown option
3370
- page.screenshot() Capture screenshot
3371
- page.snapshot() Get accessibility tree
3372
-
3373
- AGENT INTEGRATION
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 Show getting started guide
3557
- connect Create or resume browser session
3558
- exec Execute actions on current session
3559
- snapshot Get page accessibility snapshot (includes element refs)
3560
- text Extract text content from page
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 all sessions
3564
- actions Show all available actions with examples
3558
+ list List sessions
3559
+ actions Complete action reference
3565
3560
 
3566
- Global Options:
3567
- -s, --session <id> Session ID to use
3568
- -o, --output <fmt> Output format: json | pretty (default: pretty)
3569
- --trace Enable execution tracing
3570
- -h, --help Show this help message
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
- # Navigate and get snapshot with refs
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 - CDP-based browser automation for AI agents
537
-
538
- Zero production dependencies. Works in Node.js, Bun, and Cloudflare Workers.
539
-
540
- RUNNING
541
- npx browser-pilot ... # Node.js projects
542
- bunx browser-pilot ... # Bun projects (faster)
543
-
544
- CONNECTING
545
- npx browser-pilot connect <wsUrl> Connect to existing browser
546
- npx browser-pilot connect --provider browserbase --api-key <key>
547
-
548
- BASIC USAGE (Code)
549
- import { Browser } from 'browser-pilot';
550
-
551
- const browser = await Browser.connect({ wsUrl: '...' });
552
- const page = await browser.newPage();
553
- await page.goto('https://example.com');
554
- await page.click('#button');
555
- await page.fill('#input', 'text');
556
- await browser.close();
557
-
558
- KEY PATTERNS
559
- Multi-Selector await page.click(['#primary', '.fallback', 'button']);
560
- Smart Waiting Every action waits for visibility automatically
561
- Optional Actions await page.click('#banner', { optional: true });
562
-
563
- BATCH EXECUTION
564
- await page.batch([
565
- { action: 'goto', url: 'https://example.com' },
566
- { action: 'fill', selector: '#email', value: 'test@test.com' },
567
- { action: 'submit', selector: 'form' },
568
- ]);
569
-
570
- SNAPSHOTS (FOR AI AGENTS)
571
- const snapshot = await page.snapshot();
572
- // Returns accessibility tree with refs: e1, e2, e3...
573
- await page.click({ ref: 'e5' });
574
-
575
- PROVIDERS
576
- BrowserBase Browser.connect({ provider: 'browserbase', apiKey })
577
- Browserless Browser.connect({ provider: 'browserless', apiKey })
578
- Generic Browser.connect({ wsUrl: 'ws://...' })
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
- page.goto(url) Navigate to URL
582
- page.click(selector) Click element
583
- page.fill(selector, value) Fill input field
584
- page.submit(selector) Submit form
585
- page.select(selector, val) Select dropdown option
586
- page.screenshot() Capture screenshot
587
- page.snapshot() Get accessibility tree
588
-
589
- AGENT INTEGRATION
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 Show getting started guide
773
- connect Create or resume browser session
774
- exec Execute actions on current session
775
- snapshot Get page accessibility snapshot (includes element refs)
776
- text Extract text content from page
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 all sessions
780
- actions Show all available actions with examples
774
+ list List sessions
775
+ actions Complete action reference
781
776
 
782
- Global Options:
783
- -s, --session <id> Session ID to use
784
- -o, --output <fmt> Output format: json | pretty (default: pretty)
785
- --trace Enable execution tracing
786
- -h, --help Show this help message
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
- # Navigate and get snapshot with refs
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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "browser-pilot",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "Lightweight CDP-based browser automation for Node.js, Bun, and Cloudflare Workers",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",