@jeffawe/understudy 0.0.0-stage → 0.2.1
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 +166 -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 +1016 -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 +76 -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,362 @@
|
|
|
1
|
+
// GENERATED by scripts/build-extension.ts — do not edit. Run: npm run extension:build
|
|
2
|
+
// The accessible-name library, a bridge to the extension, then the recorder.
|
|
3
|
+
/*! dom-accessibility-api 0.7.1 — bundled by Understudy.
|
|
4
|
+
MIT License
|
|
5
|
+
|
|
6
|
+
Copyright (c) 2020 Sebastian Silbermann
|
|
7
|
+
|
|
8
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
10
|
+
in the Software without restriction, including without limitation the rights
|
|
11
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
furnished to do so, subject to the following conditions:
|
|
14
|
+
|
|
15
|
+
The above copyright notice and this permission notice shall be included in all
|
|
16
|
+
copies or substantial portions of the Software.
|
|
17
|
+
|
|
18
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
+
SOFTWARE.
|
|
25
|
+
*/
|
|
26
|
+
(()=>{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};})();
|
|
27
|
+
|
|
28
|
+
window.__understudyEmit = function (event) {
|
|
29
|
+
try { chrome.runtime.sendMessage({ type: 'understudy:event', event: event }); } catch (e) { /* extension reloaded */ }
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
(() => {
|
|
33
|
+
if (window.__understudyInstalled) return;
|
|
34
|
+
window.__understudyInstalled = true;
|
|
35
|
+
|
|
36
|
+
var seq = 0;
|
|
37
|
+
var STAMP = 'data-understudy-seq';
|
|
38
|
+
|
|
39
|
+
// Best-effort name, used ONLY as a fallback when Playwright cannot resolve
|
|
40
|
+
// the element (a click that navigates can destroy it before we get there).
|
|
41
|
+
// Deliberately approximate — the authoritative answer comes from Node.
|
|
42
|
+
// The authoritative path: a spec-compliant accname implementation, running
|
|
43
|
+
// IN THE PAGE and SYNCHRONOUSLY at event time. This is the whole reason the
|
|
44
|
+
// bundle is injected — clicking often destroys the element clicked, so
|
|
45
|
+
// resolving later from Node loses the race. codegen gets correct names by
|
|
46
|
+
// doing exactly this with Playwright's own bundle.
|
|
47
|
+
function a11y() {
|
|
48
|
+
return window.__understudyA11y;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// PLAYWRIGHT IS THE GROUND TRUTH, NOT THE SPEC.
|
|
52
|
+
//
|
|
53
|
+
// These names are fed back to getByRole(role, {name}) at replay, so they must
|
|
54
|
+
// match what Playwright computes, not merely what the accname spec says.
|
|
55
|
+
// Measured on saucedemo, dom-accessibility-api and Playwright disagree in
|
|
56
|
+
// exactly two places — neither is wrong, they just draw the line differently:
|
|
57
|
+
//
|
|
58
|
+
// input[type=password] ARIA gives it NO implicit role, so getRole returns
|
|
59
|
+
// null. Playwright pragmatically calls it a textbox.
|
|
60
|
+
// placeholder-only name computeAccessibleName returns "". Playwright falls
|
|
61
|
+
// back to the placeholder, which is why it reports
|
|
62
|
+
// textbox "Username" where the library reports "".
|
|
63
|
+
//
|
|
64
|
+
// Without this shim every placeholder-labelled field in every recording would
|
|
65
|
+
// carry an empty name and be unaddressable on replay.
|
|
66
|
+
function accName(el) {
|
|
67
|
+
var lib = a11y();
|
|
68
|
+
if (!lib) return null;
|
|
69
|
+
try {
|
|
70
|
+
var n = lib.computeAccessibleName(el);
|
|
71
|
+
if (typeof n === 'string' && n.trim()) return n.trim();
|
|
72
|
+
} catch (e) { /* fall through */ }
|
|
73
|
+
|
|
74
|
+
var tag = (el.tagName || '').toLowerCase();
|
|
75
|
+
if (tag === 'input' || tag === 'textarea') {
|
|
76
|
+
var ph = el.getAttribute && el.getAttribute('placeholder');
|
|
77
|
+
if (ph && ph.trim()) return ph.trim();
|
|
78
|
+
}
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function accRole(el) {
|
|
83
|
+
var lib = a11y();
|
|
84
|
+
if (!lib) return null;
|
|
85
|
+
try {
|
|
86
|
+
var r = lib.getRole(el);
|
|
87
|
+
if (r) return r;
|
|
88
|
+
} catch (e) { /* fall through */ }
|
|
89
|
+
|
|
90
|
+
var tag = (el.tagName || '').toLowerCase();
|
|
91
|
+
if (tag === 'input') {
|
|
92
|
+
var t = (el.getAttribute('type') || 'text').toLowerCase();
|
|
93
|
+
if (t === 'password') return 'textbox';
|
|
94
|
+
}
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Fallback only, for when the bundle failed to load. Kept because a weaker
|
|
99
|
+
// name still beats dropping the step.
|
|
100
|
+
function hintName(el) {
|
|
101
|
+
if (!el || !el.getAttribute) return '';
|
|
102
|
+
var tag = (el.tagName || '').toLowerCase();
|
|
103
|
+
|
|
104
|
+
// Follow the accessible-name priority order. This is an approximation of
|
|
105
|
+
// the W3C algorithm, not an implementation of it — but the shortcuts that
|
|
106
|
+
// seem harmless are exactly the ones that bite:
|
|
107
|
+
// . the 'name' ATTRIBUTE is not an accessible name. Using it recorded
|
|
108
|
+
// saucedemo's Login button as "login-button".
|
|
109
|
+
// . textContent of a <select> is every option concatenated, which
|
|
110
|
+
// produced "Name (A to Z)Name (Z to A)Price (low to high)…".
|
|
111
|
+
var labelledBy = el.getAttribute('aria-labelledby');
|
|
112
|
+
if (labelledBy) {
|
|
113
|
+
var parts = [];
|
|
114
|
+
labelledBy.split(/\s+/).forEach(function (id) {
|
|
115
|
+
var ref = document.getElementById(id);
|
|
116
|
+
if (ref) parts.push((ref.textContent || '').trim());
|
|
117
|
+
});
|
|
118
|
+
var joined = parts.join(' ').trim();
|
|
119
|
+
if (joined) return joined;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
var ariaLabel = el.getAttribute('aria-label');
|
|
123
|
+
if (ariaLabel && ariaLabel.trim()) return ariaLabel.trim();
|
|
124
|
+
|
|
125
|
+
if (el.labels && el.labels[0]) {
|
|
126
|
+
var lbl = (el.labels[0].textContent || '').trim();
|
|
127
|
+
if (lbl) return lbl;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (tag === 'input' || tag === 'textarea' || tag === 'select') {
|
|
131
|
+
var ph = el.getAttribute('placeholder');
|
|
132
|
+
if (ph && ph.trim()) return ph.trim();
|
|
133
|
+
var ttl = el.getAttribute('title');
|
|
134
|
+
if (ttl && ttl.trim()) return ttl.trim();
|
|
135
|
+
// A <select>'s text is its options; a value is not a name.
|
|
136
|
+
if (tag === 'select') return '';
|
|
137
|
+
if ((el.getAttribute('type') || '') === 'submit') return el.value || '';
|
|
138
|
+
return '';
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (tag === 'img') return (el.getAttribute('alt') || '').trim();
|
|
142
|
+
|
|
143
|
+
var text = (el.textContent || '').replace(/\s+/g, ' ').trim();
|
|
144
|
+
if (text) return text.slice(0, 80);
|
|
145
|
+
|
|
146
|
+
// An icon-only control: its name usually comes from a nested image.
|
|
147
|
+
var img = el.querySelector && el.querySelector('img[alt]');
|
|
148
|
+
if (img) return (img.getAttribute('alt') || '').trim();
|
|
149
|
+
|
|
150
|
+
return (el.getAttribute('title') || '').trim();
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function hintRole(el) {
|
|
154
|
+
var explicit = el.getAttribute && el.getAttribute('role');
|
|
155
|
+
if (explicit) return explicit;
|
|
156
|
+
var tag = (el.tagName || '').toLowerCase();
|
|
157
|
+
if (tag === 'a') return el.hasAttribute('href') ? 'link' : 'generic';
|
|
158
|
+
if (tag === 'button') return 'button';
|
|
159
|
+
if (tag === 'select') return 'combobox';
|
|
160
|
+
if (tag === 'textarea') return 'textbox';
|
|
161
|
+
if (tag === 'input') {
|
|
162
|
+
var t = (el.getAttribute('type') || 'text').toLowerCase();
|
|
163
|
+
if (t === 'checkbox') return 'checkbox';
|
|
164
|
+
if (t === 'radio') return 'radio';
|
|
165
|
+
if (t === 'submit' || t === 'button') return 'button';
|
|
166
|
+
return 'textbox';
|
|
167
|
+
}
|
|
168
|
+
return tag || 'generic';
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// A short CSS path, used when role+name can't address the element.
|
|
172
|
+
function cssPath(el) {
|
|
173
|
+
if (el.id) return '#' + CSS.escape(el.id);
|
|
174
|
+
var testId = el.getAttribute && (el.getAttribute('data-testid') || el.getAttribute('data-test'));
|
|
175
|
+
if (testId) return '[data-testid="' + testId + '"]';
|
|
176
|
+
var parts = [];
|
|
177
|
+
var node = el;
|
|
178
|
+
while (node && node.nodeType === 1 && parts.length < 4) {
|
|
179
|
+
var part = node.tagName.toLowerCase();
|
|
180
|
+
if (node.classList && node.classList.length) {
|
|
181
|
+
// Tailwind's variant/arbitrary-value classes (hover:bg-gray-200,
|
|
182
|
+
// text-[16px]) contain characters CSS reserves (: and [ ]). Joined
|
|
183
|
+
// raw, the resulting selector is not valid CSS and querySelectorAll
|
|
184
|
+
// throws — CSS.escape() is exactly what line 165 already uses for ids.
|
|
185
|
+
part += '.' + [].slice.call(node.classList).map(function (c) { return CSS.escape(c); }).join('.');
|
|
186
|
+
}
|
|
187
|
+
parts.unshift(part);
|
|
188
|
+
node = node.parentElement;
|
|
189
|
+
}
|
|
190
|
+
return parts.join(' > ');
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function frameHint() {
|
|
194
|
+
try {
|
|
195
|
+
if (window.top === window) return undefined;
|
|
196
|
+
return (window.frameElement && (window.frameElement.id || window.frameElement.name)) || 'iframe';
|
|
197
|
+
} catch (e) {
|
|
198
|
+
return 'cross-origin-iframe';
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// One element, ONE stamp. Reusing it lets a mousedown pre-resolution and the
|
|
203
|
+
// click that follows refer to the same element, which is what makes the
|
|
204
|
+
// pre-resolve cache hit.
|
|
205
|
+
function stampOf(el) {
|
|
206
|
+
var existing = el.getAttribute && el.getAttribute(STAMP);
|
|
207
|
+
if (existing !== null && existing !== undefined && existing !== '') return Number(existing);
|
|
208
|
+
var n = seq++;
|
|
209
|
+
try { el.setAttribute(STAMP, String(n)); } catch (e) { /* readonly node */ }
|
|
210
|
+
return n;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function emit(action, el, extra) {
|
|
214
|
+
if (!el || el.nodeType !== 1) return;
|
|
215
|
+
var n = stampOf(el);
|
|
216
|
+
|
|
217
|
+
var payload = {
|
|
218
|
+
seq: n,
|
|
219
|
+
action: action,
|
|
220
|
+
stamp: n,
|
|
221
|
+
url: location.href,
|
|
222
|
+
hintRole: accRole(el) || hintRole(el),
|
|
223
|
+
hintName: accName(el) || hintName(el),
|
|
224
|
+
// Records WHICH path produced the two fields above, so nothing
|
|
225
|
+
// downstream has to guess how much to trust them.
|
|
226
|
+
resolvedBy: a11y() ? 'accname' : 'heuristic',
|
|
227
|
+
css: cssPath(el),
|
|
228
|
+
testId: (el.getAttribute && (el.getAttribute('data-testid') || el.getAttribute('data-test'))) || undefined,
|
|
229
|
+
testIdAttr: (el.getAttribute && el.getAttribute('data-testid')) ? 'data-testid'
|
|
230
|
+
: (el.getAttribute && el.getAttribute('data-test')) ? 'data-test' : undefined,
|
|
231
|
+
inputType: (el.getAttribute && el.getAttribute('type')) || undefined,
|
|
232
|
+
frameHint: frameHint(),
|
|
233
|
+
};
|
|
234
|
+
if (extra) for (var k in extra) payload[k] = extra[k];
|
|
235
|
+
|
|
236
|
+
try { window.__understudyEmit(payload); } catch (e) { /* binding gone */ }
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// TEXT INPUT IS DEFERRED, NOT IMMEDIATE.
|
|
240
|
+
//
|
|
241
|
+
// 'change' on a text field fires on BLUR, not on typing. Filling a login form
|
|
242
|
+
// therefore emits the username only when the password field takes focus, and
|
|
243
|
+
// emits the password NEVER — nothing blurs the last field before submit. The
|
|
244
|
+
// final field of every form would vanish from every recording, silently.
|
|
245
|
+
//
|
|
246
|
+
// So: track the latest value per element on 'input' (which does fire per
|
|
247
|
+
// keystroke), and flush it as one 'fill' when the field is done — on blur, or
|
|
248
|
+
// when any other action happens, or when recording ends. Flushing before the
|
|
249
|
+
// triggering action also keeps the order right: fill, then the click that
|
|
250
|
+
// submits it.
|
|
251
|
+
var pending = [];
|
|
252
|
+
|
|
253
|
+
function flushOne(el) {
|
|
254
|
+
for (var i = 0; i < pending.length; i++) {
|
|
255
|
+
if (pending[i].el !== el) continue;
|
|
256
|
+
var entry = pending.splice(i, 1)[0];
|
|
257
|
+
emit('fill', entry.el, { value: entry.value });
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function flushAll() {
|
|
263
|
+
while (pending.length) {
|
|
264
|
+
var entry = pending.shift();
|
|
265
|
+
emit('fill', entry.el, { value: entry.value });
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// Called from Node before the recording is closed, so a field still focused
|
|
270
|
+
// when the browser shuts is not lost.
|
|
271
|
+
window.__understudyFlush = flushAll;
|
|
272
|
+
|
|
273
|
+
// Diagnostic hook: resolve any element exactly as the recorder would. Used to
|
|
274
|
+
// verify our role/name agree with Playwright's engine across a whole page,
|
|
275
|
+
// which is the only check that catches a systematic naming drift.
|
|
276
|
+
window.__understudyResolve = function (el) {
|
|
277
|
+
return { role: accRole(el) || hintRole(el), name: accName(el) || hintName(el) };
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
document.addEventListener('input', function (e) {
|
|
281
|
+
var el = (e.composedPath && e.composedPath()[0]) || e.target;
|
|
282
|
+
var tag = (el.tagName || '').toLowerCase();
|
|
283
|
+
if (tag !== 'input' && tag !== 'textarea') return;
|
|
284
|
+
var type = (el.getAttribute('type') || 'text').toLowerCase();
|
|
285
|
+
if (type === 'checkbox' || type === 'radio') return;
|
|
286
|
+
// A FILE INPUT'S VALUE IS A LIE. The browser masks it to 'C:\fakepath\name'
|
|
287
|
+
// so a page cannot learn where someone keeps their files. Deferring it here
|
|
288
|
+
// flushed it as an ordinary fill carrying that string: a step that cannot
|
|
289
|
+
// replay, with the file absent from the recording entirely, and nothing
|
|
290
|
+
// anywhere reporting either. The 'change' handler records it properly.
|
|
291
|
+
if (type === 'file') return;
|
|
292
|
+
|
|
293
|
+
for (var i = 0; i < pending.length; i++) {
|
|
294
|
+
if (pending[i].el === el) {
|
|
295
|
+
pending[i].value = el.value;
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
pending.push({ el: el, value: el.value });
|
|
300
|
+
}, true);
|
|
301
|
+
|
|
302
|
+
document.addEventListener('blur', function (e) {
|
|
303
|
+
var el = (e.composedPath && e.composedPath()[0]) || e.target;
|
|
304
|
+
flushOne(el);
|
|
305
|
+
}, true);
|
|
306
|
+
|
|
307
|
+
// Capture phase, so we see the event before the app can stopPropagation it,
|
|
308
|
+
// and before an anchor's default navigation tears the element down.
|
|
309
|
+
document.addEventListener('click', function (e) {
|
|
310
|
+
flushAll();
|
|
311
|
+
var el = (e.composedPath && e.composedPath()[0]) || e.target;
|
|
312
|
+
var tag = (el.tagName || '').toLowerCase();
|
|
313
|
+
var type = (el.getAttribute && (el.getAttribute('type') || '')).toLowerCase();
|
|
314
|
+
|
|
315
|
+
// Checkboxes, radios, selects and text inputs report through 'change',
|
|
316
|
+
// which carries the resulting VALUE. Emitting both would double-count.
|
|
317
|
+
if (tag === 'select' || tag === 'textarea') return;
|
|
318
|
+
if (tag === 'input' && type !== 'submit' && type !== 'button') return;
|
|
319
|
+
|
|
320
|
+
emit('click', el);
|
|
321
|
+
}, true);
|
|
322
|
+
|
|
323
|
+
document.addEventListener('change', function (e) {
|
|
324
|
+
var el = (e.composedPath && e.composedPath()[0]) || e.target;
|
|
325
|
+
var tag = (el.tagName || '').toLowerCase();
|
|
326
|
+
var type = (el.getAttribute && (el.getAttribute('type') || 'text')).toLowerCase();
|
|
327
|
+
|
|
328
|
+
if (tag === 'select') {
|
|
329
|
+
var opt = el.options && el.options[el.selectedIndex];
|
|
330
|
+
emit('select', el, { value: el.value, label: opt ? opt.textContent : undefined });
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
if (type === 'checkbox' || type === 'radio') {
|
|
334
|
+
emit(el.checked ? 'check' : 'uncheck', el);
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
if (type === 'file') {
|
|
338
|
+
// The page reports THAT an upload happened and how many files it carried.
|
|
339
|
+
// It cannot report WHICH files: el.value is masked and File exposes only
|
|
340
|
+
// .name. Node resolves the real paths from the stamp over CDP, which is
|
|
341
|
+
// the only place they can be read at all.
|
|
342
|
+
var count = el.files ? el.files.length : 0;
|
|
343
|
+
if (!count) return; // clearing a file input is not an upload
|
|
344
|
+
emit('upload', el, { fileCount: count });
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
// Text inputs are handled by the input+flush path above. Emitting here too
|
|
348
|
+
// would double-count every field that happens to blur.
|
|
349
|
+
}, true);
|
|
350
|
+
|
|
351
|
+
// Enter often submits without any click at all — a step that would otherwise
|
|
352
|
+
// vanish from the recording and make it unreplayable.
|
|
353
|
+
document.addEventListener('keydown', function (e) {
|
|
354
|
+
if (e.key !== 'Enter') return;
|
|
355
|
+
var el = (e.composedPath && e.composedPath()[0]) || e.target;
|
|
356
|
+
var tag = (el.tagName || '').toLowerCase();
|
|
357
|
+
if (tag !== 'input' && tag !== 'textarea') return;
|
|
358
|
+
flushAll();
|
|
359
|
+
emit('press', el, { value: 'Enter' });
|
|
360
|
+
}, true);
|
|
361
|
+
})();
|
|
362
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,70 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jeffawe/understudy",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"description": "End-to-end tests for your own web apps: record a flow once, and Understudy remembers it, replays it, notices when the app changes, and runs goals you describe in words — on its own or as an MCP server for AI agents.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/Jeffawe/UnderStudy.git"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://understudy.jeffawe.dev",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/Jeffawe/UnderStudy/issues"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"e2e",
|
|
17
|
+
"testing",
|
|
18
|
+
"playwright",
|
|
19
|
+
"mcp",
|
|
20
|
+
"agent",
|
|
21
|
+
"mongodb",
|
|
22
|
+
"vector-search",
|
|
23
|
+
"browser-recording"
|
|
24
|
+
],
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=22"
|
|
27
|
+
},
|
|
28
|
+
"bin": {
|
|
29
|
+
"understudy": "dist/entry/cli.js",
|
|
30
|
+
"understudy-mcp": "dist/entry/mcp.js"
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist",
|
|
34
|
+
"extension",
|
|
35
|
+
"build/extension/firefox",
|
|
36
|
+
"REASONER.md"
|
|
37
|
+
],
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"clean": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\"",
|
|
43
|
+
"build": "npm run clean && tsc",
|
|
44
|
+
"typecheck": "tsc --noEmit",
|
|
45
|
+
"test": "node --import tsx --test test/*.test.ts",
|
|
46
|
+
"prepack": "npm run extension:package && npm run build",
|
|
47
|
+
"understudy": "tsx src/entry/cli.ts",
|
|
48
|
+
"mcp": "tsx src/entry/mcp.ts",
|
|
49
|
+
"extension:build": "tsx scripts/build-extension.ts",
|
|
50
|
+
"vendor:accname": "node scripts/vendor-accname.mjs",
|
|
51
|
+
"prepublishOnly": "npm run typecheck",
|
|
52
|
+
"extension:package": "npm run extension:build && node scripts/package-extension.mjs"
|
|
53
|
+
},
|
|
54
|
+
"dependencies": {
|
|
55
|
+
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
56
|
+
"dom-accessibility-api": "^0.7.1",
|
|
57
|
+
"dotenv": "^17.2.3",
|
|
58
|
+
"mongodb": "^7.9.0",
|
|
59
|
+
"pixelmatch": "^7.2.0",
|
|
60
|
+
"playwright": "^1.62.1",
|
|
61
|
+
"pngjs": "^7.0.0",
|
|
62
|
+
"typescript": "^5.9.3",
|
|
63
|
+
"zod": "^4.6.7"
|
|
64
|
+
},
|
|
65
|
+
"devDependencies": {
|
|
66
|
+
"@types/node": "^22.18.9",
|
|
67
|
+
"@types/pngjs": "^6.0.5",
|
|
68
|
+
"tsx": "^4.20.6"
|
|
69
|
+
}
|
|
70
|
+
}
|