browser-pilot-cli
Advanced tools
+47
-13
@@ -551,2 +551,3 @@ #!/usr/bin/env node | ||
| bp click <ref> # interact \u2014 returns updated snapshot | ||
| bp click 0 --xy 400,300 # click at coordinates (canvas/maps) | ||
| bp type <ref> <text> # input text \u2014 returns updated snapshot | ||
@@ -756,17 +757,50 @@ bp keyboard <text> # type via keyboard events (Google Docs etc.) | ||
| })); | ||
| program.command("click <ref>").description("Click element by ref number and return page snapshot").option("-l, --limit <n>", "max elements in snapshot", "50").addHelpText("after", "\nRef is a number from the snapshot output.\n\nExamples:\n bp click 3\n bp click 3 --limit 10").action(action(async (ref, opts) => { | ||
| 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", ` | ||
| Ref is a number from the snapshot output, or use --xy for coordinate clicks. | ||
| Examples: | ||
| bp click 3 # click element [3] | ||
| bp click 0 --xy 400,300 # click at coordinates (ref ignored) | ||
| bp click 0 --xy 400,300 --double # double-click at coordinates | ||
| bp click 0 --xy 400,300 --right # right-click at coordinates`).action(action(async (ref, opts) => { | ||
| const limit = parseLimit(opts.limit); | ||
| await withPilot(async ({ transport, sessionId, state }) => { | ||
| const objectId = await resolveTarget(transport, sessionId, ref, state.activeTargetId); | ||
| try { | ||
| const { result } = await transport.send("Runtime.callFunctionOn", { | ||
| objectId, | ||
| functionDeclaration: GET_CLICK_COORDS, | ||
| returnByValue: true | ||
| }, sessionId); | ||
| const { x, y } = JSON.parse(result.value); | ||
| await dispatchClick(transport, sessionId, x, y); | ||
| } finally { | ||
| await transport.send("Runtime.releaseObject", { objectId }, sessionId).catch(() => { | ||
| }); | ||
| if (opts.xy) { | ||
| const [xStr, yStr] = opts.xy.split(","); | ||
| const x = parseFloat(xStr), y = parseFloat(yStr); | ||
| if (isNaN(x) || isNaN(y)) throw new Error("--xy must be x,y (e.g. --xy 400,300)"); | ||
| if (opts.right) { | ||
| await transport.send("Input.dispatchMouseEvent", { type: "mouseMoved", x, y, button: "none" }, sessionId); | ||
| await transport.send("Input.dispatchMouseEvent", { type: "mousePressed", x, y, button: "right", clickCount: 1 }, sessionId); | ||
| await transport.send("Input.dispatchMouseEvent", { type: "mouseReleased", x, y, button: "right", clickCount: 1 }, sessionId); | ||
| } else { | ||
| const clickCount = opts.double ? 2 : 1; | ||
| await transport.send("Input.dispatchMouseEvent", { type: "mouseMoved", x, y, button: "none" }, sessionId); | ||
| await transport.send("Input.dispatchMouseEvent", { type: "mousePressed", x, y, button: "left", clickCount }, sessionId); | ||
| await transport.send("Input.dispatchMouseEvent", { type: "mouseReleased", x, y, button: "left", clickCount }, sessionId); | ||
| } | ||
| } else { | ||
| const objectId = await resolveTarget(transport, sessionId, ref, state.activeTargetId); | ||
| try { | ||
| const { result } = await transport.send("Runtime.callFunctionOn", { | ||
| objectId, | ||
| functionDeclaration: GET_CLICK_COORDS, | ||
| returnByValue: true | ||
| }, sessionId); | ||
| const { x, y } = JSON.parse(result.value); | ||
| if (opts.double) { | ||
| await transport.send("Input.dispatchMouseEvent", { type: "mouseMoved", x, y, button: "none" }, sessionId); | ||
| await transport.send("Input.dispatchMouseEvent", { type: "mousePressed", x, y, button: "left", clickCount: 2 }, sessionId); | ||
| await transport.send("Input.dispatchMouseEvent", { type: "mouseReleased", x, y, button: "left", clickCount: 2 }, sessionId); | ||
| } else if (opts.right) { | ||
| await transport.send("Input.dispatchMouseEvent", { type: "mouseMoved", x, y, button: "none" }, sessionId); | ||
| await transport.send("Input.dispatchMouseEvent", { type: "mousePressed", x, y, button: "right", clickCount: 1 }, sessionId); | ||
| await transport.send("Input.dispatchMouseEvent", { type: "mouseReleased", x, y, button: "right", clickCount: 1 }, sessionId); | ||
| } else { | ||
| await dispatchClick(transport, sessionId, x, y); | ||
| } | ||
| } finally { | ||
| await transport.send("Runtime.releaseObject", { objectId }, sessionId).catch(() => { | ||
| }); | ||
| } | ||
| } | ||
@@ -773,0 +807,0 @@ emitSnapshot(await snap(transport, sessionId, state.activeTargetId, limit)); |
+1
-1
| { | ||
| "name": "browser-pilot-cli", | ||
| "version": "0.1.3", | ||
| "version": "0.1.4", | ||
| "description": "CLI tool to control your browser via Chrome DevTools Protocol", | ||
@@ -5,0 +5,0 @@ "type": "module", |
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
300620
0.83%2632
1.27%