@capagents/forgeqe 2.10.1 → 2.10.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.
Files changed (58) hide show
  1. package/dist/forgeqe.js +1703 -1669
  2. package/dist/web/assets/{Agent-DQeWzsWG.js → Agent-DyyAZPKr.js} +1 -1
  3. package/dist/web/assets/{ApiTests-DrQBxtra.js → ApiTests-p_cbulD4.js} +1 -1
  4. package/dist/web/assets/{Browse-CXqsKgMN.js → Browse-DOAlK-ox.js} +2 -2
  5. package/dist/web/assets/{Chat-rChaK9vu.js → Chat-BCV5OsEz.js} +1 -1
  6. package/dist/web/assets/{CommandPalette-LNTJ2Pie.js → CommandPalette-o9PuLas2.js} +1 -1
  7. package/dist/web/assets/{Compare-CP24uSyS.js → Compare-Bf1LhXmj.js} +1 -1
  8. package/dist/web/assets/{Cost-Cz6F4MAu.js → Cost-r7D19VSG.js} +1 -1
  9. package/dist/web/assets/{Data-RSpfLC9W.js → Data-CRttp4iM.js} +1 -1
  10. package/dist/web/assets/{Desktop-C0VftUUl.js → Desktop-DcaKyfKA.js} +1 -1
  11. package/dist/web/assets/{DesktopReview-BTYnwZKB.js → DesktopReview-BjplTYfH.js} +1 -1
  12. package/dist/web/assets/{Evidence-DxfTgGLn.js → Evidence-BAAKcK0h.js} +1 -1
  13. package/dist/web/assets/{Explore-BKAnJ0AP.js → Explore-D_RZhVAc.js} +1 -1
  14. package/dist/web/assets/{Features-YYcKT5mB.js → Features-B6azjGtN.js} +1 -1
  15. package/dist/web/assets/{Flags-B23vWmDR.js → Flags-BQR4dRaK.js} +1 -1
  16. package/dist/web/assets/{Flaky-kuhde8PW.js → Flaky-Ci1bvglt.js} +1 -1
  17. package/dist/web/assets/{Impact-DetuURYY.js → Impact-CPB7NjQF.js} +1 -1
  18. package/dist/web/assets/{Jobs-BTiCqtr9.js → Jobs-CR8SxpWA.js} +1 -1
  19. package/dist/web/assets/{KindPage-BbL7COME.js → KindPage-Bl7q-2b8.js} +1 -1
  20. package/dist/web/assets/{Migration-CPv7gDC-.js → Migration-BecNlszU.js} +1 -1
  21. package/dist/web/assets/{Product-DcrBguCI.js → Product-AMUC5arL.js} +1 -1
  22. package/dist/web/assets/{Production-N11W9Ckr.js → Production-CZ-EG3t2.js} +1 -1
  23. package/dist/web/assets/{Quality-DzXW1cvp.js → Quality-k2U9v2Dn.js} +1 -1
  24. package/dist/web/assets/{Readiness-BbHO8wa2.js → Readiness-D3_S6lDT.js} +1 -1
  25. package/dist/web/assets/Record-Ba6XRn7c.js +2 -0
  26. package/dist/web/assets/{Regression-BOSQ2Pxp.js → Regression-jpkQRkt_.js} +1 -1
  27. package/dist/web/assets/{Reports-BA1VdwoC.js → Reports-BHKtb9Oi.js} +1 -1
  28. package/dist/web/assets/{Response-0i0ww7OC.js → Response-CVNWGdun.js} +1 -1
  29. package/dist/web/assets/{RunDiff-D-4tB7Is.js → RunDiff-dbcFibiJ.js} +1 -1
  30. package/dist/web/assets/{Runs-DW7dZh2j.js → Runs-ij-80l3A.js} +1 -1
  31. package/dist/web/assets/{TestCases-BfPkdwR6.js → TestCases-BW8laQ_8.js} +1 -1
  32. package/dist/web/assets/{TestData-DRoJc7Me.js → TestData-0f1XzLdc.js} +1 -1
  33. package/dist/web/assets/{TestDebt-ly8BsLSJ.js → TestDebt-C-2y3RTV.js} +1 -1
  34. package/dist/web/assets/{Tosca-CzrCAhEs.js → Tosca-DnfpS6Zf.js} +1 -1
  35. package/dist/web/assets/{WhatsNew-Cd8D1O1X.js → WhatsNew-C1HUalPw.js} +1 -1
  36. package/dist/web/assets/{dataParts-DzHf4K4-.js → dataParts-DWD2uUxL.js} +1 -1
  37. package/dist/web/assets/{fold-CyU-Mjqe.js → fold-o_l3hXTU.js} +1 -1
  38. package/dist/web/assets/frame-CdUL-UeQ.js +4 -0
  39. package/dist/web/assets/{index-Bv3atkwB.js → index-BmJOj6t1.js} +5 -5
  40. package/dist/web/assets/index-DP3riJZe.css +2 -0
  41. package/dist/web/assets/{logos-cftOc5MX.js → logos-CMkTgBD8.js} +1 -1
  42. package/dist/web/assets/{palette-D_SCreF2.js → palette-D-wSuihi.js} +1 -1
  43. package/dist/web/assets/{qualityParts-50E_QRTX.js → qualityParts-DS83Q0nG.js} +1 -1
  44. package/dist/web/assets/{rows-JZ5MvdCQ.js → rows-DYYObxPx.js} +1 -1
  45. package/dist/web/assets/{thread-CrExMoMY.js → thread-Cnjdo5ve.js} +1 -1
  46. package/dist/web/assets/{usePageChat-DpnA7edC.js → usePageChat-DWmmQrbC.js} +1 -1
  47. package/dist/web/index.html +3 -3
  48. package/package.json +1 -1
  49. package/py/forgeqe_engine/capture.py +14 -1
  50. package/py/forgeqe_engine/memory.py +18 -4
  51. package/py/forgeqe_engine/recordsession.py +211 -15
  52. package/py/forgeqe_engine/varying.py +120 -0
  53. package/py/forgeqe_engine/webrecord.py +115 -32
  54. package/py/forgeqe_engine/webrecord_page.py +199 -29
  55. package/py/forgeqe_engine/workflow_yaml.py +18 -1
  56. package/dist/web/assets/Record-P7TKcE5d.js +0 -2
  57. package/dist/web/assets/frame-DUo0M0VF.js +0 -4
  58. package/dist/web/assets/index-DwUumNPZ.css +0 -2
