@open-take/runtime 0.4.2 → 0.4.3
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-DvXJ9UbJ.js +3 -0
- package/dist/{cdp-capture-Bm8No23R.js → cdp-capture-iGdBAriK.js} +263 -7
- package/dist/cdp-capture-iGdBAriK.js.map +1 -0
- package/dist/index.d.ts +632 -404
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1955 -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
|
@@ -438,9 +438,13 @@ function evalValue(raw) {
|
|
|
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
440
|
const CLICK_TAIL_JS = "if(m.tagName==='SELECT')return 'SELECTINERT';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 cx=Math.round(r.x+r.width/2),cy=Math.round(r.y+r.height/2);var hit=(r.width>0&&r.height>0&&document.elementFromPoint)?document.elementFromPoint(cx,cy):null;if(hit&&(hit===m||(m.contains&&m.contains(hit)))){b.cx=cx;b.cy=cy;return JSON.stringify(b);}m.click();return JSON.stringify(b);";
|
|
441
|
+
const CLICK_CANDIDATES = "button,a,[role=button],[role=link],[role=menuitem],input[type=submit],input[type=button]";
|
|
442
|
+
const FIELD_CANDIDATES = "input,textarea,[contenteditable],[contenteditable=true],[role=textbox],[role=searchbox]";
|
|
443
|
+
const BOX_CANDIDATES = "button,a,[role=button],[role=link],[role=menuitem],[aria-label],[title],img[alt],li,[draggable=true]";
|
|
444
|
+
const SCROLL_CANDIDATES = "button,a,[role=button],[role=link],[role=heading],[aria-label],[title],h1,h2,h3,li,section,p";
|
|
441
445
|
function clickByTextJs(text) {
|
|
442
446
|
const t = JSON.stringify(text);
|
|
443
|
-
return `(function(){var t=${t};var els=Array.prototype.slice.call(document.querySelectorAll('
|
|
447
|
+
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
448
|
}
|
|
445
449
|
function clickBySelectorJs(selector) {
|
|
446
450
|
const s = JSON.stringify(selector);
|
|
@@ -448,7 +452,7 @@ function clickBySelectorJs(selector) {
|
|
|
448
452
|
}
|
|
449
453
|
function focusFieldByTextJs(text) {
|
|
450
454
|
const t = JSON.stringify(text);
|
|
451
|
-
return `(function(){var t=${t};var els=Array.prototype.slice.call(document.querySelectorAll('
|
|
455
|
+
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';var r=m.getBoundingClientRect();if(r.top<0||r.bottom>window.innerHeight){m.scrollIntoView({block:'center'});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();return JSON.stringify(b);})()";
|
|
452
456
|
}
|
|
453
457
|
function focusSelectorJs(selector) {
|
|
454
458
|
const s = JSON.stringify(selector);
|
|
@@ -463,7 +467,7 @@ function boxSelectorJs(selector) {
|
|
|
463
467
|
}
|
|
464
468
|
function boxByTextJs(text) {
|
|
465
469
|
const t = JSON.stringify(text);
|
|
466
|
-
return `(function(){var t=${t};var els=Array.prototype.slice.call(document.querySelectorAll('
|
|
470
|
+
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
471
|
}
|
|
468
472
|
const CLOSEST_ANCHOR_JS = "var a=m.closest('a[href]')||m.querySelector('a[href]');if(!a||!a.href)return 'NOTFOUND';return a.href;";
|
|
469
473
|
function hrefSelectorJs(selector) {
|
|
@@ -480,7 +484,7 @@ function scrollDeltaSelectorJs(selector) {
|
|
|
480
484
|
}
|
|
481
485
|
function scrollDeltaByTextJs(text) {
|
|
482
486
|
const t = JSON.stringify(text);
|
|
483
|
-
return `(function(){var t=${t};var els=Array.prototype.slice.call(document.querySelectorAll('
|
|
487
|
+
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
488
|
}
|
|
485
489
|
function sampleAlong(pts, u) {
|
|
486
490
|
if (pts.length === 1) return pts[0];
|
|
@@ -548,7 +552,7 @@ async function ffprobe(path) {
|
|
|
548
552
|
}
|
|
549
553
|
/** Drive `plan` against the live app over CDP, return the ground-truth log. */
|
|
550
554
|
async function captureTake(plan, opts) {
|
|
551
|
-
const { captureTakeCDP: captureTakeCDP$1 } = await import("./cdp-capture-
|
|
555
|
+
const { captureTakeCDP: captureTakeCDP$1 } = await import("./cdp-capture-DvXJ9UbJ.js");
|
|
552
556
|
return captureTakeCDP$1(plan, {
|
|
553
557
|
...opts,
|
|
554
558
|
fps: opts.fps ?? 60
|
|
@@ -640,6 +644,253 @@ function safeUrl(raw, base) {
|
|
|
640
644
|
}
|
|
641
645
|
}
|
|
642
646
|
|
|
647
|
+
//#endregion
|
|
648
|
+
//#region src/precheck.ts
|
|
649
|
+
/** Thrown by the capture when error-severity findings refuse the shoot.
|
|
650
|
+
* Carries the FULL structured findings (warns included) so the CLI can emit
|
|
651
|
+
* the machine-readable defects block and exit 2 like every other gate
|
|
652
|
+
* verdict — the message is only the human rendering of the same facts, and
|
|
653
|
+
* flattening the findings into it is how the measured values used to get
|
|
654
|
+
* lost on the way to the repair loop. */
|
|
655
|
+
var PrecheckRefusal = class extends Error {
|
|
656
|
+
issues;
|
|
657
|
+
constructor(message, issues) {
|
|
658
|
+
super(message);
|
|
659
|
+
this.name = "PrecheckRefusal";
|
|
660
|
+
this.issues = issues;
|
|
661
|
+
}
|
|
662
|
+
};
|
|
663
|
+
const FIELD_ORDER = {
|
|
664
|
+
click: ["text", "selector"],
|
|
665
|
+
type: ["text", "selector"],
|
|
666
|
+
look: ["text", "selector"],
|
|
667
|
+
hover: ["text", "selector"],
|
|
668
|
+
press: ["text", "selector"],
|
|
669
|
+
select: ["selector", "text"],
|
|
670
|
+
scroll: ["toSelector", "toText"],
|
|
671
|
+
drag: ["selector", "text"]
|
|
672
|
+
};
|
|
673
|
+
const DRAG_TO_ORDER = ["toSelector", "toText"];
|
|
674
|
+
const MUTATING = new Set([
|
|
675
|
+
"click",
|
|
676
|
+
"type",
|
|
677
|
+
"press",
|
|
678
|
+
"select",
|
|
679
|
+
"drag",
|
|
680
|
+
"dropFiles",
|
|
681
|
+
"navigate",
|
|
682
|
+
"hover",
|
|
683
|
+
"scroll"
|
|
684
|
+
]);
|
|
685
|
+
/** Every named target in the plan, in step order, tagged cold/late. */
|
|
686
|
+
function planTargets(steps) {
|
|
687
|
+
const out = [];
|
|
688
|
+
let cold = true;
|
|
689
|
+
for (let i = 0; i < steps.length; i++) {
|
|
690
|
+
const s = steps[i];
|
|
691
|
+
const action = String(s.action ?? "");
|
|
692
|
+
const has = (f) => typeof s[f] === "string" && s[f];
|
|
693
|
+
/** the first field of this group the step actually carries */
|
|
694
|
+
const winner = (order$1) => order$1.find(has);
|
|
695
|
+
const order = FIELD_ORDER[action];
|
|
696
|
+
const dragTo = action === "drag" && s.to ? null : winner(DRAG_TO_ORDER);
|
|
697
|
+
const primary = action === "drag" && s.from ? null : winner(order ?? []);
|
|
698
|
+
const isUsed = (field) => !order || field === primary || field === dragTo;
|
|
699
|
+
const add = (field, kind, revealOnly) => {
|
|
700
|
+
const v = s[field];
|
|
701
|
+
if (typeof v === "string" && v) out.push({
|
|
702
|
+
step: i,
|
|
703
|
+
action,
|
|
704
|
+
field,
|
|
705
|
+
kind,
|
|
706
|
+
value: v,
|
|
707
|
+
cold: cold && !revealOnly,
|
|
708
|
+
used: isUsed(field),
|
|
709
|
+
...revealOnly ? { revealOnly } : {}
|
|
710
|
+
});
|
|
711
|
+
};
|
|
712
|
+
switch (action) {
|
|
713
|
+
case "click":
|
|
714
|
+
case "hover":
|
|
715
|
+
case "look":
|
|
716
|
+
case "type":
|
|
717
|
+
case "select":
|
|
718
|
+
add("selector", "selector");
|
|
719
|
+
add("text", "text");
|
|
720
|
+
break;
|
|
721
|
+
case "press":
|
|
722
|
+
add("selector", "selector", true);
|
|
723
|
+
add("text", "text", true);
|
|
724
|
+
break;
|
|
725
|
+
case "scroll":
|
|
726
|
+
add("toSelector", "selector");
|
|
727
|
+
add("toText", "text");
|
|
728
|
+
break;
|
|
729
|
+
case "drag": {
|
|
730
|
+
const hasPath = Array.isArray(s.path) && s.path.length > 0;
|
|
731
|
+
if (!hasPath) {
|
|
732
|
+
add("selector", "selector");
|
|
733
|
+
add("text", "text");
|
|
734
|
+
add("toSelector", "selector");
|
|
735
|
+
add("toText", "text");
|
|
736
|
+
}
|
|
737
|
+
break;
|
|
738
|
+
}
|
|
739
|
+
case "navigate": {
|
|
740
|
+
const hf = s.hrefFrom;
|
|
741
|
+
const hfField = hf?.selector ? "selector" : hf?.text ? "text" : null;
|
|
742
|
+
for (const [sub, kind] of [["selector", "selector"], ["text", "text"]]) {
|
|
743
|
+
const v = hf?.[sub];
|
|
744
|
+
if (typeof v === "string" && v) out.push({
|
|
745
|
+
step: i,
|
|
746
|
+
action,
|
|
747
|
+
field: `hrefFrom.${sub}`,
|
|
748
|
+
kind,
|
|
749
|
+
value: v,
|
|
750
|
+
cold,
|
|
751
|
+
used: sub === hfField
|
|
752
|
+
});
|
|
753
|
+
}
|
|
754
|
+
break;
|
|
755
|
+
}
|
|
756
|
+
default: break;
|
|
757
|
+
}
|
|
758
|
+
if (MUTATING.has(action)) cold = false;
|
|
759
|
+
}
|
|
760
|
+
return out;
|
|
761
|
+
}
|
|
762
|
+
/** The candidate set the ENGINE's by-text locator queries for this action —
|
|
763
|
+
* imported from capture.ts so the probe and the real resolver cannot drift. */
|
|
764
|
+
function textCandidates(action) {
|
|
765
|
+
switch (action) {
|
|
766
|
+
case "type": return FIELD_CANDIDATES;
|
|
767
|
+
case "click": return CLICK_CANDIDATES;
|
|
768
|
+
case "scroll": return SCROLL_CANDIDATES;
|
|
769
|
+
case "navigate": return "a,button,[role=link],[role=button],[aria-label],[title]";
|
|
770
|
+
default: return BOX_CANDIDATES;
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
/** One page eval: resolve a target and DESCRIBE the outcome (no side effects). */
|
|
774
|
+
function probeJs(kind, value, action) {
|
|
775
|
+
const v = JSON.stringify(value);
|
|
776
|
+
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')};}";
|
|
777
|
+
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)});})()`;
|
|
778
|
+
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)});})()`;
|
|
779
|
+
const set = textCandidates(action);
|
|
780
|
+
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)});})()`;
|
|
781
|
+
}
|
|
782
|
+
/** C3.5 parse-intent mismatch: the pick and the same-named in-main element
|
|
783
|
+
* disagree by more than a step's worth of geometry. Validated against the 36
|
|
784
|
+
* plans of the X5 corpus (23 poisoned targets). A pick that covers most of
|
|
785
|
+
* its own label (share >= 0.5) is the named control, abbreviated — for that
|
|
786
|
+
* shape only an EXACT in-main duplicate is evidence of anything; body copy
|
|
787
|
+
* merely mentioning the phrase is how landing pages talk about their own
|
|
788
|
+
* buttons. */
|
|
789
|
+
const FAR_PX = 150;
|
|
790
|
+
const ABBREVIATION_SHARE = .5;
|
|
791
|
+
function parseIntentMismatch(p) {
|
|
792
|
+
const pick = p.first;
|
|
793
|
+
if (!pick || typeof pick.x !== "number" || typeof pick.y !== "number") return null;
|
|
794
|
+
if (p.pickIsNamed) return null;
|
|
795
|
+
let matches = (p.mainMatches ?? []).filter((m) => typeof m.x === "number" && typeof m.y === "number");
|
|
796
|
+
if ((p.pickNameShare ?? 0) >= ABBREVIATION_SHARE) matches = matches.filter((m) => m.match === "exact");
|
|
797
|
+
if (!matches.length) return null;
|
|
798
|
+
const cx = pick.x + pick.w / 2;
|
|
799
|
+
const cy = pick.y + pick.h / 2;
|
|
800
|
+
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;
|
|
801
|
+
const intended = matches[0];
|
|
802
|
+
const far = Math.abs(intended.x + intended.w / 2 - cx) > FAR_PX || Math.abs(intended.y + intended.h / 2 - cy) > FAR_PX;
|
|
803
|
+
return !pick.inMain || far ? {
|
|
804
|
+
pick,
|
|
805
|
+
intended
|
|
806
|
+
} : null;
|
|
807
|
+
}
|
|
808
|
+
/** Resolve every plan target through `evalJson` (a Runtime.evaluate wrapper)
|
|
809
|
+
* and grade the outcomes. Cold-prefix misses get ONE retry after `retryMs` —
|
|
810
|
+
* a hydration-slow page may mount its controls a beat after load. */
|
|
811
|
+
async function precheckPlan(steps, evalJson, opts) {
|
|
812
|
+
const sleep$4 = opts?.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
813
|
+
const targets = planTargets(steps).filter((t) => t.used);
|
|
814
|
+
const probes = new Map();
|
|
815
|
+
const probe = async (t) => await evalJson(probeJs(t.kind, t.value, t.action)) ?? {};
|
|
816
|
+
for (const t of targets) probes.set(t, await probe(t));
|
|
817
|
+
const misses = targets.filter((t) => !probes.get(t)?.err && !probes.get(t)?.count);
|
|
818
|
+
if (misses.length) {
|
|
819
|
+
await sleep$4(opts?.retryMs ?? 1500);
|
|
820
|
+
for (const t of misses) probes.set(t, await probe(t));
|
|
821
|
+
}
|
|
822
|
+
const issues = [];
|
|
823
|
+
const lateMisses = [];
|
|
824
|
+
for (const t of targets) {
|
|
825
|
+
const p = probes.get(t) ?? {};
|
|
826
|
+
const path = `steps[${t.step}].${t.field}`;
|
|
827
|
+
const name = `${t.action} ${JSON.stringify(t.value)}`;
|
|
828
|
+
if (p.err) {
|
|
829
|
+
issues.push({
|
|
830
|
+
severity: "error",
|
|
831
|
+
path,
|
|
832
|
+
message: `${name}: invalid selector — the page rejected it (${p.err})`,
|
|
833
|
+
fix: "fix the selector syntax; the capture would skip every use of it"
|
|
834
|
+
});
|
|
835
|
+
continue;
|
|
836
|
+
}
|
|
837
|
+
if (!p.count) {
|
|
838
|
+
if (t.revealOnly) continue;
|
|
839
|
+
if (t.cold) issues.push({
|
|
840
|
+
severity: "error",
|
|
841
|
+
path,
|
|
842
|
+
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.`,
|
|
843
|
+
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"
|
|
844
|
+
});
|
|
845
|
+
else lateMisses.push(t);
|
|
846
|
+
continue;
|
|
847
|
+
}
|
|
848
|
+
if (t.kind === "text" && !t.revealOnly) {
|
|
849
|
+
const mm = parseIntentMismatch(p);
|
|
850
|
+
if (mm) {
|
|
851
|
+
const certain = t.cold && p.how === "substring" && !mm.pick.inMain && (p.pickNameShare ?? 0) < ABBREVIATION_SHARE;
|
|
852
|
+
issues.push({
|
|
853
|
+
severity: certain ? "error" : "warn",
|
|
854
|
+
path,
|
|
855
|
+
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.`,
|
|
856
|
+
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`
|
|
857
|
+
});
|
|
858
|
+
continue;
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
if (t.kind === "selector" && (p.count ?? 0) > 1) {
|
|
862
|
+
const z = p.first && (p.first.w === 0 || p.first.h === 0) ? " — and the first match is ZERO-SIZE" : "";
|
|
863
|
+
issues.push({
|
|
864
|
+
severity: "warn",
|
|
865
|
+
path,
|
|
866
|
+
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.`,
|
|
867
|
+
fix: "qualify the selector until it matches once (e.g. scope it to `main`)"
|
|
868
|
+
});
|
|
869
|
+
continue;
|
|
870
|
+
}
|
|
871
|
+
if (t.kind === "text" && (p.exact ?? 0) > 1) {
|
|
872
|
+
issues.push({
|
|
873
|
+
severity: "warn",
|
|
874
|
+
path,
|
|
875
|
+
message: `${name}: ${p.exact} elements carry this exact accessible name; the engine takes the first in document order`,
|
|
876
|
+
fix: "use a more specific name, or a CSS selector scoped to the intended region"
|
|
877
|
+
});
|
|
878
|
+
continue;
|
|
879
|
+
}
|
|
880
|
+
if (p.first && (p.first.w === 0 || p.first.h === 0)) issues.push({
|
|
881
|
+
severity: "warn",
|
|
882
|
+
path,
|
|
883
|
+
message: `${name}: resolves to a zero-size element — the cursor has nowhere real to land`
|
|
884
|
+
});
|
|
885
|
+
}
|
|
886
|
+
if (lateMisses.length) issues.push({
|
|
887
|
+
severity: "warn",
|
|
888
|
+
path: "steps",
|
|
889
|
+
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)`
|
|
890
|
+
});
|
|
891
|
+
return issues;
|
|
892
|
+
}
|
|
893
|
+
|
|
643
894
|
//#endregion
|
|
644
895
|
//#region src/settle.ts
|
|
645
896
|
const sleep$1 = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
@@ -1169,6 +1420,10 @@ async function captureTakeCDP(plan, opts) {
|
|
|
1169
1420
|
await installActivityProbe(cdp);
|
|
1170
1421
|
await awaitFonts(cdp);
|
|
1171
1422
|
inner = await fitViewport(cdp, browser.targetId, vw, vh);
|
|
1423
|
+
const precheck = await precheckPlan(plan.steps, (js) => evalAny(cdp, js));
|
|
1424
|
+
const precheckErrors = precheck.filter((p) => p.severity === "error");
|
|
1425
|
+
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);
|
|
1426
|
+
for (const p of precheck) console.error(`captureTakeCDP precheck [${p.severity}] ${p.path}: ${p.message}`);
|
|
1172
1427
|
const screencast = new Screencast(cdp, frameDir);
|
|
1173
1428
|
const t0 = Date.now();
|
|
1174
1429
|
await screencast.start(t0, {
|
|
@@ -1722,6 +1977,7 @@ async function captureTakeCDP(plan, opts) {
|
|
|
1722
1977
|
events,
|
|
1723
1978
|
tEndMs,
|
|
1724
1979
|
...skipped.length ? { skipped } : {},
|
|
1980
|
+
...precheck.length ? { precheck } : {},
|
|
1725
1981
|
...settleWaits.length ? { settleWaits } : {},
|
|
1726
1982
|
...paintedFrac >= PAINT_BLIND_FRAC ? { paintedFrac: Math.round(paintedFrac * 100) / 100 } : {}
|
|
1727
1983
|
};
|
|
@@ -1780,5 +2036,5 @@ async function navigate(cdp, url) {
|
|
|
1780
2036
|
}
|
|
1781
2037
|
|
|
1782
2038
|
//#endregion
|
|
1783
|
-
export { captureTake, captureTakeCDP, ensureChrome, inspectPage, resolveChrome, resolveNavigateUrl };
|
|
1784
|
-
//# sourceMappingURL=cdp-capture-
|
|
2039
|
+
export { PrecheckRefusal, captureTake, captureTakeCDP, ensureChrome, inspectPage, planTargets, precheckPlan, resolveChrome, resolveNavigateUrl };
|
|
2040
|
+
//# sourceMappingURL=cdp-capture-iGdBAriK.js.map
|