From d46d95bd9025ff4ff2cbf7cb4e046e35c3940a66 Mon Sep 17 00:00:00 2001 From: Daniel Pascual Date: Fri, 28 Jun 2024 10:50:48 +0200 Subject: [PATCH] Reload widget when the user is already signed in (#41) --- dist/vt-augment.min.js | 20 ++++++++++---------- package.json | 2 +- src/vt-augment.js | 21 +++++---------------- 3 files changed, 16 insertions(+), 27 deletions(-) diff --git a/dist/vt-augment.min.js b/dist/vt-augment.min.js index 4104c43..5c93502 100644 --- a/dist/vt-augment.min.js +++ b/dist/vt-augment.min.js @@ -60,17 +60,17 @@ a:a.ownerDocument||a.document).createTextNode(String(b)))}else a.innerHTML=b};/* THE SOFTWARE. */ var tb={mode:"drawer",background:"",closingFromOutside:!0}; -function Z(a,b){var c=this;if(!a)throw Error("Missing container, a valid dom element is required");this.g=a;this.h=ub(b||{});vb();this.g.classList.add("vt-augment");this.h.background&&(this.g.style.background=this.h.background);"drawer"===this.h.mode&&this.g.classList.add("drawer");this.h.closingFromOutside&&document.body.addEventListener("click",function(d){d.target!==c.g&&c.o()});window.addEventListener("message",function(d){var e;if(d.source===(null==(e=c.g.querySelector("iframe"))?void 0:e.contentWindow))switch(d.data){case "VTAUGMENT:READY":c.m(!1); -break;case "VTAUGMENT:CLOSE":c.o();break;case "VTAUGMENT:CLEAR_CACHE":case "VTAUGMENT:RELOAD":c.reload()}})} -Z.prototype.load=function(a){if(!a)return this;a=a.split("/").pop();a=ua({token:a});var b=new G(ta(a).toString(),H);this.m(!0);if(a=this.g.querySelector("iframe"))a.src=I(b);else{a=this.g;var c={style:{width:"100%",height:"100%",border:"0"},frameborder:0,tabIndex:"-1",title:"VirusTotal Augment"};"standalone"===this.h.mode&&(c.name=this.h.mode);if(b){var d=document.createElement("div");d.style.display="none";if(!(m.HTMLIFrameElement&&"sandbox"in m.HTMLIFrameElement.prototype))throw Error("The browser does not support sandboxed iframes."); -var e={};e.src=b?I(J(b)||K):null;e.srcdoc=null;e.sandbox="";var f={};b={};for(var h in e)Object.prototype.hasOwnProperty.call(e,h)&&(b[h]=e[h]);for(h in f)Object.prototype.hasOwnProperty.call(f,h)&&(b[h]=f[h]);if(c)for(h in c)if(Object.prototype.hasOwnProperty.call(c,h)){var g=h.toLowerCase();if(g in e)throw Error('Cannot override "'+g+'" attribute, got "'+h+'" with value "'+c[h]+'"');g in f&&delete b[g];b[h]=c[h]}h=null;c="";if(b)for(p in b)if(Object.prototype.hasOwnProperty.call(b,p)){if(!Wa.test(p))throw Error('Invalid attribute name "'+ -p+'".');f=b[p];if(null!=f){e=p;g=f;if(g instanceof x)g=A(g);else if("style"==e.toLowerCase()){f=void 0;if(!r(g))throw Error('The "style" attribute requires goog.html.SafeStyle or map of style properties, '+typeof g+" given: "+g);if(!(g instanceof L)){var D="";for(f in g)if(Object.prototype.hasOwnProperty.call(g,f)){if(!/^[-_a-zA-Z0-9]+$/.test(f))throw Error("Name allows only [-_a-zA-Z0-9], got: "+f);var z=g[f];null!=z&&(z=Array.isArray(z)?la(z,Ja).join(" "):Ja(z),D+=f+":"+z+";")}g=D?new L(D,M):Ia}g instanceof -L&&g.constructor===L?f=g.g:(w("expected object of type SafeStyle, got '"+g+"' of type "+q(g)),f="type_error:SafeStyle");g=f}else{if(/^on/i.test(e))throw Error('Attribute "'+e+'" requires goog.string.Const value, "'+g+'" given.');if(e.toLowerCase()in Xa)if(g instanceof E)g=ta(g).toString();else if(g instanceof G)g=I(g);else if("string"===typeof g)g=(J(g)||K).j();else throw Error('Attribute "'+e+'" on tag "iframe" requires goog.html.SafeUrl, goog.string.Const, or string, value "'+g+'" given.');}g.l&& -(g=g.j());e=e+'="'+F(String(g))+'"';c+=" "+e}}var p="":(h=$a(c),p+=">"+S(h).toString()+"",h=h.g());(b=b&&b.dir)&&(/^(ltr|rtl|auto)$/i.test(b)?h=0:h=null);p=T(p,h);if(d.tagName&&ab[d.tagName.toUpperCase()])throw Error("goog.dom.safe.setInnerHtml cannot be used to set content of "+d.tagName+".");if(bb())for(;d.lastChild;)d.removeChild(d.lastChild);d.innerHTML=S(p);d.firstChild.setAttribute("sandbox","allow-forms allow-scripts allow-same-origin allow-popups allow-storage-access-by-user-activation"); -a.appendChild(d.removeChild(d.firstChild))}}return this};Z.prototype.reload=function(){this.m(!0);var a=this.g.querySelector("iframe");a.src=a.src;return this};Z.prototype.u=function(){if("drawer"===this.h.mode){var a=this.g.querySelector("iframe");this.g.setAttribute("opened","");a&&a.removeAttribute("tabindex")}return this}; -Z.prototype.o=function(){if("drawer"===this.h.mode){var a=this.g.querySelector("iframe");this.g.removeAttribute("opened");a&&(a.setAttribute("tabindex","-1"),a.style.display="none")}return this};Z.prototype.m=function(a){var b=this.g,c=b.querySelector("div.spinner");c||(c=document.createElement("div"),c.classList.add("spinner"),b.appendChild(c));b=this.g.querySelector("iframe");c.style.display=a?"block":"none";b&&(b.style.display=a?"none":"block",b.focus());return this}; +function Z(a,b){var c=this;if(!a)throw Error("Missing container, a valid dom element is required");this.g=a;this.h=ub(b||{});vb();this.g.classList.add("vt-augment");this.h.background&&(this.g.style.background=this.h.background);"drawer"===this.h.mode&&this.g.classList.add("drawer");this.h.closingFromOutside&&document.body.addEventListener("click",function(d){d.target!==c.g&&c.m()});window.addEventListener("message",function(d){var e;if(d.source===(null==(e=c.g.querySelector("iframe"))?void 0:e.contentWindow))switch(d.data){case "VTAUGMENT:READY":c.o(!1); +break;case "VTAUGMENT:CLOSE":c.m()}})} +Z.prototype.load=function(a){if(!a)return this;a=a.split("/").pop();a=ua({token:a});var b=new G(ta(a).toString(),H);this.o(!0);if(a=this.g.querySelector("iframe")){var c={action:"VTAUGMENT:IFRAME:LOAD",payload:I(b)};a.contentWindow.postMessage(c,"*")}else{a=this.g;var d={style:{width:"100%",height:"100%",border:"0"},frameborder:0,tabIndex:"-1",title:"VirusTotal Augment"};"standalone"===this.h.mode&&(d.name=this.h.mode);if(b){c=document.createElement("div");c.style.display="none";if(!(m.HTMLIFrameElement&& +"sandbox"in m.HTMLIFrameElement.prototype))throw Error("The browser does not support sandboxed iframes.");var e={};e.src=b?I(J(b)||K):null;e.srcdoc=null;e.sandbox="";var f={};b={};for(var h in e)Object.prototype.hasOwnProperty.call(e,h)&&(b[h]=e[h]);for(h in f)Object.prototype.hasOwnProperty.call(f,h)&&(b[h]=f[h]);if(d)for(h in d)if(Object.prototype.hasOwnProperty.call(d,h)){var g=h.toLowerCase();if(g in e)throw Error('Cannot override "'+g+'" attribute, got "'+h+'" with value "'+d[h]+'"');g in f&& +delete b[g];b[h]=d[h]}h=null;d="";if(b)for(p in b)if(Object.prototype.hasOwnProperty.call(b,p)){if(!Wa.test(p))throw Error('Invalid attribute name "'+p+'".');f=b[p];if(null!=f){e=p;g=f;if(g instanceof x)g=A(g);else if("style"==e.toLowerCase()){f=void 0;if(!r(g))throw Error('The "style" attribute requires goog.html.SafeStyle or map of style properties, '+typeof g+" given: "+g);if(!(g instanceof L)){var D="";for(f in g)if(Object.prototype.hasOwnProperty.call(g,f)){if(!/^[-_a-zA-Z0-9]+$/.test(f))throw Error("Name allows only [-_a-zA-Z0-9], got: "+ +f);var z=g[f];null!=z&&(z=Array.isArray(z)?la(z,Ja).join(" "):Ja(z),D+=f+":"+z+";")}g=D?new L(D,M):Ia}g instanceof L&&g.constructor===L?f=g.g:(w("expected object of type SafeStyle, got '"+g+"' of type "+q(g)),f="type_error:SafeStyle");g=f}else{if(/^on/i.test(e))throw Error('Attribute "'+e+'" requires goog.string.Const value, "'+g+'" given.');if(e.toLowerCase()in Xa)if(g instanceof E)g=ta(g).toString();else if(g instanceof G)g=I(g);else if("string"===typeof g)g=(J(g)||K).j();else throw Error('Attribute "'+ +e+'" on tag "iframe" requires goog.html.SafeUrl, goog.string.Const, or string, value "'+g+'" given.');}g.l&&(g=g.j());e=e+'="'+F(String(g))+'"';d+=" "+e}}var p="":(h=$a(d),p+=">"+S(h).toString()+"",h=h.g());(b=b&&b.dir)&&(/^(ltr|rtl|auto)$/i.test(b)?h=0:h=null);p=T(p,h);if(c.tagName&&ab[c.tagName.toUpperCase()])throw Error("goog.dom.safe.setInnerHtml cannot be used to set content of "+c.tagName+".");if(bb())for(;c.lastChild;)c.removeChild(c.lastChild); +c.innerHTML=S(p);c.firstChild.setAttribute("sandbox","allow-forms allow-scripts allow-same-origin allow-popups allow-storage-access-by-user-activation");a.appendChild(c.removeChild(c.firstChild))}}return this};Z.prototype.u=function(){if("drawer"===this.h.mode){var a=this.g.querySelector("iframe");this.g.setAttribute("opened","");a&&a.removeAttribute("tabindex")}return this}; +Z.prototype.m=function(){if("drawer"===this.h.mode){var a=this.g.querySelector("iframe");this.g.removeAttribute("opened");a&&(a.setAttribute("tabindex","-1"),a.style.display="none")}return this};Z.prototype.o=function(a){var b=this.g,c=b.querySelector("div.spinner");c||(c=document.createElement("div"),c.classList.add("spinner"),b.appendChild(c));b=this.g.querySelector("iframe");c.style.display=a?"block":"none";b&&(b.style.display=a?"none":"block",b.focus());return this}; function vb(){var a=document.createElement("style");var b=A(new x(y,"\n .vt-augment {\n position: relative;\n display: flex;\n justify-content: center;\n align-items: center;\n }\n .vt-augment.drawer {\n display: none;\n width: 700px;\n background: white;\n border: 1px solid #e6e6e6;\n text-align: left;\n z-index: 102;\n position: fixed;\n right: 0;\n top: 0;\n height: 100vh;\n box-shadow: -4px 5px 8px -3px rgba(17, 17, 17, .16);\n animation: slideToRight 0.5s 1 forwards;\n transform: translateX(100vw);\n }\n .vt-augment.drawer[opened] {\n display: flex;\n animation: slideFromRight 0.2s 1 forwards;\n }\n .vt-augment > .spinner {\n position: absolute;\n z-index: 199;\n top: calc(50% - 50px);\n left: calc(50% - 50px);\n border: 8px solid rgba(0, 0, 0, 0.2);\n border-left-color: white;\n border-radius: 50%;\n width: 50px;\n height: 50px;\n animation: spin 1.2s linear infinite;\n }\n @keyframes spin {\n to { transform: rotate(360deg); }\n }\n @keyframes slideFromRight {\n 0% {\n transform: translateX(100vw);\n }\n 100% {\n transform: translateX(0);\n }\n }\n @keyframes slideToRight {\n 100% {\n transform: translateX(100vw);\n display: none;\n }\n }\n @media screen and (max-width: 700px) {\n .vt-augment.drawer {\n width: 100%;\n }\n }\n")); b=0===b.length?Sa:new O(b,N);var c=a?new qb(9==a.nodeType?a:a.ownerDocument||a.document):ja||(ja=new qb),d=c.g;if(U&&d.createStyleSheet)d=d.createStyleSheet(),sb(d,b);else{d=rb(c,"HEAD")[0];if(!d){var e=rb(c,"BODY")[0];d=c.h("HEAD");e.parentNode.insertBefore(d,e)}c=c.h("STYLE");if(null===n)b:{e=m.document;if((e=e.querySelector&&e.querySelector("script[nonce]"))&&(e=e.nonce||e.getAttribute("nonce"))&&fa.test(e)){n=e;break b}n=""}(e=n)&&c.setAttribute("nonce",e);sb(c,b);d.appendChild(c)}document.body.appendChild(a)} -function ub(a){var b=Object.assign({},tb);a&&Object.keys(a).map(function(c){b.hasOwnProperty(c)&&(b[c]=a[c])});return b}Z.prototype.loading=Z.prototype.m;Z.prototype.closeDrawer=Z.prototype.o;Z.prototype.openDrawer=Z.prototype.u;Z.prototype.reload=Z.prototype.reload;Z.prototype.load=Z.prototype.load;window.VTAugment=Z; +function ub(a){var b=Object.assign({},tb);a&&Object.keys(a).map(function(c){b.hasOwnProperty(c)&&(b[c]=a[c])});return b}Z.prototype.loading=Z.prototype.o;Z.prototype.closeDrawer=Z.prototype.m;Z.prototype.openDrawer=Z.prototype.u;Z.prototype.load=Z.prototype.load;window.VTAugment=Z; }.bind(this))); diff --git a/package.json b/package.json index e4aad09..88dacf7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@virustotal/vt-augment", - "version": "1.7.3", + "version": "1.7.4", "description": "Client library that wraps common patterns when interact with the VirusTotal Augment product", "main": "dist/vt-augment.min.js", "keywords": [ diff --git a/src/vt-augment.js b/src/vt-augment.js index 4a6b0e2..2de3a15 100644 --- a/src/vt-augment.js +++ b/src/vt-augment.js @@ -167,7 +167,11 @@ class VTAugment { this.loading(true); const iframe = this.container.querySelector('iframe'); if (iframe) { - iframe.src = SafeUrl.unwrap(safeUrl); + const eventMessage = { + 'action': 'VTAUGMENT:IFRAME:LOAD', + 'payload': SafeUrl.unwrap(safeUrl), + } + iframe.contentWindow.postMessage(eventMessage, '*'); } else { this.createIframe_(this.container, safeUrl); } @@ -175,17 +179,6 @@ class VTAugment { return this; } - /** - * @export - * @return {!VTAugment} - */ - reload() { - this.loading(true); - const iframe = this.container.querySelector('iframe'); - iframe.src = iframe.src - return this; - } - /** * @export * @return {!VTAugment} @@ -317,10 +310,6 @@ class VTAugment { case 'VTAUGMENT:CLOSE': this.closeDrawer(); break; - case 'VTAUGMENT:CLEAR_CACHE': - case 'VTAUGMENT:RELOAD': - this.reload(); - break; default: } }