@@ -12,7 +12,7 @@ page's DOM), so the page's own scripts can neither see nor call the binding it r
12
12
  from __future__ import annotations
13
13
 
14
14
  import json
15
- from typing import Any, Dict
15
+ from typing import Any, Dict, Optional
16
16
 
17
17
  from .memory import STATE_CLASS
18
18
 
@@ -117,6 +117,12 @@ RECORDER_JS = r"""(() => {
117
117
  if (e.labels && e.labels.length) return norm([...e.labels].map((l) => l.textContent).join(' '));
118
118
  return '';
119
119
  };
120
+ const iconsOf = (e) => {
121
+ let out = '';
122
+ const one = (x) => { for (const w of ['::before', '::after']) { const m = (getComputedStyle(x, w).content || '').match(/^"(.*)"$/); if (m) out += (m[1].match(/[\ue000-\uf8ff]/g) || []).join(''); } };
123
+ try { one(e); const kids = e.querySelectorAll('*'); for (let i = 0; i < kids.length && i < 30; i++) one(kids[i]); } catch (err) { return ''; }
124
+ return out.slice(0, 4);
125
+ };
120
126
  const accName = (e) => {
121
127
  const l = labelText(e);
122
128
  if (l) return l;
@@ -130,7 +136,12 @@ RECORDER_JS = r"""(() => {
130
136
  if (t === 'TEXTAREA' || t === 'SELECT') return norm(e.getAttribute('title'));
131
137
  if (t === 'IMG') return norm(e.getAttribute('alt'));
132
138
  const role = e.getAttribute('role') || implicitRole(e);
133
- if (['button', 'link', 'heading', 'tab', 'menuitem', 'option', 'checkbox', 'radio', 'switch', 'treeitem'].includes(role)) return textOf(e).slice(0, 120) || norm(e.getAttribute('title'));
139
+ if (['button', 'link', 'heading', 'tab', 'menuitem', 'option', 'checkbox', 'radio', 'switch', 'treeitem'].includes(role)) {
140
+ // An icon an icon font draws in it (::before) is in the name Playwright gives it: kept, so the locator matches the
141
+ // words with any icon around them (capture.py does the same).
142
+ const t = textOf(e).slice(0, 120), ic = iconsOf(e);
143
+ return (t && ic ? ic + ' ' + t : t) || norm(e.getAttribute('title'));
144
+ }
134
145
  return norm(e.getAttribute('title'));
135
146
  };
136
147
  // No XPath for an element inside a shadow root: an XPath cannot reach into one, so it would find nothing on replay.
@@ -193,20 +204,37 @@ RECORDER_JS = r"""(() => {
193
204
  const stableClass = (c) => /^[A-Za-z][\w-]{2,40}$/.test(c) && !/\d{3,}|__|^(?:css|sc|jsx|svelte|emotion)-/i.test(c) && !STATE_CLASS.test(c);
194
205
  // A class a page sets for a state (the item under the pointer, the one chosen, a menu open): it moves between elements.
195
206
  const STATE_CLASS = new RegExp(CFG.stateClass, 'i');
196
- const containerCss = (x) => { const c = [...x.classList].find(stableClass); return c ? x.tagName.toLowerCase() + '.' + c : ''; };
207
+ // A web component by its tag alone (memory.py _COMPONENT_TAG): <promo-card>, whose controls are in its shadow root.
208
+ const COMPONENT_TAG = /^[a-z][a-z0-9]{0,30}(?:-[a-z0-9]{1,30}){1,4}$/;
209
+ const componentTag = (x) => { const t = x.tagName.toLowerCase(); return COMPONENT_TAG.test(t) ? t : ''; };
210
+ const containerCss = (x) => { const c = [...x.classList].find(stableClass); return c ? x.tagName.toLowerCase() + '.' + c : componentTag(x); };
197
211
  const lowText = (x) => norm(x.textContent).toLowerCase();
212
+ // A component's own roots: it, its open shadow roots, and the one the element is in (a closed root is reached only
213
+ // from inside it), so what it holds is searched where it is, not only in its light DOM.
214
+ const boxRoots = (box, e) => {
215
+ const out = [box];
216
+ for (const r of roots()) if (r !== document && deepContains(box, r.host)) out.push(r);
217
+ const own = e && e.getRootNode();
218
+ if (own && own.nodeType === 11 && own.host && deepContains(box, own.host) && !out.includes(own)) out.push(own);
219
+ return out;
220
+ };
221
+ const boxText = (box, e) => norm(boxRoots(box, e).map((r) => (r === box ? flatText(box) : r === box.shadowRoot ? '' : flatText(r))).join(' ')).toLowerCase();
198
222
  // The texts that could tell this container from the others: its headings, then its labels, then short texts of its own.
199
- const anchorTexts = (box, own) => {
223
+ const anchorTexts = (box, own, rs = [box], self = null) => {
200
224
  const out = [];
201
- const add = (t) => { t = norm(t); if (t && t.length <= 80 && t !== own && !out.includes(t)) out.push(t); };
202
- for (const h of box.querySelectorAll('h1, h2, h3, h4, h5, h6, [role=heading]')) add(h.textContent);
203
- for (const l of box.querySelectorAll('label, legend, dt, th')) add(l.textContent);
204
- const walker = document.createTreeWalker(box, NodeFilter.SHOW_TEXT);
205
- for (let n = walker.nextNode(), k = 0; n && k < 40; n = walker.nextNode(), k++) add(n.data);
225
+ const add = (t, at) => { t = norm(t); if (t && t.length <= 80 && t !== own && !(self && at && deepContains(self, at)) && !out.includes(t)) out.push(t); };
226
+ for (const r of rs) for (const h of r.querySelectorAll('h1, h2, h3, h4, h5, h6, [role=heading]')) add(h.textContent, h);
227
+ for (const r of rs) for (const l of r.querySelectorAll('label, legend, dt, th')) add(l.textContent, l);
228
+ let k = 0;
229
+ for (const r of rs) {
230
+ const walker = document.createTreeWalker(r, NodeFilter.SHOW_TEXT);
231
+ // Never the control's own text (a "×" of a Close): it tells nothing of which container this is.
232
+ for (let n = walker.nextNode(); n && k < 40; n = walker.nextNode(), k++) if (!['STYLE', 'SCRIPT', 'TEMPLATE'].includes(n.parentNode && n.parentNode.nodeName)) add(n.data, n.parentNode);
233
+ }
206
234
  return out.slice(0, 12);
207
235
  };
208
- const innerOf = (e, f, box) => {
209
- const inBox = (sel) => [...box.querySelectorAll(sel)].filter(visible);
236
+ const innerOf = (e, f, box, rs = [box]) => {
237
+ const inBox = (sel) => rs.flatMap((r) => [...r.querySelectorAll(sel)]).filter(visible);
210
238
  if (f.role && f.name) {
211
239
  const same = inBox(ROLE_SEL).filter((x) => (x.getAttribute('role') || implicitRole(x)) === f.role && accName(x) === f.name);
212
240
  if (same.length === 1 && same[0] === e) return { type: 'role', value: f.role + '|' + f.name };
@@ -231,24 +259,30 @@ RECORDER_JS = r"""(() => {
231
259
  const role = containerRole(box);
232
260
  const css = role ? '' : containerCss(box);
233
261
  if (!role && !css) continue;
234
- const inner = innerOf(e, f, box);
262
+ // A web component (by its tag): its shadow roots are searched too, and its text is what it shows.
263
+ const comp = !role && css === componentTag(box);
264
+ const rs = comp ? boxRoots(box, e) : [box];
265
+ const inner = innerOf(e, f, box, rs);
235
266
  if (!inner) continue;
236
267
  const peers = role ? deepAll(ROLE_SEL + ', li, tr, article, dialog, fieldset').filter((x) => containerRole(x) === role) : deepAll(css);
237
- for (const t of anchorTexts(box, own)) {
268
+ for (const t of anchorTexts(box, own, rs, e)) {
238
269
  const low = t.toLowerCase();
239
- const hits = peers.filter((x) => visible(x) && lowText(x).includes(low));
270
+ const hits = peers.filter((x) => visible(x) && (comp ? boxText(x, x === box ? e : null) : lowText(x)).includes(low));
240
271
  if (hits.length === 1 && hits[0] === box) return { c: role ? { role } : { css }, t, i: inner };
241
272
  }
242
273
  }
243
274
  return null;
244
275
  };
276
+ const GENERIC_NAMES = new Set(['close', '×', 'x', '✕', 'ok', 'cancel', 'delete', 'remove', 'edit', 'dismiss', 'more', 'yes', 'no', 'save', 'next', 'back', 'view', 'open']);
245
277
  // Unique by a locator of its own: no anchor needed.
246
278
  const uniqueAlone = (m) => [m.role, m.text, m.label, m.name, m.href, m.attr && m.attr.id, m.attr && m.attr['data-testid']].some((n) => n === 1);
247
279
  const describeEl = (e) => {
248
280
  const f = facts(e);
249
281
  const m = matches(e, f);
250
282
  let anchor = null;
251
- if (!uniqueAlone(m)) { try { anchor = anchorFor(e, f); } catch (err) { anchor = null; } }
283
+ // A name many controls share ("Close", "×", "Delete"): unique now, another like it may show on a replay (a second
284
+ // toast), so the container that holds it is kept too.
285
+ if (!uniqueAlone(m) || GENERIC_NAMES.has(String(f.name || f.text || '').trim().toLowerCase())) { try { anchor = anchorFor(e, f); } catch (err) { anchor = null; } }
252
286
  return { id: ref(e), el: f, matches: m, url: location.href, ...(anchor ? { anchor } : {}) };
253
287
  };
254
288
 
@@ -508,7 +542,31 @@ RECORDER_JS = r"""(() => {
508
542
  // Any element the pointer is on (an info icon, an abbreviation): what shows while it rests there is its tooltip or
509
543
  // hover card. Kept apart ("loose") from a menu's trigger: a check of what it shows starts with hovering it.
510
544
  let pointed = null;
545
+ // The browser's permissions this site has, or is given while recording (the person allows it in the browser's
546
+ // prompt): their names only, so a replay is given the same.
547
+ // Asked once the rest is set up, each on its own: a browser that does not know a name throws for it, and nothing of
548
+ // the recorder may stop for that.
549
+ const PERMISSIONS = ['geolocation', 'notifications', 'clipboard-read', 'clipboard-write', 'camera', 'microphone'];
550
+ setTimeout(() => {
551
+ if (inFrame || !navigator.permissions) return;
552
+ for (const name of PERMISSIONS) {
553
+ try {
554
+ Promise.resolve(navigator.permissions.query({ name })).then((st) => {
555
+ const tell = () => { if (st.state === 'granted') send({ kind: 'permission', name, url: location.href }); };
556
+ tell();
557
+ st.addEventListener('change', tell);
558
+ }).catch(() => {});
559
+ } catch (err) { /* a name this browser does not know */ }
560
+ }
561
+ }, 0);
562
+ // The person's pointer left the page through its top (toward the address bar or the tab's close button): a page
563
+ // that shows something then (an "exit intent" offer) does it for that, and the step is the pointer leaving.
564
+ let leftAt = 0;
565
+ // On the window, which exists before the page does (this script runs before <html> is made): out of the page is
566
+ // a mouseout with nowhere it went.
567
+ window.addEventListener('mouseout', (ev) => { if (ev.isTrusted && !ev.relatedTarget && !paused && !picking && ev.clientY <= 0) leftAt = Date.now(); }, true);
511
568
  const onReveal = (list) => {
569
+ if (leftAt && Date.now() - leftAt < 2000 && list.some((m) => m.type === 'attributes' || m.addedNodes.length)) { leftAt = 0; send({ kind: 'leave' }); return; }
512
570
  if (Date.now() - pressedAt < 1500) return;
513
571
  const by = hovered && Date.now() - hovered.at <= 1500 ? hovered : null;
514
572
  const loose = !by && pointed && Date.now() - pointed.at <= 1500 ? pointed : null;
@@ -585,17 +643,93 @@ RECORDER_JS = r"""(() => {
585
643
  const trig = [...owner.children].find((x) => x !== e && !deepContains(x, c) && (x.matches(TRIGGER) || (x.querySelector && x.querySelector('a, button'))));
586
644
  if (trig) return trig.matches(TRIGGER) ? trig : trig.querySelector('a, button');
587
645
  }
646
+ // Shown by the page's style alone (".menu:hover .items { display: block }"): nothing changes in the page to see,
647
+ // and the menu's class can be any name. The rule that shows it names what the pointer must be on.
648
+ for (let e = c, i = 0; e && e !== document.body && i < 8; e = up(e), i++) {
649
+ const owner = cssHoverOwner(e);
650
+ if (!owner || owner === c) continue;
651
+ // Its trigger, else a part of it that shows without the hover (a card's picture): the card's own text includes
652
+ // what only the hover shows, so it is not found by it before the hover.
653
+ const kids = [...owner.children].filter((x) => !deepContains(x, c) && !deepContains(x, e));
654
+ return kids.find((x) => x.matches(TRIGGER)) || kids.find((x) => visible(x) && x.tagName !== 'SCRIPT' && x.tagName !== 'STYLE') || owner;
655
+ }
656
+ return null;
657
+ };
658
+ // The page's style rules that show an element while the pointer is on one that holds it: "A:hover B" or "A:hover > B"
659
+ // setting display (not none) or visibility: visible. Read again when the page's style sheets change in number.
660
+ let hoverRules = null, hoverSheets = -1;
661
+ const cssHoverRules = () => {
662
+ const n = document.styleSheets.length;
663
+ if (hoverRules && n === hoverSheets) return hoverRules;
664
+ hoverSheets = n;
665
+ hoverRules = [];
666
+ const walk = (list, depth) => {
667
+ for (const r of list) {
668
+ if (hoverRules.length >= 300) return;
669
+ if (r.cssRules && !r.selectorText && depth < 4) { walk(r.cssRules, depth + 1); continue; }
670
+ if (!r.selectorText || !r.style || !r.selectorText.includes(':hover')) continue;
671
+ const d = r.style.getPropertyValue('display'), v = r.style.getPropertyValue('visibility');
672
+ if (!(d && d !== 'none') && v !== 'visible') continue;
673
+ for (const part of r.selectorText.split(',')) {
674
+ const at = part.indexOf(':hover');
675
+ if (at < 0 || !/^\s*>?\s*\S/.test(part.slice(at + 6)) || !/^[\s>]/.test(part.slice(at + 6))) continue;
676
+ hoverRules.push({ sel: part.trim(), owner: part.slice(0, at + 6).trim() });
677
+ }
678
+ }
679
+ };
680
+ for (const sheet of document.styleSheets) { try { walk(sheet.cssRules, 0); } catch (err) { /* another site's sheet */ } }
681
+ return hoverRules;
682
+ };
683
+ const cssHoverOwner = (e) => {
684
+ if (e.nodeType !== 1 || e.getRootNode() !== document) return null;
685
+ for (const r of cssHoverRules()) {
686
+ try {
687
+ if (!e.matches(r.sel)) continue;
688
+ const o = e.parentElement && e.parentElement.closest(r.owner);
689
+ if (o && o !== document.body && o !== document.documentElement) return o;
690
+ } catch (err) { /* a selector this browser cannot match */ }
691
+ }
588
692
  return null;
589
693
  };
590
694
 
591
695
  // ---- typing: one fill with the field's final text when the tester moves on -------------------------------------
592
696
  let dirty = null;
697
+ // Which saved login a typed password is, never the password: ForgeQE gives a slow salted fingerprint (PBKDF2) of each
698
+ // saved login's password for this recording, and the typed one is fingerprinted here, as it is typed, the same way.
699
+ // Only the matching login's variable, or that none matched, is sent.
700
+ const PW = CFG.pw && Array.isArray(CFG.pw.logins) && CFG.pw.logins.length ? CFG.pw : null;
701
+ const pwPrints = new WeakMap();
702
+ const hexBytes = (h) => new Uint8Array((h.match(/../g) || []).map((b) => parseInt(b, 16)));
703
+ const hostOk = (hosts) => (hosts || []).some((h) => location.hostname === h || location.hostname.endsWith('.' + h));
704
+ const printPassword = (e) => {
705
+ if (!PW || !(window.crypto && crypto.subtle) || !PW.logins.some((l) => hostOk(l.hosts))) return;
706
+ const v = String(e.value || '').trim();
707
+ const st = { pending: true, len: v.length, fp: '' };
708
+ pwPrints.set(e, st);
709
+ if (!v) { st.pending = false; return; }
710
+ crypto.subtle.importKey('raw', new TextEncoder().encode(v), 'PBKDF2', false, ['deriveBits'])
711
+ .then((key) => crypto.subtle.deriveBits({ name: 'PBKDF2', hash: 'SHA-256', salt: hexBytes(PW.salt), iterations: PW.rounds }, key, 256))
712
+ .then((bits) => { if (pwPrints.get(e) === st) { st.fp = [...new Uint8Array(bits)].map((b) => b.toString(16).padStart(2, '0')).join(''); st.pending = false; } })
713
+ .catch(() => {});
714
+ };
715
+ const whosePassword = (e) => {
716
+ const st = pwPrints.get(e);
717
+ if (!PW || !st || st.pending || st.len !== String(e.value || '').trim().length) return {};
718
+ const mine = PW.logins.filter((l) => hostOk(l.hosts));
719
+ const hit = mine.find((l) => l.fp === st.fp);
720
+ return hit ? { secret_env: hit.env } : mine.length ? { secret_mismatch: true } : {};
721
+ };
722
+ // Texts the person kept from the page as variables (a one-time code it shows): typed into a password field, the
723
+ // step types the variable, not a secret (the text is the variable's, kept with the recording already).
724
+ const keptTexts = [];
593
725
  const flush = () => {
594
726
  const e = dirty;
595
727
  dirty = null;
596
728
  if (!e) return;
597
729
  const pw = isPassword(e);
598
- send({ kind: 'fill', ...describeEl(e), password: pw, value: pw ? null : (e.isContentEditable ? norm(e.innerText) : e.value) });
730
+ const typed = pw ? String(e.value || '').trim() : '';
731
+ const kept = pw && typed && keptTexts.includes(typed);
732
+ send({ kind: 'fill', ...describeEl(e), password: pw && !kept, value: pw && !kept ? null : (e.isContentEditable ? norm(e.innerText) : kept ? typed : e.value), ...(kept ? { kept: true } : pw ? whosePassword(e) : {}) });
599
733
  };
600
734
  window.addEventListener('input', (ev) => {
601
735
  if (!ev.isTrusted || picking || ours(ev) || paused) return;
@@ -603,6 +737,7 @@ RECORDER_JS = r"""(() => {
603
737
  const e = t && t.isContentEditable ? editableRoot(t) : t;
604
738
  if (!isField(e)) return;
605
739
  if (dirty && dirty !== e) flush();
740
+ if (isPassword(e)) printPassword(e);
606
741
  dirty = e;
607
742
  }, true);
608
743
  window.addEventListener('focusout', (ev) => { if (dirty && (deep(ev) === dirty || ev.target === dirty)) flush(); }, true);
@@ -613,7 +748,7 @@ RECORDER_JS = r"""(() => {
613
748
  function onChange(ev) {
614
749
  if (!ev.isTrusted || picking || ours(ev) || paused) return;
615
750
  const e = deep(ev);
616
- if (e.tagName === 'SELECT') { flush(); send({ kind: 'select', ...describeEl(e), text: shown(e) }); return; }
751
+ if (e.tagName === 'SELECT') { flush(); send({ kind: 'select', ...describeEl(e), text: shown(e), ...(e.multiple ? { options: [...e.selectedOptions].slice(0, 50).map((o) => norm(o.text)) } : {}) }); return; }
617
752
  // The files' paths are read by ForgeQE through the DevTools protocol: the page itself only sees their names.
618
753
  if (e.tagName === 'INPUT' && (e.getAttribute('type') || '').toLowerCase() === 'file') { send({ kind: 'upload', ...describeEl(e), count: e.files ? e.files.length : 0 }); return; }
619
754
  if (dirty === e) flush();
@@ -632,8 +767,11 @@ RECORDER_JS = r"""(() => {
632
767
  };
633
768
  // A canvas has no elements in it: where in it the click landed is the step, as Playwright's recorder keeps it
634
769
  // (locator.click({ position })), in the canvas's own pixels from its top left corner.
770
+ // Blank space of a box that holds controls (a click outside a menu to close it): the replay clicks the same place,
771
+ // never the box's middle, where a control may be.
772
+ const blankOf = (c) => !!c && c.nodeType === 1 && !actionable(c) && !!c.querySelector('a[href], button, input, select, textarea, [role=button], [role=link], [onclick]');
635
773
  const where = (c, ev) => {
636
- if (!c || c.tagName !== 'CANVAS') return {};
774
+ if (!c || (c.tagName !== 'CANVAS' && !blankOf(c))) return {};
637
775
  const r = c.getBoundingClientRect();
638
776
  return { position: { x: Math.round(ev.clientX - r.left), y: Math.round(ev.clientY - r.top) } };
639
777
  };
@@ -649,12 +787,16 @@ RECORDER_JS = r"""(() => {
649
787
  endPick();
650
788
  if (!e) return;
651
789
  const h = hoverForCheck(e);
790
+ if (purpose === 'variable') { keptTexts.push(norm(shown(e))); if (keptTexts.length > 20) keptTexts.shift(); }
652
791
  send({ kind: 'pick', purpose, ...describeEl(e), text: shown(e), password: isPassword(e), checked: 'checked' in e ? !!e.checked : null, field: e.tagName === 'INPUT' || e.tagName === 'TEXTAREA' || e.tagName === 'SELECT', ...(h ? { hover: describeEl(h) } : {}) });
653
792
  return;
654
793
  }
655
794
  if (paused) return;
656
795
  const c = control(deep(ev));
657
796
  if (!c || c.tagName === 'OPTION' || c.tagName === 'SELECT') return;
797
+ // A click on the page itself (to leave a field, or the one Chrome sends when an option of a select list's own list
798
+ // is chosen): no step. A replay clicking the page would land on whatever is in its middle.
799
+ if (c === document.documentElement || c === document.body) return;
658
800
  // A click on a label also clicks its control: one step.
659
801
  if (lastLabel && lastLabel.control === c && Date.now() - lastLabel.at < 100) return;
660
802
  if (c.tagName === 'LABEL') lastLabel = { control: c.control, at: Date.now() };
@@ -662,7 +804,12 @@ RECORDER_JS = r"""(() => {
662
804
  const cap = captchaNear(c);
663
805
  if (cap) { send({ kind: 'captcha', provider: cap }); return; }
664
806
  const h = hoverFor(c);
665
- send({ kind: 'click', ...describeEl(c), field: isField(c), ...(h ? { hover: describeEl(h) } : {}), ...where(c, ev) });
807
+ // Held down a while (a "press and hold"): how long, so a replay holds it as long.
808
+ const held = Date.now() - pressedAt;
809
+ // A menu inside a menu: each trigger on the way, outermost first, as the pointer went (at most three).
810
+ const outer = [];
811
+ for (let x = h, i = 0; x && i < 2; i++) { const o = hoverFor(x); if (!o || o === x || deepContains(o, x) || outer.includes(o)) break; outer.unshift(o); x = o; }
812
+ send({ kind: 'click', ...describeEl(c), field: isField(c), ...(h ? { hover: describeEl(h) } : {}), ...(outer.length ? { outer_hovers: outer.map(describeEl) } : {}), ...where(c, ev), ...(pressedAt && held >= 600 && held <= 10000 ? { held: Math.round(held) } : {}) });
666
813
  }, true);
667
814
  // ---- scrolls: the page, or a box that scrolls on its own (a list that loads more at its end), by the person's wheel
668
815
  // or keys (never one the page made: an anchor, its own script). One step when it settles, if it went half a screen.
@@ -677,9 +824,11 @@ RECORDER_JS = r"""(() => {
677
824
  if (!s || paused || picking) return;
678
825
  const height = s.box ? s.box.clientHeight : innerHeight;
679
826
  const dy = scrollTop(s.box) - s.top;
680
- if (!height || Math.abs(dy) < height / 2) return;
827
+ if (!height || Math.abs(dy) < 40) return;
681
828
  if (s.box && !s.box.isConnected) return;
682
- send({ kind: 'scroll', down: dy > 0, pages: Math.round(Math.abs(dy) / height * 10) / 10, ...(s.box ? { box: describeEl(s.box) } : {}) });
829
+ // Less than half a screen is not a step of its own, but it moves where the scroll before it ended.
830
+ const small = Math.abs(dy) < height / 2;
831
+ send({ kind: 'scroll', down: dy > 0, pages: Math.max(0.1, Math.round(Math.abs(dy) / height * 10) / 10), end: Math.max(0, Math.round(scrollTop(s.box))), ...(small ? { small: true } : {}), ...(s.box ? { box: describeEl(s.box) } : {}) });
683
832
  };
684
833
  window.addEventListener('scroll', (ev) => {
685
834
  if (!ev.isTrusted || paused || picking || Date.now() - scrollBy > 1500) return;
@@ -762,7 +911,10 @@ RECORDER_JS = r"""(() => {
762
911
  const r = p.src.getBoundingClientRect();
763
912
  if (Math.abs(r.left - p.left) >= 4 || Math.abs(r.top - p.top) >= 4) return true;
764
913
  for (let e = p.el, i = 0; e && e.nodeType === 1 && i <= 6; e = up(e), i++) {
765
- if (e.getAttribute('draggable') === 'true' || MOVE_CURSOR.test(getComputedStyle(e).cursor)) return true;
914
+ const cs = getComputedStyle(e);
915
+ if (e.getAttribute('draggable') === 'true' || MOVE_CURSOR.test(cs.cursor)) return true;
916
+ // A page that handles the pointer's gestures there itself (a swipe area, a canvas to draw on) says so.
917
+ if (/^(none|pan-x|pan-y|pan-left|pan-right|pan-up|pan-down)$/.test(cs.touchAction)) return true;
766
918
  if (e === p.src) break;
767
919
  }
768
920
  const role = roleOf(p.src);
@@ -816,6 +968,17 @@ RECORDER_JS = r"""(() => {
816
968
  }, true);
817
969
 
818
970
  // ---- keys: the leader key and its letter, then Enter, Escape, and chords ----------------------------------------
971
+ const WIDGET_ROLES = new Set(['combobox', 'listbox', 'option', 'menu', 'menubar', 'menuitem', 'menuitemcheckbox', 'menuitemradio', 'slider', 'spinbutton', 'tab', 'tablist', 'tree', 'treeitem', 'grid', 'gridcell', 'treegrid', 'radiogroup', 'application']);
972
+ const WIDGET_KEYS = new Set(['ArrowDown', 'ArrowUp', 'ArrowLeft', 'ArrowRight', 'Home', 'End', 'PageUp', 'PageDown', 'Space', 'Enter', 'Escape', 'Tab']);
973
+ // A native slider too (its keys change it, as dragging does); never a native select list, whose choice is a step.
974
+ const keyWidget = (e) => !!e && e.nodeType === 1 && (WIDGET_ROLES.has(e.getAttribute('role')) || e.tagName === 'CANVAS' || (e.tagName === 'INPUT' && (e.getAttribute('type') || '').toLowerCase() === 'range'));
975
+ // What the browser itself clicks on Enter (that click is recorded): a link, a button, a summary.
976
+ const clicksOnEnter = (e) => {
977
+ if (!e || e.nodeType !== 1 || keyWidget(e)) return false;
978
+ if (e.tagName === 'A') return e.hasAttribute('href');
979
+ if (e.tagName === 'INPUT') return /^(submit|button|reset|image)$/i.test(e.getAttribute('type') || '');
980
+ return e.tagName === 'BUTTON' || e.tagName === 'SUMMARY' || actionable(e);
981
+ };
819
982
  let leader = 0;
820
983
  const L = CFG.leader;
821
984
  const isLeader = (ev) => ev.code === L.code && !!ev.ctrlKey === !!L.ctrl && !!ev.shiftKey === !!L.shift && !!ev.altKey === !!L.alt && !!ev.metaKey === !!L.meta;
@@ -851,15 +1014,19 @@ RECORDER_JS = r"""(() => {
851
1014
  const t = deep(ev);
852
1015
  const e = t && t.nodeType === 1 ? (t.isContentEditable ? editableRoot(t) : t) : null;
853
1016
  const inField = isField(e);
1017
+ // A widget that takes keys itself (a list box, a menu, a slider, a canvas): the keys a person moves through it
1018
+ // with, and what they type into it, are steps.
1019
+ const widget = !inField && keyWidget(e);
854
1020
  const mods = [ev.ctrlKey && 'Control', ev.altKey && 'Alt', ev.metaKey && 'Meta', ev.shiftKey && ev.key.length > 1 && 'Shift'].filter(Boolean);
855
- const key = ev.key === ' ' ? 'Space' : ev.key.length === 1 ? ev.key.toLowerCase() : ev.key;
1021
+ const typed = widget && !mods.length && ev.key.length === 1 && ev.key !== ' ';
1022
+ const key = ev.key === ' ' ? 'Space' : typed ? ev.key : ev.key.length === 1 ? ev.key.toLowerCase() : ev.key;
856
1023
  if (inField && !mods.length && ['Tab'].includes(key)) return;
857
1024
  const chord = [...mods, key].join('+');
858
1025
  if (inField && !mods.length && !['Enter', 'Escape', 'ArrowDown', 'ArrowUp'].includes(key)) return;
859
1026
  if (inField && mods.length && ['Control', 'Meta'].some((m) => mods.includes(m)) && 'acvxzy'.includes(key)) return;
860
- if (!inField && !mods.length && !['Enter', 'Escape'].includes(key)) return;
861
- // Enter on a focused button or link clicks it, and the click is the step.
862
- if (!inField && !mods.length && key === 'Enter' && actionable(e)) return;
1027
+ if (!inField && !mods.length && !['Enter', 'Escape'].includes(key) && !(widget && (WIDGET_KEYS.has(key) || typed))) return;
1028
+ // Enter on a focused button or link clicks it, and the click is the step: never on a widget, where it is the key.
1029
+ if (!inField && !mods.length && key === 'Enter' && clicksOnEnter(e)) return;
863
1030
  if (dirty) flush();
864
1031
  send({ kind: 'press', keys: chord, in_field: inField, autocomplete: autocomplete(e) });
865
1032
  }, true);
@@ -893,7 +1060,10 @@ RECORDER_JS = r"""(() => {
893
1060
  })()"""
894
1061
 
895
1062
 
896
- def recorder_js(binding: str, kept: Any, *, leader: Dict[str, Any], badge: bool = False) -> str:
897
- """The page script; ``badge``: no panel, only a badge that says it records (a recording started from the web app)."""
898
- config = {"binding": binding, "kept": list(kept), "leader": leader, "commands": [list(c) for c in COMMAND_KEYS], "badge": bool(badge), "stateClass": STATE_CLASS}
1063
+ def recorder_js(binding: str, kept: Any, *, leader: Dict[str, Any], badge: bool = False, pw: Optional[Dict[str, Any]] = None) -> str:
1064
+ """
1065
+ The page script; ``badge``: no panel, only a badge that says it records (a recording started from the web app);
1066
+ ``pw``: the saved logins' password fingerprints for this recording (recordsession.password_prints), never a password.
1067
+ """
1068
+ config = {"binding": binding, "kept": list(kept), "leader": leader, "commands": [list(c) for c in COMMAND_KEYS], "badge": bool(badge), "stateClass": STATE_CLASS, **({"pw": pw} if pw else {})}
899
1069
  return RECORDER_JS.replace("__CONFIG__", json.dumps(config))
@@ -18,6 +18,23 @@ from typing import Any, Dict, List, Optional
18
18
 
19
19
  import yaml
20
20
 
21
+ # A text a YAML 1.2 reader (ForgeQE's own, in TypeScript) would take for a number: written quoted. PyYAML quotes only what
22
+ # YAML 1.1 reads as one, so a step's picture "008" was written bare and read back as the number 8.
23
+ _NUMBER_12 = re.compile(r"[-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?|0o[0-7]+|0x[0-9a-fA-F]+|[-+]?\.(inf|Inf|INF)|\.(nan|NaN|NAN)")
24
+
25
+
26
+ class _PlainTextDumper(yaml.Dumper):
27
+ pass
28
+
29
+
30
+ def _text(dumper: yaml.Dumper, value: str) -> yaml.Node:
31
+ if _NUMBER_12.fullmatch(value):
32
+ return dumper.represent_scalar("tag:yaml.org,2002:str", value, style="'")
33
+ return dumper.represent_str(value)
34
+
35
+
36
+ _PlainTextDumper.add_representer(str, _text)
37
+
21
38
  logger = logging.getLogger(__name__)
22
39
 
23
40
  FORMAT_V2_COMPACT = "forgeqe-v2-compact"
@@ -682,7 +699,7 @@ def save_browser_use_run_yaml(
682
699
  doc["history"] = serialize_browser_use_history(history)
683
700
  try:
684
701
  with open(path, "w", encoding="utf-8") as f:
685
- yaml.dump(doc, f, default_flow_style=False, allow_unicode=True, sort_keys=False)
702
+ yaml.dump(doc, f, Dumper=_PlainTextDumper, default_flow_style=False, allow_unicode=True, sort_keys=False)
686
703
  return str(path.resolve()), compact_steps
687
704
  except Exception as e:
688
705
  logger.warning("Could not save the workflow YAML: %s", e)