@open-take/runtime 0.4.3 → 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-iGdBAriK.js → cdp-capture-Ckt-tZVU.js} +47 -9
- package/dist/cdp-capture-Ckt-tZVU.js.map +1 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -3
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/dist/cdp-capture-DvXJ9UbJ.js +0 -3
- package/dist/cdp-capture-iGdBAriK.js.map +0 -1
|
@@ -437,7 +437,8 @@ 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);";
|
|
441
442
|
const CLICK_CANDIDATES = "button,a,[role=button],[role=link],[role=menuitem],input[type=submit],input[type=button]";
|
|
442
443
|
const FIELD_CANDIDATES = "input,textarea,[contenteditable],[contenteditable=true],[role=textbox],[role=searchbox]";
|
|
443
444
|
const BOX_CANDIDATES = "button,a,[role=button],[role=link],[role=menuitem],[aria-label],[title],img[alt],li,[draggable=true]";
|
|
@@ -450,13 +451,20 @@ function clickBySelectorJs(selector) {
|
|
|
450
451
|
const s = JSON.stringify(selector);
|
|
451
452
|
return `(function(){var m=document.querySelector(${s});if(!m)return 'NOTFOUND';` + CLICK_TAIL_JS + `})()`;
|
|
452
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);";
|
|
453
456
|
function focusFieldByTextJs(text) {
|
|
454
457
|
const t = JSON.stringify(text);
|
|
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';
|
|
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 + `})()`;
|
|
456
459
|
}
|
|
457
460
|
function focusSelectorJs(selector) {
|
|
458
461
|
const s = JSON.stringify(selector);
|
|
459
|
-
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';})()";
|
|
460
468
|
}
|
|
461
469
|
function selectAllInFocusedJs() {
|
|
462
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';})()";
|
|
@@ -552,7 +560,7 @@ async function ffprobe(path) {
|
|
|
552
560
|
}
|
|
553
561
|
/** Drive `plan` against the live app over CDP, return the ground-truth log. */
|
|
554
562
|
async function captureTake(plan, opts) {
|
|
555
|
-
const { captureTakeCDP: captureTakeCDP$1 } = await import("./cdp-capture-
|
|
563
|
+
const { captureTakeCDP: captureTakeCDP$1 } = await import("./cdp-capture-BPfyq-2O.js");
|
|
556
564
|
return captureTakeCDP$1(plan, {
|
|
557
565
|
...opts,
|
|
558
566
|
fps: opts.fps ?? 60
|
|
@@ -1542,13 +1550,44 @@ async function captureTakeCDP(plan, opts) {
|
|
|
1542
1550
|
}
|
|
1543
1551
|
if (step.action === "type") {
|
|
1544
1552
|
const label$1 = step.text ?? step.selector;
|
|
1545
|
-
|
|
1546
|
-
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;
|
|
1547
1556
|
if (!box$1) {
|
|
1548
1557
|
skip("type", label$1, "target not found");
|
|
1549
1558
|
await hold(600);
|
|
1550
1559
|
continue;
|
|
1551
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
|
+
}
|
|
1552
1591
|
if (process.env.OPEN_TAKE_CI && await evalString(cdp, credentialFieldProbeJs()) === "secret") {
|
|
1553
1592
|
skip("type", label$1, "refusing to type into a credential field (OPEN_TAKE_CI)");
|
|
1554
1593
|
await hold(600);
|
|
@@ -1559,7 +1598,6 @@ async function captureTakeCDP(plan, opts) {
|
|
|
1559
1598
|
const cjk = chars.filter((c) => /[\u2E80-\u9FFF\uAC00-\uD7AF\uF900-\uFAFF\uFF66-\uFF9F]/.test(c)).length;
|
|
1560
1599
|
const auto = Math.min(90, Math.max(28, Math.round(1100 / Math.max(1, chars.length)))) * (cjk * 2 > chars.length ? 1.4 : 1);
|
|
1561
1600
|
const perChar = Math.round(step.perCharMs ?? auto);
|
|
1562
|
-
const tType = Date.now();
|
|
1563
1601
|
for (const ch of chars) {
|
|
1564
1602
|
await cdp.send("Input.insertText", { text: ch });
|
|
1565
1603
|
await sleep(perChar);
|
|
@@ -1573,7 +1611,7 @@ async function captureTakeCDP(plan, opts) {
|
|
|
1573
1611
|
note: step.note,
|
|
1574
1612
|
...step.caption ? { caption: step.caption } : {},
|
|
1575
1613
|
text: step.value,
|
|
1576
|
-
durationMs: Date.now() -
|
|
1614
|
+
durationMs: Date.now() - t0 - tMs$1,
|
|
1577
1615
|
...step.zoom ? { zoom: step.zoom } : {}
|
|
1578
1616
|
});
|
|
1579
1617
|
await hold(900);
|
|
@@ -2037,4 +2075,4 @@ async function navigate(cdp, url) {
|
|
|
2037
2075
|
|
|
2038
2076
|
//#endregion
|
|
2039
2077
|
export { PrecheckRefusal, captureTake, captureTakeCDP, ensureChrome, inspectPage, planTargets, precheckPlan, resolveChrome, resolveNavigateUrl };
|
|
2040
|
-
//# sourceMappingURL=cdp-capture-
|
|
2078
|
+
//# sourceMappingURL=cdp-capture-Ckt-tZVU.js.map
|