@jeffawe/understudy 0.0.0-stage → 0.2.0
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/LICENSE +201 -0
- package/README.md +171 -2
- package/REASONER.md +67 -0
- package/build/extension/firefox/background.js +186 -0
- package/build/extension/firefox/icons/icon-128.png +0 -0
- package/build/extension/firefox/icons/icon-16.png +0 -0
- package/build/extension/firefox/icons/icon-32.png +0 -0
- package/build/extension/firefox/icons/icon-48.png +0 -0
- package/build/extension/firefox/manifest.json +54 -0
- package/build/extension/firefox/popup.html +52 -0
- package/build/extension/firefox/popup.js +106 -0
- package/build/extension/firefox/recorder.js +362 -0
- package/dist/adapters/recorder/accname-bundle.d.ts +12 -0
- package/dist/adapters/recorder/accname-bundle.js +12 -0
- package/dist/adapters/recorder/extension.d.ts +57 -0
- package/dist/adapters/recorder/extension.js +146 -0
- package/dist/adapters/recorder/injected.d.ts +21 -0
- package/dist/adapters/recorder/injected.js +352 -0
- package/dist/adapters/recorder/live.d.ts +105 -0
- package/dist/adapters/recorder/live.js +317 -0
- package/dist/adapters/recorder/script.d.ts +43 -0
- package/dist/adapters/recorder/script.js +530 -0
- package/dist/adapters/recorder/wire.d.ts +42 -0
- package/dist/adapters/recorder/wire.js +51 -0
- package/dist/core/auth-cache.d.ts +119 -0
- package/dist/core/auth-cache.js +216 -0
- package/dist/core/browser.d.ts +47 -0
- package/dist/core/browser.js +82 -0
- package/dist/core/distill.d.ts +118 -0
- package/dist/core/distill.js +197 -0
- package/dist/core/fingerprint.d.ts +15 -0
- package/dist/core/fingerprint.js +21 -0
- package/dist/core/recording-store.d.ts +34 -0
- package/dist/core/recording-store.js +64 -0
- package/dist/core/recording.d.ts +185 -0
- package/dist/core/recording.js +100 -0
- package/dist/core/replay.d.ts +307 -0
- package/dist/core/replay.js +804 -0
- package/dist/core/sig.d.ts +70 -0
- package/dist/core/sig.js +0 -0
- package/dist/core/trigger.d.ts +18 -0
- package/dist/core/trigger.js +35 -0
- package/dist/core/types.d.ts +28 -0
- package/dist/core/types.js +8 -0
- package/dist/core/visual.d.ts +80 -0
- package/dist/core/visual.js +111 -0
- package/dist/entry/cli.d.ts +9 -0
- package/dist/entry/cli.js +1008 -0
- package/dist/entry/mcp.d.ts +20 -0
- package/dist/entry/mcp.js +288 -0
- package/dist/flows/destructive.d.ts +19 -0
- package/dist/flows/destructive.js +48 -0
- package/dist/flows/distill.d.ts +28 -0
- package/dist/flows/distill.js +109 -0
- package/dist/flows/drift.d.ts +43 -0
- package/dist/flows/drift.js +116 -0
- package/dist/flows/emit.d.ts +23 -0
- package/dist/flows/emit.js +133 -0
- package/dist/flows/execute.d.ts +75 -0
- package/dist/flows/execute.js +133 -0
- package/dist/flows/findings.d.ts +38 -0
- package/dist/flows/findings.js +136 -0
- package/dist/flows/runs.d.ts +42 -0
- package/dist/flows/runs.js +93 -0
- package/dist/flows/save.d.ts +74 -0
- package/dist/flows/save.js +171 -0
- package/dist/memory/notes.d.ts +89 -0
- package/dist/memory/notes.js +163 -0
- package/dist/memory/placeholders.d.ts +41 -0
- package/dist/memory/placeholders.js +139 -0
- package/dist/memory/recall.d.ts +118 -0
- package/dist/memory/recall.js +147 -0
- package/dist/memory/vocabulary.d.ts +9 -0
- package/dist/memory/vocabulary.js +24 -0
- package/dist/plan/planner.d.ts +69 -0
- package/dist/plan/planner.js +211 -0
- package/dist/plan/seams.d.ts +58 -0
- package/dist/plan/seams.js +99 -0
- package/dist/store/db.d.ts +62 -0
- package/dist/store/db.js +183 -0
- package/dist/store/embed.d.ts +46 -0
- package/dist/store/embed.js +100 -0
- package/dist/store/reembed.d.ts +13 -0
- package/dist/store/reembed.js +32 -0
- package/dist/store/settings.d.ts +67 -0
- package/dist/store/settings.js +151 -0
- package/dist/store/types.d.ts +220 -0
- package/dist/store/types.js +14 -0
- package/extension/README.md +79 -0
- package/extension/background.js +186 -0
- package/extension/icons/icon-128.png +0 -0
- package/extension/icons/icon-16.png +0 -0
- package/extension/icons/icon-32.png +0 -0
- package/extension/icons/icon-48.png +0 -0
- package/extension/manifest.json +38 -0
- package/extension/popup.html +52 -0
- package/extension/popup.js +106 -0
- package/extension/recorder.js +362 -0
- package/package.json +68 -4
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GENERATED — do not edit. Regenerate with `npm run vendor:accname`.
|
|
3
|
+
*
|
|
4
|
+
* dom-accessibility-api (MIT, Copyright (c) 2020 Sebastian Silbermann) bundled
|
|
5
|
+
* as a browser IIFE; its full license notice is at the top of the bundle. Installs
|
|
6
|
+
* window.__understudyA11y = { computeAccessibleName, getRole, isInaccessible }.
|
|
7
|
+
*
|
|
8
|
+
* Injected ahead of the recorder's listener so role and accessible name can be
|
|
9
|
+
* computed in-page and synchronously, before a click can re-render the element
|
|
10
|
+
* away. See scripts/vendor-accname.mjs for why this is vendored as a constant.
|
|
11
|
+
*/
|
|
12
|
+
export const ACCNAME_BUNDLE = "/*! dom-accessibility-api 0.7.1 — bundled by Understudy.\nMIT License\n\nCopyright (c) 2020 Sebastian Silbermann\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n*/\n(()=>{var ge=Object.prototype.toString;function W(e){return typeof e==\"function\"||ge.call(e)===\"[object Function]\"}function ve(e){var t=Number(e);return isNaN(t)?0:t===0||!isFinite(t)?t:(t>0?1:-1)*Math.floor(Math.abs(t))}var ye=Math.pow(2,53)-1;function he(e){var t=ve(e);return Math.min(Math.max(t,0),ye)}function c(e,t){var n=Array,i=Object(e);if(e==null)throw new TypeError(\"Array.from requires an array-like object - not null or undefined\");if(typeof t!=\"undefined\"&&!W(t))throw new TypeError(\"Array.from: when provided, the second argument must be a function\");for(var o=he(i.length),b=W(n)?Object(new n(o)):new Array(o),f=0,d;f<o;)d=i[f],t?b[f]=t(d,f):b[f]=d,f+=1;return b.length=o,b}function N(e){\"@babel/helpers - typeof\";return N=typeof Symbol==\"function\"&&typeof Symbol.iterator==\"symbol\"?function(t){return typeof t}:function(t){return t&&typeof Symbol==\"function\"&&t.constructor===Symbol&&t!==Symbol.prototype?\"symbol\":typeof t},N(e)}function we(e,t){if(!(e instanceof t))throw new TypeError(\"Cannot call a class as a function\")}function Q(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,\"value\"in i&&(i.writable=!0),Object.defineProperty(e,X(i.key),i)}}function Se(e,t,n){return t&&Q(e.prototype,t),n&&Q(e,n),Object.defineProperty(e,\"prototype\",{writable:!1}),e}function Ee(e,t,n){return t=X(t),t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function X(e){var t=xe(e,\"string\");return N(t)==\"symbol\"?t:t+\"\"}function xe(e,t){if(N(e)!=\"object\"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var i=n.call(e,t||\"default\");if(N(i)!=\"object\")return i;throw new TypeError(\"@@toPrimitive must return a primitive value.\")}return(t===\"string\"?String:Number)(e)}var Ae=(function(){function e(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];we(this,e),Ee(this,\"items\",void 0),this.items=t}return Se(e,[{key:\"add\",value:function(n){return this.has(n)===!1&&this.items.push(n),this}},{key:\"clear\",value:function(){this.items=[]}},{key:\"delete\",value:function(n){var i=this.items.length;return this.items=this.items.filter(function(o){return o!==n}),i!==this.items.length}},{key:\"forEach\",value:function(n){var i=this;this.items.forEach(function(o){n(o,o,i)})}},{key:\"has\",value:function(n){return this.items.indexOf(n)!==-1}},{key:\"size\",get:function(){return this.items.length}}])})(),J=typeof Set==\"undefined\"?Set:Ae;function s(e){var t;return(t=e.localName)!==null&&t!==void 0?t:e.tagName.toLowerCase()}var Te={article:\"article\",aside:\"complementary\",button:\"button\",datalist:\"listbox\",dd:\"definition\",details:\"group\",dialog:\"dialog\",dt:\"term\",fieldset:\"group\",figure:\"figure\",form:\"form\",footer:\"contentinfo\",h1:\"heading\",h2:\"heading\",h3:\"heading\",h4:\"heading\",h5:\"heading\",h6:\"heading\",header:\"banner\",hr:\"separator\",html:\"document\",legend:\"legend\",li:\"listitem\",math:\"math\",main:\"main\",menu:\"list\",nav:\"navigation\",ol:\"list\",optgroup:\"group\",option:\"option\",output:\"status\",progress:\"progressbar\",section:\"region\",summary:\"button\",table:\"table\",tbody:\"rowgroup\",textarea:\"textbox\",tfoot:\"rowgroup\",td:\"cell\",th:\"columnheader\",thead:\"rowgroup\",tr:\"row\",ul:\"list\"},Le={caption:new Set([\"aria-label\",\"aria-labelledby\"]),code:new Set([\"aria-label\",\"aria-labelledby\"]),deletion:new Set([\"aria-label\",\"aria-labelledby\"]),emphasis:new Set([\"aria-label\",\"aria-labelledby\"]),generic:new Set([\"aria-label\",\"aria-labelledby\",\"aria-roledescription\"]),insertion:new Set([\"aria-label\",\"aria-labelledby\"]),none:new Set([\"aria-label\",\"aria-labelledby\"]),paragraph:new Set([\"aria-label\",\"aria-labelledby\"]),presentation:new Set([\"aria-label\",\"aria-labelledby\"]),strong:new Set([\"aria-label\",\"aria-labelledby\"]),subscript:new Set([\"aria-label\",\"aria-labelledby\"]),superscript:new Set([\"aria-label\",\"aria-labelledby\"])};function Ne(e,t){return[\"aria-atomic\",\"aria-busy\",\"aria-controls\",\"aria-current\",\"aria-description\",\"aria-describedby\",\"aria-details\",\"aria-dropeffect\",\"aria-flowto\",\"aria-grabbed\",\"aria-hidden\",\"aria-keyshortcuts\",\"aria-label\",\"aria-labelledby\",\"aria-live\",\"aria-owns\",\"aria-relevant\",\"aria-roledescription\"].some(function(n){var i;return e.hasAttribute(n)&&!((i=Le[t])!==null&&i!==void 0&&i.has(n))})}function U(e,t){return Ne(e,t)}function T(e){var t=Ce(e);if(t===null||O.indexOf(t)!==-1){var n=Oe(e);if(O.indexOf(t||\"\")===-1||U(e,n||\"\"))return n}return t}function Oe(e){var t=Te[s(e)];if(t!==void 0)return t;switch(s(e)){case\"a\":case\"area\":case\"link\":if(e.hasAttribute(\"href\"))return\"link\";break;case\"img\":return e.getAttribute(\"alt\")===\"\"&&!U(e,\"img\")?\"presentation\":\"img\";case\"input\":{var n=e,i=n.type;switch(i){case\"button\":case\"image\":case\"reset\":case\"submit\":return\"button\";case\"checkbox\":case\"radio\":return i;case\"range\":return\"slider\";case\"email\":case\"tel\":case\"text\":case\"url\":return e.hasAttribute(\"list\")?\"combobox\":\"textbox\";case\"search\":return e.hasAttribute(\"list\")?\"combobox\":\"searchbox\";case\"number\":return\"spinbutton\";default:return null}}case\"select\":return e.hasAttribute(\"multiple\")||e.size>1?\"listbox\":\"combobox\"}return null}function Ce(e){var t=e.getAttribute(\"role\");if(t!==null){var n=t.trim().split(\" \")[0];if(n.length>0)return n}return null}var O=[\"presentation\",\"none\"];function a(e){return e!==null&&e.nodeType===e.ELEMENT_NODE}function H(e){return a(e)&&s(e)===\"caption\"}function C(e){return a(e)&&s(e)===\"input\"}function Y(e){return a(e)&&s(e)===\"optgroup\"}function Z(e){return a(e)&&s(e)===\"select\"}function F(e){return a(e)&&s(e)===\"table\"}function ee(e){return a(e)&&s(e)===\"textarea\"}function te(e){var t=e.ownerDocument===null?e:e.ownerDocument,n=t.defaultView;if(n===null)throw new TypeError(\"no window available\");return n}function re(e){return a(e)&&s(e)===\"fieldset\"}function ne(e){return a(e)&&s(e)===\"legend\"}function ie(e){return a(e)&&s(e)===\"slot\"}function Re(e){return a(e)&&e.ownerSVGElement!==void 0}function ae(e){return a(e)&&s(e)===\"svg\"}function oe(e){return Re(e)&&s(e)===\"title\"}function R(e,t){if(a(e)&&e.hasAttribute(t)){var n=e.getAttribute(t).split(\" \"),i=e.getRootNode?e.getRootNode():e.ownerDocument;return n.map(function(o){return i.getElementById(o)}).filter(function(o){return o!==null})}return[]}function p(e,t){return a(e)?t.indexOf(T(e))!==-1:!1}function Ie(e){return e.trim().replace(/\\s\\s+/g,\" \")}function Pe(e,t){if(!a(e))return!1;if(e.hasAttribute(\"hidden\")||e.getAttribute(\"aria-hidden\")===\"true\")return!0;var n=t(e);return n.getPropertyValue(\"display\")===\"none\"||n.getPropertyValue(\"visibility\")===\"hidden\"}function Me(e){return p(e,[\"button\",\"combobox\",\"listbox\",\"textbox\"])||se(e,\"range\")}function se(e,t){if(!a(e))return!1;if(t===\"range\")return p(e,[\"meter\",\"progressbar\",\"scrollbar\",\"slider\",\"spinbutton\"]);throw new TypeError(\"No knowledge about abstract role '\".concat(t,\"'. This is likely a bug :(\"))}function ue(e,t){var n=c(e.querySelectorAll(t));return R(e,\"aria-owns\").forEach(function(i){n.push.apply(n,c(i.querySelectorAll(t)))}),n}function je(e){return Z(e)?e.selectedOptions||ue(e,\"[selected]\"):ue(e,'[aria-selected=\"true\"]')}function He(e){return p(e,O)}function _e(e){return H(e)}function De(e){return p(e,[\"button\",\"cell\",\"checkbox\",\"columnheader\",\"gridcell\",\"heading\",\"label\",\"legend\",\"link\",\"menuitem\",\"menuitemcheckbox\",\"menuitemradio\",\"option\",\"radio\",\"row\",\"rowheader\",\"switch\",\"tab\",\"tooltip\",\"treeitem\"])}function Ve(e){return!1}function ke(e){return C(e)||ee(e)?e.value:e.textContent||\"\"}function le(e){var t=e.getPropertyValue(\"content\");return/^[\"'].*[\"']$/.test(t)?t.slice(1,-1):\"\"}function fe(e){var t=s(e);return t===\"button\"||t===\"input\"&&e.getAttribute(\"type\")!==\"hidden\"||t===\"meter\"||t===\"output\"||t===\"progress\"||t===\"select\"||t===\"textarea\"}function ce(e){if(fe(e))return e;var t=null;return e.childNodes.forEach(function(n){if(t===null&&a(n)){var i=ce(n);i!==null&&(t=i)}}),t}function Ge(e){if(e.control!==void 0)return e.control;var t=e.getAttribute(\"for\");return t!==null?e.ownerDocument.getElementById(t):ce(e)}function $e(e){var t=e.labels;if(t===null)return t;if(t!==void 0)return c(t);if(!fe(e))return null;var n=e.ownerDocument;return c(n.querySelectorAll(\"label\")).filter(function(i){return Ge(i)===e})}function qe(e){var t=e.assignedNodes();return t.length===0?c(e.childNodes):t}function _(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},n=new J,i=typeof Map==\"undefined\"?void 0:new Map,o=te(e),b=t.compute,f=b===void 0?\"name\":b,d=t.computedStyleSupportsPseudoElements,V=d===void 0?t.getComputedStyle!==void 0:d,k=t.getComputedStyle,I=k===void 0?o.getComputedStyle.bind(o):k,G=t.hidden,pe=G===void 0?!1:G,$=function(u,l){if(l!==void 0)throw new Error(\"use uncachedGetComputedStyle directly for pseudo elements\");if(i===void 0)return I(u);var m=i.get(u);if(m)return m;var g=I(u,l);return i.set(u,g),g};function P(r,u){var l=\"\";if(a(r)&&V){var m=I(r,\"::before\"),g=le(m);l=\"\".concat(g,\" \").concat(l)}var y=ie(r)?qe(r):c(r.childNodes).concat(R(r,\"aria-owns\"));if(y.forEach(function(v){var x=w(v,{isEmbeddedInLabel:u.isEmbeddedInLabel,isReferenced:!1,recursion:!0}),h=a(v)?$(v).getPropertyValue(\"display\"):\"inline\",L=h!==\"inline\"?\" \":\"\";l+=\"\".concat(L).concat(x).concat(L)}),a(r)&&V){var S=I(r,\"::after\"),E=le(S);l=\"\".concat(l,\" \").concat(E)}return l.trim()}function A(r,u){var l=r.getAttributeNode(u);return l!==null&&!n.has(l)&&l.value.trim()!==\"\"?(n.add(l),l.value):null}function be(r){return a(r)?A(r,\"title\"):null}function me(r){if(!a(r))return null;if(re(r)){n.add(r);for(var u=c(r.childNodes),l=0;l<u.length;l+=1){var m=u[l];if(ne(m))return w(m,{isEmbeddedInLabel:!1,isReferenced:!1,recursion:!1})}}else if(F(r)){n.add(r);for(var g=c(r.childNodes),y=0;y<g.length;y+=1){var S=g[y];if(H(S))return w(S,{isEmbeddedInLabel:!1,isReferenced:!1,recursion:!1})}}else if(ae(r)){n.add(r);for(var E=c(r.childNodes),v=0;v<E.length;v+=1){var x=E[v];if(oe(x))return x.textContent}return null}else if(s(r)===\"img\"||s(r)===\"area\"){var h=A(r,\"alt\");if(h!==null)return h}else if(Y(r)){var L=A(r,\"label\");if(L!==null)return L}if(C(r)&&(r.type===\"button\"||r.type===\"submit\"||r.type===\"reset\")){var q=A(r,\"value\");if(q!==null)return q;if(r.type===\"submit\")return\"Submit\";if(r.type===\"reset\")return\"Reset\"}var M=$e(r);if(M!==null&&M.length!==0)return n.add(r),c(M).map(function(j){return w(j,{isEmbeddedInLabel:!0,isReferenced:!1,recursion:!0})}).filter(function(j){return j.length>0}).join(\" \");if(C(r)&&r.type===\"image\"){var B=A(r,\"alt\");if(B!==null)return B;var K=A(r,\"title\");return K!==null?K:\"Submit Query\"}if(p(r,[\"button\"])){var z=P(r,{isEmbeddedInLabel:!1,isReferenced:!1});if(z!==\"\")return z}return null}function w(r,u){if(n.has(r))return\"\";if(!pe&&Pe(r,$)&&!u.isReferenced)return n.add(r),\"\";var l=a(r)?r.getAttributeNode(\"aria-labelledby\"):null,m=l!==null&&!n.has(l)?R(r,\"aria-labelledby\"):[];if(f===\"name\"&&!u.isReferenced&&m.length>0)return n.add(l),m.map(function(h){return w(h,{isEmbeddedInLabel:u.isEmbeddedInLabel,isReferenced:!0,recursion:!1})}).join(\" \");var g=u.recursion&&Me(r)&&f===\"name\";if(!g){var y=(a(r)&&r.getAttribute(\"aria-label\")||\"\").trim();if(y!==\"\"&&f===\"name\")return n.add(r),y;if(!He(r)){var S=me(r);if(S!==null)return n.add(r),S}}if(p(r,[\"menu\"]))return n.add(r),\"\";if(g||u.isEmbeddedInLabel||u.isReferenced){if(p(r,[\"combobox\",\"listbox\"])){n.add(r);var E=je(r);return E.length===0?C(r)?r.value:\"\":c(E).map(function(h){return w(h,{isEmbeddedInLabel:u.isEmbeddedInLabel,isReferenced:!1,recursion:!0})}).join(\" \")}if(se(r,\"range\"))return n.add(r),r.hasAttribute(\"aria-valuetext\")?r.getAttribute(\"aria-valuetext\"):r.hasAttribute(\"aria-valuenow\")?r.getAttribute(\"aria-valuenow\"):r.getAttribute(\"value\")||\"\";if(p(r,[\"textbox\"]))return n.add(r),ke(r)}if(De(r)||a(r)&&u.isReferenced||_e(r)||Ve(r)){var v=P(r,{isEmbeddedInLabel:u.isEmbeddedInLabel,isReferenced:!1});if(v!==\"\")return n.add(r),v}if(r.nodeType===r.TEXT_NODE)return n.add(r),r.textContent||\"\";if(u.recursion)return n.add(r),P(r,{isEmbeddedInLabel:u.isEmbeddedInLabel,isReferenced:!1});var x=be(r);return x!==null?(n.add(r),x):(n.add(r),\"\")}return Ie(w(e,{isEmbeddedInLabel:!1,isReferenced:f===\"description\",recursion:!1}))}function Be(e){return p(e,[\"caption\",\"code\",\"deletion\",\"emphasis\",\"generic\",\"insertion\",\"none\",\"paragraph\",\"presentation\",\"strong\",\"subscript\",\"superscript\"])}function D(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return Be(e)?\"\":_(e,t)}function de(e){var t,n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},i=n.getComputedStyle,o=i===void 0?(t=e.ownerDocument.defaultView)===null||t===void 0?void 0:t.getComputedStyle:i,b=n.isSubtreeInaccessible,f=b===void 0?Ke:b;if(typeof o!=\"function\")throw new TypeError(\"Owner document of the element needs to have an associated window.\");if(o(e).visibility===\"hidden\")return!0;for(var d=e;d;){if(f(d,{getComputedStyle:o}))return!0;d=d.parentElement}return!1}function Ke(e){var t,n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},i=n.getComputedStyle,o=i===void 0?(t=e.ownerDocument.defaultView)===null||t===void 0?void 0:t.getComputedStyle:i;if(typeof o!=\"function\")throw new TypeError(\"Owner document of the element needs to have an associated window.\");return e.hidden===!0||e.getAttribute(\"aria-hidden\")===\"true\"||o(e).display===\"none\"}window.__understudyA11y={computeAccessibleName:D,getRole:T,isInaccessible:de};})();\n";
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recording from the Chrome extension: record in the browser you already have
|
|
3
|
+
* open, on the tab you're already on.
|
|
4
|
+
*
|
|
5
|
+
* `understudy record <app>` starts this tiny local server; the
|
|
6
|
+
* extension (extension/ in the repo) finds it, and while you record, sends
|
|
7
|
+
* each action here. Nothing about the page is stored by the extension itself.
|
|
8
|
+
*
|
|
9
|
+
* GET /hello → { app, token } which recording is waiting, and its token
|
|
10
|
+
* POST /start { token, url, storageState? }
|
|
11
|
+
* POST /event { token, event } one action, as the in-page recorder saw it
|
|
12
|
+
* POST /stop { token }
|
|
13
|
+
*
|
|
14
|
+
* SAFETY. It listens on 127.0.0.1 only. The token is random per recording and
|
|
15
|
+
* only handed to Chrome extensions: a web page can send requests to localhost,
|
|
16
|
+
* but the browser won't let it READ /hello's answer (no CORS header for web
|
|
17
|
+
* origins), so it can never learn the token, so it can't inject steps.
|
|
18
|
+
*
|
|
19
|
+
* SIGN-IN. When recording starts, the extension always sends that site's
|
|
20
|
+
* cookies and local storage; they're saved as a session file (0600,
|
|
21
|
+
* gitignored). If you ticked "I'm signed in here", the flow starts signed in.
|
|
22
|
+
* If you didn't, `save` works it out: it replays in an empty browser first and
|
|
23
|
+
* deletes the session if that passes; only if it fails is the session tried,
|
|
24
|
+
* and kept if that passes (flows/execute.ts: prove).
|
|
25
|
+
*/
|
|
26
|
+
import { type RawRecording } from '../../core/recording.js';
|
|
27
|
+
export declare const DEFAULT_PORT = 7397;
|
|
28
|
+
export interface ExtensionRecorder {
|
|
29
|
+
/** Where it's listening. */
|
|
30
|
+
url: string;
|
|
31
|
+
/** Resolves when the extension says stop (or `stop()` is called). */
|
|
32
|
+
done: Promise<ExtensionRecording>;
|
|
33
|
+
/** Stop from this side, keeping whatever was recorded (e.g. on Ctrl+C). */
|
|
34
|
+
stop(): void;
|
|
35
|
+
}
|
|
36
|
+
export interface ExtensionRecording {
|
|
37
|
+
recording: RawRecording;
|
|
38
|
+
/** False if the extension never started recording. */
|
|
39
|
+
started: boolean;
|
|
40
|
+
/** File uploads seen but not recordable — the page can't say which file. */
|
|
41
|
+
droppedUploads: number;
|
|
42
|
+
/** Where the tab's session was saved for proving to try, if one was sent. */
|
|
43
|
+
sessionPath?: string;
|
|
44
|
+
/** The user ticked "Save as a flow when I stop" and named it: save it under this name. */
|
|
45
|
+
saveAs?: string;
|
|
46
|
+
}
|
|
47
|
+
export declare function startExtensionRecorder(opts: {
|
|
48
|
+
appSlug: string;
|
|
49
|
+
port?: number;
|
|
50
|
+
startUrl?: string;
|
|
51
|
+
/** Who saves the recording as a flow: the terminal (the user's `record`), or an agent that will call save itself. */
|
|
52
|
+
savedBy?: 'terminal' | 'agent';
|
|
53
|
+
}): Promise<ExtensionRecorder>;
|
|
54
|
+
/** The extension's folder: it ships inside the package, beside dist/ and src/. */
|
|
55
|
+
export declare function extensionDir(): string;
|
|
56
|
+
/** The Firefox build of it (npm run extension:package), also shipped in the package. */
|
|
57
|
+
export declare function firefoxExtensionDir(): string;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recording from the Chrome extension: record in the browser you already have
|
|
3
|
+
* open, on the tab you're already on.
|
|
4
|
+
*
|
|
5
|
+
* `understudy record <app>` starts this tiny local server; the
|
|
6
|
+
* extension (extension/ in the repo) finds it, and while you record, sends
|
|
7
|
+
* each action here. Nothing about the page is stored by the extension itself.
|
|
8
|
+
*
|
|
9
|
+
* GET /hello → { app, token } which recording is waiting, and its token
|
|
10
|
+
* POST /start { token, url, storageState? }
|
|
11
|
+
* POST /event { token, event } one action, as the in-page recorder saw it
|
|
12
|
+
* POST /stop { token }
|
|
13
|
+
*
|
|
14
|
+
* SAFETY. It listens on 127.0.0.1 only. The token is random per recording and
|
|
15
|
+
* only handed to Chrome extensions: a web page can send requests to localhost,
|
|
16
|
+
* but the browser won't let it READ /hello's answer (no CORS header for web
|
|
17
|
+
* origins), so it can never learn the token, so it can't inject steps.
|
|
18
|
+
*
|
|
19
|
+
* SIGN-IN. When recording starts, the extension always sends that site's
|
|
20
|
+
* cookies and local storage; they're saved as a session file (0600,
|
|
21
|
+
* gitignored). If you ticked "I'm signed in here", the flow starts signed in.
|
|
22
|
+
* If you didn't, `save` works it out: it replays in an empty browser first and
|
|
23
|
+
* deletes the session if that passes; only if it fails is the session tried,
|
|
24
|
+
* and kept if that passes (flows/execute.ts: prove).
|
|
25
|
+
*/
|
|
26
|
+
import { createServer } from 'node:http';
|
|
27
|
+
import { randomBytes } from 'node:crypto';
|
|
28
|
+
import { fileURLToPath } from 'node:url';
|
|
29
|
+
import { saveSessionById } from '../../core/auth-cache.js';
|
|
30
|
+
import { buildRecording } from '../../core/recording.js';
|
|
31
|
+
import { toRawEvent } from './wire.js';
|
|
32
|
+
export const DEFAULT_PORT = 7397;
|
|
33
|
+
/** Chrome, Edge, Brave… use chrome-extension://<32 letters>; Firefox uses moz-extension://<uuid>. */
|
|
34
|
+
const isExtensionOrigin = (origin) => !!origin && (/^chrome-extension:\/\/[a-p]{32}$/.test(origin) || /^moz-extension:\/\/[0-9a-f-]{36}$/.test(origin));
|
|
35
|
+
async function body(req) {
|
|
36
|
+
let s = '';
|
|
37
|
+
for await (const chunk of req) {
|
|
38
|
+
s += chunk;
|
|
39
|
+
if (s.length > 5_000_000)
|
|
40
|
+
throw new Error('request too large');
|
|
41
|
+
}
|
|
42
|
+
return s ? JSON.parse(s) : {};
|
|
43
|
+
}
|
|
44
|
+
export async function startExtensionRecorder(opts) {
|
|
45
|
+
const savedBy = opts.savedBy ?? 'terminal';
|
|
46
|
+
let saveAs;
|
|
47
|
+
const token = randomBytes(18).toString('base64url');
|
|
48
|
+
const events = [];
|
|
49
|
+
let startedAt = 0;
|
|
50
|
+
let started = false;
|
|
51
|
+
let startUrl = opts.startUrl ?? '';
|
|
52
|
+
let entry;
|
|
53
|
+
let sessionPath;
|
|
54
|
+
let droppedUploads = 0;
|
|
55
|
+
let finish;
|
|
56
|
+
const stopped = new Promise((r) => (finish = r));
|
|
57
|
+
const reply = (res, origin, status, data) => {
|
|
58
|
+
res.writeHead(status, {
|
|
59
|
+
'content-type': 'application/json',
|
|
60
|
+
// Only an extension may read the answer — this is what keeps the token secret.
|
|
61
|
+
...(isExtensionOrigin(origin) ? { 'access-control-allow-origin': origin, 'access-control-allow-headers': 'content-type' } : {}),
|
|
62
|
+
});
|
|
63
|
+
res.end(JSON.stringify(data));
|
|
64
|
+
};
|
|
65
|
+
const server = createServer(async (req, res) => {
|
|
66
|
+
const origin = req.headers.origin;
|
|
67
|
+
try {
|
|
68
|
+
if (req.method === 'OPTIONS')
|
|
69
|
+
return reply(res, origin, 204, {});
|
|
70
|
+
// A web page has its own origin; refuse anything that isn't an extension.
|
|
71
|
+
if (origin && !isExtensionOrigin(origin))
|
|
72
|
+
return reply(res, origin, 403, { error: 'only the Understudy extension may talk to this' });
|
|
73
|
+
const path = new URL(req.url ?? '/', 'http://x').pathname;
|
|
74
|
+
if (req.method === 'GET' && path === '/hello')
|
|
75
|
+
return reply(res, origin, 200, { app: opts.appSlug, token, started, savedBy });
|
|
76
|
+
if (req.method !== 'POST')
|
|
77
|
+
return reply(res, origin, 404, { error: 'not found' });
|
|
78
|
+
const b = await body(req);
|
|
79
|
+
if (b.token !== token)
|
|
80
|
+
return reply(res, origin, 401, { error: 'wrong token — start a new recording from the extension' });
|
|
81
|
+
if (path === '/start') {
|
|
82
|
+
if (started)
|
|
83
|
+
return reply(res, origin, 409, { error: 'already recording' });
|
|
84
|
+
startUrl = String(b.url);
|
|
85
|
+
startedAt = Date.now();
|
|
86
|
+
started = true;
|
|
87
|
+
if (b.storageState) {
|
|
88
|
+
const id = `ext-${randomBytes(6).toString('hex')}`;
|
|
89
|
+
sessionPath = await saveSessionById(opts.appSlug, id, b.storageState);
|
|
90
|
+
// Ticked: required. Unticked: available — proving decides.
|
|
91
|
+
entry = b.signedIn === true ? { requiresSession: true, session: id } : { session: id };
|
|
92
|
+
}
|
|
93
|
+
// Step 0: replay opens the page recording started on.
|
|
94
|
+
events.push({ seq: 0, ts: 0, action: 'goto', value: startUrl, url: startUrl, resolution: 'script-literal' });
|
|
95
|
+
return reply(res, origin, 200, { ok: true });
|
|
96
|
+
}
|
|
97
|
+
if (path === '/event') {
|
|
98
|
+
if (!started)
|
|
99
|
+
return reply(res, origin, 409, { error: 'not recording' });
|
|
100
|
+
const wire = b.event;
|
|
101
|
+
// The page can count the files on an upload but never say which ones,
|
|
102
|
+
// so an upload can't be replayed. Dropped and reported, never faked.
|
|
103
|
+
if (wire.action === 'upload') {
|
|
104
|
+
droppedUploads++;
|
|
105
|
+
return reply(res, origin, 200, { ok: true, dropped: 'upload' });
|
|
106
|
+
}
|
|
107
|
+
events.push(toRawEvent(wire, Date.now() - startedAt));
|
|
108
|
+
return reply(res, origin, 200, { ok: true });
|
|
109
|
+
}
|
|
110
|
+
if (path === '/stop') {
|
|
111
|
+
// A name means "save it as a flow" — only the terminal does that here;
|
|
112
|
+
// when an agent started this, the agent saves it.
|
|
113
|
+
const name = typeof b.name === 'string' ? b.name.trim().slice(0, 200) : '';
|
|
114
|
+
if (name && savedBy === 'terminal')
|
|
115
|
+
saveAs = name;
|
|
116
|
+
reply(res, origin, 200, { ok: true, events: events.length, hash: build().hash, saving: Boolean(saveAs) });
|
|
117
|
+
finish();
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
return reply(res, origin, 404, { error: 'not found' });
|
|
121
|
+
}
|
|
122
|
+
catch (e) {
|
|
123
|
+
return reply(res, origin, 400, { error: e instanceof Error ? e.message : String(e) });
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
await new Promise((resolve, reject) => {
|
|
127
|
+
server.once('error', reject);
|
|
128
|
+
server.listen(opts.port ?? DEFAULT_PORT, '127.0.0.1', resolve);
|
|
129
|
+
});
|
|
130
|
+
const { port } = server.address();
|
|
131
|
+
/** The recording as it stands: events in the order they happened. */
|
|
132
|
+
const build = () => buildRecording({ source: 'live', origin: 'chrome-extension', appSlug: opts.appSlug, startUrl, ...(entry ? { entry } : {}) }, events.slice().sort((a, b) => a.ts - b.ts).map((e, i) => ({ ...e, seq: i })));
|
|
133
|
+
const done = stopped.then(async () => {
|
|
134
|
+
await new Promise((r) => server.close(() => r()));
|
|
135
|
+
return { recording: build(), started, droppedUploads, ...(sessionPath ? { sessionPath } : {}), ...(saveAs ? { saveAs } : {}) };
|
|
136
|
+
});
|
|
137
|
+
return { url: `http://127.0.0.1:${port}`, done, stop: finish };
|
|
138
|
+
}
|
|
139
|
+
/** The extension's folder: it ships inside the package, beside dist/ and src/. */
|
|
140
|
+
export function extensionDir() {
|
|
141
|
+
return fileURLToPath(new URL('../../../extension/', import.meta.url));
|
|
142
|
+
}
|
|
143
|
+
/** The Firefox build of it (npm run extension:package), also shipped in the package. */
|
|
144
|
+
export function firefoxExtensionDir() {
|
|
145
|
+
return fileURLToPath(new URL('../../../build/extension/firefox/', import.meta.url));
|
|
146
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The in-page listener, as a STRING.
|
|
3
|
+
*
|
|
4
|
+
* It must not be authored as a TypeScript closure passed to addInitScript.
|
|
5
|
+
* tsx/esbuild rewrites function declarations to preserve their names via a
|
|
6
|
+
* `__name()` helper, and `addInitScript` serializes the function with
|
|
7
|
+
* `.toString()` — so the injected body references a helper that does not exist
|
|
8
|
+
* in the browser and dies with `ReferenceError: __name is not defined`.
|
|
9
|
+
*
|
|
10
|
+
* It fails SILENTLY: zero events captured, nothing logged, unless you happen to
|
|
11
|
+
* have attached a `pageerror` listener. Shipping it as a string sidesteps the
|
|
12
|
+
* compiler entirely.
|
|
13
|
+
*
|
|
14
|
+
* The script is deliberately dumb. It records WHAT happened and stamps WHICH
|
|
15
|
+
* element; it does not decide what any of it means. Role and accessible name
|
|
16
|
+
* are resolved on the Node side by Playwright's own engine — reimplementing
|
|
17
|
+
* the accessible-name algorithm here would be wrong in exactly the cases that
|
|
18
|
+
* matter (icon buttons, labelled inputs, aria-labelledby chains).
|
|
19
|
+
*/
|
|
20
|
+
export declare const STAMP_ATTR = "data-understudy-seq";
|
|
21
|
+
export declare const INJECTED_LISTENER = "\n(() => {\n if (window.__understudyInstalled) return;\n window.__understudyInstalled = true;\n\n var seq = 0;\n var STAMP = 'data-understudy-seq';\n\n // Best-effort name, used ONLY as a fallback when Playwright cannot resolve\n // the element (a click that navigates can destroy it before we get there).\n // Deliberately approximate \u2014 the authoritative answer comes from Node.\n // The authoritative path: a spec-compliant accname implementation, running\n // IN THE PAGE and SYNCHRONOUSLY at event time. This is the whole reason the\n // bundle is injected \u2014 clicking often destroys the element clicked, so\n // resolving later from Node loses the race. codegen gets correct names by\n // doing exactly this with Playwright's own bundle.\n function a11y() {\n return window.__understudyA11y;\n }\n\n // PLAYWRIGHT IS THE GROUND TRUTH, NOT THE SPEC.\n //\n // These names are fed back to getByRole(role, {name}) at replay, so they must\n // match what Playwright computes, not merely what the accname spec says.\n // Measured on saucedemo, dom-accessibility-api and Playwright disagree in\n // exactly two places \u2014 neither is wrong, they just draw the line differently:\n //\n // input[type=password] ARIA gives it NO implicit role, so getRole returns\n // null. Playwright pragmatically calls it a textbox.\n // placeholder-only name computeAccessibleName returns \"\". Playwright falls\n // back to the placeholder, which is why it reports\n // textbox \"Username\" where the library reports \"\".\n //\n // Without this shim every placeholder-labelled field in every recording would\n // carry an empty name and be unaddressable on replay.\n function accName(el) {\n var lib = a11y();\n if (!lib) return null;\n try {\n var n = lib.computeAccessibleName(el);\n if (typeof n === 'string' && n.trim()) return n.trim();\n } catch (e) { /* fall through */ }\n\n var tag = (el.tagName || '').toLowerCase();\n if (tag === 'input' || tag === 'textarea') {\n var ph = el.getAttribute && el.getAttribute('placeholder');\n if (ph && ph.trim()) return ph.trim();\n }\n return null;\n }\n\n function accRole(el) {\n var lib = a11y();\n if (!lib) return null;\n try {\n var r = lib.getRole(el);\n if (r) return r;\n } catch (e) { /* fall through */ }\n\n var tag = (el.tagName || '').toLowerCase();\n if (tag === 'input') {\n var t = (el.getAttribute('type') || 'text').toLowerCase();\n if (t === 'password') return 'textbox';\n }\n return null;\n }\n\n // Fallback only, for when the bundle failed to load. Kept because a weaker\n // name still beats dropping the step.\n function hintName(el) {\n if (!el || !el.getAttribute) return '';\n var tag = (el.tagName || '').toLowerCase();\n\n // Follow the accessible-name priority order. This is an approximation of\n // the W3C algorithm, not an implementation of it \u2014 but the shortcuts that\n // seem harmless are exactly the ones that bite:\n // . the 'name' ATTRIBUTE is not an accessible name. Using it recorded\n // saucedemo's Login button as \"login-button\".\n // . textContent of a <select> is every option concatenated, which\n // produced \"Name (A to Z)Name (Z to A)Price (low to high)\u2026\".\n var labelledBy = el.getAttribute('aria-labelledby');\n if (labelledBy) {\n var parts = [];\n labelledBy.split(/\\s+/).forEach(function (id) {\n var ref = document.getElementById(id);\n if (ref) parts.push((ref.textContent || '').trim());\n });\n var joined = parts.join(' ').trim();\n if (joined) return joined;\n }\n\n var ariaLabel = el.getAttribute('aria-label');\n if (ariaLabel && ariaLabel.trim()) return ariaLabel.trim();\n\n if (el.labels && el.labels[0]) {\n var lbl = (el.labels[0].textContent || '').trim();\n if (lbl) return lbl;\n }\n\n if (tag === 'input' || tag === 'textarea' || tag === 'select') {\n var ph = el.getAttribute('placeholder');\n if (ph && ph.trim()) return ph.trim();\n var ttl = el.getAttribute('title');\n if (ttl && ttl.trim()) return ttl.trim();\n // A <select>'s text is its options; a value is not a name.\n if (tag === 'select') return '';\n if ((el.getAttribute('type') || '') === 'submit') return el.value || '';\n return '';\n }\n\n if (tag === 'img') return (el.getAttribute('alt') || '').trim();\n\n var text = (el.textContent || '').replace(/\\s+/g, ' ').trim();\n if (text) return text.slice(0, 80);\n\n // An icon-only control: its name usually comes from a nested image.\n var img = el.querySelector && el.querySelector('img[alt]');\n if (img) return (img.getAttribute('alt') || '').trim();\n\n return (el.getAttribute('title') || '').trim();\n }\n\n function hintRole(el) {\n var explicit = el.getAttribute && el.getAttribute('role');\n if (explicit) return explicit;\n var tag = (el.tagName || '').toLowerCase();\n if (tag === 'a') return el.hasAttribute('href') ? 'link' : 'generic';\n if (tag === 'button') return 'button';\n if (tag === 'select') return 'combobox';\n if (tag === 'textarea') return 'textbox';\n if (tag === 'input') {\n var t = (el.getAttribute('type') || 'text').toLowerCase();\n if (t === 'checkbox') return 'checkbox';\n if (t === 'radio') return 'radio';\n if (t === 'submit' || t === 'button') return 'button';\n return 'textbox';\n }\n return tag || 'generic';\n }\n\n // A short CSS path, used when role+name can't address the element.\n function cssPath(el) {\n if (el.id) return '#' + CSS.escape(el.id);\n var testId = el.getAttribute && (el.getAttribute('data-testid') || el.getAttribute('data-test'));\n if (testId) return '[data-testid=\"' + testId + '\"]';\n var parts = [];\n var node = el;\n while (node && node.nodeType === 1 && parts.length < 4) {\n var part = node.tagName.toLowerCase();\n if (node.classList && node.classList.length) {\n // Tailwind's variant/arbitrary-value classes (hover:bg-gray-200,\n // text-[16px]) contain characters CSS reserves (: and [ ]). Joined\n // raw, the resulting selector is not valid CSS and querySelectorAll\n // throws \u2014 CSS.escape() is exactly what line 165 already uses for ids.\n part += '.' + [].slice.call(node.classList).map(function (c) { return CSS.escape(c); }).join('.');\n }\n parts.unshift(part);\n node = node.parentElement;\n }\n return parts.join(' > ');\n }\n\n function frameHint() {\n try {\n if (window.top === window) return undefined;\n return (window.frameElement && (window.frameElement.id || window.frameElement.name)) || 'iframe';\n } catch (e) {\n return 'cross-origin-iframe';\n }\n }\n\n // One element, ONE stamp. Reusing it lets a mousedown pre-resolution and the\n // click that follows refer to the same element, which is what makes the\n // pre-resolve cache hit.\n function stampOf(el) {\n var existing = el.getAttribute && el.getAttribute(STAMP);\n if (existing !== null && existing !== undefined && existing !== '') return Number(existing);\n var n = seq++;\n try { el.setAttribute(STAMP, String(n)); } catch (e) { /* readonly node */ }\n return n;\n }\n\n function emit(action, el, extra) {\n if (!el || el.nodeType !== 1) return;\n var n = stampOf(el);\n\n var payload = {\n seq: n,\n action: action,\n stamp: n,\n url: location.href,\n hintRole: accRole(el) || hintRole(el),\n hintName: accName(el) || hintName(el),\n // Records WHICH path produced the two fields above, so nothing\n // downstream has to guess how much to trust them.\n resolvedBy: a11y() ? 'accname' : 'heuristic',\n css: cssPath(el),\n testId: (el.getAttribute && (el.getAttribute('data-testid') || el.getAttribute('data-test'))) || undefined,\n testIdAttr: (el.getAttribute && el.getAttribute('data-testid')) ? 'data-testid'\n : (el.getAttribute && el.getAttribute('data-test')) ? 'data-test' : undefined,\n inputType: (el.getAttribute && el.getAttribute('type')) || undefined,\n frameHint: frameHint(),\n };\n if (extra) for (var k in extra) payload[k] = extra[k];\n\n try { window.__understudyEmit(payload); } catch (e) { /* binding gone */ }\n }\n\n // TEXT INPUT IS DEFERRED, NOT IMMEDIATE.\n //\n // 'change' on a text field fires on BLUR, not on typing. Filling a login form\n // therefore emits the username only when the password field takes focus, and\n // emits the password NEVER \u2014 nothing blurs the last field before submit. The\n // final field of every form would vanish from every recording, silently.\n //\n // So: track the latest value per element on 'input' (which does fire per\n // keystroke), and flush it as one 'fill' when the field is done \u2014 on blur, or\n // when any other action happens, or when recording ends. Flushing before the\n // triggering action also keeps the order right: fill, then the click that\n // submits it.\n var pending = [];\n\n function flushOne(el) {\n for (var i = 0; i < pending.length; i++) {\n if (pending[i].el !== el) continue;\n var entry = pending.splice(i, 1)[0];\n emit('fill', entry.el, { value: entry.value });\n return;\n }\n }\n\n function flushAll() {\n while (pending.length) {\n var entry = pending.shift();\n emit('fill', entry.el, { value: entry.value });\n }\n }\n\n // Called from Node before the recording is closed, so a field still focused\n // when the browser shuts is not lost.\n window.__understudyFlush = flushAll;\n\n // Diagnostic hook: resolve any element exactly as the recorder would. Used to\n // verify our role/name agree with Playwright's engine across a whole page,\n // which is the only check that catches a systematic naming drift.\n window.__understudyResolve = function (el) {\n return { role: accRole(el) || hintRole(el), name: accName(el) || hintName(el) };\n };\n\n document.addEventListener('input', function (e) {\n var el = (e.composedPath && e.composedPath()[0]) || e.target;\n var tag = (el.tagName || '').toLowerCase();\n if (tag !== 'input' && tag !== 'textarea') return;\n var type = (el.getAttribute('type') || 'text').toLowerCase();\n if (type === 'checkbox' || type === 'radio') return;\n // A FILE INPUT'S VALUE IS A LIE. The browser masks it to 'C:\\fakepath\\name'\n // so a page cannot learn where someone keeps their files. Deferring it here\n // flushed it as an ordinary fill carrying that string: a step that cannot\n // replay, with the file absent from the recording entirely, and nothing\n // anywhere reporting either. The 'change' handler records it properly.\n if (type === 'file') return;\n\n for (var i = 0; i < pending.length; i++) {\n if (pending[i].el === el) {\n pending[i].value = el.value;\n return;\n }\n }\n pending.push({ el: el, value: el.value });\n }, true);\n\n document.addEventListener('blur', function (e) {\n var el = (e.composedPath && e.composedPath()[0]) || e.target;\n flushOne(el);\n }, true);\n\n // Capture phase, so we see the event before the app can stopPropagation it,\n // and before an anchor's default navigation tears the element down.\n document.addEventListener('click', function (e) {\n flushAll();\n var el = (e.composedPath && e.composedPath()[0]) || e.target;\n var tag = (el.tagName || '').toLowerCase();\n var type = (el.getAttribute && (el.getAttribute('type') || '')).toLowerCase();\n\n // Checkboxes, radios, selects and text inputs report through 'change',\n // which carries the resulting VALUE. Emitting both would double-count.\n if (tag === 'select' || tag === 'textarea') return;\n if (tag === 'input' && type !== 'submit' && type !== 'button') return;\n\n emit('click', el);\n }, true);\n\n document.addEventListener('change', function (e) {\n var el = (e.composedPath && e.composedPath()[0]) || e.target;\n var tag = (el.tagName || '').toLowerCase();\n var type = (el.getAttribute && (el.getAttribute('type') || 'text')).toLowerCase();\n\n if (tag === 'select') {\n var opt = el.options && el.options[el.selectedIndex];\n emit('select', el, { value: el.value, label: opt ? opt.textContent : undefined });\n return;\n }\n if (type === 'checkbox' || type === 'radio') {\n emit(el.checked ? 'check' : 'uncheck', el);\n return;\n }\n if (type === 'file') {\n // The page reports THAT an upload happened and how many files it carried.\n // It cannot report WHICH files: el.value is masked and File exposes only\n // .name. Node resolves the real paths from the stamp over CDP, which is\n // the only place they can be read at all.\n var count = el.files ? el.files.length : 0;\n if (!count) return; // clearing a file input is not an upload\n emit('upload', el, { fileCount: count });\n return;\n }\n // Text inputs are handled by the input+flush path above. Emitting here too\n // would double-count every field that happens to blur.\n }, true);\n\n // Enter often submits without any click at all \u2014 a step that would otherwise\n // vanish from the recording and make it unreplayable.\n document.addEventListener('keydown', function (e) {\n if (e.key !== 'Enter') return;\n var el = (e.composedPath && e.composedPath()[0]) || e.target;\n var tag = (el.tagName || '').toLowerCase();\n if (tag !== 'input' && tag !== 'textarea') return;\n flushAll();\n emit('press', el, { value: 'Enter' });\n }, true);\n})();\n";
|