browser-pilot-cli 0.1.5 → 0.1.6

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 (2) hide show
  1. package/dist/cli.js +37 -9
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -551,7 +551,8 @@ Workflow:
551
551
  bp connect # one-time setup (click Allow in Chrome)
552
552
  bp open <url> # navigate \u2014 returns snapshot with [ref] numbers
553
553
  bp click <ref> # interact \u2014 returns updated snapshot
554
- bp click 0 --xy 400,300 # click at coordinates (canvas/maps)
554
+ bp click --xy 400,300 # click at coordinates (canvas/maps)
555
+ bp locate ".selector" # get element coordinates for click --xy
555
556
  bp type <ref> <text> # input text \u2014 returns updated snapshot
556
557
  bp keyboard <text> # type via keyboard events (Google Docs etc.)
557
558
  bp press <key> # press key \u2014 returns updated snapshot
@@ -779,15 +780,15 @@ program.command("snapshot").description("Get interactive elements on the page").
779
780
  emitSnapshot(await takeSnapshot(transport, sessionId, state.activeTargetId, limit));
780
781
  });
781
782
  }));
782
- program.command("click <ref>").description("Click element by ref number and return page snapshot").option("--xy <coords>", "click at x,y coordinates instead of ref (e.g. --xy 400,300)").option("--double", "double-click").option("--right", "right-click (context menu)").option("-l, --limit <n>", "max elements in snapshot", "50").addHelpText("after", `
783
- Ref is a number from the snapshot output, or use --xy for coordinate clicks.
784
-
783
+ program.command("click [ref]").description("Click element by ref number or at x,y coordinates").option("--xy <coords>", "click at x,y viewport coordinates (e.g. --xy 400,300)").option("--double", "double-click").option("--right", "right-click (context menu)").option("-l, --limit <n>", "max elements in snapshot", "50").addHelpText("after", `
785
784
  Examples:
786
- bp click 3 # click element [3]
787
- bp click 0 --xy 400,300 # click at coordinates (ref ignored)
788
- bp click 0 --xy 400,300 --double # double-click at coordinates
789
- bp click 0 --xy 400,300 --right # right-click at coordinates`).action(action(async (ref, opts) => {
785
+ bp click 3 # click element [3] from snapshot
786
+ bp click --xy 400,300 # click at viewport coordinates
787
+ bp click --xy 400,300 --double # double-click at coordinates
788
+ bp click --xy 400,300 --right # right-click (context menu)
789
+ bp click 3 --right # right-click element [3]`).action(action(async (ref, opts) => {
790
790
  if (opts.double && opts.right) throw new Error("--double and --right are mutually exclusive");
791
+ if (!ref && !opts.xy) throw new Error("Provide a ref number or --xy coordinates");
791
792
  const limit = parseLimit(opts.limit);
792
793
  await withPilot(async ({ transport, sessionId, state }) => {
793
794
  if (opts.xy) {
@@ -832,6 +833,28 @@ Examples:
832
833
  emitSnapshot(await snap(transport, sessionId, state.activeTargetId, limit));
833
834
  });
834
835
  }));
836
+ program.command("locate <selector>").description("Get element coordinates by CSS selector (for use with click --xy)").addHelpText("after", `
837
+ Returns center coordinates and bounding box of an element.
838
+ Use with click --xy for canvas apps, charts, or elements not in snapshot.
839
+
840
+ Examples:
841
+ bp locate ".kix-appview-editor" # Google Docs editor area
842
+ bp locate "canvas" # canvas element
843
+ bp locate "#map" # map container`).action(action(async (selector) => {
844
+ await withPilot(async ({ transport, sessionId }) => {
845
+ const { result } = await transport.send("Runtime.evaluate", {
846
+ expression: `JSON.stringify((function(){var el=document.querySelector(${JSON.stringify(selector)});if(!el)return null;el.scrollIntoView({block:'center',inline:'center'});var r=el.getBoundingClientRect();return{x:Math.round(r.x+r.width/2),y:Math.round(r.y+r.height/2),top:Math.round(r.top),left:Math.round(r.left),width:Math.round(r.width),height:Math.round(r.height)}})())`,
847
+ returnByValue: true
848
+ }, sessionId);
849
+ const coords = result.value ? JSON.parse(result.value) : null;
850
+ if (!coords) throw new Error(`Element not found: ${selector}`);
851
+ if (useJson()) {
852
+ console.log(JSON.stringify({ ok: true, ...coords }));
853
+ } else {
854
+ console.log(`center: ${coords.x},${coords.y} size: ${coords.width}x${coords.height} (top:${coords.top} left:${coords.left})`);
855
+ }
856
+ });
857
+ }));
835
858
  program.command("type <ref> <text>").description("Type text into element and return page snapshot").option("-c, --clear", "clear field before typing").option("-s, --submit", "press Enter after typing").option("-l, --limit <n>", "max elements in snapshot", "50").addHelpText("after", '\nExamples:\n bp type 2 "hello world"\n bp type 5 "query" --submit\n bp type 3 "new value" --clear').action(action(async (ref, text, opts) => {
836
859
  const limit = parseLimit(opts.limit);
837
860
  await withPilot(async ({ transport, sessionId, state }) => {
@@ -948,7 +971,12 @@ Examples:
948
971
  await typeViaKeyboard(transport, sessionId, text);
949
972
  }
950
973
  if (opts.submit) await dispatchKey(transport, sessionId, "Enter");
951
- emitSnapshot(await snap(transport, sessionId, state.activeTargetId, limit));
974
+ const snapResult = await snap(transport, sessionId, state.activeTargetId, limit);
975
+ if (useJson()) {
976
+ console.log(JSON.stringify({ ok: true, typed: text, ...snapResult.data }));
977
+ } else {
978
+ console.log(snapResult.text);
979
+ }
952
980
  });
953
981
  }));
954
982
  program.command("press <key>").description("Press key combo (e.g. Enter, Escape, Control+a) and return snapshot").option("-l, --limit <n>", "max elements in snapshot", "50").addHelpText("after", "\nKeys: Enter, Escape, Tab, Space, Backspace, Delete,\n ArrowUp, ArrowDown, ArrowLeft, ArrowRight,\n Home, End, PageUp, PageDown\nModifiers: Control (Ctrl), Shift, Alt, Meta (Cmd)\n\nExamples:\n bp press Enter\n bp press Escape\n bp press Control+a\n bp press Meta+c").action(action(async (key, opts) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "browser-pilot-cli",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "CLI tool to control your browser via Chrome DevTools Protocol",
5
5
  "type": "module",
6
6
  "bin": {