@generativereality/browser-automation 0.4.1 → 0.4.2
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/.claude-plugin/plugin.json +1 -1
- package/dist/index.js +112 -2
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "browser-automation",
|
|
3
3
|
"description": "Daemonless, per-tab-isolated browser automation for Claude Code via the `browser-automation` CLI. Drives one shared headed Chrome (persistent profile + extensions) over per-target CDP — many parallel sessions, no focus stealing, nothing long-lived to crash.",
|
|
4
|
-
"version": "0.4.
|
|
4
|
+
"version": "0.4.2",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "generativereality"
|
|
7
7
|
},
|
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import { existsSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, s
|
|
|
7
7
|
import { spawnSync } from "node:child_process";
|
|
8
8
|
import { fileURLToPath } from "node:url";
|
|
9
9
|
//#region package.json
|
|
10
|
-
var version = "0.4.
|
|
10
|
+
var version = "0.4.2";
|
|
11
11
|
var description = "Daemonless, per-tab-isolated browser automation CLI for Claude Code. Drives one shared headed Chrome (persistent profile + extensions) over per-target CDP — many parallel sessions, no focus stealing, nothing long-lived to crash.";
|
|
12
12
|
//#endregion
|
|
13
13
|
//#region src/core/session.ts
|
|
@@ -471,6 +471,25 @@ function clickExpr(ref) {
|
|
|
471
471
|
return {ok:true,tag:el.tagName.toLowerCase()};
|
|
472
472
|
})()`;
|
|
473
473
|
}
|
|
474
|
+
function actionabilityExpr(ref) {
|
|
475
|
+
const r = JSON.stringify(ref);
|
|
476
|
+
return WALK + `(() => {
|
|
477
|
+
const el=__baFind(${r});
|
|
478
|
+
if(!el)return {err:'ref not found: '+${r}+' (re-run snapshot)'};
|
|
479
|
+
el.scrollIntoView({block:'center',inline:'center'});
|
|
480
|
+
const b=el.getBoundingClientRect();
|
|
481
|
+
if(b.width===0&&b.height===0)return {err:'ref '+${r}+' has zero size / not visible'};
|
|
482
|
+
const vw=innerWidth,vh=innerHeight;
|
|
483
|
+
const x=Math.min(Math.max(b.left+b.width/2,1),vw-1);
|
|
484
|
+
const y=Math.min(Math.max(b.top+b.height/2,1),vh-1);
|
|
485
|
+
const root=el.getRootNode();
|
|
486
|
+
let top=(root&&root.elementFromPoint?root:document).elementFromPoint(x,y);
|
|
487
|
+
// descend through any shadow root under the point to find the deepest target
|
|
488
|
+
while(top&&top.shadowRoot){const inner=top.shadowRoot.elementFromPoint(x,y);if(!inner||inner===top)break;top=inner;}
|
|
489
|
+
const hit=!!top&&(top===el||el.contains(top)||(top.contains&&top.contains(el)));
|
|
490
|
+
return {ok:true,tag:el.tagName.toLowerCase(),x,y,hit};
|
|
491
|
+
})()`;
|
|
492
|
+
}
|
|
474
493
|
function fillExpr(ref, value, submit) {
|
|
475
494
|
const r = JSON.stringify(ref);
|
|
476
495
|
const v = JSON.stringify(value);
|
|
@@ -566,6 +585,7 @@ const snapshotCommand = define({
|
|
|
566
585
|
});
|
|
567
586
|
//#endregion
|
|
568
587
|
//#region src/commands/click.ts
|
|
588
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
569
589
|
const clickCommand = define({
|
|
570
590
|
name: "click",
|
|
571
591
|
description: "Click an element by ref (from the latest snapshot)",
|
|
@@ -574,6 +594,10 @@ const clickCommand = define({
|
|
|
574
594
|
ref: {
|
|
575
595
|
type: "positional",
|
|
576
596
|
description: "Element ref, e.g. e7"
|
|
597
|
+
},
|
|
598
|
+
trusted: {
|
|
599
|
+
type: "boolean",
|
|
600
|
+
description: "Dispatch a real, genuinely-trusted CDP mouse click (Input.dispatchMouseEvent) at the element instead of the default JS-dispatched el.click(). Brings the tab to front and WAITS for it to be focused+visible (CDP input no-ops on a backgrounded tab), then waits for the element to be actionable (stable position + unoccluded hit-test) before pressing — mirroring Playwright. Use for widgets that demand isTrusted events AND animate in: artdeco dropdown menu items (LinkedIn More→Connect), Radix dropdown/popover triggers, cmdk comboboxes — which a default click, or an immediate trusted click on stale coordinates, only highlights without firing."
|
|
577
601
|
}
|
|
578
602
|
},
|
|
579
603
|
async run(ctx) {
|
|
@@ -582,7 +606,93 @@ const clickCommand = define({
|
|
|
582
606
|
consola.error("A ref like \"e7\" is required (run `browser-automation snapshot` first)");
|
|
583
607
|
process.exit(1);
|
|
584
608
|
}
|
|
585
|
-
const
|
|
609
|
+
const targetId = await resolveExistingTargetId(targetOpts(ctx.values));
|
|
610
|
+
if (ctx.values.trusted ?? false) {
|
|
611
|
+
const trustedTag = await withPage(targetId, async (s) => {
|
|
612
|
+
const evalIn = async (expr) => {
|
|
613
|
+
const res = await s.send("Runtime.evaluate", {
|
|
614
|
+
expression: expr,
|
|
615
|
+
returnByValue: true,
|
|
616
|
+
awaitPromise: true
|
|
617
|
+
});
|
|
618
|
+
if (res.exceptionDetails) {
|
|
619
|
+
const e = res.exceptionDetails;
|
|
620
|
+
throw new Error("page JS exception: " + (e.exception?.description || e.text || "unknown"));
|
|
621
|
+
}
|
|
622
|
+
return res.result?.value;
|
|
623
|
+
};
|
|
624
|
+
await s.send("Page.bringToFront").catch(() => {});
|
|
625
|
+
const focusDeadline = Date.now() + 2e3;
|
|
626
|
+
while (Date.now() < focusDeadline) {
|
|
627
|
+
const f = await evalIn(`({f:document.hasFocus(),v:document.visibilityState})`);
|
|
628
|
+
if (f && f.f && f.v === "visible") break;
|
|
629
|
+
await sleep(50);
|
|
630
|
+
}
|
|
631
|
+
let prev = null;
|
|
632
|
+
let point = null;
|
|
633
|
+
let lastReason = "never became actionable";
|
|
634
|
+
const actDeadline = Date.now() + 5e3;
|
|
635
|
+
while (Date.now() < actDeadline) {
|
|
636
|
+
const a = await evalIn(actionabilityExpr(ref));
|
|
637
|
+
if (a?.err) {
|
|
638
|
+
consola.error(a.err);
|
|
639
|
+
process.exit(1);
|
|
640
|
+
}
|
|
641
|
+
const stable = prev !== null && Math.abs(prev.x - a.x) < .5 && Math.abs(prev.y - a.y) < .5;
|
|
642
|
+
if (a.hit && stable) {
|
|
643
|
+
point = {
|
|
644
|
+
x: a.x,
|
|
645
|
+
y: a.y,
|
|
646
|
+
tag: a.tag
|
|
647
|
+
};
|
|
648
|
+
break;
|
|
649
|
+
}
|
|
650
|
+
lastReason = a.hit ? "position not yet stable (still animating)" : "click-point occluded (hit-test miss)";
|
|
651
|
+
prev = {
|
|
652
|
+
x: a.x,
|
|
653
|
+
y: a.y
|
|
654
|
+
};
|
|
655
|
+
await sleep(60);
|
|
656
|
+
}
|
|
657
|
+
if (!point) {
|
|
658
|
+
consola.error(`<${ref}> not actionable for a trusted click: ${lastReason}`);
|
|
659
|
+
process.exit(1);
|
|
660
|
+
}
|
|
661
|
+
const { x, y } = point;
|
|
662
|
+
await s.send("Input.dispatchMouseEvent", {
|
|
663
|
+
type: "mouseMoved",
|
|
664
|
+
x,
|
|
665
|
+
y,
|
|
666
|
+
button: "none",
|
|
667
|
+
buttons: 0,
|
|
668
|
+
pointerType: "mouse"
|
|
669
|
+
});
|
|
670
|
+
await sleep(20);
|
|
671
|
+
await s.send("Input.dispatchMouseEvent", {
|
|
672
|
+
type: "mousePressed",
|
|
673
|
+
x,
|
|
674
|
+
y,
|
|
675
|
+
button: "left",
|
|
676
|
+
buttons: 1,
|
|
677
|
+
clickCount: 1,
|
|
678
|
+
pointerType: "mouse",
|
|
679
|
+
force: .5
|
|
680
|
+
});
|
|
681
|
+
await s.send("Input.dispatchMouseEvent", {
|
|
682
|
+
type: "mouseReleased",
|
|
683
|
+
x,
|
|
684
|
+
y,
|
|
685
|
+
button: "left",
|
|
686
|
+
buttons: 0,
|
|
687
|
+
clickCount: 1,
|
|
688
|
+
pointerType: "mouse"
|
|
689
|
+
});
|
|
690
|
+
return point.tag;
|
|
691
|
+
});
|
|
692
|
+
consola.success(`clicked ${ref} <${trustedTag}> (trusted)`);
|
|
693
|
+
return;
|
|
694
|
+
}
|
|
695
|
+
const r = await evaluate(targetId, clickExpr(ref));
|
|
586
696
|
if (r.err) {
|
|
587
697
|
consola.error(r.err);
|
|
588
698
|
process.exit(1);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@generativereality/browser-automation",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "Daemonless, per-tab-isolated browser automation CLI for Claude Code. Drives one shared headed Chrome (persistent profile + extensions) over per-target CDP — many parallel sessions, no focus stealing, nothing long-lived to crash.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|