From 07201ce610a81dd32a4399692060fa66882de5a0 Mon Sep 17 00:00:00 2001 From: Claudio Gamboa Date: Thu, 18 Jun 2026 18:57:24 +0100 Subject: [PATCH 1/2] v1.2.1 - Improve checkbox event. Update example file --- OUTPUT-EXAMPLE.md | 12 ++++++++++-- package.json | 2 +- src/manifest-firefox.json | 2 +- src/pages/Content/modules/collectEvents.js | 15 +++++++++++---- test-build-firefox/contentScript.bundle.js | 2 +- test-build-firefox/manifest.json | 2 +- test-build/contentScript.bundle.js | 2 +- test-build/manifest.json | 2 +- 8 files changed, 27 insertions(+), 12 deletions(-) diff --git a/OUTPUT-EXAMPLE.md b/OUTPUT-EXAMPLE.md index 54a4b4e..e1e0241 100644 --- a/OUTPUT-EXAMPLE.md +++ b/OUTPUT-EXAMPLE.md @@ -1,4 +1,4 @@ -# Result Example +# Output Example JSON example containing all possible step types produced by the sequence recorder. @@ -124,6 +124,14 @@ JSON example containing all possible step types produced by the sequence recorde "type": "click", "value": "Submit", "frame": "#content-iframe" + }, + { + "timestamp": 1718724013000, + "css": ".nested-btn", + "xpath": "/html/body/div/button", + "type": "click", + "value": "Confirm", + "frame": "#outer-iframe >>> #inner-iframe" } ] ``` @@ -153,4 +161,4 @@ JSON example containing all possible step types produced by the sequence recorde | `xpath` | XPath selector for the target element | | `type` | Event type identifier | | `value` | Element value or trimmed text content (max 20 chars for clicks) | -| `frame` | CSS selector of the containing iframe, empty string if top-level | +| `frame` | CSS selector of the containing iframe, empty string if top-level. For nested iframes, selectors are joined with ` >>> ` from outermost to innermost (e.g. `#outer-iframe >>> #inner-iframe`) | diff --git a/package.json b/package.json index ac83dbd..568ff5d 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "snyk-api-and-web-record-sequence", - "version": "1.2.0", + "version": "1.2.1", "description": "Snyk API & Web Record login/sequence", "license": "MIT", "scripts": { diff --git a/src/manifest-firefox.json b/src/manifest-firefox.json index 080126f..2fb4186 100755 --- a/src/manifest-firefox.json +++ b/src/manifest-firefox.json @@ -1,6 +1,6 @@ { "name": "Snyk API & Web Sequence Recorder", - "version": "1.2.0", + "version": "1.2.1", "browser_specific_settings": { "gecko": { "id": "sequence-recorder@probely.com", diff --git a/src/pages/Content/modules/collectEvents.js b/src/pages/Content/modules/collectEvents.js index 3438765..7487901 100644 --- a/src/pages/Content/modules/collectEvents.js +++ b/src/pages/Content/modules/collectEvents.js @@ -199,10 +199,17 @@ export function interceptEvents(event, doc, ifrSelector, callback) { ) { return; } - if (nodeName === 'label') { - const forAttr = tgt.getAttribute('for'); - if (forAttr && document.getElementById(forAttr)) { - // can be ignored... will fire checkbox + const parentLabel = tgt.closest && tgt.closest('label'); + if (parentLabel) { + const forAttr = parentLabel.getAttribute('for'); + if (forAttr) { + const forEl = document.getElementById(forAttr); + if (forEl && forEl.nodeName.toLowerCase() === 'input' && + (forEl.type === 'checkbox' || forEl.type === 'radio')) { + return; + } + } + if (parentLabel.querySelector('input[type="checkbox"], input[type="radio"]')) { return; } } diff --git a/test-build-firefox/contentScript.bundle.js b/test-build-firefox/contentScript.bundle.js index 9a6eafe..56cf190 100644 --- a/test-build-firefox/contentScript.bundle.js +++ b/test-build-firefox/contentScript.bundle.js @@ -1 +1 @@ -(()=>{"use strict";let e,t;function n(n,r){if(n.nodeType!==Node.ELEMENT_NODE)throw new Error("Can't generate CSS selector for non-element node type.");if("html"===n.tagName.toLowerCase())return"html";const i={root:document.body,idName:e=>!0,className:e=>!0,tagName:e=>!0,attr:(e,t)=>!1,seedMinLength:1,optimizedMinLength:2,threshold:1e3,maxNumberOfTries:1e4};e={...i,...r},t=function(e,t){if(e.nodeType===Node.DOCUMENT_NODE)return e;if(e===t.root)return e.ownerDocument;return e}(e.root,i);let a=o(n,"all",(()=>o(n,"two",(()=>o(n,"one",(()=>o(n,"none")))))));if(a){const e=w(v(a,n));return e.length>0&&(a=e[0]),l(a)}throw new Error("Selector was not found.")}function o(t,n,o){let l=null,i=[],a=t,g=0;for(;a;){let t=p(s(a))||p(...c(a))||p(...u(a))||p(f(a))||[{name:"*",penalty:3}];const y=d(a);if("all"==n)y&&(t=t.concat(t.filter(h).map((e=>m(e,y)))));else if("two"==n)t=t.slice(0,1),y&&(t=t.concat(t.filter(h).map((e=>m(e,y)))));else if("one"==n){const[e]=t=t.slice(0,1);y&&h(e)&&(t=[m(e,y)])}else"none"==n&&(t=[{name:"*",penalty:3}],y&&(t=[m(t[0],y)]));for(let e of t)e.level=g;if(i.push(t),i.length>=e.seedMinLength&&(l=r(i,o),l))break;a=a.parentElement,g++}return l||(l=r(i,o)),!l&&o?o():l}function r(t,n){const o=w(y(t));if(o.length>e.threshold)return n?n():null;for(let e of o)if(a(e))return e;return null}function l(e){let t=e[0],n=t.name;for(let o=1;o ${n}`:`${e[o].name} ${n}`,t=e[o]}return n}function i(e){return e.map((e=>e.penalty)).reduce(((e,t)=>e+t),0)}function a(e){const n=l(e);switch(t.querySelectorAll(n).length){case 0:throw new Error(`Can't select any node with this selector: ${n}`);case 1:return!0;default:return!1}}function s(t){const n=t.getAttribute("id");return n&&e.idName(n)?{name:"#"+CSS.escape(n),penalty:0}:null}function c(t){const n=Array.from(t.attributes).filter((t=>e.attr(t.name,t.value)));return n.map((e=>({name:`[${CSS.escape(e.name)}="${CSS.escape(e.value)}"]`,penalty:.5})))}function u(t){return Array.from(t.classList).filter(e.className).map((e=>({name:"."+CSS.escape(e),penalty:1})))}function f(t){const n=t.tagName.toLowerCase();return e.tagName(n)?{name:n,penalty:2}:null}function d(e){const t=e.parentNode;if(!t)return null;let n=t.firstChild;if(!n)return null;let o=0;for(;n&&(n.nodeType===Node.ELEMENT_NODE&&o++,n!==e);)n=n.nextSibling;return o}function m(e,t){return{name:e.name+`:nth-child(${t})`,penalty:e.penalty+1}}function h(e){return"html"!==e.name&&!e.name.startsWith("#")}function p(...e){const t=e.filter(g);return t.length>0?t:null}function g(e){return null!=e}function*y(e,t=[]){if(e.length>0)for(let n of e[0])yield*y(e.slice(1,e.length),t.concat(n));else yield t}function w(e){return[...e].sort(((e,t)=>i(e)-i(t)))}function*v(t,n,o={counter:0,visited:new Map}){if(t.length>2&&t.length>e.optimizedMinLength)for(let r=1;re.maxNumberOfTries)return;o.counter+=1;const i=[...t];i.splice(r,1);const s=l(i);if(o.visited.has(s))return;a(i)&&b(i,n)&&(yield i,o.visited.set(s,!0),yield*v(i,n,o))}}function b(e,n){return t.querySelector(l(e))===n}function N(e,t){let n="",o=null,r=!1;try{if(o=e.nodeName&&"string"==typeof e.nodeName?e.nodeName.toLowerCase():null,!o)return null;n=`${o}`,e.getAttribute("id")&&(n=`${n}#${CSS.escape(e.getAttribute("id"))}`,r=!0);const t=["data-test-id","data-testid","data-test","data-cy"];if(e.matches(t.map((e=>`[${e}]`)).join(",")))for(const o of t){const t=e.getAttribute(o);if(t){n=`${n}[${o}="${CSS.escape(t)}"]`;break}}if(["input","button","textarea","select","option"].includes(o)){e.getAttribute("type")&&(n=`${n}[type="${CSS.escape(e.getAttribute("type"))}"]`),e.getAttribute("name")&&(n=`${n}[name="${CSS.escape(e.getAttribute("name"))}"]`);const t=e.closest("form");if(t){let e="form";t.getAttribute("id")&&(e=`${e}#${CSS.escape(t.getAttribute("id"))}`),n=`${e} ${n}`}}const l=e.getAttribute("aria-label");if(l&&!r&&(n=`${n}[aria-label="${CSS.escape(l)}"]`),n){const t=e.closest("body");if(t)try{1!==t.querySelectorAll(n).length&&(n="")}catch(e){n=""}}}catch(e){}return n}function E(e,t){let n,o=e,r=[];for(;o;){let e=0,n=o.previousElementSibling;for(;n;)n.nodeName===o.nodeName&&e++,n=n.previousElementSibling;let l=o.nodeName.toLowerCase();e>0&&(l=l+"["+(e+1)+"]"),o!==t&&r.unshift(l),o=o.parentNode}if(n="/"+r.join("/"),function(e,t){const n=t.evaluate(e,t,null,XPathResult.ANY_TYPE,null),o=n.iterateNext();return o}(n,t)===e)return n}const S={},C={keydown:null,return:null,blur:null,change:null,click:null,dblclick:null,contextmenu:null,focus:null,mouseover:null,mouseout:null};let A=!1,$=null,k=null;const L=new WeakMap;function T(e){const t=e.value;return t&&t.trim()?t:L.get(e)||t}function x(e){const t=e.value;return!(t&&t.trim())&&L.has(e)}function M(e,t){const n=["focus","highlight","editable","caret"],o=Array.from(e.classList||[]).filter((e=>{const t=e.toLowerCase();return!n.some((e=>t.includes(e)))&&!/^[0-9]/.test(e)}));for(const n of o){const o="."+n;try{const n=t.querySelectorAll(o);if(1===n.length&&n[0]===e)return o}catch(e){}}return null}function O(e,t){let n;var o;let r,l;function i(e,t,o){let l=null;const i=[];let s=e,c=0;for(;s&&s!==r.root.parentElement;){let e=w(f(s))||w(...d(s))||w(...m(s))||w(h(s))||[{name:"*",penalty:3}];const u=p(s);if(t===n.All)u&&(e=e.concat(e.filter(y).map((e=>g(e,u)))));else if(t===n.Two)e=e.slice(0,1),u&&(e=e.concat(e.filter(y).map((e=>g(e,u)))));else if(t===n.One){const[t]=e=e.slice(0,1);u&&y(t)&&(e=[g(t,u)])}for(const t of e)t.level=c;if(i.push(e),i.length>=r.seedMinLength&&(l=a(i,o),l))break;s=s.parentElement,c++}return l||(l=a(i,o)),l}function a(e,t){const n=N(b(e));if(n.length>r.threshold)return t?t():null;for(const e of n)if(u(e))return e;return null}function s(e){let t=e[0],n=t.name;for(let o=1;o ${n}`:`${e[o].name} ${n}`,t=e[o]}return n}function c(e){return e.map((e=>e.penalty)).reduce(((e,t)=>e+t),0)}function u(e){switch(l.querySelectorAll(s(e)).length){case 0:throw new Error(`Can't select any node with this selector: ${s(e)}`);case 1:return!0;default:return!1}}function f(e){const t=e.getAttribute("id");return t&&r.idName(t)?{name:`#${k(t,{isIdentifier:!0})}`,penalty:0}:null}function d(e){return Array.from(e.attributes).filter((e=>r.attr(e.name,e.value))).map((e=>({name:"["+k(e.name,{isIdentifier:!0})+'="'+k(e.value)+'"]',penalty:.5})))}function m(e){return Array.from(e.classList).filter(r.className).map((e=>({name:"."+k(e,{isIdentifier:!0}),penalty:1})))}function h(e){const t=e.tagName.toLowerCase();return r.tagName(t)?{name:t,penalty:2}:null}function p(e){const t=e.parentNode;if(!t)return null;let n=t.firstChild;if(!n)return null;let o=0;for(;n&&(n.nodeType===Node.ELEMENT_NODE&&o++,n!==e);)n=n.nextSibling;return o}function g(e,t){return{name:e.name+`:nth-child(${t})`,penalty:e.penalty+1}}function y(e){return"html"!==e.name&&!e.name.startsWith("#")}function w(...e){const t=e.filter(v);return 0c(e)-c(t)))}function E(e,t){return l.querySelector(s(e))===t}(o=n||(n={}))[o.All=0]="All",o[o.Two=1]="Two",o[o.One=2]="One";const S=/[ -,\.\/:-@\[-\^`\{-~]/,C=/[ -,\.\/:-@\[\]\^`\{-~]/,A=/(^|\\+)?(\\[A-F0-9]{1,6})\x20(?![a-fA-F0-9\x20])/g,$={escapeEverything:!1,isIdentifier:!1,quotes:"single",wrap:!1};function k(e,t={}){const n=Object.assign(Object.assign({},$),t);"single"!==n.quotes&&"double"!==n.quotes&&(n.quotes="single");const o="double"==n.quotes?'"':"'",r=n.isIdentifier,l=e.charAt(0);let i="",a=0;for(const t=e.length;ac||126=c&&a!0,className:()=>!0,tagName:()=>!0,attr:()=>!1,seedMinLength:1,optimizedMinLength:2,threshold:1e3,maxNumberOfTries:1e4};r=Object.assign(Object.assign({},L),t),l=function(e,t){return e.nodeType===Node.DOCUMENT_NODE?e:e===t.root?e.ownerDocument:e}(r.root,L);let T=i(e,n.All,(()=>i(e,n.Two,(()=>i(e,n.One)))));if(T){const t=N(function*e(t,n,o={counter:0,visited:new Map}){if(2r.optimizedMinLength)for(let l=1;lr.maxNumberOfTries)return;o.counter+=1;const i=[...t];i.splice(l,1);const a=s(i);if(o.visited.has(a))return;u(i)&&E(i,n)&&(yield i,o.visited.set(a,!0),yield*e(i,n,o))}}(T,e));return 0{if(!l.isRecording)return;let i=!1,a=null;function s(e){e&&"mouseover"===e.type&&!i||function(e,t,o,r){let l=!1,i=null,a=null;e&&e.composed&&e.composedPath&&(a=e.composedPath());let s=-1;a&&a.length>0&&(s=a.findIndex((e=>e instanceof ShadowRoot))),i=s>-1?a[0]:e.target;const c=e.type;let u=null,f=null;if(!i||!i.getAttribute)return;u=i.nodeName.toLowerCase(),f=i.getAttribute("type");let d=null,m=null;try{m=function(e){let t=null;try{if(t=e.nodeName&&"string"==typeof e.nodeName?e.nodeName.toLowerCase():null,!t)return e;if(["input","button","a","textarea","select","option","progress"].includes(t))return e;const n=e.closest("button,a");if(n)return n;const o=e.closest("svg");o&&(e=o);const r=["data-test-id","data-testid","data-test","data-cy"];if(e.matches(r.map((e=>`[${e}]`)).join(",")))return e;if(e.parentNode.matches(r.map((e=>`[${e}]`)).join(",")))return e.parentNode}catch(e){}return e}(i),d=N(m)}catch(e){}if(!d)try{d=n(m,{root:t,idName:e=>!/^[0-9]+.*/i.test(e),className:e=>!e.includes("focus")&&!e.includes("highlight")&&!/^[0-9]+.*/i.test(e)})}catch(e){}if(d&&"html"===d.toLowerCase())return;let h=null;try{h=E(m,t)}catch(e){}s>-1&&(h="/html/node/shadow");let p={timestamp:(new Date).getTime(),css:d||i,xpath:h||""},g={};if("click"===c){if(C.click=i,$&&$.element!==i&&r){const e=x($.element),n={...$.oEventBase,type:e?"bfill_value":"fill_value",value:T($.element),frame:$.frame};if(e){const e=M($.element,t);e&&(n.css=e)}r({messageType:"events",event:{...n}}),L.delete($.element),k=$.element,$=null}if(!(C.return!==C.change||i===C.return||"input"!==u&&"button"!==u||"submit"!==f&&"image"!==f||null===C.return))return;if("input"===u&&("checkbox"===f||"radio"===f))return;if("label"===u){const e=i.getAttribute("for");if(e&&document.getElementById(e))return}let l="click";if(function(e){if("canvas"===e.nodeName.toLowerCase())return!0;if(e.shadowRoot)try{if(e.shadowRoot.querySelector("canvas"))return!0}catch(e){}for(const t of e.children||[])if(t.shadowRoot)try{if(t.shadowRoot.querySelector("canvas"))return!0}catch(e){}return!1}(i)){const t=i.getBoundingClientRect(),n={x:e.clientX-t.left,y:e.clientY-t.top,width:t.width,height:t.height};p={...p,coords:n},l="bclick"}if(g={...p,type:l,value:(i.value||i.textContent||"").trim().substr(0,20).replace(/\n/gi,""),frame:o},"bclick"===l&&s>-1&&a){const e=a[s].host;if(e){let o=null;try{o=N(e)}catch(e){}if(!o)try{o=n(e,{root:t,idName:e=>!/^[0-9]+.*/i.test(e),className:e=>!e.includes("focus")&&!e.includes("highlight")&&!/^[0-9]+.*/i.test(e)})}catch(e){}o&&(g.shadow_host_css=o)}}}else if("dblclick"===c)C.dblclick=i,g={...p,type:"dblclick",value:(i.value||i.textContent||"").trim().substr(0,20).replace(/\n/gi,""),frame:o};else if("contextmenu"===c)C.contextmenu=i,g={...p,type:"contextmenu",value:(i.value||i.textContent||"").trim().substr(0,20).replace(/\n/gi,""),frame:o};else if("focus"===c);else if("mouseover"===c)A&&(clearTimeout(A),A=!1),A=setTimeout((()=>{A=!1,C.mouseover=i,g={...p,type:"mouseover",value:(i.value||i.textContent||"").trim().substr(0,20).replace(/\n/gi,""),frame:o},g&&g.type&&r&&r({messageType:"events",event:{...g}})}),500);else if("mouseout"===c);else if("keydown"===c){if(C.keydown=i,["input","textarea"].indexOf(u)>-1)if(S[i]=i.value,$={element:i,oEventBase:{...p},frame:o},e.key&&1===e.key.length){const t=L.get(i)||"";L.set(i,t+e.key)}else if("Backspace"===e.key){const e=L.get(i)||"";e.length>0&&L.set(i,e.slice(0,-1))}if("input"===u&&13===e.keyCode){l=!0,C.return=i;const e=x(i);if(g={...p,type:e?"bfill_value":"fill_value",value:T(i),frame:o},e){const e=M(i,t);e&&(g.css=e)}L.delete(i)}}else if("blur"===c){if(C.blur=i,i===k)return void(k=null);if($&&$.element===i&&($=null),["input","textarea"].indexOf(u)>-1){if(S[i]=i.value,i===C.return)return void(C.return=null);if("input"===u&&("submit"===i.type||"button"===i.type||"image"===i.type))return;const e=x(i);if(g={...p,type:e?"bfill_value":"fill_value",value:T(i),frame:o},e){const e=M(i,t);e&&(g.css=e)}L.delete(i)}}else if("change"===c)if(C.change=i,"input"===u)"checkbox"!==f&&"radio"!==f||(g={...p,type:"change",subtype:"check",checked:i.checked,frame:o});else if("select"===u)if(i.multiple){const e=[];for(let t=0;t{window!==window.top?window.parent.postMessage({source:"event-from-iframe",obj:{...e},framePath:[]},"*"):chrome.runtime.sendMessage(e)}))}window===window.top&&window.addEventListener("message",(e=>{if(e.data&&e.data.source&&"event-from-iframe"===e.data.source){const t=document.querySelectorAll("iframe, frame");let n=!1;for(const o of t)if(o.contentWindow===e.source){n=!0;break}if(!n)return;const o={...e.data.obj},r=e.data.framePath||[];for(const n of t)if(n.contentWindow===e.source){let e=null;try{e=N(n)}catch(e){}if(!e)try{e=O(n,{root:window.document,idName:e=>!/^[0-9]+.*/i.test(e),className:e=>!e.includes("focus")&&!e.includes("highlight")&&!/^[0-9]+.*/i.test(e)})}catch(e){}if(e&&o.event){const t=[e,...r];o.event.frame=t.join(" >>> "),chrome.runtime.sendMessage(o)}break}}})),window!==window.top&&window.addEventListener("message",(e=>{if(e.data&&e.data.source&&"event-from-iframe"===e.data.source){const t=document.querySelectorAll("iframe, frame");let n=!1;for(const o of t)if(o.contentWindow===e.source){n=!0;break}if(!n)return;const o=e.data.framePath||[];for(const n of t)if(n.contentWindow===e.source){let t=null;try{t=N(n)}catch(e){}if(!t)try{t=O(n,{root:window.document,idName:e=>!/^[0-9]+.*/i.test(e),className:e=>!e.includes("focus")&&!e.includes("highlight")&&!/^[0-9]+.*/i.test(e)})}catch(e){}t&&o.push(t),window.parent.postMessage({source:"event-from-iframe",obj:e.data.obj,framePath:o},"*");break}}})),l.isRecording&&(t=!0,e=document.title,function(){if(!t)return document.title=`${e}`,r=!1,void(o&&(clearInterval(o),o=!1));o=setInterval((()=>{r?(document.title=`${e}`,r=!1):(document.title=`🔴 ${e}`,r=!0)}),1e3)}(),window===window.top&&chrome.runtime.sendMessage({messageType:"events",event:{type:"goto",timestamp:(new Date).getTime(),windowWidth:window.innerWidth,windowHeight:window.innerHeight,url:window.location.href}}),document.addEventListener("click",s,!0),document.addEventListener("mouseover",s,!0),document.addEventListener("dblclick",s,!0),document.addEventListener("contextmenu",s,!0),document.addEventListener("keydown",s,!0),document.addEventListener("blur",s,!0),document.addEventListener("change",s,!0));const c={attributes:!1,childList:!0,subtree:!0},u=new MutationObserver((async(e,t)=>{i=!0,a&&(clearTimeout(a),a=null),a=setTimeout((()=>{i=!1}),200)}));document.body&&u.observe(document.body,c)}))}()})(); \ No newline at end of file +(()=>{"use strict";let e,t;function n(n,r){if(n.nodeType!==Node.ELEMENT_NODE)throw new Error("Can't generate CSS selector for non-element node type.");if("html"===n.tagName.toLowerCase())return"html";const i={root:document.body,idName:e=>!0,className:e=>!0,tagName:e=>!0,attr:(e,t)=>!1,seedMinLength:1,optimizedMinLength:2,threshold:1e3,maxNumberOfTries:1e4};e={...i,...r},t=function(e,t){if(e.nodeType===Node.DOCUMENT_NODE)return e;if(e===t.root)return e.ownerDocument;return e}(e.root,i);let s=o(n,"all",(()=>o(n,"two",(()=>o(n,"one",(()=>o(n,"none")))))));if(s){const e=w(v(s,n));return e.length>0&&(s=e[0]),l(s)}throw new Error("Selector was not found.")}function o(t,n,o){let l=null,i=[],s=t,g=0;for(;s;){let t=p(a(s))||p(...c(s))||p(...u(s))||p(f(s))||[{name:"*",penalty:3}];const y=d(s);if("all"==n)y&&(t=t.concat(t.filter(h).map((e=>m(e,y)))));else if("two"==n)t=t.slice(0,1),y&&(t=t.concat(t.filter(h).map((e=>m(e,y)))));else if("one"==n){const[e]=t=t.slice(0,1);y&&h(e)&&(t=[m(e,y)])}else"none"==n&&(t=[{name:"*",penalty:3}],y&&(t=[m(t[0],y)]));for(let e of t)e.level=g;if(i.push(t),i.length>=e.seedMinLength&&(l=r(i,o),l))break;s=s.parentElement,g++}return l||(l=r(i,o)),!l&&o?o():l}function r(t,n){const o=w(y(t));if(o.length>e.threshold)return n?n():null;for(let e of o)if(s(e))return e;return null}function l(e){let t=e[0],n=t.name;for(let o=1;o ${n}`:`${e[o].name} ${n}`,t=e[o]}return n}function i(e){return e.map((e=>e.penalty)).reduce(((e,t)=>e+t),0)}function s(e){const n=l(e);switch(t.querySelectorAll(n).length){case 0:throw new Error(`Can't select any node with this selector: ${n}`);case 1:return!0;default:return!1}}function a(t){const n=t.getAttribute("id");return n&&e.idName(n)?{name:"#"+CSS.escape(n),penalty:0}:null}function c(t){const n=Array.from(t.attributes).filter((t=>e.attr(t.name,t.value)));return n.map((e=>({name:`[${CSS.escape(e.name)}="${CSS.escape(e.value)}"]`,penalty:.5})))}function u(t){return Array.from(t.classList).filter(e.className).map((e=>({name:"."+CSS.escape(e),penalty:1})))}function f(t){const n=t.tagName.toLowerCase();return e.tagName(n)?{name:n,penalty:2}:null}function d(e){const t=e.parentNode;if(!t)return null;let n=t.firstChild;if(!n)return null;let o=0;for(;n&&(n.nodeType===Node.ELEMENT_NODE&&o++,n!==e);)n=n.nextSibling;return o}function m(e,t){return{name:e.name+`:nth-child(${t})`,penalty:e.penalty+1}}function h(e){return"html"!==e.name&&!e.name.startsWith("#")}function p(...e){const t=e.filter(g);return t.length>0?t:null}function g(e){return null!=e}function*y(e,t=[]){if(e.length>0)for(let n of e[0])yield*y(e.slice(1,e.length),t.concat(n));else yield t}function w(e){return[...e].sort(((e,t)=>i(e)-i(t)))}function*v(t,n,o={counter:0,visited:new Map}){if(t.length>2&&t.length>e.optimizedMinLength)for(let r=1;re.maxNumberOfTries)return;o.counter+=1;const i=[...t];i.splice(r,1);const a=l(i);if(o.visited.has(a))return;s(i)&&b(i,n)&&(yield i,o.visited.set(a,!0),yield*v(i,n,o))}}function b(e,n){return t.querySelector(l(e))===n}function N(e,t){let n="",o=null,r=!1;try{if(o=e.nodeName&&"string"==typeof e.nodeName?e.nodeName.toLowerCase():null,!o)return null;n=`${o}`,e.getAttribute("id")&&(n=`${n}#${CSS.escape(e.getAttribute("id"))}`,r=!0);const t=["data-test-id","data-testid","data-test","data-cy"];if(e.matches(t.map((e=>`[${e}]`)).join(",")))for(const o of t){const t=e.getAttribute(o);if(t){n=`${n}[${o}="${CSS.escape(t)}"]`;break}}if(["input","button","textarea","select","option"].includes(o)){e.getAttribute("type")&&(n=`${n}[type="${CSS.escape(e.getAttribute("type"))}"]`),e.getAttribute("name")&&(n=`${n}[name="${CSS.escape(e.getAttribute("name"))}"]`);const t=e.closest("form");if(t){let e="form";t.getAttribute("id")&&(e=`${e}#${CSS.escape(t.getAttribute("id"))}`),n=`${e} ${n}`}}const l=e.getAttribute("aria-label");if(l&&!r&&(n=`${n}[aria-label="${CSS.escape(l)}"]`),n){const t=e.closest("body");if(t)try{1!==t.querySelectorAll(n).length&&(n="")}catch(e){n=""}}}catch(e){}return n}function E(e,t){let n,o=e,r=[];for(;o;){let e=0,n=o.previousElementSibling;for(;n;)n.nodeName===o.nodeName&&e++,n=n.previousElementSibling;let l=o.nodeName.toLowerCase();e>0&&(l=l+"["+(e+1)+"]"),o!==t&&r.unshift(l),o=o.parentNode}if(n="/"+r.join("/"),function(e,t){const n=t.evaluate(e,t,null,XPathResult.ANY_TYPE,null),o=n.iterateNext();return o}(n,t)===e)return n}const S={},C={keydown:null,return:null,blur:null,change:null,click:null,dblclick:null,contextmenu:null,focus:null,mouseover:null,mouseout:null};let k=!1,A=null,L=null;const $=new WeakMap;function x(e){const t=e.value;return t&&t.trim()?t:$.get(e)||t}function T(e){const t=e.value;return!(t&&t.trim())&&$.has(e)}function M(e,t){const n=["focus","highlight","editable","caret"],o=Array.from(e.classList||[]).filter((e=>{const t=e.toLowerCase();return!n.some((e=>t.includes(e)))&&!/^[0-9]/.test(e)}));for(const n of o){const o="."+n;try{const n=t.querySelectorAll(o);if(1===n.length&&n[0]===e)return o}catch(e){}}return null}function O(e,t){let n;var o;let r,l;function i(e,t,o){let l=null;const i=[];let a=e,c=0;for(;a&&a!==r.root.parentElement;){let e=w(f(a))||w(...d(a))||w(...m(a))||w(h(a))||[{name:"*",penalty:3}];const u=p(a);if(t===n.All)u&&(e=e.concat(e.filter(y).map((e=>g(e,u)))));else if(t===n.Two)e=e.slice(0,1),u&&(e=e.concat(e.filter(y).map((e=>g(e,u)))));else if(t===n.One){const[t]=e=e.slice(0,1);u&&y(t)&&(e=[g(t,u)])}for(const t of e)t.level=c;if(i.push(e),i.length>=r.seedMinLength&&(l=s(i,o),l))break;a=a.parentElement,c++}return l||(l=s(i,o)),l}function s(e,t){const n=N(b(e));if(n.length>r.threshold)return t?t():null;for(const e of n)if(u(e))return e;return null}function a(e){let t=e[0],n=t.name;for(let o=1;o ${n}`:`${e[o].name} ${n}`,t=e[o]}return n}function c(e){return e.map((e=>e.penalty)).reduce(((e,t)=>e+t),0)}function u(e){switch(l.querySelectorAll(a(e)).length){case 0:throw new Error(`Can't select any node with this selector: ${a(e)}`);case 1:return!0;default:return!1}}function f(e){const t=e.getAttribute("id");return t&&r.idName(t)?{name:`#${L(t,{isIdentifier:!0})}`,penalty:0}:null}function d(e){return Array.from(e.attributes).filter((e=>r.attr(e.name,e.value))).map((e=>({name:"["+L(e.name,{isIdentifier:!0})+'="'+L(e.value)+'"]',penalty:.5})))}function m(e){return Array.from(e.classList).filter(r.className).map((e=>({name:"."+L(e,{isIdentifier:!0}),penalty:1})))}function h(e){const t=e.tagName.toLowerCase();return r.tagName(t)?{name:t,penalty:2}:null}function p(e){const t=e.parentNode;if(!t)return null;let n=t.firstChild;if(!n)return null;let o=0;for(;n&&(n.nodeType===Node.ELEMENT_NODE&&o++,n!==e);)n=n.nextSibling;return o}function g(e,t){return{name:e.name+`:nth-child(${t})`,penalty:e.penalty+1}}function y(e){return"html"!==e.name&&!e.name.startsWith("#")}function w(...e){const t=e.filter(v);return 0c(e)-c(t)))}function E(e,t){return l.querySelector(a(e))===t}(o=n||(n={}))[o.All=0]="All",o[o.Two=1]="Two",o[o.One=2]="One";const S=/[ -,\.\/:-@\[-\^`\{-~]/,C=/[ -,\.\/:-@\[\]\^`\{-~]/,k=/(^|\\+)?(\\[A-F0-9]{1,6})\x20(?![a-fA-F0-9\x20])/g,A={escapeEverything:!1,isIdentifier:!1,quotes:"single",wrap:!1};function L(e,t={}){const n=Object.assign(Object.assign({},A),t);"single"!==n.quotes&&"double"!==n.quotes&&(n.quotes="single");const o="double"==n.quotes?'"':"'",r=n.isIdentifier,l=e.charAt(0);let i="",s=0;for(const t=e.length;sc||126=c&&s!0,className:()=>!0,tagName:()=>!0,attr:()=>!1,seedMinLength:1,optimizedMinLength:2,threshold:1e3,maxNumberOfTries:1e4};r=Object.assign(Object.assign({},$),t),l=function(e,t){return e.nodeType===Node.DOCUMENT_NODE?e:e===t.root?e.ownerDocument:e}(r.root,$);let x=i(e,n.All,(()=>i(e,n.Two,(()=>i(e,n.One)))));if(x){const t=N(function*e(t,n,o={counter:0,visited:new Map}){if(2r.optimizedMinLength)for(let l=1;lr.maxNumberOfTries)return;o.counter+=1;const i=[...t];i.splice(l,1);const s=a(i);if(o.visited.has(s))return;u(i)&&E(i,n)&&(yield i,o.visited.set(s,!0),yield*e(i,n,o))}}(x,e));return 0{if(!l.isRecording)return;let i=!1,s=null;function a(e){e&&"mouseover"===e.type&&!i||function(e,t,o,r){let l=!1,i=null,s=null;e&&e.composed&&e.composedPath&&(s=e.composedPath());let a=-1;s&&s.length>0&&(a=s.findIndex((e=>e instanceof ShadowRoot))),i=a>-1?s[0]:e.target;const c=e.type;let u=null,f=null;if(!i||!i.getAttribute)return;u=i.nodeName.toLowerCase(),f=i.getAttribute("type");let d=null,m=null;try{m=function(e){let t=null;try{if(t=e.nodeName&&"string"==typeof e.nodeName?e.nodeName.toLowerCase():null,!t)return e;if(["input","button","a","textarea","select","option","progress"].includes(t))return e;const n=e.closest("button,a");if(n)return n;const o=e.closest("svg");o&&(e=o);const r=["data-test-id","data-testid","data-test","data-cy"];if(e.matches(r.map((e=>`[${e}]`)).join(",")))return e;if(e.parentNode.matches(r.map((e=>`[${e}]`)).join(",")))return e.parentNode}catch(e){}return e}(i),d=N(m)}catch(e){}if(!d)try{d=n(m,{root:t,idName:e=>!/^[0-9]+.*/i.test(e),className:e=>!e.includes("focus")&&!e.includes("highlight")&&!/^[0-9]+.*/i.test(e)})}catch(e){}if(d&&"html"===d.toLowerCase())return;let h=null;try{h=E(m,t)}catch(e){}a>-1&&(h="/html/node/shadow");let p={timestamp:(new Date).getTime(),css:d||i,xpath:h||""},g={};if("click"===c){if(C.click=i,A&&A.element!==i&&r){const e=T(A.element),n={...A.oEventBase,type:e?"bfill_value":"fill_value",value:x(A.element),frame:A.frame};if(e){const e=M(A.element,t);e&&(n.css=e)}r({messageType:"events",event:{...n}}),$.delete(A.element),L=A.element,A=null}if(!(C.return!==C.change||i===C.return||"input"!==u&&"button"!==u||"submit"!==f&&"image"!==f||null===C.return))return;if("input"===u&&("checkbox"===f||"radio"===f))return;const l=i.closest&&i.closest("label");if(l){const e=l.getAttribute("for");if(e){const t=document.getElementById(e);if(t&&"input"===t.nodeName.toLowerCase()&&("checkbox"===t.type||"radio"===t.type))return}if(l.querySelector('input[type="checkbox"], input[type="radio"]'))return}let c="click";if(function(e){if("canvas"===e.nodeName.toLowerCase())return!0;if(e.shadowRoot)try{if(e.shadowRoot.querySelector("canvas"))return!0}catch(e){}for(const t of e.children||[])if(t.shadowRoot)try{if(t.shadowRoot.querySelector("canvas"))return!0}catch(e){}return!1}(i)){const t=i.getBoundingClientRect(),n={x:e.clientX-t.left,y:e.clientY-t.top,width:t.width,height:t.height};p={...p,coords:n},c="bclick"}if(g={...p,type:c,value:(i.value||i.textContent||"").trim().substr(0,20).replace(/\n/gi,""),frame:o},"bclick"===c&&a>-1&&s){const e=s[a].host;if(e){let o=null;try{o=N(e)}catch(e){}if(!o)try{o=n(e,{root:t,idName:e=>!/^[0-9]+.*/i.test(e),className:e=>!e.includes("focus")&&!e.includes("highlight")&&!/^[0-9]+.*/i.test(e)})}catch(e){}o&&(g.shadow_host_css=o)}}}else if("dblclick"===c)C.dblclick=i,g={...p,type:"dblclick",value:(i.value||i.textContent||"").trim().substr(0,20).replace(/\n/gi,""),frame:o};else if("contextmenu"===c)C.contextmenu=i,g={...p,type:"contextmenu",value:(i.value||i.textContent||"").trim().substr(0,20).replace(/\n/gi,""),frame:o};else if("focus"===c);else if("mouseover"===c)k&&(clearTimeout(k),k=!1),k=setTimeout((()=>{k=!1,C.mouseover=i,g={...p,type:"mouseover",value:(i.value||i.textContent||"").trim().substr(0,20).replace(/\n/gi,""),frame:o},g&&g.type&&r&&r({messageType:"events",event:{...g}})}),500);else if("mouseout"===c);else if("keydown"===c){if(C.keydown=i,["input","textarea"].indexOf(u)>-1)if(S[i]=i.value,A={element:i,oEventBase:{...p},frame:o},e.key&&1===e.key.length){const t=$.get(i)||"";$.set(i,t+e.key)}else if("Backspace"===e.key){const e=$.get(i)||"";e.length>0&&$.set(i,e.slice(0,-1))}if("input"===u&&13===e.keyCode){l=!0,C.return=i;const e=T(i);if(g={...p,type:e?"bfill_value":"fill_value",value:x(i),frame:o},e){const e=M(i,t);e&&(g.css=e)}$.delete(i)}}else if("blur"===c){if(C.blur=i,i===L)return void(L=null);if(A&&A.element===i&&(A=null),["input","textarea"].indexOf(u)>-1){if(S[i]=i.value,i===C.return)return void(C.return=null);if("input"===u&&("submit"===i.type||"button"===i.type||"image"===i.type))return;const e=T(i);if(g={...p,type:e?"bfill_value":"fill_value",value:x(i),frame:o},e){const e=M(i,t);e&&(g.css=e)}$.delete(i)}}else if("change"===c)if(C.change=i,"input"===u)"checkbox"!==f&&"radio"!==f||(g={...p,type:"change",subtype:"check",checked:i.checked,frame:o});else if("select"===u)if(i.multiple){const e=[];for(let t=0;t{window!==window.top?window.parent.postMessage({source:"event-from-iframe",obj:{...e},framePath:[]},"*"):chrome.runtime.sendMessage(e)}))}window===window.top&&window.addEventListener("message",(e=>{if(e.data&&e.data.source&&"event-from-iframe"===e.data.source){const t=document.querySelectorAll("iframe, frame");let n=!1;for(const o of t)if(o.contentWindow===e.source){n=!0;break}if(!n)return;const o={...e.data.obj},r=e.data.framePath||[];for(const n of t)if(n.contentWindow===e.source){let e=null;try{e=N(n)}catch(e){}if(!e)try{e=O(n,{root:window.document,idName:e=>!/^[0-9]+.*/i.test(e),className:e=>!e.includes("focus")&&!e.includes("highlight")&&!/^[0-9]+.*/i.test(e)})}catch(e){}if(e&&o.event){const t=[e,...r];o.event.frame=t.join(" >>> "),chrome.runtime.sendMessage(o)}break}}})),window!==window.top&&window.addEventListener("message",(e=>{if(e.data&&e.data.source&&"event-from-iframe"===e.data.source){const t=document.querySelectorAll("iframe, frame");let n=!1;for(const o of t)if(o.contentWindow===e.source){n=!0;break}if(!n)return;const o=e.data.framePath||[];for(const n of t)if(n.contentWindow===e.source){let t=null;try{t=N(n)}catch(e){}if(!t)try{t=O(n,{root:window.document,idName:e=>!/^[0-9]+.*/i.test(e),className:e=>!e.includes("focus")&&!e.includes("highlight")&&!/^[0-9]+.*/i.test(e)})}catch(e){}t&&o.push(t),window.parent.postMessage({source:"event-from-iframe",obj:e.data.obj,framePath:o},"*");break}}})),l.isRecording&&(t=!0,e=document.title,function(){if(!t)return document.title=`${e}`,r=!1,void(o&&(clearInterval(o),o=!1));o=setInterval((()=>{r?(document.title=`${e}`,r=!1):(document.title=`🔴 ${e}`,r=!0)}),1e3)}(),window===window.top&&chrome.runtime.sendMessage({messageType:"events",event:{type:"goto",timestamp:(new Date).getTime(),windowWidth:window.innerWidth,windowHeight:window.innerHeight,url:window.location.href}}),document.addEventListener("click",a,!0),document.addEventListener("mouseover",a,!0),document.addEventListener("dblclick",a,!0),document.addEventListener("contextmenu",a,!0),document.addEventListener("keydown",a,!0),document.addEventListener("blur",a,!0),document.addEventListener("change",a,!0));const c={attributes:!1,childList:!0,subtree:!0},u=new MutationObserver((async(e,t)=>{i=!0,s&&(clearTimeout(s),s=null),s=setTimeout((()=>{i=!1}),200)}));document.body&&u.observe(document.body,c)}))}()})(); \ No newline at end of file diff --git a/test-build-firefox/manifest.json b/test-build-firefox/manifest.json index 080126f..2fb4186 100644 --- a/test-build-firefox/manifest.json +++ b/test-build-firefox/manifest.json @@ -1,6 +1,6 @@ { "name": "Snyk API & Web Sequence Recorder", - "version": "1.2.0", + "version": "1.2.1", "browser_specific_settings": { "gecko": { "id": "sequence-recorder@probely.com", diff --git a/test-build/contentScript.bundle.js b/test-build/contentScript.bundle.js index 9a6eafe..56cf190 100644 --- a/test-build/contentScript.bundle.js +++ b/test-build/contentScript.bundle.js @@ -1 +1 @@ -(()=>{"use strict";let e,t;function n(n,r){if(n.nodeType!==Node.ELEMENT_NODE)throw new Error("Can't generate CSS selector for non-element node type.");if("html"===n.tagName.toLowerCase())return"html";const i={root:document.body,idName:e=>!0,className:e=>!0,tagName:e=>!0,attr:(e,t)=>!1,seedMinLength:1,optimizedMinLength:2,threshold:1e3,maxNumberOfTries:1e4};e={...i,...r},t=function(e,t){if(e.nodeType===Node.DOCUMENT_NODE)return e;if(e===t.root)return e.ownerDocument;return e}(e.root,i);let a=o(n,"all",(()=>o(n,"two",(()=>o(n,"one",(()=>o(n,"none")))))));if(a){const e=w(v(a,n));return e.length>0&&(a=e[0]),l(a)}throw new Error("Selector was not found.")}function o(t,n,o){let l=null,i=[],a=t,g=0;for(;a;){let t=p(s(a))||p(...c(a))||p(...u(a))||p(f(a))||[{name:"*",penalty:3}];const y=d(a);if("all"==n)y&&(t=t.concat(t.filter(h).map((e=>m(e,y)))));else if("two"==n)t=t.slice(0,1),y&&(t=t.concat(t.filter(h).map((e=>m(e,y)))));else if("one"==n){const[e]=t=t.slice(0,1);y&&h(e)&&(t=[m(e,y)])}else"none"==n&&(t=[{name:"*",penalty:3}],y&&(t=[m(t[0],y)]));for(let e of t)e.level=g;if(i.push(t),i.length>=e.seedMinLength&&(l=r(i,o),l))break;a=a.parentElement,g++}return l||(l=r(i,o)),!l&&o?o():l}function r(t,n){const o=w(y(t));if(o.length>e.threshold)return n?n():null;for(let e of o)if(a(e))return e;return null}function l(e){let t=e[0],n=t.name;for(let o=1;o ${n}`:`${e[o].name} ${n}`,t=e[o]}return n}function i(e){return e.map((e=>e.penalty)).reduce(((e,t)=>e+t),0)}function a(e){const n=l(e);switch(t.querySelectorAll(n).length){case 0:throw new Error(`Can't select any node with this selector: ${n}`);case 1:return!0;default:return!1}}function s(t){const n=t.getAttribute("id");return n&&e.idName(n)?{name:"#"+CSS.escape(n),penalty:0}:null}function c(t){const n=Array.from(t.attributes).filter((t=>e.attr(t.name,t.value)));return n.map((e=>({name:`[${CSS.escape(e.name)}="${CSS.escape(e.value)}"]`,penalty:.5})))}function u(t){return Array.from(t.classList).filter(e.className).map((e=>({name:"."+CSS.escape(e),penalty:1})))}function f(t){const n=t.tagName.toLowerCase();return e.tagName(n)?{name:n,penalty:2}:null}function d(e){const t=e.parentNode;if(!t)return null;let n=t.firstChild;if(!n)return null;let o=0;for(;n&&(n.nodeType===Node.ELEMENT_NODE&&o++,n!==e);)n=n.nextSibling;return o}function m(e,t){return{name:e.name+`:nth-child(${t})`,penalty:e.penalty+1}}function h(e){return"html"!==e.name&&!e.name.startsWith("#")}function p(...e){const t=e.filter(g);return t.length>0?t:null}function g(e){return null!=e}function*y(e,t=[]){if(e.length>0)for(let n of e[0])yield*y(e.slice(1,e.length),t.concat(n));else yield t}function w(e){return[...e].sort(((e,t)=>i(e)-i(t)))}function*v(t,n,o={counter:0,visited:new Map}){if(t.length>2&&t.length>e.optimizedMinLength)for(let r=1;re.maxNumberOfTries)return;o.counter+=1;const i=[...t];i.splice(r,1);const s=l(i);if(o.visited.has(s))return;a(i)&&b(i,n)&&(yield i,o.visited.set(s,!0),yield*v(i,n,o))}}function b(e,n){return t.querySelector(l(e))===n}function N(e,t){let n="",o=null,r=!1;try{if(o=e.nodeName&&"string"==typeof e.nodeName?e.nodeName.toLowerCase():null,!o)return null;n=`${o}`,e.getAttribute("id")&&(n=`${n}#${CSS.escape(e.getAttribute("id"))}`,r=!0);const t=["data-test-id","data-testid","data-test","data-cy"];if(e.matches(t.map((e=>`[${e}]`)).join(",")))for(const o of t){const t=e.getAttribute(o);if(t){n=`${n}[${o}="${CSS.escape(t)}"]`;break}}if(["input","button","textarea","select","option"].includes(o)){e.getAttribute("type")&&(n=`${n}[type="${CSS.escape(e.getAttribute("type"))}"]`),e.getAttribute("name")&&(n=`${n}[name="${CSS.escape(e.getAttribute("name"))}"]`);const t=e.closest("form");if(t){let e="form";t.getAttribute("id")&&(e=`${e}#${CSS.escape(t.getAttribute("id"))}`),n=`${e} ${n}`}}const l=e.getAttribute("aria-label");if(l&&!r&&(n=`${n}[aria-label="${CSS.escape(l)}"]`),n){const t=e.closest("body");if(t)try{1!==t.querySelectorAll(n).length&&(n="")}catch(e){n=""}}}catch(e){}return n}function E(e,t){let n,o=e,r=[];for(;o;){let e=0,n=o.previousElementSibling;for(;n;)n.nodeName===o.nodeName&&e++,n=n.previousElementSibling;let l=o.nodeName.toLowerCase();e>0&&(l=l+"["+(e+1)+"]"),o!==t&&r.unshift(l),o=o.parentNode}if(n="/"+r.join("/"),function(e,t){const n=t.evaluate(e,t,null,XPathResult.ANY_TYPE,null),o=n.iterateNext();return o}(n,t)===e)return n}const S={},C={keydown:null,return:null,blur:null,change:null,click:null,dblclick:null,contextmenu:null,focus:null,mouseover:null,mouseout:null};let A=!1,$=null,k=null;const L=new WeakMap;function T(e){const t=e.value;return t&&t.trim()?t:L.get(e)||t}function x(e){const t=e.value;return!(t&&t.trim())&&L.has(e)}function M(e,t){const n=["focus","highlight","editable","caret"],o=Array.from(e.classList||[]).filter((e=>{const t=e.toLowerCase();return!n.some((e=>t.includes(e)))&&!/^[0-9]/.test(e)}));for(const n of o){const o="."+n;try{const n=t.querySelectorAll(o);if(1===n.length&&n[0]===e)return o}catch(e){}}return null}function O(e,t){let n;var o;let r,l;function i(e,t,o){let l=null;const i=[];let s=e,c=0;for(;s&&s!==r.root.parentElement;){let e=w(f(s))||w(...d(s))||w(...m(s))||w(h(s))||[{name:"*",penalty:3}];const u=p(s);if(t===n.All)u&&(e=e.concat(e.filter(y).map((e=>g(e,u)))));else if(t===n.Two)e=e.slice(0,1),u&&(e=e.concat(e.filter(y).map((e=>g(e,u)))));else if(t===n.One){const[t]=e=e.slice(0,1);u&&y(t)&&(e=[g(t,u)])}for(const t of e)t.level=c;if(i.push(e),i.length>=r.seedMinLength&&(l=a(i,o),l))break;s=s.parentElement,c++}return l||(l=a(i,o)),l}function a(e,t){const n=N(b(e));if(n.length>r.threshold)return t?t():null;for(const e of n)if(u(e))return e;return null}function s(e){let t=e[0],n=t.name;for(let o=1;o ${n}`:`${e[o].name} ${n}`,t=e[o]}return n}function c(e){return e.map((e=>e.penalty)).reduce(((e,t)=>e+t),0)}function u(e){switch(l.querySelectorAll(s(e)).length){case 0:throw new Error(`Can't select any node with this selector: ${s(e)}`);case 1:return!0;default:return!1}}function f(e){const t=e.getAttribute("id");return t&&r.idName(t)?{name:`#${k(t,{isIdentifier:!0})}`,penalty:0}:null}function d(e){return Array.from(e.attributes).filter((e=>r.attr(e.name,e.value))).map((e=>({name:"["+k(e.name,{isIdentifier:!0})+'="'+k(e.value)+'"]',penalty:.5})))}function m(e){return Array.from(e.classList).filter(r.className).map((e=>({name:"."+k(e,{isIdentifier:!0}),penalty:1})))}function h(e){const t=e.tagName.toLowerCase();return r.tagName(t)?{name:t,penalty:2}:null}function p(e){const t=e.parentNode;if(!t)return null;let n=t.firstChild;if(!n)return null;let o=0;for(;n&&(n.nodeType===Node.ELEMENT_NODE&&o++,n!==e);)n=n.nextSibling;return o}function g(e,t){return{name:e.name+`:nth-child(${t})`,penalty:e.penalty+1}}function y(e){return"html"!==e.name&&!e.name.startsWith("#")}function w(...e){const t=e.filter(v);return 0c(e)-c(t)))}function E(e,t){return l.querySelector(s(e))===t}(o=n||(n={}))[o.All=0]="All",o[o.Two=1]="Two",o[o.One=2]="One";const S=/[ -,\.\/:-@\[-\^`\{-~]/,C=/[ -,\.\/:-@\[\]\^`\{-~]/,A=/(^|\\+)?(\\[A-F0-9]{1,6})\x20(?![a-fA-F0-9\x20])/g,$={escapeEverything:!1,isIdentifier:!1,quotes:"single",wrap:!1};function k(e,t={}){const n=Object.assign(Object.assign({},$),t);"single"!==n.quotes&&"double"!==n.quotes&&(n.quotes="single");const o="double"==n.quotes?'"':"'",r=n.isIdentifier,l=e.charAt(0);let i="",a=0;for(const t=e.length;ac||126=c&&a!0,className:()=>!0,tagName:()=>!0,attr:()=>!1,seedMinLength:1,optimizedMinLength:2,threshold:1e3,maxNumberOfTries:1e4};r=Object.assign(Object.assign({},L),t),l=function(e,t){return e.nodeType===Node.DOCUMENT_NODE?e:e===t.root?e.ownerDocument:e}(r.root,L);let T=i(e,n.All,(()=>i(e,n.Two,(()=>i(e,n.One)))));if(T){const t=N(function*e(t,n,o={counter:0,visited:new Map}){if(2r.optimizedMinLength)for(let l=1;lr.maxNumberOfTries)return;o.counter+=1;const i=[...t];i.splice(l,1);const a=s(i);if(o.visited.has(a))return;u(i)&&E(i,n)&&(yield i,o.visited.set(a,!0),yield*e(i,n,o))}}(T,e));return 0{if(!l.isRecording)return;let i=!1,a=null;function s(e){e&&"mouseover"===e.type&&!i||function(e,t,o,r){let l=!1,i=null,a=null;e&&e.composed&&e.composedPath&&(a=e.composedPath());let s=-1;a&&a.length>0&&(s=a.findIndex((e=>e instanceof ShadowRoot))),i=s>-1?a[0]:e.target;const c=e.type;let u=null,f=null;if(!i||!i.getAttribute)return;u=i.nodeName.toLowerCase(),f=i.getAttribute("type");let d=null,m=null;try{m=function(e){let t=null;try{if(t=e.nodeName&&"string"==typeof e.nodeName?e.nodeName.toLowerCase():null,!t)return e;if(["input","button","a","textarea","select","option","progress"].includes(t))return e;const n=e.closest("button,a");if(n)return n;const o=e.closest("svg");o&&(e=o);const r=["data-test-id","data-testid","data-test","data-cy"];if(e.matches(r.map((e=>`[${e}]`)).join(",")))return e;if(e.parentNode.matches(r.map((e=>`[${e}]`)).join(",")))return e.parentNode}catch(e){}return e}(i),d=N(m)}catch(e){}if(!d)try{d=n(m,{root:t,idName:e=>!/^[0-9]+.*/i.test(e),className:e=>!e.includes("focus")&&!e.includes("highlight")&&!/^[0-9]+.*/i.test(e)})}catch(e){}if(d&&"html"===d.toLowerCase())return;let h=null;try{h=E(m,t)}catch(e){}s>-1&&(h="/html/node/shadow");let p={timestamp:(new Date).getTime(),css:d||i,xpath:h||""},g={};if("click"===c){if(C.click=i,$&&$.element!==i&&r){const e=x($.element),n={...$.oEventBase,type:e?"bfill_value":"fill_value",value:T($.element),frame:$.frame};if(e){const e=M($.element,t);e&&(n.css=e)}r({messageType:"events",event:{...n}}),L.delete($.element),k=$.element,$=null}if(!(C.return!==C.change||i===C.return||"input"!==u&&"button"!==u||"submit"!==f&&"image"!==f||null===C.return))return;if("input"===u&&("checkbox"===f||"radio"===f))return;if("label"===u){const e=i.getAttribute("for");if(e&&document.getElementById(e))return}let l="click";if(function(e){if("canvas"===e.nodeName.toLowerCase())return!0;if(e.shadowRoot)try{if(e.shadowRoot.querySelector("canvas"))return!0}catch(e){}for(const t of e.children||[])if(t.shadowRoot)try{if(t.shadowRoot.querySelector("canvas"))return!0}catch(e){}return!1}(i)){const t=i.getBoundingClientRect(),n={x:e.clientX-t.left,y:e.clientY-t.top,width:t.width,height:t.height};p={...p,coords:n},l="bclick"}if(g={...p,type:l,value:(i.value||i.textContent||"").trim().substr(0,20).replace(/\n/gi,""),frame:o},"bclick"===l&&s>-1&&a){const e=a[s].host;if(e){let o=null;try{o=N(e)}catch(e){}if(!o)try{o=n(e,{root:t,idName:e=>!/^[0-9]+.*/i.test(e),className:e=>!e.includes("focus")&&!e.includes("highlight")&&!/^[0-9]+.*/i.test(e)})}catch(e){}o&&(g.shadow_host_css=o)}}}else if("dblclick"===c)C.dblclick=i,g={...p,type:"dblclick",value:(i.value||i.textContent||"").trim().substr(0,20).replace(/\n/gi,""),frame:o};else if("contextmenu"===c)C.contextmenu=i,g={...p,type:"contextmenu",value:(i.value||i.textContent||"").trim().substr(0,20).replace(/\n/gi,""),frame:o};else if("focus"===c);else if("mouseover"===c)A&&(clearTimeout(A),A=!1),A=setTimeout((()=>{A=!1,C.mouseover=i,g={...p,type:"mouseover",value:(i.value||i.textContent||"").trim().substr(0,20).replace(/\n/gi,""),frame:o},g&&g.type&&r&&r({messageType:"events",event:{...g}})}),500);else if("mouseout"===c);else if("keydown"===c){if(C.keydown=i,["input","textarea"].indexOf(u)>-1)if(S[i]=i.value,$={element:i,oEventBase:{...p},frame:o},e.key&&1===e.key.length){const t=L.get(i)||"";L.set(i,t+e.key)}else if("Backspace"===e.key){const e=L.get(i)||"";e.length>0&&L.set(i,e.slice(0,-1))}if("input"===u&&13===e.keyCode){l=!0,C.return=i;const e=x(i);if(g={...p,type:e?"bfill_value":"fill_value",value:T(i),frame:o},e){const e=M(i,t);e&&(g.css=e)}L.delete(i)}}else if("blur"===c){if(C.blur=i,i===k)return void(k=null);if($&&$.element===i&&($=null),["input","textarea"].indexOf(u)>-1){if(S[i]=i.value,i===C.return)return void(C.return=null);if("input"===u&&("submit"===i.type||"button"===i.type||"image"===i.type))return;const e=x(i);if(g={...p,type:e?"bfill_value":"fill_value",value:T(i),frame:o},e){const e=M(i,t);e&&(g.css=e)}L.delete(i)}}else if("change"===c)if(C.change=i,"input"===u)"checkbox"!==f&&"radio"!==f||(g={...p,type:"change",subtype:"check",checked:i.checked,frame:o});else if("select"===u)if(i.multiple){const e=[];for(let t=0;t{window!==window.top?window.parent.postMessage({source:"event-from-iframe",obj:{...e},framePath:[]},"*"):chrome.runtime.sendMessage(e)}))}window===window.top&&window.addEventListener("message",(e=>{if(e.data&&e.data.source&&"event-from-iframe"===e.data.source){const t=document.querySelectorAll("iframe, frame");let n=!1;for(const o of t)if(o.contentWindow===e.source){n=!0;break}if(!n)return;const o={...e.data.obj},r=e.data.framePath||[];for(const n of t)if(n.contentWindow===e.source){let e=null;try{e=N(n)}catch(e){}if(!e)try{e=O(n,{root:window.document,idName:e=>!/^[0-9]+.*/i.test(e),className:e=>!e.includes("focus")&&!e.includes("highlight")&&!/^[0-9]+.*/i.test(e)})}catch(e){}if(e&&o.event){const t=[e,...r];o.event.frame=t.join(" >>> "),chrome.runtime.sendMessage(o)}break}}})),window!==window.top&&window.addEventListener("message",(e=>{if(e.data&&e.data.source&&"event-from-iframe"===e.data.source){const t=document.querySelectorAll("iframe, frame");let n=!1;for(const o of t)if(o.contentWindow===e.source){n=!0;break}if(!n)return;const o=e.data.framePath||[];for(const n of t)if(n.contentWindow===e.source){let t=null;try{t=N(n)}catch(e){}if(!t)try{t=O(n,{root:window.document,idName:e=>!/^[0-9]+.*/i.test(e),className:e=>!e.includes("focus")&&!e.includes("highlight")&&!/^[0-9]+.*/i.test(e)})}catch(e){}t&&o.push(t),window.parent.postMessage({source:"event-from-iframe",obj:e.data.obj,framePath:o},"*");break}}})),l.isRecording&&(t=!0,e=document.title,function(){if(!t)return document.title=`${e}`,r=!1,void(o&&(clearInterval(o),o=!1));o=setInterval((()=>{r?(document.title=`${e}`,r=!1):(document.title=`🔴 ${e}`,r=!0)}),1e3)}(),window===window.top&&chrome.runtime.sendMessage({messageType:"events",event:{type:"goto",timestamp:(new Date).getTime(),windowWidth:window.innerWidth,windowHeight:window.innerHeight,url:window.location.href}}),document.addEventListener("click",s,!0),document.addEventListener("mouseover",s,!0),document.addEventListener("dblclick",s,!0),document.addEventListener("contextmenu",s,!0),document.addEventListener("keydown",s,!0),document.addEventListener("blur",s,!0),document.addEventListener("change",s,!0));const c={attributes:!1,childList:!0,subtree:!0},u=new MutationObserver((async(e,t)=>{i=!0,a&&(clearTimeout(a),a=null),a=setTimeout((()=>{i=!1}),200)}));document.body&&u.observe(document.body,c)}))}()})(); \ No newline at end of file +(()=>{"use strict";let e,t;function n(n,r){if(n.nodeType!==Node.ELEMENT_NODE)throw new Error("Can't generate CSS selector for non-element node type.");if("html"===n.tagName.toLowerCase())return"html";const i={root:document.body,idName:e=>!0,className:e=>!0,tagName:e=>!0,attr:(e,t)=>!1,seedMinLength:1,optimizedMinLength:2,threshold:1e3,maxNumberOfTries:1e4};e={...i,...r},t=function(e,t){if(e.nodeType===Node.DOCUMENT_NODE)return e;if(e===t.root)return e.ownerDocument;return e}(e.root,i);let s=o(n,"all",(()=>o(n,"two",(()=>o(n,"one",(()=>o(n,"none")))))));if(s){const e=w(v(s,n));return e.length>0&&(s=e[0]),l(s)}throw new Error("Selector was not found.")}function o(t,n,o){let l=null,i=[],s=t,g=0;for(;s;){let t=p(a(s))||p(...c(s))||p(...u(s))||p(f(s))||[{name:"*",penalty:3}];const y=d(s);if("all"==n)y&&(t=t.concat(t.filter(h).map((e=>m(e,y)))));else if("two"==n)t=t.slice(0,1),y&&(t=t.concat(t.filter(h).map((e=>m(e,y)))));else if("one"==n){const[e]=t=t.slice(0,1);y&&h(e)&&(t=[m(e,y)])}else"none"==n&&(t=[{name:"*",penalty:3}],y&&(t=[m(t[0],y)]));for(let e of t)e.level=g;if(i.push(t),i.length>=e.seedMinLength&&(l=r(i,o),l))break;s=s.parentElement,g++}return l||(l=r(i,o)),!l&&o?o():l}function r(t,n){const o=w(y(t));if(o.length>e.threshold)return n?n():null;for(let e of o)if(s(e))return e;return null}function l(e){let t=e[0],n=t.name;for(let o=1;o ${n}`:`${e[o].name} ${n}`,t=e[o]}return n}function i(e){return e.map((e=>e.penalty)).reduce(((e,t)=>e+t),0)}function s(e){const n=l(e);switch(t.querySelectorAll(n).length){case 0:throw new Error(`Can't select any node with this selector: ${n}`);case 1:return!0;default:return!1}}function a(t){const n=t.getAttribute("id");return n&&e.idName(n)?{name:"#"+CSS.escape(n),penalty:0}:null}function c(t){const n=Array.from(t.attributes).filter((t=>e.attr(t.name,t.value)));return n.map((e=>({name:`[${CSS.escape(e.name)}="${CSS.escape(e.value)}"]`,penalty:.5})))}function u(t){return Array.from(t.classList).filter(e.className).map((e=>({name:"."+CSS.escape(e),penalty:1})))}function f(t){const n=t.tagName.toLowerCase();return e.tagName(n)?{name:n,penalty:2}:null}function d(e){const t=e.parentNode;if(!t)return null;let n=t.firstChild;if(!n)return null;let o=0;for(;n&&(n.nodeType===Node.ELEMENT_NODE&&o++,n!==e);)n=n.nextSibling;return o}function m(e,t){return{name:e.name+`:nth-child(${t})`,penalty:e.penalty+1}}function h(e){return"html"!==e.name&&!e.name.startsWith("#")}function p(...e){const t=e.filter(g);return t.length>0?t:null}function g(e){return null!=e}function*y(e,t=[]){if(e.length>0)for(let n of e[0])yield*y(e.slice(1,e.length),t.concat(n));else yield t}function w(e){return[...e].sort(((e,t)=>i(e)-i(t)))}function*v(t,n,o={counter:0,visited:new Map}){if(t.length>2&&t.length>e.optimizedMinLength)for(let r=1;re.maxNumberOfTries)return;o.counter+=1;const i=[...t];i.splice(r,1);const a=l(i);if(o.visited.has(a))return;s(i)&&b(i,n)&&(yield i,o.visited.set(a,!0),yield*v(i,n,o))}}function b(e,n){return t.querySelector(l(e))===n}function N(e,t){let n="",o=null,r=!1;try{if(o=e.nodeName&&"string"==typeof e.nodeName?e.nodeName.toLowerCase():null,!o)return null;n=`${o}`,e.getAttribute("id")&&(n=`${n}#${CSS.escape(e.getAttribute("id"))}`,r=!0);const t=["data-test-id","data-testid","data-test","data-cy"];if(e.matches(t.map((e=>`[${e}]`)).join(",")))for(const o of t){const t=e.getAttribute(o);if(t){n=`${n}[${o}="${CSS.escape(t)}"]`;break}}if(["input","button","textarea","select","option"].includes(o)){e.getAttribute("type")&&(n=`${n}[type="${CSS.escape(e.getAttribute("type"))}"]`),e.getAttribute("name")&&(n=`${n}[name="${CSS.escape(e.getAttribute("name"))}"]`);const t=e.closest("form");if(t){let e="form";t.getAttribute("id")&&(e=`${e}#${CSS.escape(t.getAttribute("id"))}`),n=`${e} ${n}`}}const l=e.getAttribute("aria-label");if(l&&!r&&(n=`${n}[aria-label="${CSS.escape(l)}"]`),n){const t=e.closest("body");if(t)try{1!==t.querySelectorAll(n).length&&(n="")}catch(e){n=""}}}catch(e){}return n}function E(e,t){let n,o=e,r=[];for(;o;){let e=0,n=o.previousElementSibling;for(;n;)n.nodeName===o.nodeName&&e++,n=n.previousElementSibling;let l=o.nodeName.toLowerCase();e>0&&(l=l+"["+(e+1)+"]"),o!==t&&r.unshift(l),o=o.parentNode}if(n="/"+r.join("/"),function(e,t){const n=t.evaluate(e,t,null,XPathResult.ANY_TYPE,null),o=n.iterateNext();return o}(n,t)===e)return n}const S={},C={keydown:null,return:null,blur:null,change:null,click:null,dblclick:null,contextmenu:null,focus:null,mouseover:null,mouseout:null};let k=!1,A=null,L=null;const $=new WeakMap;function x(e){const t=e.value;return t&&t.trim()?t:$.get(e)||t}function T(e){const t=e.value;return!(t&&t.trim())&&$.has(e)}function M(e,t){const n=["focus","highlight","editable","caret"],o=Array.from(e.classList||[]).filter((e=>{const t=e.toLowerCase();return!n.some((e=>t.includes(e)))&&!/^[0-9]/.test(e)}));for(const n of o){const o="."+n;try{const n=t.querySelectorAll(o);if(1===n.length&&n[0]===e)return o}catch(e){}}return null}function O(e,t){let n;var o;let r,l;function i(e,t,o){let l=null;const i=[];let a=e,c=0;for(;a&&a!==r.root.parentElement;){let e=w(f(a))||w(...d(a))||w(...m(a))||w(h(a))||[{name:"*",penalty:3}];const u=p(a);if(t===n.All)u&&(e=e.concat(e.filter(y).map((e=>g(e,u)))));else if(t===n.Two)e=e.slice(0,1),u&&(e=e.concat(e.filter(y).map((e=>g(e,u)))));else if(t===n.One){const[t]=e=e.slice(0,1);u&&y(t)&&(e=[g(t,u)])}for(const t of e)t.level=c;if(i.push(e),i.length>=r.seedMinLength&&(l=s(i,o),l))break;a=a.parentElement,c++}return l||(l=s(i,o)),l}function s(e,t){const n=N(b(e));if(n.length>r.threshold)return t?t():null;for(const e of n)if(u(e))return e;return null}function a(e){let t=e[0],n=t.name;for(let o=1;o ${n}`:`${e[o].name} ${n}`,t=e[o]}return n}function c(e){return e.map((e=>e.penalty)).reduce(((e,t)=>e+t),0)}function u(e){switch(l.querySelectorAll(a(e)).length){case 0:throw new Error(`Can't select any node with this selector: ${a(e)}`);case 1:return!0;default:return!1}}function f(e){const t=e.getAttribute("id");return t&&r.idName(t)?{name:`#${L(t,{isIdentifier:!0})}`,penalty:0}:null}function d(e){return Array.from(e.attributes).filter((e=>r.attr(e.name,e.value))).map((e=>({name:"["+L(e.name,{isIdentifier:!0})+'="'+L(e.value)+'"]',penalty:.5})))}function m(e){return Array.from(e.classList).filter(r.className).map((e=>({name:"."+L(e,{isIdentifier:!0}),penalty:1})))}function h(e){const t=e.tagName.toLowerCase();return r.tagName(t)?{name:t,penalty:2}:null}function p(e){const t=e.parentNode;if(!t)return null;let n=t.firstChild;if(!n)return null;let o=0;for(;n&&(n.nodeType===Node.ELEMENT_NODE&&o++,n!==e);)n=n.nextSibling;return o}function g(e,t){return{name:e.name+`:nth-child(${t})`,penalty:e.penalty+1}}function y(e){return"html"!==e.name&&!e.name.startsWith("#")}function w(...e){const t=e.filter(v);return 0c(e)-c(t)))}function E(e,t){return l.querySelector(a(e))===t}(o=n||(n={}))[o.All=0]="All",o[o.Two=1]="Two",o[o.One=2]="One";const S=/[ -,\.\/:-@\[-\^`\{-~]/,C=/[ -,\.\/:-@\[\]\^`\{-~]/,k=/(^|\\+)?(\\[A-F0-9]{1,6})\x20(?![a-fA-F0-9\x20])/g,A={escapeEverything:!1,isIdentifier:!1,quotes:"single",wrap:!1};function L(e,t={}){const n=Object.assign(Object.assign({},A),t);"single"!==n.quotes&&"double"!==n.quotes&&(n.quotes="single");const o="double"==n.quotes?'"':"'",r=n.isIdentifier,l=e.charAt(0);let i="",s=0;for(const t=e.length;sc||126=c&&s!0,className:()=>!0,tagName:()=>!0,attr:()=>!1,seedMinLength:1,optimizedMinLength:2,threshold:1e3,maxNumberOfTries:1e4};r=Object.assign(Object.assign({},$),t),l=function(e,t){return e.nodeType===Node.DOCUMENT_NODE?e:e===t.root?e.ownerDocument:e}(r.root,$);let x=i(e,n.All,(()=>i(e,n.Two,(()=>i(e,n.One)))));if(x){const t=N(function*e(t,n,o={counter:0,visited:new Map}){if(2r.optimizedMinLength)for(let l=1;lr.maxNumberOfTries)return;o.counter+=1;const i=[...t];i.splice(l,1);const s=a(i);if(o.visited.has(s))return;u(i)&&E(i,n)&&(yield i,o.visited.set(s,!0),yield*e(i,n,o))}}(x,e));return 0{if(!l.isRecording)return;let i=!1,s=null;function a(e){e&&"mouseover"===e.type&&!i||function(e,t,o,r){let l=!1,i=null,s=null;e&&e.composed&&e.composedPath&&(s=e.composedPath());let a=-1;s&&s.length>0&&(a=s.findIndex((e=>e instanceof ShadowRoot))),i=a>-1?s[0]:e.target;const c=e.type;let u=null,f=null;if(!i||!i.getAttribute)return;u=i.nodeName.toLowerCase(),f=i.getAttribute("type");let d=null,m=null;try{m=function(e){let t=null;try{if(t=e.nodeName&&"string"==typeof e.nodeName?e.nodeName.toLowerCase():null,!t)return e;if(["input","button","a","textarea","select","option","progress"].includes(t))return e;const n=e.closest("button,a");if(n)return n;const o=e.closest("svg");o&&(e=o);const r=["data-test-id","data-testid","data-test","data-cy"];if(e.matches(r.map((e=>`[${e}]`)).join(",")))return e;if(e.parentNode.matches(r.map((e=>`[${e}]`)).join(",")))return e.parentNode}catch(e){}return e}(i),d=N(m)}catch(e){}if(!d)try{d=n(m,{root:t,idName:e=>!/^[0-9]+.*/i.test(e),className:e=>!e.includes("focus")&&!e.includes("highlight")&&!/^[0-9]+.*/i.test(e)})}catch(e){}if(d&&"html"===d.toLowerCase())return;let h=null;try{h=E(m,t)}catch(e){}a>-1&&(h="/html/node/shadow");let p={timestamp:(new Date).getTime(),css:d||i,xpath:h||""},g={};if("click"===c){if(C.click=i,A&&A.element!==i&&r){const e=T(A.element),n={...A.oEventBase,type:e?"bfill_value":"fill_value",value:x(A.element),frame:A.frame};if(e){const e=M(A.element,t);e&&(n.css=e)}r({messageType:"events",event:{...n}}),$.delete(A.element),L=A.element,A=null}if(!(C.return!==C.change||i===C.return||"input"!==u&&"button"!==u||"submit"!==f&&"image"!==f||null===C.return))return;if("input"===u&&("checkbox"===f||"radio"===f))return;const l=i.closest&&i.closest("label");if(l){const e=l.getAttribute("for");if(e){const t=document.getElementById(e);if(t&&"input"===t.nodeName.toLowerCase()&&("checkbox"===t.type||"radio"===t.type))return}if(l.querySelector('input[type="checkbox"], input[type="radio"]'))return}let c="click";if(function(e){if("canvas"===e.nodeName.toLowerCase())return!0;if(e.shadowRoot)try{if(e.shadowRoot.querySelector("canvas"))return!0}catch(e){}for(const t of e.children||[])if(t.shadowRoot)try{if(t.shadowRoot.querySelector("canvas"))return!0}catch(e){}return!1}(i)){const t=i.getBoundingClientRect(),n={x:e.clientX-t.left,y:e.clientY-t.top,width:t.width,height:t.height};p={...p,coords:n},c="bclick"}if(g={...p,type:c,value:(i.value||i.textContent||"").trim().substr(0,20).replace(/\n/gi,""),frame:o},"bclick"===c&&a>-1&&s){const e=s[a].host;if(e){let o=null;try{o=N(e)}catch(e){}if(!o)try{o=n(e,{root:t,idName:e=>!/^[0-9]+.*/i.test(e),className:e=>!e.includes("focus")&&!e.includes("highlight")&&!/^[0-9]+.*/i.test(e)})}catch(e){}o&&(g.shadow_host_css=o)}}}else if("dblclick"===c)C.dblclick=i,g={...p,type:"dblclick",value:(i.value||i.textContent||"").trim().substr(0,20).replace(/\n/gi,""),frame:o};else if("contextmenu"===c)C.contextmenu=i,g={...p,type:"contextmenu",value:(i.value||i.textContent||"").trim().substr(0,20).replace(/\n/gi,""),frame:o};else if("focus"===c);else if("mouseover"===c)k&&(clearTimeout(k),k=!1),k=setTimeout((()=>{k=!1,C.mouseover=i,g={...p,type:"mouseover",value:(i.value||i.textContent||"").trim().substr(0,20).replace(/\n/gi,""),frame:o},g&&g.type&&r&&r({messageType:"events",event:{...g}})}),500);else if("mouseout"===c);else if("keydown"===c){if(C.keydown=i,["input","textarea"].indexOf(u)>-1)if(S[i]=i.value,A={element:i,oEventBase:{...p},frame:o},e.key&&1===e.key.length){const t=$.get(i)||"";$.set(i,t+e.key)}else if("Backspace"===e.key){const e=$.get(i)||"";e.length>0&&$.set(i,e.slice(0,-1))}if("input"===u&&13===e.keyCode){l=!0,C.return=i;const e=T(i);if(g={...p,type:e?"bfill_value":"fill_value",value:x(i),frame:o},e){const e=M(i,t);e&&(g.css=e)}$.delete(i)}}else if("blur"===c){if(C.blur=i,i===L)return void(L=null);if(A&&A.element===i&&(A=null),["input","textarea"].indexOf(u)>-1){if(S[i]=i.value,i===C.return)return void(C.return=null);if("input"===u&&("submit"===i.type||"button"===i.type||"image"===i.type))return;const e=T(i);if(g={...p,type:e?"bfill_value":"fill_value",value:x(i),frame:o},e){const e=M(i,t);e&&(g.css=e)}$.delete(i)}}else if("change"===c)if(C.change=i,"input"===u)"checkbox"!==f&&"radio"!==f||(g={...p,type:"change",subtype:"check",checked:i.checked,frame:o});else if("select"===u)if(i.multiple){const e=[];for(let t=0;t{window!==window.top?window.parent.postMessage({source:"event-from-iframe",obj:{...e},framePath:[]},"*"):chrome.runtime.sendMessage(e)}))}window===window.top&&window.addEventListener("message",(e=>{if(e.data&&e.data.source&&"event-from-iframe"===e.data.source){const t=document.querySelectorAll("iframe, frame");let n=!1;for(const o of t)if(o.contentWindow===e.source){n=!0;break}if(!n)return;const o={...e.data.obj},r=e.data.framePath||[];for(const n of t)if(n.contentWindow===e.source){let e=null;try{e=N(n)}catch(e){}if(!e)try{e=O(n,{root:window.document,idName:e=>!/^[0-9]+.*/i.test(e),className:e=>!e.includes("focus")&&!e.includes("highlight")&&!/^[0-9]+.*/i.test(e)})}catch(e){}if(e&&o.event){const t=[e,...r];o.event.frame=t.join(" >>> "),chrome.runtime.sendMessage(o)}break}}})),window!==window.top&&window.addEventListener("message",(e=>{if(e.data&&e.data.source&&"event-from-iframe"===e.data.source){const t=document.querySelectorAll("iframe, frame");let n=!1;for(const o of t)if(o.contentWindow===e.source){n=!0;break}if(!n)return;const o=e.data.framePath||[];for(const n of t)if(n.contentWindow===e.source){let t=null;try{t=N(n)}catch(e){}if(!t)try{t=O(n,{root:window.document,idName:e=>!/^[0-9]+.*/i.test(e),className:e=>!e.includes("focus")&&!e.includes("highlight")&&!/^[0-9]+.*/i.test(e)})}catch(e){}t&&o.push(t),window.parent.postMessage({source:"event-from-iframe",obj:e.data.obj,framePath:o},"*");break}}})),l.isRecording&&(t=!0,e=document.title,function(){if(!t)return document.title=`${e}`,r=!1,void(o&&(clearInterval(o),o=!1));o=setInterval((()=>{r?(document.title=`${e}`,r=!1):(document.title=`🔴 ${e}`,r=!0)}),1e3)}(),window===window.top&&chrome.runtime.sendMessage({messageType:"events",event:{type:"goto",timestamp:(new Date).getTime(),windowWidth:window.innerWidth,windowHeight:window.innerHeight,url:window.location.href}}),document.addEventListener("click",a,!0),document.addEventListener("mouseover",a,!0),document.addEventListener("dblclick",a,!0),document.addEventListener("contextmenu",a,!0),document.addEventListener("keydown",a,!0),document.addEventListener("blur",a,!0),document.addEventListener("change",a,!0));const c={attributes:!1,childList:!0,subtree:!0},u=new MutationObserver((async(e,t)=>{i=!0,s&&(clearTimeout(s),s=null),s=setTimeout((()=>{i=!1}),200)}));document.body&&u.observe(document.body,c)}))}()})(); \ No newline at end of file diff --git a/test-build/manifest.json b/test-build/manifest.json index b64e930..b287239 100644 --- a/test-build/manifest.json +++ b/test-build/manifest.json @@ -1 +1 @@ -{"version":"1.2.0","manifest_version":3,"name":"Snyk API & Web Sequence Recorder","action":{"default_popup":"popup.html","default_icon":{"16":"icon-34.png","48":"icon-48.png"}},"icons":{"128":"icon-128.png"},"background":{"service_worker":"background.bundle.js"},"content_scripts":[{"matches":["http://*/*","https://*/*"],"js":["contentScript.bundle.js"],"css":["content.styles.css"],"run_at":"document_start","all_frames":true,"match_about_blank":true}],"web_accessible_resources":[{"resources":["content.styles.css","icon-128.png","icon-34.png"],"matches":[""]}],"permissions":["storage","activeTab"],"host_permissions":["http://*/*","https://*/*"]} \ No newline at end of file +{"version":"1.2.1","manifest_version":3,"name":"Snyk API & Web Sequence Recorder","action":{"default_popup":"popup.html","default_icon":{"16":"icon-34.png","48":"icon-48.png"}},"icons":{"128":"icon-128.png"},"background":{"service_worker":"background.bundle.js"},"content_scripts":[{"matches":["http://*/*","https://*/*"],"js":["contentScript.bundle.js"],"css":["content.styles.css"],"run_at":"document_start","all_frames":true,"match_about_blank":true}],"web_accessible_resources":[{"resources":["content.styles.css","icon-128.png","icon-34.png"],"matches":[""]}],"permissions":["storage","activeTab"],"host_permissions":["http://*/*","https://*/*"]} \ No newline at end of file From a2d258f7c907fdb6c46b9362243e3d09c3d83dec Mon Sep 17 00:00:00 2001 From: Claudio Gamboa Date: Fri, 19 Jun 2026 15:20:46 +0100 Subject: [PATCH 2/2] fix checkbox/radio handler --- package.json | 2 +- src/manifest-firefox.json | 2 +- src/pages/Content/modules/collectEvents.js | 25 +++++++++++++++------- test-build-firefox/contentScript.bundle.js | 2 +- test-build-firefox/manifest.json | 2 +- test-build/contentScript.bundle.js | 2 +- test-build/manifest.json | 2 +- 7 files changed, 23 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 568ff5d..2fbe0ae 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "snyk-api-and-web-record-sequence", - "version": "1.2.1", + "version": "1.2.2", "description": "Snyk API & Web Record login/sequence", "license": "MIT", "scripts": { diff --git a/src/manifest-firefox.json b/src/manifest-firefox.json index 2fb4186..559ce27 100755 --- a/src/manifest-firefox.json +++ b/src/manifest-firefox.json @@ -1,6 +1,6 @@ { "name": "Snyk API & Web Sequence Recorder", - "version": "1.2.1", + "version": "1.2.2", "browser_specific_settings": { "gecko": { "id": "sequence-recorder@probely.com", diff --git a/src/pages/Content/modules/collectEvents.js b/src/pages/Content/modules/collectEvents.js index 7487901..eef36db 100644 --- a/src/pages/Content/modules/collectEvents.js +++ b/src/pages/Content/modules/collectEvents.js @@ -201,17 +201,26 @@ export function interceptEvents(event, doc, ifrSelector, callback) { } const parentLabel = tgt.closest && tgt.closest('label'); if (parentLabel) { - const forAttr = parentLabel.getAttribute('for'); - if (forAttr) { - const forEl = document.getElementById(forAttr); - if (forEl && forEl.nodeName.toLowerCase() === 'input' && - (forEl.type === 'checkbox' || forEl.type === 'radio')) { + // Only suppress when the click is actually forwarded to the labeled control. + // Clicks on interactive descendants (links, buttons, other fields) are NOT + // forwarded by the browser and must still be recorded. + const interactiveHit = tgt.closest('a, button, input, select, textarea'); + const forwardsToControl = !interactiveHit || !parentLabel.contains(interactiveHit); + if (forwardsToControl) { + const forAttr = parentLabel.getAttribute('for'); + if (forAttr) { + const root = tgt.getRootNode(); + const lookup = root && root.getElementById ? root : document; // shadow-DOM safe + const forEl = lookup.getElementById(forAttr); + if (forEl && forEl.nodeName.toLowerCase() === 'input' && + (forEl.type === 'checkbox' || forEl.type === 'radio')) { + return; + } + } + if (parentLabel.querySelector('input[type="checkbox"], input[type="radio"]')) { return; } } - if (parentLabel.querySelector('input[type="checkbox"], input[type="radio"]')) { - return; - } } let typeStr = 'click'; if (isCanvasSurface(tgt)) { diff --git a/test-build-firefox/contentScript.bundle.js b/test-build-firefox/contentScript.bundle.js index 56cf190..328e00f 100644 --- a/test-build-firefox/contentScript.bundle.js +++ b/test-build-firefox/contentScript.bundle.js @@ -1 +1 @@ -(()=>{"use strict";let e,t;function n(n,r){if(n.nodeType!==Node.ELEMENT_NODE)throw new Error("Can't generate CSS selector for non-element node type.");if("html"===n.tagName.toLowerCase())return"html";const i={root:document.body,idName:e=>!0,className:e=>!0,tagName:e=>!0,attr:(e,t)=>!1,seedMinLength:1,optimizedMinLength:2,threshold:1e3,maxNumberOfTries:1e4};e={...i,...r},t=function(e,t){if(e.nodeType===Node.DOCUMENT_NODE)return e;if(e===t.root)return e.ownerDocument;return e}(e.root,i);let s=o(n,"all",(()=>o(n,"two",(()=>o(n,"one",(()=>o(n,"none")))))));if(s){const e=w(v(s,n));return e.length>0&&(s=e[0]),l(s)}throw new Error("Selector was not found.")}function o(t,n,o){let l=null,i=[],s=t,g=0;for(;s;){let t=p(a(s))||p(...c(s))||p(...u(s))||p(f(s))||[{name:"*",penalty:3}];const y=d(s);if("all"==n)y&&(t=t.concat(t.filter(h).map((e=>m(e,y)))));else if("two"==n)t=t.slice(0,1),y&&(t=t.concat(t.filter(h).map((e=>m(e,y)))));else if("one"==n){const[e]=t=t.slice(0,1);y&&h(e)&&(t=[m(e,y)])}else"none"==n&&(t=[{name:"*",penalty:3}],y&&(t=[m(t[0],y)]));for(let e of t)e.level=g;if(i.push(t),i.length>=e.seedMinLength&&(l=r(i,o),l))break;s=s.parentElement,g++}return l||(l=r(i,o)),!l&&o?o():l}function r(t,n){const o=w(y(t));if(o.length>e.threshold)return n?n():null;for(let e of o)if(s(e))return e;return null}function l(e){let t=e[0],n=t.name;for(let o=1;o ${n}`:`${e[o].name} ${n}`,t=e[o]}return n}function i(e){return e.map((e=>e.penalty)).reduce(((e,t)=>e+t),0)}function s(e){const n=l(e);switch(t.querySelectorAll(n).length){case 0:throw new Error(`Can't select any node with this selector: ${n}`);case 1:return!0;default:return!1}}function a(t){const n=t.getAttribute("id");return n&&e.idName(n)?{name:"#"+CSS.escape(n),penalty:0}:null}function c(t){const n=Array.from(t.attributes).filter((t=>e.attr(t.name,t.value)));return n.map((e=>({name:`[${CSS.escape(e.name)}="${CSS.escape(e.value)}"]`,penalty:.5})))}function u(t){return Array.from(t.classList).filter(e.className).map((e=>({name:"."+CSS.escape(e),penalty:1})))}function f(t){const n=t.tagName.toLowerCase();return e.tagName(n)?{name:n,penalty:2}:null}function d(e){const t=e.parentNode;if(!t)return null;let n=t.firstChild;if(!n)return null;let o=0;for(;n&&(n.nodeType===Node.ELEMENT_NODE&&o++,n!==e);)n=n.nextSibling;return o}function m(e,t){return{name:e.name+`:nth-child(${t})`,penalty:e.penalty+1}}function h(e){return"html"!==e.name&&!e.name.startsWith("#")}function p(...e){const t=e.filter(g);return t.length>0?t:null}function g(e){return null!=e}function*y(e,t=[]){if(e.length>0)for(let n of e[0])yield*y(e.slice(1,e.length),t.concat(n));else yield t}function w(e){return[...e].sort(((e,t)=>i(e)-i(t)))}function*v(t,n,o={counter:0,visited:new Map}){if(t.length>2&&t.length>e.optimizedMinLength)for(let r=1;re.maxNumberOfTries)return;o.counter+=1;const i=[...t];i.splice(r,1);const a=l(i);if(o.visited.has(a))return;s(i)&&b(i,n)&&(yield i,o.visited.set(a,!0),yield*v(i,n,o))}}function b(e,n){return t.querySelector(l(e))===n}function N(e,t){let n="",o=null,r=!1;try{if(o=e.nodeName&&"string"==typeof e.nodeName?e.nodeName.toLowerCase():null,!o)return null;n=`${o}`,e.getAttribute("id")&&(n=`${n}#${CSS.escape(e.getAttribute("id"))}`,r=!0);const t=["data-test-id","data-testid","data-test","data-cy"];if(e.matches(t.map((e=>`[${e}]`)).join(",")))for(const o of t){const t=e.getAttribute(o);if(t){n=`${n}[${o}="${CSS.escape(t)}"]`;break}}if(["input","button","textarea","select","option"].includes(o)){e.getAttribute("type")&&(n=`${n}[type="${CSS.escape(e.getAttribute("type"))}"]`),e.getAttribute("name")&&(n=`${n}[name="${CSS.escape(e.getAttribute("name"))}"]`);const t=e.closest("form");if(t){let e="form";t.getAttribute("id")&&(e=`${e}#${CSS.escape(t.getAttribute("id"))}`),n=`${e} ${n}`}}const l=e.getAttribute("aria-label");if(l&&!r&&(n=`${n}[aria-label="${CSS.escape(l)}"]`),n){const t=e.closest("body");if(t)try{1!==t.querySelectorAll(n).length&&(n="")}catch(e){n=""}}}catch(e){}return n}function E(e,t){let n,o=e,r=[];for(;o;){let e=0,n=o.previousElementSibling;for(;n;)n.nodeName===o.nodeName&&e++,n=n.previousElementSibling;let l=o.nodeName.toLowerCase();e>0&&(l=l+"["+(e+1)+"]"),o!==t&&r.unshift(l),o=o.parentNode}if(n="/"+r.join("/"),function(e,t){const n=t.evaluate(e,t,null,XPathResult.ANY_TYPE,null),o=n.iterateNext();return o}(n,t)===e)return n}const S={},C={keydown:null,return:null,blur:null,change:null,click:null,dblclick:null,contextmenu:null,focus:null,mouseover:null,mouseout:null};let k=!1,A=null,L=null;const $=new WeakMap;function x(e){const t=e.value;return t&&t.trim()?t:$.get(e)||t}function T(e){const t=e.value;return!(t&&t.trim())&&$.has(e)}function M(e,t){const n=["focus","highlight","editable","caret"],o=Array.from(e.classList||[]).filter((e=>{const t=e.toLowerCase();return!n.some((e=>t.includes(e)))&&!/^[0-9]/.test(e)}));for(const n of o){const o="."+n;try{const n=t.querySelectorAll(o);if(1===n.length&&n[0]===e)return o}catch(e){}}return null}function O(e,t){let n;var o;let r,l;function i(e,t,o){let l=null;const i=[];let a=e,c=0;for(;a&&a!==r.root.parentElement;){let e=w(f(a))||w(...d(a))||w(...m(a))||w(h(a))||[{name:"*",penalty:3}];const u=p(a);if(t===n.All)u&&(e=e.concat(e.filter(y).map((e=>g(e,u)))));else if(t===n.Two)e=e.slice(0,1),u&&(e=e.concat(e.filter(y).map((e=>g(e,u)))));else if(t===n.One){const[t]=e=e.slice(0,1);u&&y(t)&&(e=[g(t,u)])}for(const t of e)t.level=c;if(i.push(e),i.length>=r.seedMinLength&&(l=s(i,o),l))break;a=a.parentElement,c++}return l||(l=s(i,o)),l}function s(e,t){const n=N(b(e));if(n.length>r.threshold)return t?t():null;for(const e of n)if(u(e))return e;return null}function a(e){let t=e[0],n=t.name;for(let o=1;o ${n}`:`${e[o].name} ${n}`,t=e[o]}return n}function c(e){return e.map((e=>e.penalty)).reduce(((e,t)=>e+t),0)}function u(e){switch(l.querySelectorAll(a(e)).length){case 0:throw new Error(`Can't select any node with this selector: ${a(e)}`);case 1:return!0;default:return!1}}function f(e){const t=e.getAttribute("id");return t&&r.idName(t)?{name:`#${L(t,{isIdentifier:!0})}`,penalty:0}:null}function d(e){return Array.from(e.attributes).filter((e=>r.attr(e.name,e.value))).map((e=>({name:"["+L(e.name,{isIdentifier:!0})+'="'+L(e.value)+'"]',penalty:.5})))}function m(e){return Array.from(e.classList).filter(r.className).map((e=>({name:"."+L(e,{isIdentifier:!0}),penalty:1})))}function h(e){const t=e.tagName.toLowerCase();return r.tagName(t)?{name:t,penalty:2}:null}function p(e){const t=e.parentNode;if(!t)return null;let n=t.firstChild;if(!n)return null;let o=0;for(;n&&(n.nodeType===Node.ELEMENT_NODE&&o++,n!==e);)n=n.nextSibling;return o}function g(e,t){return{name:e.name+`:nth-child(${t})`,penalty:e.penalty+1}}function y(e){return"html"!==e.name&&!e.name.startsWith("#")}function w(...e){const t=e.filter(v);return 0c(e)-c(t)))}function E(e,t){return l.querySelector(a(e))===t}(o=n||(n={}))[o.All=0]="All",o[o.Two=1]="Two",o[o.One=2]="One";const S=/[ -,\.\/:-@\[-\^`\{-~]/,C=/[ -,\.\/:-@\[\]\^`\{-~]/,k=/(^|\\+)?(\\[A-F0-9]{1,6})\x20(?![a-fA-F0-9\x20])/g,A={escapeEverything:!1,isIdentifier:!1,quotes:"single",wrap:!1};function L(e,t={}){const n=Object.assign(Object.assign({},A),t);"single"!==n.quotes&&"double"!==n.quotes&&(n.quotes="single");const o="double"==n.quotes?'"':"'",r=n.isIdentifier,l=e.charAt(0);let i="",s=0;for(const t=e.length;sc||126=c&&s!0,className:()=>!0,tagName:()=>!0,attr:()=>!1,seedMinLength:1,optimizedMinLength:2,threshold:1e3,maxNumberOfTries:1e4};r=Object.assign(Object.assign({},$),t),l=function(e,t){return e.nodeType===Node.DOCUMENT_NODE?e:e===t.root?e.ownerDocument:e}(r.root,$);let x=i(e,n.All,(()=>i(e,n.Two,(()=>i(e,n.One)))));if(x){const t=N(function*e(t,n,o={counter:0,visited:new Map}){if(2r.optimizedMinLength)for(let l=1;lr.maxNumberOfTries)return;o.counter+=1;const i=[...t];i.splice(l,1);const s=a(i);if(o.visited.has(s))return;u(i)&&E(i,n)&&(yield i,o.visited.set(s,!0),yield*e(i,n,o))}}(x,e));return 0{if(!l.isRecording)return;let i=!1,s=null;function a(e){e&&"mouseover"===e.type&&!i||function(e,t,o,r){let l=!1,i=null,s=null;e&&e.composed&&e.composedPath&&(s=e.composedPath());let a=-1;s&&s.length>0&&(a=s.findIndex((e=>e instanceof ShadowRoot))),i=a>-1?s[0]:e.target;const c=e.type;let u=null,f=null;if(!i||!i.getAttribute)return;u=i.nodeName.toLowerCase(),f=i.getAttribute("type");let d=null,m=null;try{m=function(e){let t=null;try{if(t=e.nodeName&&"string"==typeof e.nodeName?e.nodeName.toLowerCase():null,!t)return e;if(["input","button","a","textarea","select","option","progress"].includes(t))return e;const n=e.closest("button,a");if(n)return n;const o=e.closest("svg");o&&(e=o);const r=["data-test-id","data-testid","data-test","data-cy"];if(e.matches(r.map((e=>`[${e}]`)).join(",")))return e;if(e.parentNode.matches(r.map((e=>`[${e}]`)).join(",")))return e.parentNode}catch(e){}return e}(i),d=N(m)}catch(e){}if(!d)try{d=n(m,{root:t,idName:e=>!/^[0-9]+.*/i.test(e),className:e=>!e.includes("focus")&&!e.includes("highlight")&&!/^[0-9]+.*/i.test(e)})}catch(e){}if(d&&"html"===d.toLowerCase())return;let h=null;try{h=E(m,t)}catch(e){}a>-1&&(h="/html/node/shadow");let p={timestamp:(new Date).getTime(),css:d||i,xpath:h||""},g={};if("click"===c){if(C.click=i,A&&A.element!==i&&r){const e=T(A.element),n={...A.oEventBase,type:e?"bfill_value":"fill_value",value:x(A.element),frame:A.frame};if(e){const e=M(A.element,t);e&&(n.css=e)}r({messageType:"events",event:{...n}}),$.delete(A.element),L=A.element,A=null}if(!(C.return!==C.change||i===C.return||"input"!==u&&"button"!==u||"submit"!==f&&"image"!==f||null===C.return))return;if("input"===u&&("checkbox"===f||"radio"===f))return;const l=i.closest&&i.closest("label");if(l){const e=l.getAttribute("for");if(e){const t=document.getElementById(e);if(t&&"input"===t.nodeName.toLowerCase()&&("checkbox"===t.type||"radio"===t.type))return}if(l.querySelector('input[type="checkbox"], input[type="radio"]'))return}let c="click";if(function(e){if("canvas"===e.nodeName.toLowerCase())return!0;if(e.shadowRoot)try{if(e.shadowRoot.querySelector("canvas"))return!0}catch(e){}for(const t of e.children||[])if(t.shadowRoot)try{if(t.shadowRoot.querySelector("canvas"))return!0}catch(e){}return!1}(i)){const t=i.getBoundingClientRect(),n={x:e.clientX-t.left,y:e.clientY-t.top,width:t.width,height:t.height};p={...p,coords:n},c="bclick"}if(g={...p,type:c,value:(i.value||i.textContent||"").trim().substr(0,20).replace(/\n/gi,""),frame:o},"bclick"===c&&a>-1&&s){const e=s[a].host;if(e){let o=null;try{o=N(e)}catch(e){}if(!o)try{o=n(e,{root:t,idName:e=>!/^[0-9]+.*/i.test(e),className:e=>!e.includes("focus")&&!e.includes("highlight")&&!/^[0-9]+.*/i.test(e)})}catch(e){}o&&(g.shadow_host_css=o)}}}else if("dblclick"===c)C.dblclick=i,g={...p,type:"dblclick",value:(i.value||i.textContent||"").trim().substr(0,20).replace(/\n/gi,""),frame:o};else if("contextmenu"===c)C.contextmenu=i,g={...p,type:"contextmenu",value:(i.value||i.textContent||"").trim().substr(0,20).replace(/\n/gi,""),frame:o};else if("focus"===c);else if("mouseover"===c)k&&(clearTimeout(k),k=!1),k=setTimeout((()=>{k=!1,C.mouseover=i,g={...p,type:"mouseover",value:(i.value||i.textContent||"").trim().substr(0,20).replace(/\n/gi,""),frame:o},g&&g.type&&r&&r({messageType:"events",event:{...g}})}),500);else if("mouseout"===c);else if("keydown"===c){if(C.keydown=i,["input","textarea"].indexOf(u)>-1)if(S[i]=i.value,A={element:i,oEventBase:{...p},frame:o},e.key&&1===e.key.length){const t=$.get(i)||"";$.set(i,t+e.key)}else if("Backspace"===e.key){const e=$.get(i)||"";e.length>0&&$.set(i,e.slice(0,-1))}if("input"===u&&13===e.keyCode){l=!0,C.return=i;const e=T(i);if(g={...p,type:e?"bfill_value":"fill_value",value:x(i),frame:o},e){const e=M(i,t);e&&(g.css=e)}$.delete(i)}}else if("blur"===c){if(C.blur=i,i===L)return void(L=null);if(A&&A.element===i&&(A=null),["input","textarea"].indexOf(u)>-1){if(S[i]=i.value,i===C.return)return void(C.return=null);if("input"===u&&("submit"===i.type||"button"===i.type||"image"===i.type))return;const e=T(i);if(g={...p,type:e?"bfill_value":"fill_value",value:x(i),frame:o},e){const e=M(i,t);e&&(g.css=e)}$.delete(i)}}else if("change"===c)if(C.change=i,"input"===u)"checkbox"!==f&&"radio"!==f||(g={...p,type:"change",subtype:"check",checked:i.checked,frame:o});else if("select"===u)if(i.multiple){const e=[];for(let t=0;t{window!==window.top?window.parent.postMessage({source:"event-from-iframe",obj:{...e},framePath:[]},"*"):chrome.runtime.sendMessage(e)}))}window===window.top&&window.addEventListener("message",(e=>{if(e.data&&e.data.source&&"event-from-iframe"===e.data.source){const t=document.querySelectorAll("iframe, frame");let n=!1;for(const o of t)if(o.contentWindow===e.source){n=!0;break}if(!n)return;const o={...e.data.obj},r=e.data.framePath||[];for(const n of t)if(n.contentWindow===e.source){let e=null;try{e=N(n)}catch(e){}if(!e)try{e=O(n,{root:window.document,idName:e=>!/^[0-9]+.*/i.test(e),className:e=>!e.includes("focus")&&!e.includes("highlight")&&!/^[0-9]+.*/i.test(e)})}catch(e){}if(e&&o.event){const t=[e,...r];o.event.frame=t.join(" >>> "),chrome.runtime.sendMessage(o)}break}}})),window!==window.top&&window.addEventListener("message",(e=>{if(e.data&&e.data.source&&"event-from-iframe"===e.data.source){const t=document.querySelectorAll("iframe, frame");let n=!1;for(const o of t)if(o.contentWindow===e.source){n=!0;break}if(!n)return;const o=e.data.framePath||[];for(const n of t)if(n.contentWindow===e.source){let t=null;try{t=N(n)}catch(e){}if(!t)try{t=O(n,{root:window.document,idName:e=>!/^[0-9]+.*/i.test(e),className:e=>!e.includes("focus")&&!e.includes("highlight")&&!/^[0-9]+.*/i.test(e)})}catch(e){}t&&o.push(t),window.parent.postMessage({source:"event-from-iframe",obj:e.data.obj,framePath:o},"*");break}}})),l.isRecording&&(t=!0,e=document.title,function(){if(!t)return document.title=`${e}`,r=!1,void(o&&(clearInterval(o),o=!1));o=setInterval((()=>{r?(document.title=`${e}`,r=!1):(document.title=`🔴 ${e}`,r=!0)}),1e3)}(),window===window.top&&chrome.runtime.sendMessage({messageType:"events",event:{type:"goto",timestamp:(new Date).getTime(),windowWidth:window.innerWidth,windowHeight:window.innerHeight,url:window.location.href}}),document.addEventListener("click",a,!0),document.addEventListener("mouseover",a,!0),document.addEventListener("dblclick",a,!0),document.addEventListener("contextmenu",a,!0),document.addEventListener("keydown",a,!0),document.addEventListener("blur",a,!0),document.addEventListener("change",a,!0));const c={attributes:!1,childList:!0,subtree:!0},u=new MutationObserver((async(e,t)=>{i=!0,s&&(clearTimeout(s),s=null),s=setTimeout((()=>{i=!1}),200)}));document.body&&u.observe(document.body,c)}))}()})(); \ No newline at end of file +(()=>{"use strict";let e,t;function n(n,r){if(n.nodeType!==Node.ELEMENT_NODE)throw new Error("Can't generate CSS selector for non-element node type.");if("html"===n.tagName.toLowerCase())return"html";const i={root:document.body,idName:e=>!0,className:e=>!0,tagName:e=>!0,attr:(e,t)=>!1,seedMinLength:1,optimizedMinLength:2,threshold:1e3,maxNumberOfTries:1e4};e={...i,...r},t=function(e,t){if(e.nodeType===Node.DOCUMENT_NODE)return e;if(e===t.root)return e.ownerDocument;return e}(e.root,i);let s=o(n,"all",(()=>o(n,"two",(()=>o(n,"one",(()=>o(n,"none")))))));if(s){const e=w(v(s,n));return e.length>0&&(s=e[0]),l(s)}throw new Error("Selector was not found.")}function o(t,n,o){let l=null,i=[],s=t,g=0;for(;s;){let t=p(a(s))||p(...c(s))||p(...u(s))||p(f(s))||[{name:"*",penalty:3}];const y=d(s);if("all"==n)y&&(t=t.concat(t.filter(h).map((e=>m(e,y)))));else if("two"==n)t=t.slice(0,1),y&&(t=t.concat(t.filter(h).map((e=>m(e,y)))));else if("one"==n){const[e]=t=t.slice(0,1);y&&h(e)&&(t=[m(e,y)])}else"none"==n&&(t=[{name:"*",penalty:3}],y&&(t=[m(t[0],y)]));for(let e of t)e.level=g;if(i.push(t),i.length>=e.seedMinLength&&(l=r(i,o),l))break;s=s.parentElement,g++}return l||(l=r(i,o)),!l&&o?o():l}function r(t,n){const o=w(y(t));if(o.length>e.threshold)return n?n():null;for(let e of o)if(s(e))return e;return null}function l(e){let t=e[0],n=t.name;for(let o=1;o ${n}`:`${e[o].name} ${n}`,t=e[o]}return n}function i(e){return e.map((e=>e.penalty)).reduce(((e,t)=>e+t),0)}function s(e){const n=l(e);switch(t.querySelectorAll(n).length){case 0:throw new Error(`Can't select any node with this selector: ${n}`);case 1:return!0;default:return!1}}function a(t){const n=t.getAttribute("id");return n&&e.idName(n)?{name:"#"+CSS.escape(n),penalty:0}:null}function c(t){const n=Array.from(t.attributes).filter((t=>e.attr(t.name,t.value)));return n.map((e=>({name:`[${CSS.escape(e.name)}="${CSS.escape(e.value)}"]`,penalty:.5})))}function u(t){return Array.from(t.classList).filter(e.className).map((e=>({name:"."+CSS.escape(e),penalty:1})))}function f(t){const n=t.tagName.toLowerCase();return e.tagName(n)?{name:n,penalty:2}:null}function d(e){const t=e.parentNode;if(!t)return null;let n=t.firstChild;if(!n)return null;let o=0;for(;n&&(n.nodeType===Node.ELEMENT_NODE&&o++,n!==e);)n=n.nextSibling;return o}function m(e,t){return{name:e.name+`:nth-child(${t})`,penalty:e.penalty+1}}function h(e){return"html"!==e.name&&!e.name.startsWith("#")}function p(...e){const t=e.filter(g);return t.length>0?t:null}function g(e){return null!=e}function*y(e,t=[]){if(e.length>0)for(let n of e[0])yield*y(e.slice(1,e.length),t.concat(n));else yield t}function w(e){return[...e].sort(((e,t)=>i(e)-i(t)))}function*v(t,n,o={counter:0,visited:new Map}){if(t.length>2&&t.length>e.optimizedMinLength)for(let r=1;re.maxNumberOfTries)return;o.counter+=1;const i=[...t];i.splice(r,1);const a=l(i);if(o.visited.has(a))return;s(i)&&b(i,n)&&(yield i,o.visited.set(a,!0),yield*v(i,n,o))}}function b(e,n){return t.querySelector(l(e))===n}function N(e,t){let n="",o=null,r=!1;try{if(o=e.nodeName&&"string"==typeof e.nodeName?e.nodeName.toLowerCase():null,!o)return null;n=`${o}`,e.getAttribute("id")&&(n=`${n}#${CSS.escape(e.getAttribute("id"))}`,r=!0);const t=["data-test-id","data-testid","data-test","data-cy"];if(e.matches(t.map((e=>`[${e}]`)).join(",")))for(const o of t){const t=e.getAttribute(o);if(t){n=`${n}[${o}="${CSS.escape(t)}"]`;break}}if(["input","button","textarea","select","option"].includes(o)){e.getAttribute("type")&&(n=`${n}[type="${CSS.escape(e.getAttribute("type"))}"]`),e.getAttribute("name")&&(n=`${n}[name="${CSS.escape(e.getAttribute("name"))}"]`);const t=e.closest("form");if(t){let e="form";t.getAttribute("id")&&(e=`${e}#${CSS.escape(t.getAttribute("id"))}`),n=`${e} ${n}`}}const l=e.getAttribute("aria-label");if(l&&!r&&(n=`${n}[aria-label="${CSS.escape(l)}"]`),n){const t=e.closest("body");if(t)try{1!==t.querySelectorAll(n).length&&(n="")}catch(e){n=""}}}catch(e){}return n}function E(e,t){let n,o=e,r=[];for(;o;){let e=0,n=o.previousElementSibling;for(;n;)n.nodeName===o.nodeName&&e++,n=n.previousElementSibling;let l=o.nodeName.toLowerCase();e>0&&(l=l+"["+(e+1)+"]"),o!==t&&r.unshift(l),o=o.parentNode}if(n="/"+r.join("/"),function(e,t){const n=t.evaluate(e,t,null,XPathResult.ANY_TYPE,null),o=n.iterateNext();return o}(n,t)===e)return n}const S={},C={keydown:null,return:null,blur:null,change:null,click:null,dblclick:null,contextmenu:null,focus:null,mouseover:null,mouseout:null};let k=!1,A=null,L=null;const $=new WeakMap;function x(e){const t=e.value;return t&&t.trim()?t:$.get(e)||t}function T(e){const t=e.value;return!(t&&t.trim())&&$.has(e)}function M(e,t){const n=["focus","highlight","editable","caret"],o=Array.from(e.classList||[]).filter((e=>{const t=e.toLowerCase();return!n.some((e=>t.includes(e)))&&!/^[0-9]/.test(e)}));for(const n of o){const o="."+n;try{const n=t.querySelectorAll(o);if(1===n.length&&n[0]===e)return o}catch(e){}}return null}function O(e,t){let n;var o;let r,l;function i(e,t,o){let l=null;const i=[];let a=e,c=0;for(;a&&a!==r.root.parentElement;){let e=w(f(a))||w(...d(a))||w(...m(a))||w(h(a))||[{name:"*",penalty:3}];const u=p(a);if(t===n.All)u&&(e=e.concat(e.filter(y).map((e=>g(e,u)))));else if(t===n.Two)e=e.slice(0,1),u&&(e=e.concat(e.filter(y).map((e=>g(e,u)))));else if(t===n.One){const[t]=e=e.slice(0,1);u&&y(t)&&(e=[g(t,u)])}for(const t of e)t.level=c;if(i.push(e),i.length>=r.seedMinLength&&(l=s(i,o),l))break;a=a.parentElement,c++}return l||(l=s(i,o)),l}function s(e,t){const n=N(b(e));if(n.length>r.threshold)return t?t():null;for(const e of n)if(u(e))return e;return null}function a(e){let t=e[0],n=t.name;for(let o=1;o ${n}`:`${e[o].name} ${n}`,t=e[o]}return n}function c(e){return e.map((e=>e.penalty)).reduce(((e,t)=>e+t),0)}function u(e){switch(l.querySelectorAll(a(e)).length){case 0:throw new Error(`Can't select any node with this selector: ${a(e)}`);case 1:return!0;default:return!1}}function f(e){const t=e.getAttribute("id");return t&&r.idName(t)?{name:`#${L(t,{isIdentifier:!0})}`,penalty:0}:null}function d(e){return Array.from(e.attributes).filter((e=>r.attr(e.name,e.value))).map((e=>({name:"["+L(e.name,{isIdentifier:!0})+'="'+L(e.value)+'"]',penalty:.5})))}function m(e){return Array.from(e.classList).filter(r.className).map((e=>({name:"."+L(e,{isIdentifier:!0}),penalty:1})))}function h(e){const t=e.tagName.toLowerCase();return r.tagName(t)?{name:t,penalty:2}:null}function p(e){const t=e.parentNode;if(!t)return null;let n=t.firstChild;if(!n)return null;let o=0;for(;n&&(n.nodeType===Node.ELEMENT_NODE&&o++,n!==e);)n=n.nextSibling;return o}function g(e,t){return{name:e.name+`:nth-child(${t})`,penalty:e.penalty+1}}function y(e){return"html"!==e.name&&!e.name.startsWith("#")}function w(...e){const t=e.filter(v);return 0c(e)-c(t)))}function E(e,t){return l.querySelector(a(e))===t}(o=n||(n={}))[o.All=0]="All",o[o.Two=1]="Two",o[o.One=2]="One";const S=/[ -,\.\/:-@\[-\^`\{-~]/,C=/[ -,\.\/:-@\[\]\^`\{-~]/,k=/(^|\\+)?(\\[A-F0-9]{1,6})\x20(?![a-fA-F0-9\x20])/g,A={escapeEverything:!1,isIdentifier:!1,quotes:"single",wrap:!1};function L(e,t={}){const n=Object.assign(Object.assign({},A),t);"single"!==n.quotes&&"double"!==n.quotes&&(n.quotes="single");const o="double"==n.quotes?'"':"'",r=n.isIdentifier,l=e.charAt(0);let i="",s=0;for(const t=e.length;sc||126=c&&s!0,className:()=>!0,tagName:()=>!0,attr:()=>!1,seedMinLength:1,optimizedMinLength:2,threshold:1e3,maxNumberOfTries:1e4};r=Object.assign(Object.assign({},$),t),l=function(e,t){return e.nodeType===Node.DOCUMENT_NODE?e:e===t.root?e.ownerDocument:e}(r.root,$);let x=i(e,n.All,(()=>i(e,n.Two,(()=>i(e,n.One)))));if(x){const t=N(function*e(t,n,o={counter:0,visited:new Map}){if(2r.optimizedMinLength)for(let l=1;lr.maxNumberOfTries)return;o.counter+=1;const i=[...t];i.splice(l,1);const s=a(i);if(o.visited.has(s))return;u(i)&&E(i,n)&&(yield i,o.visited.set(s,!0),yield*e(i,n,o))}}(x,e));return 0{if(!l.isRecording)return;let i=!1,s=null;function a(e){e&&"mouseover"===e.type&&!i||function(e,t,o,r){let l=!1,i=null,s=null;e&&e.composed&&e.composedPath&&(s=e.composedPath());let a=-1;s&&s.length>0&&(a=s.findIndex((e=>e instanceof ShadowRoot))),i=a>-1?s[0]:e.target;const c=e.type;let u=null,f=null;if(!i||!i.getAttribute)return;u=i.nodeName.toLowerCase(),f=i.getAttribute("type");let d=null,m=null;try{m=function(e){let t=null;try{if(t=e.nodeName&&"string"==typeof e.nodeName?e.nodeName.toLowerCase():null,!t)return e;if(["input","button","a","textarea","select","option","progress"].includes(t))return e;const n=e.closest("button,a");if(n)return n;const o=e.closest("svg");o&&(e=o);const r=["data-test-id","data-testid","data-test","data-cy"];if(e.matches(r.map((e=>`[${e}]`)).join(",")))return e;if(e.parentNode.matches(r.map((e=>`[${e}]`)).join(",")))return e.parentNode}catch(e){}return e}(i),d=N(m)}catch(e){}if(!d)try{d=n(m,{root:t,idName:e=>!/^[0-9]+.*/i.test(e),className:e=>!e.includes("focus")&&!e.includes("highlight")&&!/^[0-9]+.*/i.test(e)})}catch(e){}if(d&&"html"===d.toLowerCase())return;let h=null;try{h=E(m,t)}catch(e){}a>-1&&(h="/html/node/shadow");let p={timestamp:(new Date).getTime(),css:d||i,xpath:h||""},g={};if("click"===c){if(C.click=i,A&&A.element!==i&&r){const e=T(A.element),n={...A.oEventBase,type:e?"bfill_value":"fill_value",value:x(A.element),frame:A.frame};if(e){const e=M(A.element,t);e&&(n.css=e)}r({messageType:"events",event:{...n}}),$.delete(A.element),L=A.element,A=null}if(!(C.return!==C.change||i===C.return||"input"!==u&&"button"!==u||"submit"!==f&&"image"!==f||null===C.return))return;if("input"===u&&("checkbox"===f||"radio"===f))return;const l=i.closest&&i.closest("label");if(l){const e=i.closest("a, button, input, select, textarea");if(!e||!l.contains(e)){const e=l.getAttribute("for");if(e){const t=i.getRootNode(),n=(t&&t.getElementById?t:document).getElementById(e);if(n&&"input"===n.nodeName.toLowerCase()&&("checkbox"===n.type||"radio"===n.type))return}if(l.querySelector('input[type="checkbox"], input[type="radio"]'))return}}let c="click";if(function(e){if("canvas"===e.nodeName.toLowerCase())return!0;if(e.shadowRoot)try{if(e.shadowRoot.querySelector("canvas"))return!0}catch(e){}for(const t of e.children||[])if(t.shadowRoot)try{if(t.shadowRoot.querySelector("canvas"))return!0}catch(e){}return!1}(i)){const t=i.getBoundingClientRect(),n={x:e.clientX-t.left,y:e.clientY-t.top,width:t.width,height:t.height};p={...p,coords:n},c="bclick"}if(g={...p,type:c,value:(i.value||i.textContent||"").trim().substr(0,20).replace(/\n/gi,""),frame:o},"bclick"===c&&a>-1&&s){const e=s[a].host;if(e){let o=null;try{o=N(e)}catch(e){}if(!o)try{o=n(e,{root:t,idName:e=>!/^[0-9]+.*/i.test(e),className:e=>!e.includes("focus")&&!e.includes("highlight")&&!/^[0-9]+.*/i.test(e)})}catch(e){}o&&(g.shadow_host_css=o)}}}else if("dblclick"===c)C.dblclick=i,g={...p,type:"dblclick",value:(i.value||i.textContent||"").trim().substr(0,20).replace(/\n/gi,""),frame:o};else if("contextmenu"===c)C.contextmenu=i,g={...p,type:"contextmenu",value:(i.value||i.textContent||"").trim().substr(0,20).replace(/\n/gi,""),frame:o};else if("focus"===c);else if("mouseover"===c)k&&(clearTimeout(k),k=!1),k=setTimeout((()=>{k=!1,C.mouseover=i,g={...p,type:"mouseover",value:(i.value||i.textContent||"").trim().substr(0,20).replace(/\n/gi,""),frame:o},g&&g.type&&r&&r({messageType:"events",event:{...g}})}),500);else if("mouseout"===c);else if("keydown"===c){if(C.keydown=i,["input","textarea"].indexOf(u)>-1)if(S[i]=i.value,A={element:i,oEventBase:{...p},frame:o},e.key&&1===e.key.length){const t=$.get(i)||"";$.set(i,t+e.key)}else if("Backspace"===e.key){const e=$.get(i)||"";e.length>0&&$.set(i,e.slice(0,-1))}if("input"===u&&13===e.keyCode){l=!0,C.return=i;const e=T(i);if(g={...p,type:e?"bfill_value":"fill_value",value:x(i),frame:o},e){const e=M(i,t);e&&(g.css=e)}$.delete(i)}}else if("blur"===c){if(C.blur=i,i===L)return void(L=null);if(A&&A.element===i&&(A=null),["input","textarea"].indexOf(u)>-1){if(S[i]=i.value,i===C.return)return void(C.return=null);if("input"===u&&("submit"===i.type||"button"===i.type||"image"===i.type))return;const e=T(i);if(g={...p,type:e?"bfill_value":"fill_value",value:x(i),frame:o},e){const e=M(i,t);e&&(g.css=e)}$.delete(i)}}else if("change"===c)if(C.change=i,"input"===u)"checkbox"!==f&&"radio"!==f||(g={...p,type:"change",subtype:"check",checked:i.checked,frame:o});else if("select"===u)if(i.multiple){const e=[];for(let t=0;t{window!==window.top?window.parent.postMessage({source:"event-from-iframe",obj:{...e},framePath:[]},"*"):chrome.runtime.sendMessage(e)}))}window===window.top&&window.addEventListener("message",(e=>{if(e.data&&e.data.source&&"event-from-iframe"===e.data.source){const t=document.querySelectorAll("iframe, frame");let n=!1;for(const o of t)if(o.contentWindow===e.source){n=!0;break}if(!n)return;const o={...e.data.obj},r=e.data.framePath||[];for(const n of t)if(n.contentWindow===e.source){let e=null;try{e=N(n)}catch(e){}if(!e)try{e=O(n,{root:window.document,idName:e=>!/^[0-9]+.*/i.test(e),className:e=>!e.includes("focus")&&!e.includes("highlight")&&!/^[0-9]+.*/i.test(e)})}catch(e){}if(e&&o.event){const t=[e,...r];o.event.frame=t.join(" >>> "),chrome.runtime.sendMessage(o)}break}}})),window!==window.top&&window.addEventListener("message",(e=>{if(e.data&&e.data.source&&"event-from-iframe"===e.data.source){const t=document.querySelectorAll("iframe, frame");let n=!1;for(const o of t)if(o.contentWindow===e.source){n=!0;break}if(!n)return;const o=e.data.framePath||[];for(const n of t)if(n.contentWindow===e.source){let t=null;try{t=N(n)}catch(e){}if(!t)try{t=O(n,{root:window.document,idName:e=>!/^[0-9]+.*/i.test(e),className:e=>!e.includes("focus")&&!e.includes("highlight")&&!/^[0-9]+.*/i.test(e)})}catch(e){}t&&o.push(t),window.parent.postMessage({source:"event-from-iframe",obj:e.data.obj,framePath:o},"*");break}}})),l.isRecording&&(t=!0,e=document.title,function(){if(!t)return document.title=`${e}`,r=!1,void(o&&(clearInterval(o),o=!1));o=setInterval((()=>{r?(document.title=`${e}`,r=!1):(document.title=`🔴 ${e}`,r=!0)}),1e3)}(),window===window.top&&chrome.runtime.sendMessage({messageType:"events",event:{type:"goto",timestamp:(new Date).getTime(),windowWidth:window.innerWidth,windowHeight:window.innerHeight,url:window.location.href}}),document.addEventListener("click",a,!0),document.addEventListener("mouseover",a,!0),document.addEventListener("dblclick",a,!0),document.addEventListener("contextmenu",a,!0),document.addEventListener("keydown",a,!0),document.addEventListener("blur",a,!0),document.addEventListener("change",a,!0));const c={attributes:!1,childList:!0,subtree:!0},u=new MutationObserver((async(e,t)=>{i=!0,s&&(clearTimeout(s),s=null),s=setTimeout((()=>{i=!1}),200)}));document.body&&u.observe(document.body,c)}))}()})(); \ No newline at end of file diff --git a/test-build-firefox/manifest.json b/test-build-firefox/manifest.json index 2fb4186..559ce27 100644 --- a/test-build-firefox/manifest.json +++ b/test-build-firefox/manifest.json @@ -1,6 +1,6 @@ { "name": "Snyk API & Web Sequence Recorder", - "version": "1.2.1", + "version": "1.2.2", "browser_specific_settings": { "gecko": { "id": "sequence-recorder@probely.com", diff --git a/test-build/contentScript.bundle.js b/test-build/contentScript.bundle.js index 56cf190..328e00f 100644 --- a/test-build/contentScript.bundle.js +++ b/test-build/contentScript.bundle.js @@ -1 +1 @@ -(()=>{"use strict";let e,t;function n(n,r){if(n.nodeType!==Node.ELEMENT_NODE)throw new Error("Can't generate CSS selector for non-element node type.");if("html"===n.tagName.toLowerCase())return"html";const i={root:document.body,idName:e=>!0,className:e=>!0,tagName:e=>!0,attr:(e,t)=>!1,seedMinLength:1,optimizedMinLength:2,threshold:1e3,maxNumberOfTries:1e4};e={...i,...r},t=function(e,t){if(e.nodeType===Node.DOCUMENT_NODE)return e;if(e===t.root)return e.ownerDocument;return e}(e.root,i);let s=o(n,"all",(()=>o(n,"two",(()=>o(n,"one",(()=>o(n,"none")))))));if(s){const e=w(v(s,n));return e.length>0&&(s=e[0]),l(s)}throw new Error("Selector was not found.")}function o(t,n,o){let l=null,i=[],s=t,g=0;for(;s;){let t=p(a(s))||p(...c(s))||p(...u(s))||p(f(s))||[{name:"*",penalty:3}];const y=d(s);if("all"==n)y&&(t=t.concat(t.filter(h).map((e=>m(e,y)))));else if("two"==n)t=t.slice(0,1),y&&(t=t.concat(t.filter(h).map((e=>m(e,y)))));else if("one"==n){const[e]=t=t.slice(0,1);y&&h(e)&&(t=[m(e,y)])}else"none"==n&&(t=[{name:"*",penalty:3}],y&&(t=[m(t[0],y)]));for(let e of t)e.level=g;if(i.push(t),i.length>=e.seedMinLength&&(l=r(i,o),l))break;s=s.parentElement,g++}return l||(l=r(i,o)),!l&&o?o():l}function r(t,n){const o=w(y(t));if(o.length>e.threshold)return n?n():null;for(let e of o)if(s(e))return e;return null}function l(e){let t=e[0],n=t.name;for(let o=1;o ${n}`:`${e[o].name} ${n}`,t=e[o]}return n}function i(e){return e.map((e=>e.penalty)).reduce(((e,t)=>e+t),0)}function s(e){const n=l(e);switch(t.querySelectorAll(n).length){case 0:throw new Error(`Can't select any node with this selector: ${n}`);case 1:return!0;default:return!1}}function a(t){const n=t.getAttribute("id");return n&&e.idName(n)?{name:"#"+CSS.escape(n),penalty:0}:null}function c(t){const n=Array.from(t.attributes).filter((t=>e.attr(t.name,t.value)));return n.map((e=>({name:`[${CSS.escape(e.name)}="${CSS.escape(e.value)}"]`,penalty:.5})))}function u(t){return Array.from(t.classList).filter(e.className).map((e=>({name:"."+CSS.escape(e),penalty:1})))}function f(t){const n=t.tagName.toLowerCase();return e.tagName(n)?{name:n,penalty:2}:null}function d(e){const t=e.parentNode;if(!t)return null;let n=t.firstChild;if(!n)return null;let o=0;for(;n&&(n.nodeType===Node.ELEMENT_NODE&&o++,n!==e);)n=n.nextSibling;return o}function m(e,t){return{name:e.name+`:nth-child(${t})`,penalty:e.penalty+1}}function h(e){return"html"!==e.name&&!e.name.startsWith("#")}function p(...e){const t=e.filter(g);return t.length>0?t:null}function g(e){return null!=e}function*y(e,t=[]){if(e.length>0)for(let n of e[0])yield*y(e.slice(1,e.length),t.concat(n));else yield t}function w(e){return[...e].sort(((e,t)=>i(e)-i(t)))}function*v(t,n,o={counter:0,visited:new Map}){if(t.length>2&&t.length>e.optimizedMinLength)for(let r=1;re.maxNumberOfTries)return;o.counter+=1;const i=[...t];i.splice(r,1);const a=l(i);if(o.visited.has(a))return;s(i)&&b(i,n)&&(yield i,o.visited.set(a,!0),yield*v(i,n,o))}}function b(e,n){return t.querySelector(l(e))===n}function N(e,t){let n="",o=null,r=!1;try{if(o=e.nodeName&&"string"==typeof e.nodeName?e.nodeName.toLowerCase():null,!o)return null;n=`${o}`,e.getAttribute("id")&&(n=`${n}#${CSS.escape(e.getAttribute("id"))}`,r=!0);const t=["data-test-id","data-testid","data-test","data-cy"];if(e.matches(t.map((e=>`[${e}]`)).join(",")))for(const o of t){const t=e.getAttribute(o);if(t){n=`${n}[${o}="${CSS.escape(t)}"]`;break}}if(["input","button","textarea","select","option"].includes(o)){e.getAttribute("type")&&(n=`${n}[type="${CSS.escape(e.getAttribute("type"))}"]`),e.getAttribute("name")&&(n=`${n}[name="${CSS.escape(e.getAttribute("name"))}"]`);const t=e.closest("form");if(t){let e="form";t.getAttribute("id")&&(e=`${e}#${CSS.escape(t.getAttribute("id"))}`),n=`${e} ${n}`}}const l=e.getAttribute("aria-label");if(l&&!r&&(n=`${n}[aria-label="${CSS.escape(l)}"]`),n){const t=e.closest("body");if(t)try{1!==t.querySelectorAll(n).length&&(n="")}catch(e){n=""}}}catch(e){}return n}function E(e,t){let n,o=e,r=[];for(;o;){let e=0,n=o.previousElementSibling;for(;n;)n.nodeName===o.nodeName&&e++,n=n.previousElementSibling;let l=o.nodeName.toLowerCase();e>0&&(l=l+"["+(e+1)+"]"),o!==t&&r.unshift(l),o=o.parentNode}if(n="/"+r.join("/"),function(e,t){const n=t.evaluate(e,t,null,XPathResult.ANY_TYPE,null),o=n.iterateNext();return o}(n,t)===e)return n}const S={},C={keydown:null,return:null,blur:null,change:null,click:null,dblclick:null,contextmenu:null,focus:null,mouseover:null,mouseout:null};let k=!1,A=null,L=null;const $=new WeakMap;function x(e){const t=e.value;return t&&t.trim()?t:$.get(e)||t}function T(e){const t=e.value;return!(t&&t.trim())&&$.has(e)}function M(e,t){const n=["focus","highlight","editable","caret"],o=Array.from(e.classList||[]).filter((e=>{const t=e.toLowerCase();return!n.some((e=>t.includes(e)))&&!/^[0-9]/.test(e)}));for(const n of o){const o="."+n;try{const n=t.querySelectorAll(o);if(1===n.length&&n[0]===e)return o}catch(e){}}return null}function O(e,t){let n;var o;let r,l;function i(e,t,o){let l=null;const i=[];let a=e,c=0;for(;a&&a!==r.root.parentElement;){let e=w(f(a))||w(...d(a))||w(...m(a))||w(h(a))||[{name:"*",penalty:3}];const u=p(a);if(t===n.All)u&&(e=e.concat(e.filter(y).map((e=>g(e,u)))));else if(t===n.Two)e=e.slice(0,1),u&&(e=e.concat(e.filter(y).map((e=>g(e,u)))));else if(t===n.One){const[t]=e=e.slice(0,1);u&&y(t)&&(e=[g(t,u)])}for(const t of e)t.level=c;if(i.push(e),i.length>=r.seedMinLength&&(l=s(i,o),l))break;a=a.parentElement,c++}return l||(l=s(i,o)),l}function s(e,t){const n=N(b(e));if(n.length>r.threshold)return t?t():null;for(const e of n)if(u(e))return e;return null}function a(e){let t=e[0],n=t.name;for(let o=1;o ${n}`:`${e[o].name} ${n}`,t=e[o]}return n}function c(e){return e.map((e=>e.penalty)).reduce(((e,t)=>e+t),0)}function u(e){switch(l.querySelectorAll(a(e)).length){case 0:throw new Error(`Can't select any node with this selector: ${a(e)}`);case 1:return!0;default:return!1}}function f(e){const t=e.getAttribute("id");return t&&r.idName(t)?{name:`#${L(t,{isIdentifier:!0})}`,penalty:0}:null}function d(e){return Array.from(e.attributes).filter((e=>r.attr(e.name,e.value))).map((e=>({name:"["+L(e.name,{isIdentifier:!0})+'="'+L(e.value)+'"]',penalty:.5})))}function m(e){return Array.from(e.classList).filter(r.className).map((e=>({name:"."+L(e,{isIdentifier:!0}),penalty:1})))}function h(e){const t=e.tagName.toLowerCase();return r.tagName(t)?{name:t,penalty:2}:null}function p(e){const t=e.parentNode;if(!t)return null;let n=t.firstChild;if(!n)return null;let o=0;for(;n&&(n.nodeType===Node.ELEMENT_NODE&&o++,n!==e);)n=n.nextSibling;return o}function g(e,t){return{name:e.name+`:nth-child(${t})`,penalty:e.penalty+1}}function y(e){return"html"!==e.name&&!e.name.startsWith("#")}function w(...e){const t=e.filter(v);return 0c(e)-c(t)))}function E(e,t){return l.querySelector(a(e))===t}(o=n||(n={}))[o.All=0]="All",o[o.Two=1]="Two",o[o.One=2]="One";const S=/[ -,\.\/:-@\[-\^`\{-~]/,C=/[ -,\.\/:-@\[\]\^`\{-~]/,k=/(^|\\+)?(\\[A-F0-9]{1,6})\x20(?![a-fA-F0-9\x20])/g,A={escapeEverything:!1,isIdentifier:!1,quotes:"single",wrap:!1};function L(e,t={}){const n=Object.assign(Object.assign({},A),t);"single"!==n.quotes&&"double"!==n.quotes&&(n.quotes="single");const o="double"==n.quotes?'"':"'",r=n.isIdentifier,l=e.charAt(0);let i="",s=0;for(const t=e.length;sc||126=c&&s!0,className:()=>!0,tagName:()=>!0,attr:()=>!1,seedMinLength:1,optimizedMinLength:2,threshold:1e3,maxNumberOfTries:1e4};r=Object.assign(Object.assign({},$),t),l=function(e,t){return e.nodeType===Node.DOCUMENT_NODE?e:e===t.root?e.ownerDocument:e}(r.root,$);let x=i(e,n.All,(()=>i(e,n.Two,(()=>i(e,n.One)))));if(x){const t=N(function*e(t,n,o={counter:0,visited:new Map}){if(2r.optimizedMinLength)for(let l=1;lr.maxNumberOfTries)return;o.counter+=1;const i=[...t];i.splice(l,1);const s=a(i);if(o.visited.has(s))return;u(i)&&E(i,n)&&(yield i,o.visited.set(s,!0),yield*e(i,n,o))}}(x,e));return 0{if(!l.isRecording)return;let i=!1,s=null;function a(e){e&&"mouseover"===e.type&&!i||function(e,t,o,r){let l=!1,i=null,s=null;e&&e.composed&&e.composedPath&&(s=e.composedPath());let a=-1;s&&s.length>0&&(a=s.findIndex((e=>e instanceof ShadowRoot))),i=a>-1?s[0]:e.target;const c=e.type;let u=null,f=null;if(!i||!i.getAttribute)return;u=i.nodeName.toLowerCase(),f=i.getAttribute("type");let d=null,m=null;try{m=function(e){let t=null;try{if(t=e.nodeName&&"string"==typeof e.nodeName?e.nodeName.toLowerCase():null,!t)return e;if(["input","button","a","textarea","select","option","progress"].includes(t))return e;const n=e.closest("button,a");if(n)return n;const o=e.closest("svg");o&&(e=o);const r=["data-test-id","data-testid","data-test","data-cy"];if(e.matches(r.map((e=>`[${e}]`)).join(",")))return e;if(e.parentNode.matches(r.map((e=>`[${e}]`)).join(",")))return e.parentNode}catch(e){}return e}(i),d=N(m)}catch(e){}if(!d)try{d=n(m,{root:t,idName:e=>!/^[0-9]+.*/i.test(e),className:e=>!e.includes("focus")&&!e.includes("highlight")&&!/^[0-9]+.*/i.test(e)})}catch(e){}if(d&&"html"===d.toLowerCase())return;let h=null;try{h=E(m,t)}catch(e){}a>-1&&(h="/html/node/shadow");let p={timestamp:(new Date).getTime(),css:d||i,xpath:h||""},g={};if("click"===c){if(C.click=i,A&&A.element!==i&&r){const e=T(A.element),n={...A.oEventBase,type:e?"bfill_value":"fill_value",value:x(A.element),frame:A.frame};if(e){const e=M(A.element,t);e&&(n.css=e)}r({messageType:"events",event:{...n}}),$.delete(A.element),L=A.element,A=null}if(!(C.return!==C.change||i===C.return||"input"!==u&&"button"!==u||"submit"!==f&&"image"!==f||null===C.return))return;if("input"===u&&("checkbox"===f||"radio"===f))return;const l=i.closest&&i.closest("label");if(l){const e=l.getAttribute("for");if(e){const t=document.getElementById(e);if(t&&"input"===t.nodeName.toLowerCase()&&("checkbox"===t.type||"radio"===t.type))return}if(l.querySelector('input[type="checkbox"], input[type="radio"]'))return}let c="click";if(function(e){if("canvas"===e.nodeName.toLowerCase())return!0;if(e.shadowRoot)try{if(e.shadowRoot.querySelector("canvas"))return!0}catch(e){}for(const t of e.children||[])if(t.shadowRoot)try{if(t.shadowRoot.querySelector("canvas"))return!0}catch(e){}return!1}(i)){const t=i.getBoundingClientRect(),n={x:e.clientX-t.left,y:e.clientY-t.top,width:t.width,height:t.height};p={...p,coords:n},c="bclick"}if(g={...p,type:c,value:(i.value||i.textContent||"").trim().substr(0,20).replace(/\n/gi,""),frame:o},"bclick"===c&&a>-1&&s){const e=s[a].host;if(e){let o=null;try{o=N(e)}catch(e){}if(!o)try{o=n(e,{root:t,idName:e=>!/^[0-9]+.*/i.test(e),className:e=>!e.includes("focus")&&!e.includes("highlight")&&!/^[0-9]+.*/i.test(e)})}catch(e){}o&&(g.shadow_host_css=o)}}}else if("dblclick"===c)C.dblclick=i,g={...p,type:"dblclick",value:(i.value||i.textContent||"").trim().substr(0,20).replace(/\n/gi,""),frame:o};else if("contextmenu"===c)C.contextmenu=i,g={...p,type:"contextmenu",value:(i.value||i.textContent||"").trim().substr(0,20).replace(/\n/gi,""),frame:o};else if("focus"===c);else if("mouseover"===c)k&&(clearTimeout(k),k=!1),k=setTimeout((()=>{k=!1,C.mouseover=i,g={...p,type:"mouseover",value:(i.value||i.textContent||"").trim().substr(0,20).replace(/\n/gi,""),frame:o},g&&g.type&&r&&r({messageType:"events",event:{...g}})}),500);else if("mouseout"===c);else if("keydown"===c){if(C.keydown=i,["input","textarea"].indexOf(u)>-1)if(S[i]=i.value,A={element:i,oEventBase:{...p},frame:o},e.key&&1===e.key.length){const t=$.get(i)||"";$.set(i,t+e.key)}else if("Backspace"===e.key){const e=$.get(i)||"";e.length>0&&$.set(i,e.slice(0,-1))}if("input"===u&&13===e.keyCode){l=!0,C.return=i;const e=T(i);if(g={...p,type:e?"bfill_value":"fill_value",value:x(i),frame:o},e){const e=M(i,t);e&&(g.css=e)}$.delete(i)}}else if("blur"===c){if(C.blur=i,i===L)return void(L=null);if(A&&A.element===i&&(A=null),["input","textarea"].indexOf(u)>-1){if(S[i]=i.value,i===C.return)return void(C.return=null);if("input"===u&&("submit"===i.type||"button"===i.type||"image"===i.type))return;const e=T(i);if(g={...p,type:e?"bfill_value":"fill_value",value:x(i),frame:o},e){const e=M(i,t);e&&(g.css=e)}$.delete(i)}}else if("change"===c)if(C.change=i,"input"===u)"checkbox"!==f&&"radio"!==f||(g={...p,type:"change",subtype:"check",checked:i.checked,frame:o});else if("select"===u)if(i.multiple){const e=[];for(let t=0;t{window!==window.top?window.parent.postMessage({source:"event-from-iframe",obj:{...e},framePath:[]},"*"):chrome.runtime.sendMessage(e)}))}window===window.top&&window.addEventListener("message",(e=>{if(e.data&&e.data.source&&"event-from-iframe"===e.data.source){const t=document.querySelectorAll("iframe, frame");let n=!1;for(const o of t)if(o.contentWindow===e.source){n=!0;break}if(!n)return;const o={...e.data.obj},r=e.data.framePath||[];for(const n of t)if(n.contentWindow===e.source){let e=null;try{e=N(n)}catch(e){}if(!e)try{e=O(n,{root:window.document,idName:e=>!/^[0-9]+.*/i.test(e),className:e=>!e.includes("focus")&&!e.includes("highlight")&&!/^[0-9]+.*/i.test(e)})}catch(e){}if(e&&o.event){const t=[e,...r];o.event.frame=t.join(" >>> "),chrome.runtime.sendMessage(o)}break}}})),window!==window.top&&window.addEventListener("message",(e=>{if(e.data&&e.data.source&&"event-from-iframe"===e.data.source){const t=document.querySelectorAll("iframe, frame");let n=!1;for(const o of t)if(o.contentWindow===e.source){n=!0;break}if(!n)return;const o=e.data.framePath||[];for(const n of t)if(n.contentWindow===e.source){let t=null;try{t=N(n)}catch(e){}if(!t)try{t=O(n,{root:window.document,idName:e=>!/^[0-9]+.*/i.test(e),className:e=>!e.includes("focus")&&!e.includes("highlight")&&!/^[0-9]+.*/i.test(e)})}catch(e){}t&&o.push(t),window.parent.postMessage({source:"event-from-iframe",obj:e.data.obj,framePath:o},"*");break}}})),l.isRecording&&(t=!0,e=document.title,function(){if(!t)return document.title=`${e}`,r=!1,void(o&&(clearInterval(o),o=!1));o=setInterval((()=>{r?(document.title=`${e}`,r=!1):(document.title=`🔴 ${e}`,r=!0)}),1e3)}(),window===window.top&&chrome.runtime.sendMessage({messageType:"events",event:{type:"goto",timestamp:(new Date).getTime(),windowWidth:window.innerWidth,windowHeight:window.innerHeight,url:window.location.href}}),document.addEventListener("click",a,!0),document.addEventListener("mouseover",a,!0),document.addEventListener("dblclick",a,!0),document.addEventListener("contextmenu",a,!0),document.addEventListener("keydown",a,!0),document.addEventListener("blur",a,!0),document.addEventListener("change",a,!0));const c={attributes:!1,childList:!0,subtree:!0},u=new MutationObserver((async(e,t)=>{i=!0,s&&(clearTimeout(s),s=null),s=setTimeout((()=>{i=!1}),200)}));document.body&&u.observe(document.body,c)}))}()})(); \ No newline at end of file +(()=>{"use strict";let e,t;function n(n,r){if(n.nodeType!==Node.ELEMENT_NODE)throw new Error("Can't generate CSS selector for non-element node type.");if("html"===n.tagName.toLowerCase())return"html";const i={root:document.body,idName:e=>!0,className:e=>!0,tagName:e=>!0,attr:(e,t)=>!1,seedMinLength:1,optimizedMinLength:2,threshold:1e3,maxNumberOfTries:1e4};e={...i,...r},t=function(e,t){if(e.nodeType===Node.DOCUMENT_NODE)return e;if(e===t.root)return e.ownerDocument;return e}(e.root,i);let s=o(n,"all",(()=>o(n,"two",(()=>o(n,"one",(()=>o(n,"none")))))));if(s){const e=w(v(s,n));return e.length>0&&(s=e[0]),l(s)}throw new Error("Selector was not found.")}function o(t,n,o){let l=null,i=[],s=t,g=0;for(;s;){let t=p(a(s))||p(...c(s))||p(...u(s))||p(f(s))||[{name:"*",penalty:3}];const y=d(s);if("all"==n)y&&(t=t.concat(t.filter(h).map((e=>m(e,y)))));else if("two"==n)t=t.slice(0,1),y&&(t=t.concat(t.filter(h).map((e=>m(e,y)))));else if("one"==n){const[e]=t=t.slice(0,1);y&&h(e)&&(t=[m(e,y)])}else"none"==n&&(t=[{name:"*",penalty:3}],y&&(t=[m(t[0],y)]));for(let e of t)e.level=g;if(i.push(t),i.length>=e.seedMinLength&&(l=r(i,o),l))break;s=s.parentElement,g++}return l||(l=r(i,o)),!l&&o?o():l}function r(t,n){const o=w(y(t));if(o.length>e.threshold)return n?n():null;for(let e of o)if(s(e))return e;return null}function l(e){let t=e[0],n=t.name;for(let o=1;o ${n}`:`${e[o].name} ${n}`,t=e[o]}return n}function i(e){return e.map((e=>e.penalty)).reduce(((e,t)=>e+t),0)}function s(e){const n=l(e);switch(t.querySelectorAll(n).length){case 0:throw new Error(`Can't select any node with this selector: ${n}`);case 1:return!0;default:return!1}}function a(t){const n=t.getAttribute("id");return n&&e.idName(n)?{name:"#"+CSS.escape(n),penalty:0}:null}function c(t){const n=Array.from(t.attributes).filter((t=>e.attr(t.name,t.value)));return n.map((e=>({name:`[${CSS.escape(e.name)}="${CSS.escape(e.value)}"]`,penalty:.5})))}function u(t){return Array.from(t.classList).filter(e.className).map((e=>({name:"."+CSS.escape(e),penalty:1})))}function f(t){const n=t.tagName.toLowerCase();return e.tagName(n)?{name:n,penalty:2}:null}function d(e){const t=e.parentNode;if(!t)return null;let n=t.firstChild;if(!n)return null;let o=0;for(;n&&(n.nodeType===Node.ELEMENT_NODE&&o++,n!==e);)n=n.nextSibling;return o}function m(e,t){return{name:e.name+`:nth-child(${t})`,penalty:e.penalty+1}}function h(e){return"html"!==e.name&&!e.name.startsWith("#")}function p(...e){const t=e.filter(g);return t.length>0?t:null}function g(e){return null!=e}function*y(e,t=[]){if(e.length>0)for(let n of e[0])yield*y(e.slice(1,e.length),t.concat(n));else yield t}function w(e){return[...e].sort(((e,t)=>i(e)-i(t)))}function*v(t,n,o={counter:0,visited:new Map}){if(t.length>2&&t.length>e.optimizedMinLength)for(let r=1;re.maxNumberOfTries)return;o.counter+=1;const i=[...t];i.splice(r,1);const a=l(i);if(o.visited.has(a))return;s(i)&&b(i,n)&&(yield i,o.visited.set(a,!0),yield*v(i,n,o))}}function b(e,n){return t.querySelector(l(e))===n}function N(e,t){let n="",o=null,r=!1;try{if(o=e.nodeName&&"string"==typeof e.nodeName?e.nodeName.toLowerCase():null,!o)return null;n=`${o}`,e.getAttribute("id")&&(n=`${n}#${CSS.escape(e.getAttribute("id"))}`,r=!0);const t=["data-test-id","data-testid","data-test","data-cy"];if(e.matches(t.map((e=>`[${e}]`)).join(",")))for(const o of t){const t=e.getAttribute(o);if(t){n=`${n}[${o}="${CSS.escape(t)}"]`;break}}if(["input","button","textarea","select","option"].includes(o)){e.getAttribute("type")&&(n=`${n}[type="${CSS.escape(e.getAttribute("type"))}"]`),e.getAttribute("name")&&(n=`${n}[name="${CSS.escape(e.getAttribute("name"))}"]`);const t=e.closest("form");if(t){let e="form";t.getAttribute("id")&&(e=`${e}#${CSS.escape(t.getAttribute("id"))}`),n=`${e} ${n}`}}const l=e.getAttribute("aria-label");if(l&&!r&&(n=`${n}[aria-label="${CSS.escape(l)}"]`),n){const t=e.closest("body");if(t)try{1!==t.querySelectorAll(n).length&&(n="")}catch(e){n=""}}}catch(e){}return n}function E(e,t){let n,o=e,r=[];for(;o;){let e=0,n=o.previousElementSibling;for(;n;)n.nodeName===o.nodeName&&e++,n=n.previousElementSibling;let l=o.nodeName.toLowerCase();e>0&&(l=l+"["+(e+1)+"]"),o!==t&&r.unshift(l),o=o.parentNode}if(n="/"+r.join("/"),function(e,t){const n=t.evaluate(e,t,null,XPathResult.ANY_TYPE,null),o=n.iterateNext();return o}(n,t)===e)return n}const S={},C={keydown:null,return:null,blur:null,change:null,click:null,dblclick:null,contextmenu:null,focus:null,mouseover:null,mouseout:null};let k=!1,A=null,L=null;const $=new WeakMap;function x(e){const t=e.value;return t&&t.trim()?t:$.get(e)||t}function T(e){const t=e.value;return!(t&&t.trim())&&$.has(e)}function M(e,t){const n=["focus","highlight","editable","caret"],o=Array.from(e.classList||[]).filter((e=>{const t=e.toLowerCase();return!n.some((e=>t.includes(e)))&&!/^[0-9]/.test(e)}));for(const n of o){const o="."+n;try{const n=t.querySelectorAll(o);if(1===n.length&&n[0]===e)return o}catch(e){}}return null}function O(e,t){let n;var o;let r,l;function i(e,t,o){let l=null;const i=[];let a=e,c=0;for(;a&&a!==r.root.parentElement;){let e=w(f(a))||w(...d(a))||w(...m(a))||w(h(a))||[{name:"*",penalty:3}];const u=p(a);if(t===n.All)u&&(e=e.concat(e.filter(y).map((e=>g(e,u)))));else if(t===n.Two)e=e.slice(0,1),u&&(e=e.concat(e.filter(y).map((e=>g(e,u)))));else if(t===n.One){const[t]=e=e.slice(0,1);u&&y(t)&&(e=[g(t,u)])}for(const t of e)t.level=c;if(i.push(e),i.length>=r.seedMinLength&&(l=s(i,o),l))break;a=a.parentElement,c++}return l||(l=s(i,o)),l}function s(e,t){const n=N(b(e));if(n.length>r.threshold)return t?t():null;for(const e of n)if(u(e))return e;return null}function a(e){let t=e[0],n=t.name;for(let o=1;o ${n}`:`${e[o].name} ${n}`,t=e[o]}return n}function c(e){return e.map((e=>e.penalty)).reduce(((e,t)=>e+t),0)}function u(e){switch(l.querySelectorAll(a(e)).length){case 0:throw new Error(`Can't select any node with this selector: ${a(e)}`);case 1:return!0;default:return!1}}function f(e){const t=e.getAttribute("id");return t&&r.idName(t)?{name:`#${L(t,{isIdentifier:!0})}`,penalty:0}:null}function d(e){return Array.from(e.attributes).filter((e=>r.attr(e.name,e.value))).map((e=>({name:"["+L(e.name,{isIdentifier:!0})+'="'+L(e.value)+'"]',penalty:.5})))}function m(e){return Array.from(e.classList).filter(r.className).map((e=>({name:"."+L(e,{isIdentifier:!0}),penalty:1})))}function h(e){const t=e.tagName.toLowerCase();return r.tagName(t)?{name:t,penalty:2}:null}function p(e){const t=e.parentNode;if(!t)return null;let n=t.firstChild;if(!n)return null;let o=0;for(;n&&(n.nodeType===Node.ELEMENT_NODE&&o++,n!==e);)n=n.nextSibling;return o}function g(e,t){return{name:e.name+`:nth-child(${t})`,penalty:e.penalty+1}}function y(e){return"html"!==e.name&&!e.name.startsWith("#")}function w(...e){const t=e.filter(v);return 0c(e)-c(t)))}function E(e,t){return l.querySelector(a(e))===t}(o=n||(n={}))[o.All=0]="All",o[o.Two=1]="Two",o[o.One=2]="One";const S=/[ -,\.\/:-@\[-\^`\{-~]/,C=/[ -,\.\/:-@\[\]\^`\{-~]/,k=/(^|\\+)?(\\[A-F0-9]{1,6})\x20(?![a-fA-F0-9\x20])/g,A={escapeEverything:!1,isIdentifier:!1,quotes:"single",wrap:!1};function L(e,t={}){const n=Object.assign(Object.assign({},A),t);"single"!==n.quotes&&"double"!==n.quotes&&(n.quotes="single");const o="double"==n.quotes?'"':"'",r=n.isIdentifier,l=e.charAt(0);let i="",s=0;for(const t=e.length;sc||126=c&&s!0,className:()=>!0,tagName:()=>!0,attr:()=>!1,seedMinLength:1,optimizedMinLength:2,threshold:1e3,maxNumberOfTries:1e4};r=Object.assign(Object.assign({},$),t),l=function(e,t){return e.nodeType===Node.DOCUMENT_NODE?e:e===t.root?e.ownerDocument:e}(r.root,$);let x=i(e,n.All,(()=>i(e,n.Two,(()=>i(e,n.One)))));if(x){const t=N(function*e(t,n,o={counter:0,visited:new Map}){if(2r.optimizedMinLength)for(let l=1;lr.maxNumberOfTries)return;o.counter+=1;const i=[...t];i.splice(l,1);const s=a(i);if(o.visited.has(s))return;u(i)&&E(i,n)&&(yield i,o.visited.set(s,!0),yield*e(i,n,o))}}(x,e));return 0{if(!l.isRecording)return;let i=!1,s=null;function a(e){e&&"mouseover"===e.type&&!i||function(e,t,o,r){let l=!1,i=null,s=null;e&&e.composed&&e.composedPath&&(s=e.composedPath());let a=-1;s&&s.length>0&&(a=s.findIndex((e=>e instanceof ShadowRoot))),i=a>-1?s[0]:e.target;const c=e.type;let u=null,f=null;if(!i||!i.getAttribute)return;u=i.nodeName.toLowerCase(),f=i.getAttribute("type");let d=null,m=null;try{m=function(e){let t=null;try{if(t=e.nodeName&&"string"==typeof e.nodeName?e.nodeName.toLowerCase():null,!t)return e;if(["input","button","a","textarea","select","option","progress"].includes(t))return e;const n=e.closest("button,a");if(n)return n;const o=e.closest("svg");o&&(e=o);const r=["data-test-id","data-testid","data-test","data-cy"];if(e.matches(r.map((e=>`[${e}]`)).join(",")))return e;if(e.parentNode.matches(r.map((e=>`[${e}]`)).join(",")))return e.parentNode}catch(e){}return e}(i),d=N(m)}catch(e){}if(!d)try{d=n(m,{root:t,idName:e=>!/^[0-9]+.*/i.test(e),className:e=>!e.includes("focus")&&!e.includes("highlight")&&!/^[0-9]+.*/i.test(e)})}catch(e){}if(d&&"html"===d.toLowerCase())return;let h=null;try{h=E(m,t)}catch(e){}a>-1&&(h="/html/node/shadow");let p={timestamp:(new Date).getTime(),css:d||i,xpath:h||""},g={};if("click"===c){if(C.click=i,A&&A.element!==i&&r){const e=T(A.element),n={...A.oEventBase,type:e?"bfill_value":"fill_value",value:x(A.element),frame:A.frame};if(e){const e=M(A.element,t);e&&(n.css=e)}r({messageType:"events",event:{...n}}),$.delete(A.element),L=A.element,A=null}if(!(C.return!==C.change||i===C.return||"input"!==u&&"button"!==u||"submit"!==f&&"image"!==f||null===C.return))return;if("input"===u&&("checkbox"===f||"radio"===f))return;const l=i.closest&&i.closest("label");if(l){const e=i.closest("a, button, input, select, textarea");if(!e||!l.contains(e)){const e=l.getAttribute("for");if(e){const t=i.getRootNode(),n=(t&&t.getElementById?t:document).getElementById(e);if(n&&"input"===n.nodeName.toLowerCase()&&("checkbox"===n.type||"radio"===n.type))return}if(l.querySelector('input[type="checkbox"], input[type="radio"]'))return}}let c="click";if(function(e){if("canvas"===e.nodeName.toLowerCase())return!0;if(e.shadowRoot)try{if(e.shadowRoot.querySelector("canvas"))return!0}catch(e){}for(const t of e.children||[])if(t.shadowRoot)try{if(t.shadowRoot.querySelector("canvas"))return!0}catch(e){}return!1}(i)){const t=i.getBoundingClientRect(),n={x:e.clientX-t.left,y:e.clientY-t.top,width:t.width,height:t.height};p={...p,coords:n},c="bclick"}if(g={...p,type:c,value:(i.value||i.textContent||"").trim().substr(0,20).replace(/\n/gi,""),frame:o},"bclick"===c&&a>-1&&s){const e=s[a].host;if(e){let o=null;try{o=N(e)}catch(e){}if(!o)try{o=n(e,{root:t,idName:e=>!/^[0-9]+.*/i.test(e),className:e=>!e.includes("focus")&&!e.includes("highlight")&&!/^[0-9]+.*/i.test(e)})}catch(e){}o&&(g.shadow_host_css=o)}}}else if("dblclick"===c)C.dblclick=i,g={...p,type:"dblclick",value:(i.value||i.textContent||"").trim().substr(0,20).replace(/\n/gi,""),frame:o};else if("contextmenu"===c)C.contextmenu=i,g={...p,type:"contextmenu",value:(i.value||i.textContent||"").trim().substr(0,20).replace(/\n/gi,""),frame:o};else if("focus"===c);else if("mouseover"===c)k&&(clearTimeout(k),k=!1),k=setTimeout((()=>{k=!1,C.mouseover=i,g={...p,type:"mouseover",value:(i.value||i.textContent||"").trim().substr(0,20).replace(/\n/gi,""),frame:o},g&&g.type&&r&&r({messageType:"events",event:{...g}})}),500);else if("mouseout"===c);else if("keydown"===c){if(C.keydown=i,["input","textarea"].indexOf(u)>-1)if(S[i]=i.value,A={element:i,oEventBase:{...p},frame:o},e.key&&1===e.key.length){const t=$.get(i)||"";$.set(i,t+e.key)}else if("Backspace"===e.key){const e=$.get(i)||"";e.length>0&&$.set(i,e.slice(0,-1))}if("input"===u&&13===e.keyCode){l=!0,C.return=i;const e=T(i);if(g={...p,type:e?"bfill_value":"fill_value",value:x(i),frame:o},e){const e=M(i,t);e&&(g.css=e)}$.delete(i)}}else if("blur"===c){if(C.blur=i,i===L)return void(L=null);if(A&&A.element===i&&(A=null),["input","textarea"].indexOf(u)>-1){if(S[i]=i.value,i===C.return)return void(C.return=null);if("input"===u&&("submit"===i.type||"button"===i.type||"image"===i.type))return;const e=T(i);if(g={...p,type:e?"bfill_value":"fill_value",value:x(i),frame:o},e){const e=M(i,t);e&&(g.css=e)}$.delete(i)}}else if("change"===c)if(C.change=i,"input"===u)"checkbox"!==f&&"radio"!==f||(g={...p,type:"change",subtype:"check",checked:i.checked,frame:o});else if("select"===u)if(i.multiple){const e=[];for(let t=0;t{window!==window.top?window.parent.postMessage({source:"event-from-iframe",obj:{...e},framePath:[]},"*"):chrome.runtime.sendMessage(e)}))}window===window.top&&window.addEventListener("message",(e=>{if(e.data&&e.data.source&&"event-from-iframe"===e.data.source){const t=document.querySelectorAll("iframe, frame");let n=!1;for(const o of t)if(o.contentWindow===e.source){n=!0;break}if(!n)return;const o={...e.data.obj},r=e.data.framePath||[];for(const n of t)if(n.contentWindow===e.source){let e=null;try{e=N(n)}catch(e){}if(!e)try{e=O(n,{root:window.document,idName:e=>!/^[0-9]+.*/i.test(e),className:e=>!e.includes("focus")&&!e.includes("highlight")&&!/^[0-9]+.*/i.test(e)})}catch(e){}if(e&&o.event){const t=[e,...r];o.event.frame=t.join(" >>> "),chrome.runtime.sendMessage(o)}break}}})),window!==window.top&&window.addEventListener("message",(e=>{if(e.data&&e.data.source&&"event-from-iframe"===e.data.source){const t=document.querySelectorAll("iframe, frame");let n=!1;for(const o of t)if(o.contentWindow===e.source){n=!0;break}if(!n)return;const o=e.data.framePath||[];for(const n of t)if(n.contentWindow===e.source){let t=null;try{t=N(n)}catch(e){}if(!t)try{t=O(n,{root:window.document,idName:e=>!/^[0-9]+.*/i.test(e),className:e=>!e.includes("focus")&&!e.includes("highlight")&&!/^[0-9]+.*/i.test(e)})}catch(e){}t&&o.push(t),window.parent.postMessage({source:"event-from-iframe",obj:e.data.obj,framePath:o},"*");break}}})),l.isRecording&&(t=!0,e=document.title,function(){if(!t)return document.title=`${e}`,r=!1,void(o&&(clearInterval(o),o=!1));o=setInterval((()=>{r?(document.title=`${e}`,r=!1):(document.title=`🔴 ${e}`,r=!0)}),1e3)}(),window===window.top&&chrome.runtime.sendMessage({messageType:"events",event:{type:"goto",timestamp:(new Date).getTime(),windowWidth:window.innerWidth,windowHeight:window.innerHeight,url:window.location.href}}),document.addEventListener("click",a,!0),document.addEventListener("mouseover",a,!0),document.addEventListener("dblclick",a,!0),document.addEventListener("contextmenu",a,!0),document.addEventListener("keydown",a,!0),document.addEventListener("blur",a,!0),document.addEventListener("change",a,!0));const c={attributes:!1,childList:!0,subtree:!0},u=new MutationObserver((async(e,t)=>{i=!0,s&&(clearTimeout(s),s=null),s=setTimeout((()=>{i=!1}),200)}));document.body&&u.observe(document.body,c)}))}()})(); \ No newline at end of file diff --git a/test-build/manifest.json b/test-build/manifest.json index b287239..7787a55 100644 --- a/test-build/manifest.json +++ b/test-build/manifest.json @@ -1 +1 @@ -{"version":"1.2.1","manifest_version":3,"name":"Snyk API & Web Sequence Recorder","action":{"default_popup":"popup.html","default_icon":{"16":"icon-34.png","48":"icon-48.png"}},"icons":{"128":"icon-128.png"},"background":{"service_worker":"background.bundle.js"},"content_scripts":[{"matches":["http://*/*","https://*/*"],"js":["contentScript.bundle.js"],"css":["content.styles.css"],"run_at":"document_start","all_frames":true,"match_about_blank":true}],"web_accessible_resources":[{"resources":["content.styles.css","icon-128.png","icon-34.png"],"matches":[""]}],"permissions":["storage","activeTab"],"host_permissions":["http://*/*","https://*/*"]} \ No newline at end of file +{"version":"1.2.2","manifest_version":3,"name":"Snyk API & Web Sequence Recorder","action":{"default_popup":"popup.html","default_icon":{"16":"icon-34.png","48":"icon-48.png"}},"icons":{"128":"icon-128.png"},"background":{"service_worker":"background.bundle.js"},"content_scripts":[{"matches":["http://*/*","https://*/*"],"js":["contentScript.bundle.js"],"css":["content.styles.css"],"run_at":"document_start","all_frames":true,"match_about_blank":true}],"web_accessible_resources":[{"resources":["content.styles.css","icon-128.png","icon-34.png"],"matches":[""]}],"permissions":["storage","activeTab"],"host_permissions":["http://*/*","https://*/*"]} \ No newline at end of file