@open-take/runtime 0.4.2 → 0.4.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/cdp-capture-BPfyq-2O.js +3 -0
- package/dist/{cdp-capture-Bm8No23R.js → cdp-capture-Ckt-tZVU.js} +307 -13
- package/dist/cdp-capture-Ckt-tZVU.js.map +1 -0
- package/dist/index.d.ts +635 -404
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1958 -1193
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/dist/cdp-capture-Bm8No23R.js.map +0 -1
- package/dist/cdp-capture-CDmaguHO.js +0 -3
|
@@ -437,22 +437,34 @@ function evalValue(raw) {
|
|
|
437
437
|
return deepParse(top);
|
|
438
438
|
}
|
|
439
439
|
const NAME_JS = "function names(e){var raw=[e.getAttribute('aria-label'),e.textContent,e.getAttribute('title'),e.getAttribute('alt'),e.getAttribute('placeholder')];var out=[];for(var i=0;i<raw.length;i++){var s=(raw[i]||'').replace(/\\s+/g,' ').trim();if(s&&out.indexOf(s)===-1)out.push(s);}return out;}function dispName(e){var a=[e.getAttribute('aria-label'),e.textContent,e.getAttribute('title'),e.getAttribute('alt')];for(var i=0;i<a.length;i++){var s=(a[i]||'').replace(/\\s+/g,' ').trim();if(s)return s;}return '';}function pick(els,t){var i,n,j;for(i=0;i<els.length;i++){if(names(els[i]).indexOf(t)!==-1)return els[i];}for(i=0;i<els.length;i++){n=names(els[i]);for(j=0;j<n.length;j++){if(n[j].indexOf(t)!==-1)return els[i];}}return null;}";
|
|
440
|
-
const
|
|
440
|
+
const HITTABLE_JS = "function hittable(m,r){var cx=Math.round(r.x+r.width/2),cy=Math.round(r.y+r.height/2);if(!(r.width>0&&r.height>0&&document.elementFromPoint))return null;var hit=document.elementFromPoint(cx,cy);var ok=!!hit&&(hit===m||(m.contains&&m.contains(hit)));if(!ok&&document.elementsFromPoint){var top=document.elementsFromPoint(cx,cy)[0];ok=!!top&&(top===m||(m.contains&&m.contains(top)));}return ok?{cx:cx,cy:cy}:null;}";
|
|
441
|
+
const CLICK_TAIL_JS = `if(m.tagName==='SELECT')return 'SELECTINERT';` + HITTABLE_JS + "var r=m.getBoundingClientRect();if(r.top<0||r.bottom>window.innerHeight){m.scrollIntoView({block:'center',behavior:'instant'});r=m.getBoundingClientRect();}var b={x:Math.round(r.x),y:Math.round(r.y),w:Math.round(r.width),h:Math.round(r.height)};var p=hittable(m,r);if(p){b.cx=p.cx;b.cy=p.cy;return JSON.stringify(b);}m.click();return JSON.stringify(b);";
|
|
442
|
+
const CLICK_CANDIDATES = "button,a,[role=button],[role=link],[role=menuitem],input[type=submit],input[type=button]";
|
|
443
|
+
const FIELD_CANDIDATES = "input,textarea,[contenteditable],[contenteditable=true],[role=textbox],[role=searchbox]";
|
|
444
|
+
const BOX_CANDIDATES = "button,a,[role=button],[role=link],[role=menuitem],[aria-label],[title],img[alt],li,[draggable=true]";
|
|
445
|
+
const SCROLL_CANDIDATES = "button,a,[role=button],[role=link],[role=heading],[aria-label],[title],h1,h2,h3,li,section,p";
|
|
441
446
|
function clickByTextJs(text) {
|
|
442
447
|
const t = JSON.stringify(text);
|
|
443
|
-
return `(function(){var t=${t};var els=Array.prototype.slice.call(document.querySelectorAll('
|
|
448
|
+
return `(function(){var t=${t};var els=Array.prototype.slice.call(document.querySelectorAll('${CLICK_CANDIDATES}'));` + NAME_JS + "var m=pick(els,t);if(!m)return 'NOTFOUND';" + CLICK_TAIL_JS + `})()`;
|
|
444
449
|
}
|
|
445
450
|
function clickBySelectorJs(selector) {
|
|
446
451
|
const s = JSON.stringify(selector);
|
|
447
452
|
return `(function(){var m=document.querySelector(${s});if(!m)return 'NOTFOUND';` + CLICK_TAIL_JS + `})()`;
|
|
448
453
|
}
|
|
454
|
+
const FOCUS_STATE_JS = "function deepActive(){var a=document.activeElement;while(a&&a.shadowRoot&&a.shadowRoot.activeElement){a=a.shadowRoot.activeElement;}return a;}function editable(a){if(!a)return false;if(a.isContentEditable)return true;return typeof a.value==='string'&&!a.readOnly&&!a.disabled;}function withinTarget(a){var n=a;while(n){if(n===m||(m.contains&&m.contains(n)))return true;var rn=n.getRootNode?n.getRootNode():null;n=n.parentElement||((rn&&rn.host)?rn.host:null);}return false;}var ae=deepActive();var ok=!!ae&&(ae!==document.body||m===document.body)&&editable(ae)&&(withinTarget(ae)||(ae.isContentEditable&&ae.contains&&ae.contains(m)));";
|
|
455
|
+
const FOCUS_TAIL_JS = HITTABLE_JS + "var r=m.getBoundingClientRect();if(r.top<0||r.bottom>window.innerHeight){m.scrollIntoView({block:'center',behavior:'instant'});r=m.getBoundingClientRect();}var b={x:Math.round(r.x),y:Math.round(r.y),w:Math.round(r.width),h:Math.round(r.height)};m.focus();m.click();m.focus();" + FOCUS_STATE_JS + "b.f=ok?1:0;if(!ok){b.hit=hittable(m,m.getBoundingClientRect())?1:0;}return JSON.stringify(b);";
|
|
449
456
|
function focusFieldByTextJs(text) {
|
|
450
457
|
const t = JSON.stringify(text);
|
|
451
|
-
return `(function(){var t=${t};var els=Array.prototype.slice.call(document.querySelectorAll('
|
|
458
|
+
return `(function(){var t=${t};var els=Array.prototype.slice.call(document.querySelectorAll('${FIELD_CANDIDATES}'));` + NAME_JS + "var m=pick(els,t);if(!m)return 'NOTFOUND';" + FOCUS_TAIL_JS + `})()`;
|
|
452
459
|
}
|
|
453
460
|
function focusSelectorJs(selector) {
|
|
454
461
|
const s = JSON.stringify(selector);
|
|
455
|
-
return `(function(){var m=document.querySelector(${s});if(!m)return 'NOTFOUND'
|
|
462
|
+
return `(function(){var m=document.querySelector(${s});if(!m)return 'NOTFOUND';` + FOCUS_TAIL_JS + `})()`;
|
|
463
|
+
}
|
|
464
|
+
function verifyFocusJs(target) {
|
|
465
|
+
if (!target.text && !target.selector) return `'0'`;
|
|
466
|
+
const resolve$1 = target.text ? `var els=Array.prototype.slice.call(document.querySelectorAll('${FIELD_CANDIDATES}'));` + NAME_JS + `var m=pick(els,${JSON.stringify(target.text)});` : `var m=document.querySelector(${JSON.stringify(target.selector ?? "")});`;
|
|
467
|
+
return `(function(){${resolve$1}if(!m)return '0';` + FOCUS_STATE_JS + "if(ok)return '1';return (!!ae&&ae!==document.body&&editable(ae))?'1':'0';})()";
|
|
456
468
|
}
|
|
457
469
|
function selectAllInFocusedJs() {
|
|
458
470
|
return "(function(){var el=document.activeElement;if(!el)return 'NOFOCUS';if(typeof el.select==='function'&&typeof el.value==='string'){el.select();return 'SEL';}if(el.isContentEditable){var r=document.createRange();r.selectNodeContents(el);var s=window.getSelection();s.removeAllRanges();s.addRange(r);return 'SEL';}return 'NOSEL';})()";
|
|
@@ -463,7 +475,7 @@ function boxSelectorJs(selector) {
|
|
|
463
475
|
}
|
|
464
476
|
function boxByTextJs(text) {
|
|
465
477
|
const t = JSON.stringify(text);
|
|
466
|
-
return `(function(){var t=${t};var els=Array.prototype.slice.call(document.querySelectorAll('
|
|
478
|
+
return `(function(){var t=${t};var els=Array.prototype.slice.call(document.querySelectorAll('${BOX_CANDIDATES}'));` + NAME_JS + "var m=pick(els,t);if(!m)return 'NOTFOUND';var r=m.getBoundingClientRect();if(r.top<0||r.bottom>window.innerHeight){m.scrollIntoView({block:'center'});r=m.getBoundingClientRect();}return JSON.stringify({x:Math.round(r.x),y:Math.round(r.y),w:Math.round(r.width),h:Math.round(r.height)});})()";
|
|
467
479
|
}
|
|
468
480
|
const CLOSEST_ANCHOR_JS = "var a=m.closest('a[href]')||m.querySelector('a[href]');if(!a||!a.href)return 'NOTFOUND';return a.href;";
|
|
469
481
|
function hrefSelectorJs(selector) {
|
|
@@ -480,7 +492,7 @@ function scrollDeltaSelectorJs(selector) {
|
|
|
480
492
|
}
|
|
481
493
|
function scrollDeltaByTextJs(text) {
|
|
482
494
|
const t = JSON.stringify(text);
|
|
483
|
-
return `(function(){var t=${t};var els=Array.prototype.slice.call(document.querySelectorAll('
|
|
495
|
+
return `(function(){var t=${t};var els=Array.prototype.slice.call(document.querySelectorAll('${SCROLL_CANDIDATES}'));` + NAME_JS + "var m=pick(els,t);if(!m)return 'NOTFOUND';var r=m.getBoundingClientRect();return JSON.stringify({dy:Math.round(r.top+r.height/2-window.innerHeight/2)});})()";
|
|
484
496
|
}
|
|
485
497
|
function sampleAlong(pts, u) {
|
|
486
498
|
if (pts.length === 1) return pts[0];
|
|
@@ -548,7 +560,7 @@ async function ffprobe(path) {
|
|
|
548
560
|
}
|
|
549
561
|
/** Drive `plan` against the live app over CDP, return the ground-truth log. */
|
|
550
562
|
async function captureTake(plan, opts) {
|
|
551
|
-
const { captureTakeCDP: captureTakeCDP$1 } = await import("./cdp-capture-
|
|
563
|
+
const { captureTakeCDP: captureTakeCDP$1 } = await import("./cdp-capture-BPfyq-2O.js");
|
|
552
564
|
return captureTakeCDP$1(plan, {
|
|
553
565
|
...opts,
|
|
554
566
|
fps: opts.fps ?? 60
|
|
@@ -640,6 +652,253 @@ function safeUrl(raw, base) {
|
|
|
640
652
|
}
|
|
641
653
|
}
|
|
642
654
|
|
|
655
|
+
//#endregion
|
|
656
|
+
//#region src/precheck.ts
|
|
657
|
+
/** Thrown by the capture when error-severity findings refuse the shoot.
|
|
658
|
+
* Carries the FULL structured findings (warns included) so the CLI can emit
|
|
659
|
+
* the machine-readable defects block and exit 2 like every other gate
|
|
660
|
+
* verdict — the message is only the human rendering of the same facts, and
|
|
661
|
+
* flattening the findings into it is how the measured values used to get
|
|
662
|
+
* lost on the way to the repair loop. */
|
|
663
|
+
var PrecheckRefusal = class extends Error {
|
|
664
|
+
issues;
|
|
665
|
+
constructor(message, issues) {
|
|
666
|
+
super(message);
|
|
667
|
+
this.name = "PrecheckRefusal";
|
|
668
|
+
this.issues = issues;
|
|
669
|
+
}
|
|
670
|
+
};
|
|
671
|
+
const FIELD_ORDER = {
|
|
672
|
+
click: ["text", "selector"],
|
|
673
|
+
type: ["text", "selector"],
|
|
674
|
+
look: ["text", "selector"],
|
|
675
|
+
hover: ["text", "selector"],
|
|
676
|
+
press: ["text", "selector"],
|
|
677
|
+
select: ["selector", "text"],
|
|
678
|
+
scroll: ["toSelector", "toText"],
|
|
679
|
+
drag: ["selector", "text"]
|
|
680
|
+
};
|
|
681
|
+
const DRAG_TO_ORDER = ["toSelector", "toText"];
|
|
682
|
+
const MUTATING = new Set([
|
|
683
|
+
"click",
|
|
684
|
+
"type",
|
|
685
|
+
"press",
|
|
686
|
+
"select",
|
|
687
|
+
"drag",
|
|
688
|
+
"dropFiles",
|
|
689
|
+
"navigate",
|
|
690
|
+
"hover",
|
|
691
|
+
"scroll"
|
|
692
|
+
]);
|
|
693
|
+
/** Every named target in the plan, in step order, tagged cold/late. */
|
|
694
|
+
function planTargets(steps) {
|
|
695
|
+
const out = [];
|
|
696
|
+
let cold = true;
|
|
697
|
+
for (let i = 0; i < steps.length; i++) {
|
|
698
|
+
const s = steps[i];
|
|
699
|
+
const action = String(s.action ?? "");
|
|
700
|
+
const has = (f) => typeof s[f] === "string" && s[f];
|
|
701
|
+
/** the first field of this group the step actually carries */
|
|
702
|
+
const winner = (order$1) => order$1.find(has);
|
|
703
|
+
const order = FIELD_ORDER[action];
|
|
704
|
+
const dragTo = action === "drag" && s.to ? null : winner(DRAG_TO_ORDER);
|
|
705
|
+
const primary = action === "drag" && s.from ? null : winner(order ?? []);
|
|
706
|
+
const isUsed = (field) => !order || field === primary || field === dragTo;
|
|
707
|
+
const add = (field, kind, revealOnly) => {
|
|
708
|
+
const v = s[field];
|
|
709
|
+
if (typeof v === "string" && v) out.push({
|
|
710
|
+
step: i,
|
|
711
|
+
action,
|
|
712
|
+
field,
|
|
713
|
+
kind,
|
|
714
|
+
value: v,
|
|
715
|
+
cold: cold && !revealOnly,
|
|
716
|
+
used: isUsed(field),
|
|
717
|
+
...revealOnly ? { revealOnly } : {}
|
|
718
|
+
});
|
|
719
|
+
};
|
|
720
|
+
switch (action) {
|
|
721
|
+
case "click":
|
|
722
|
+
case "hover":
|
|
723
|
+
case "look":
|
|
724
|
+
case "type":
|
|
725
|
+
case "select":
|
|
726
|
+
add("selector", "selector");
|
|
727
|
+
add("text", "text");
|
|
728
|
+
break;
|
|
729
|
+
case "press":
|
|
730
|
+
add("selector", "selector", true);
|
|
731
|
+
add("text", "text", true);
|
|
732
|
+
break;
|
|
733
|
+
case "scroll":
|
|
734
|
+
add("toSelector", "selector");
|
|
735
|
+
add("toText", "text");
|
|
736
|
+
break;
|
|
737
|
+
case "drag": {
|
|
738
|
+
const hasPath = Array.isArray(s.path) && s.path.length > 0;
|
|
739
|
+
if (!hasPath) {
|
|
740
|
+
add("selector", "selector");
|
|
741
|
+
add("text", "text");
|
|
742
|
+
add("toSelector", "selector");
|
|
743
|
+
add("toText", "text");
|
|
744
|
+
}
|
|
745
|
+
break;
|
|
746
|
+
}
|
|
747
|
+
case "navigate": {
|
|
748
|
+
const hf = s.hrefFrom;
|
|
749
|
+
const hfField = hf?.selector ? "selector" : hf?.text ? "text" : null;
|
|
750
|
+
for (const [sub, kind] of [["selector", "selector"], ["text", "text"]]) {
|
|
751
|
+
const v = hf?.[sub];
|
|
752
|
+
if (typeof v === "string" && v) out.push({
|
|
753
|
+
step: i,
|
|
754
|
+
action,
|
|
755
|
+
field: `hrefFrom.${sub}`,
|
|
756
|
+
kind,
|
|
757
|
+
value: v,
|
|
758
|
+
cold,
|
|
759
|
+
used: sub === hfField
|
|
760
|
+
});
|
|
761
|
+
}
|
|
762
|
+
break;
|
|
763
|
+
}
|
|
764
|
+
default: break;
|
|
765
|
+
}
|
|
766
|
+
if (MUTATING.has(action)) cold = false;
|
|
767
|
+
}
|
|
768
|
+
return out;
|
|
769
|
+
}
|
|
770
|
+
/** The candidate set the ENGINE's by-text locator queries for this action —
|
|
771
|
+
* imported from capture.ts so the probe and the real resolver cannot drift. */
|
|
772
|
+
function textCandidates(action) {
|
|
773
|
+
switch (action) {
|
|
774
|
+
case "type": return FIELD_CANDIDATES;
|
|
775
|
+
case "click": return CLICK_CANDIDATES;
|
|
776
|
+
case "scroll": return SCROLL_CANDIDATES;
|
|
777
|
+
case "navigate": return "a,button,[role=link],[role=button],[aria-label],[title]";
|
|
778
|
+
default: return BOX_CANDIDATES;
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
/** One page eval: resolve a target and DESCRIBE the outcome (no side effects). */
|
|
782
|
+
function probeJs(kind, value, action) {
|
|
783
|
+
const v = JSON.stringify(value);
|
|
784
|
+
const desc = "function desc(m){if(!m)return null;var r=m.getBoundingClientRect();return {tag:m.tagName,w:Math.round(r.width),h:Math.round(r.height),x:Math.round(r.x),y:Math.round(r.y),inMain:!!m.closest('main')};}";
|
|
785
|
+
if (kind === "selector") return `(function(){${desc}var all;try{all=Array.prototype.slice.call(document.querySelectorAll(${v}));}catch(e){return JSON.stringify({err:String(e.message||e)});}return JSON.stringify({count:all.length,first:desc(all[0]||null)});})()`;
|
|
786
|
+
if (action === "select") return `(function(){${desc}var n=${v};var els=Array.prototype.slice.call(document.querySelectorAll('select'));var hits=els.filter(function(e){var a=(e.getAttribute('aria-label')||'').trim();if(a===n)return true;var id=e.id;if(id){var l=document.querySelector('label[for="'+id+'"]');if(l&&(l.textContent||'').trim().indexOf(n)>=0)return true;}var p=e.closest('label');if(p&&(p.textContent||'').trim().indexOf(n)>=0)return true;return false;});return JSON.stringify({count:hits.length?1:0,exact:hits.length,first:desc(hits[0]||null)});})()`;
|
|
787
|
+
const set = textCandidates(action);
|
|
788
|
+
return `(function(){${desc}${NAME_JS}var els=Array.prototype.slice.call(document.querySelectorAll('${set}'));var m=pick(els,${v});var exact=0;for(var i=0;i<els.length;i++){if(names(els[i]).indexOf(${v})!==-1)exact++;}var how=m?(names(m).indexOf(${v})!==-1?'exact':'substring'):'none';var share=how==='exact'?1:0,pn=null;if(m&&how==='substring'){var mn=names(m);for(var k=0;k<mn.length;k++){if(mn[k].indexOf(${v})!==-1&&(pn===null||mn[k].length<pn.length))pn=mn[k];}if(pn)share=${v}.length/pn.length;}function nm(e){var n=names(e),k;for(k=0;k<n.length;k++){if(n[k]===${v})return 'exact';}if(${v}.length>6){for(k=0;k<n.length;k++){if(n[k].length>6&&(n[k].indexOf(${v})!==-1||${v}.indexOf(n[k])!==-1))return 'contains';}}return null;}var inM=[],same=false,am=document.querySelectorAll('main *'),vwA=window.innerWidth*window.innerHeight;for(var i=0;i<am.length;i++){var e=am[i],mk=nm(e);if(!mk)continue;if(m&&e===m){if(mk==='exact')same=true;continue;}if(m&&(m.contains(e)||e.contains(m))){same=true;continue;}var d=desc(e);if(d.w<3||d.h<3)continue;if(mk==='contains'&&d.w*d.h>vwA*0.25)continue;d.match=mk;inM.push(d);}inM.sort(function(a,b){if(a.match!==b.match)return a.match==='exact'?-1:1;return a.w*a.h-b.w*b.h;});return JSON.stringify({count:m?1:0,exact:exact,first:desc(m),how:how,pickNameShare:Math.round(share*100)/100,pickName:pn?pn.slice(0,60):null,pickIsNamed:same,mainMatches:inM.slice(0,4)});})()`;
|
|
789
|
+
}
|
|
790
|
+
/** C3.5 parse-intent mismatch: the pick and the same-named in-main element
|
|
791
|
+
* disagree by more than a step's worth of geometry. Validated against the 36
|
|
792
|
+
* plans of the X5 corpus (23 poisoned targets). A pick that covers most of
|
|
793
|
+
* its own label (share >= 0.5) is the named control, abbreviated — for that
|
|
794
|
+
* shape only an EXACT in-main duplicate is evidence of anything; body copy
|
|
795
|
+
* merely mentioning the phrase is how landing pages talk about their own
|
|
796
|
+
* buttons. */
|
|
797
|
+
const FAR_PX = 150;
|
|
798
|
+
const ABBREVIATION_SHARE = .5;
|
|
799
|
+
function parseIntentMismatch(p) {
|
|
800
|
+
const pick = p.first;
|
|
801
|
+
if (!pick || typeof pick.x !== "number" || typeof pick.y !== "number") return null;
|
|
802
|
+
if (p.pickIsNamed) return null;
|
|
803
|
+
let matches = (p.mainMatches ?? []).filter((m) => typeof m.x === "number" && typeof m.y === "number");
|
|
804
|
+
if ((p.pickNameShare ?? 0) >= ABBREVIATION_SHARE) matches = matches.filter((m) => m.match === "exact");
|
|
805
|
+
if (!matches.length) return null;
|
|
806
|
+
const cx = pick.x + pick.w / 2;
|
|
807
|
+
const cy = pick.y + pick.h / 2;
|
|
808
|
+
for (const m of matches) if (Math.abs(m.x + m.w / 2 - cx) <= 5 && Math.abs(m.y + m.h / 2 - cy) <= 5) return null;
|
|
809
|
+
const intended = matches[0];
|
|
810
|
+
const far = Math.abs(intended.x + intended.w / 2 - cx) > FAR_PX || Math.abs(intended.y + intended.h / 2 - cy) > FAR_PX;
|
|
811
|
+
return !pick.inMain || far ? {
|
|
812
|
+
pick,
|
|
813
|
+
intended
|
|
814
|
+
} : null;
|
|
815
|
+
}
|
|
816
|
+
/** Resolve every plan target through `evalJson` (a Runtime.evaluate wrapper)
|
|
817
|
+
* and grade the outcomes. Cold-prefix misses get ONE retry after `retryMs` —
|
|
818
|
+
* a hydration-slow page may mount its controls a beat after load. */
|
|
819
|
+
async function precheckPlan(steps, evalJson, opts) {
|
|
820
|
+
const sleep$4 = opts?.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
821
|
+
const targets = planTargets(steps).filter((t) => t.used);
|
|
822
|
+
const probes = new Map();
|
|
823
|
+
const probe = async (t) => await evalJson(probeJs(t.kind, t.value, t.action)) ?? {};
|
|
824
|
+
for (const t of targets) probes.set(t, await probe(t));
|
|
825
|
+
const misses = targets.filter((t) => !probes.get(t)?.err && !probes.get(t)?.count);
|
|
826
|
+
if (misses.length) {
|
|
827
|
+
await sleep$4(opts?.retryMs ?? 1500);
|
|
828
|
+
for (const t of misses) probes.set(t, await probe(t));
|
|
829
|
+
}
|
|
830
|
+
const issues = [];
|
|
831
|
+
const lateMisses = [];
|
|
832
|
+
for (const t of targets) {
|
|
833
|
+
const p = probes.get(t) ?? {};
|
|
834
|
+
const path = `steps[${t.step}].${t.field}`;
|
|
835
|
+
const name = `${t.action} ${JSON.stringify(t.value)}`;
|
|
836
|
+
if (p.err) {
|
|
837
|
+
issues.push({
|
|
838
|
+
severity: "error",
|
|
839
|
+
path,
|
|
840
|
+
message: `${name}: invalid selector — the page rejected it (${p.err})`,
|
|
841
|
+
fix: "fix the selector syntax; the capture would skip every use of it"
|
|
842
|
+
});
|
|
843
|
+
continue;
|
|
844
|
+
}
|
|
845
|
+
if (!p.count) {
|
|
846
|
+
if (t.revealOnly) continue;
|
|
847
|
+
if (t.cold) issues.push({
|
|
848
|
+
severity: "error",
|
|
849
|
+
path,
|
|
850
|
+
message: `${name}: target not found in the page as loaded — this step runs before anything has changed the page, so it is CERTAIN to be skipped. Refusing in seconds what would fail after the full capture.`,
|
|
851
|
+
fix: "point it at an element that exists at load (`open-take inspect <url>` lists them), or move it after the step that reveals it"
|
|
852
|
+
});
|
|
853
|
+
else lateMisses.push(t);
|
|
854
|
+
continue;
|
|
855
|
+
}
|
|
856
|
+
if (t.kind === "text" && !t.revealOnly) {
|
|
857
|
+
const mm = parseIntentMismatch(p);
|
|
858
|
+
if (mm) {
|
|
859
|
+
const certain = t.cold && p.how === "substring" && !mm.pick.inMain && (p.pickNameShare ?? 0) < ABBREVIATION_SHARE;
|
|
860
|
+
issues.push({
|
|
861
|
+
severity: certain ? "error" : "warn",
|
|
862
|
+
path,
|
|
863
|
+
message: `${name}: resolves to the WRONG element. The by-text lookup for ${t.action} searches only its candidate set and ${p.how === "substring" ? "substring-" : ""}matched a ${mm.pick.w}x${mm.pick.h} ${mm.pick.tag.toLowerCase()} at (${mm.pick.x},${mm.pick.y})${mm.pick.inMain ? "" : " OUTSIDE <main>"}${p.pickName ? ` (its actual name: ${JSON.stringify(p.pickName)})` : ""}, while the element named ${JSON.stringify(t.value.slice(0, 40))} is a ${mm.intended.tag.toLowerCase()} at (${mm.intended.x},${mm.intended.y}) inside <main>. The step would land on the impostor.`,
|
|
864
|
+
fix: `target the in-main ${mm.intended.tag.toLowerCase()} with a CSS selector scoped to \`main\` (\`open-take inspect <url>\` lists one), or name a real control instead`
|
|
865
|
+
});
|
|
866
|
+
continue;
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
if (t.kind === "selector" && (p.count ?? 0) > 1) {
|
|
870
|
+
const z = p.first && (p.first.w === 0 || p.first.h === 0) ? " — and the first match is ZERO-SIZE" : "";
|
|
871
|
+
issues.push({
|
|
872
|
+
severity: "warn",
|
|
873
|
+
path,
|
|
874
|
+
message: `${name}: matches ${p.count} nodes; the engine takes the FIRST in document order${z}. A sidebar thumbnail or an off-screen clone outranking the real element is exactly how a whole take dies.`,
|
|
875
|
+
fix: "qualify the selector until it matches once (e.g. scope it to `main`)"
|
|
876
|
+
});
|
|
877
|
+
continue;
|
|
878
|
+
}
|
|
879
|
+
if (t.kind === "text" && (p.exact ?? 0) > 1) {
|
|
880
|
+
issues.push({
|
|
881
|
+
severity: "warn",
|
|
882
|
+
path,
|
|
883
|
+
message: `${name}: ${p.exact} elements carry this exact accessible name; the engine takes the first in document order`,
|
|
884
|
+
fix: "use a more specific name, or a CSS selector scoped to the intended region"
|
|
885
|
+
});
|
|
886
|
+
continue;
|
|
887
|
+
}
|
|
888
|
+
if (p.first && (p.first.w === 0 || p.first.h === 0)) issues.push({
|
|
889
|
+
severity: "warn",
|
|
890
|
+
path,
|
|
891
|
+
message: `${name}: resolves to a zero-size element — the cursor has nowhere real to land`
|
|
892
|
+
});
|
|
893
|
+
}
|
|
894
|
+
if (lateMisses.length) issues.push({
|
|
895
|
+
severity: "warn",
|
|
896
|
+
path: "steps",
|
|
897
|
+
message: `${lateMisses.length} target${lateMisses.length === 1 ? " is" : "s are"} not in the initial DOM (${lateMisses.map((t) => `steps[${t.step}] ${JSON.stringify(t.value)}`).join(", ")}) — fine if earlier steps reveal them; any that never appears is SKIPPED at capture time (and the run exits non-zero)`
|
|
898
|
+
});
|
|
899
|
+
return issues;
|
|
900
|
+
}
|
|
901
|
+
|
|
643
902
|
//#endregion
|
|
644
903
|
//#region src/settle.ts
|
|
645
904
|
const sleep$1 = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
@@ -1169,6 +1428,10 @@ async function captureTakeCDP(plan, opts) {
|
|
|
1169
1428
|
await installActivityProbe(cdp);
|
|
1170
1429
|
await awaitFonts(cdp);
|
|
1171
1430
|
inner = await fitViewport(cdp, browser.targetId, vw, vh);
|
|
1431
|
+
const precheck = await precheckPlan(plan.steps, (js) => evalAny(cdp, js));
|
|
1432
|
+
const precheckErrors = precheck.filter((p) => p.severity === "error");
|
|
1433
|
+
if (precheckErrors.length) throw new PrecheckRefusal(`captureTakeCDP: ${precheckErrors.length} plan target(s) failed the pre-capture check — nothing was recorded:\n` + precheckErrors.map((p) => ` ${p.path}: ${p.message}${p.fix ? `\n fix: ${p.fix}` : ""}`).join("\n"), precheck);
|
|
1434
|
+
for (const p of precheck) console.error(`captureTakeCDP precheck [${p.severity}] ${p.path}: ${p.message}`);
|
|
1172
1435
|
const screencast = new Screencast(cdp, frameDir);
|
|
1173
1436
|
const t0 = Date.now();
|
|
1174
1437
|
await screencast.start(t0, {
|
|
@@ -1287,13 +1550,44 @@ async function captureTakeCDP(plan, opts) {
|
|
|
1287
1550
|
}
|
|
1288
1551
|
if (step.action === "type") {
|
|
1289
1552
|
const label$1 = step.text ?? step.selector;
|
|
1290
|
-
|
|
1291
|
-
const
|
|
1553
|
+
let tMs$1 = Date.now() - t0;
|
|
1554
|
+
const focusRaw = step.text ? await evalAny(cdp, focusFieldByTextJs(step.text)) : step.selector ? await evalAny(cdp, focusSelectorJs(step.selector)) : null;
|
|
1555
|
+
const box$1 = focusRaw ? findBox(focusRaw) : null;
|
|
1292
1556
|
if (!box$1) {
|
|
1293
1557
|
skip("type", label$1, "target not found");
|
|
1294
1558
|
await hold(600);
|
|
1295
1559
|
continue;
|
|
1296
1560
|
}
|
|
1561
|
+
let focused = focusRaw.f === 1;
|
|
1562
|
+
if (!focused && focusRaw.hit !== 1) {
|
|
1563
|
+
skip("type", label$1, "focus never reached the target — its centre is covered, so no click could arm it");
|
|
1564
|
+
await hold(600);
|
|
1565
|
+
continue;
|
|
1566
|
+
}
|
|
1567
|
+
if (!focused) {
|
|
1568
|
+
const pt$1 = center(box$1);
|
|
1569
|
+
pumpPaused = true;
|
|
1570
|
+
await sleep(160);
|
|
1571
|
+
tMs$1 = Date.now() - t0;
|
|
1572
|
+
mouse(cdp, "mouseMoved", pt$1.x, pt$1.y, 0).catch(() => {});
|
|
1573
|
+
mouse(cdp, "mousePressed", pt$1.x, pt$1.y, 1).catch(() => {});
|
|
1574
|
+
await sleep(60);
|
|
1575
|
+
mouse(cdp, "mouseReleased", pt$1.x, pt$1.y, 0).catch(() => {});
|
|
1576
|
+
await sleep(120);
|
|
1577
|
+
pumpPaused = false;
|
|
1578
|
+
for (let poll = 0; poll < 3 && !focused; poll++) {
|
|
1579
|
+
await sleep(250);
|
|
1580
|
+
focused = await evalString(cdp, verifyFocusJs({
|
|
1581
|
+
text: step.text,
|
|
1582
|
+
selector: step.selector
|
|
1583
|
+
})) === "1";
|
|
1584
|
+
}
|
|
1585
|
+
}
|
|
1586
|
+
if (!focused) {
|
|
1587
|
+
skip("type", label$1, "focus never reached the target — typing would go nowhere");
|
|
1588
|
+
await hold(600);
|
|
1589
|
+
continue;
|
|
1590
|
+
}
|
|
1297
1591
|
if (process.env.OPEN_TAKE_CI && await evalString(cdp, credentialFieldProbeJs()) === "secret") {
|
|
1298
1592
|
skip("type", label$1, "refusing to type into a credential field (OPEN_TAKE_CI)");
|
|
1299
1593
|
await hold(600);
|
|
@@ -1304,7 +1598,6 @@ async function captureTakeCDP(plan, opts) {
|
|
|
1304
1598
|
const cjk = chars.filter((c) => /[\u2E80-\u9FFF\uAC00-\uD7AF\uF900-\uFAFF\uFF66-\uFF9F]/.test(c)).length;
|
|
1305
1599
|
const auto = Math.min(90, Math.max(28, Math.round(1100 / Math.max(1, chars.length)))) * (cjk * 2 > chars.length ? 1.4 : 1);
|
|
1306
1600
|
const perChar = Math.round(step.perCharMs ?? auto);
|
|
1307
|
-
const tType = Date.now();
|
|
1308
1601
|
for (const ch of chars) {
|
|
1309
1602
|
await cdp.send("Input.insertText", { text: ch });
|
|
1310
1603
|
await sleep(perChar);
|
|
@@ -1318,7 +1611,7 @@ async function captureTakeCDP(plan, opts) {
|
|
|
1318
1611
|
note: step.note,
|
|
1319
1612
|
...step.caption ? { caption: step.caption } : {},
|
|
1320
1613
|
text: step.value,
|
|
1321
|
-
durationMs: Date.now() -
|
|
1614
|
+
durationMs: Date.now() - t0 - tMs$1,
|
|
1322
1615
|
...step.zoom ? { zoom: step.zoom } : {}
|
|
1323
1616
|
});
|
|
1324
1617
|
await hold(900);
|
|
@@ -1722,6 +2015,7 @@ async function captureTakeCDP(plan, opts) {
|
|
|
1722
2015
|
events,
|
|
1723
2016
|
tEndMs,
|
|
1724
2017
|
...skipped.length ? { skipped } : {},
|
|
2018
|
+
...precheck.length ? { precheck } : {},
|
|
1725
2019
|
...settleWaits.length ? { settleWaits } : {},
|
|
1726
2020
|
...paintedFrac >= PAINT_BLIND_FRAC ? { paintedFrac: Math.round(paintedFrac * 100) / 100 } : {}
|
|
1727
2021
|
};
|
|
@@ -1780,5 +2074,5 @@ async function navigate(cdp, url) {
|
|
|
1780
2074
|
}
|
|
1781
2075
|
|
|
1782
2076
|
//#endregion
|
|
1783
|
-
export { captureTake, captureTakeCDP, ensureChrome, inspectPage, resolveChrome, resolveNavigateUrl };
|
|
1784
|
-
//# sourceMappingURL=cdp-capture-
|
|
2077
|
+
export { PrecheckRefusal, captureTake, captureTakeCDP, ensureChrome, inspectPage, planTargets, precheckPlan, resolveChrome, resolveNavigateUrl };
|
|
2078
|
+
//# sourceMappingURL=cdp-capture-Ckt-tZVU.js.map
|