diff --git a/libs/src/LSPlugin.caller.ts b/libs/src/LSPlugin.caller.ts index 214c1cbc2..4c2022102 100644 --- a/libs/src/LSPlugin.caller.ts +++ b/libs/src/LSPlugin.caller.ts @@ -72,7 +72,7 @@ class LSPluginCaller extends EventEmitter { let syncGCTimer: any = 0 let syncTag = 0 const syncActors = new Map() - const readyDeferred = deferred(1000 * 5) + const readyDeferred = deferred(1000 * 60) const model: any = this._extendUserModel({ [LSPMSG_READY]: async (baseInfo) => { @@ -266,7 +266,8 @@ class LSPluginCaller extends EventEmitter { return new Promise((resolve, reject) => { timer = setTimeout(() => { reject(new Error(`handshake Timeout`)) - }, 8 * 1000) // 8 secs + pt.destroy() + }, 4 * 1000) // 4 secs handshake .then((refChild: ParentAPI) => { diff --git a/libs/src/LSPlugin.core.ts b/libs/src/LSPlugin.core.ts index 0afa1a8c4..700496824 100644 --- a/libs/src/LSPlugin.core.ts +++ b/libs/src/LSPlugin.core.ts @@ -1128,6 +1128,7 @@ class LSPluginCore | 'registered' | 'error' | 'unregistered' + | 'ready' | 'themes-changed' | 'theme-selected' | 'reset-custom-theme' @@ -1261,7 +1262,26 @@ class LSPluginCore await this.loadUserPreferences() - const externals = new Set(this._userPreferences.externals) + let externals = new Set(this._userPreferences.externals) + + // valid externals + if (externals?.size) { + try { + const validatedExternals: Record = await invokeHostExportedApi( + 'validate_external_plugins', [...externals] + ) + + externals = new Set([...Object.entries(validatedExternals)].reduce( + (a, [k, v]) => { + if (v) { + a.push(k) + } + return a + }, [])) + } catch (e) { + console.error('[validatedExternals Error]', e) + } + } if (initial) { plugins = plugins.concat( @@ -1287,10 +1307,12 @@ class LSPluginCore ) const perfInfo = { o: pluginLocal, s: performance.now(), e: 0 } - perfTable.set(pluginLocal.id, perfInfo) + perfTable.set(url, perfInfo) await pluginLocal.load({ indicator: readyIndicator }) + perfInfo.e = performance.now() + const { loadErr } = pluginLocal if (loadErr) { @@ -1307,7 +1329,6 @@ class LSPluginCore } } - perfInfo.e = performance.now() pluginLocal.settings?.on('change', (a) => { this.emit('settings-changed', pluginLocal.id, a) @@ -1331,6 +1352,7 @@ class LSPluginCore console.error(e) } finally { this._isRegistering = false + this.emit('ready', perfTable) debugPerfInfo() } } diff --git a/libs/src/postmate/index.ts b/libs/src/postmate/index.ts index 11f4ab6ca..f7c1bb9c4 100644 --- a/libs/src/postmate/index.ts +++ b/libs/src/postmate/index.ts @@ -374,6 +374,14 @@ export class Postmate { this.frame.src = url }) } + + + destroy() { + if (process.env.NODE_ENV !== 'production') { + log('Postmate: Destroying Postmate instance') + } + this.frame.parentNode.removeChild(this.frame) + } } /** diff --git a/resources/js/lsplugin.core.js b/resources/js/lsplugin.core.js index c644503eb..c0c5d451a 100644 --- a/resources/js/lsplugin.core.js +++ b/resources/js/lsplugin.core.js @@ -1,2 +1,2 @@ /*! For license information please see lsplugin.core.js.LICENSE.txt */ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.LSPlugin=t():e.LSPlugin=t()}(self,(()=>(()=>{var e={227:(e,t,n)=>{var r=n(155);t.formatArgs=function(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+e.exports.humanize(this.diff),!this.useColors)return;const n="color: "+this.color;t.splice(1,0,n,"color: inherit");let r=0,i=0;t[0].replace(/%[a-zA-Z%]/g,(e=>{"%%"!==e&&(r++,"%c"===e&&(i=r))})),t.splice(i,0,n)},t.save=function(e){try{e?t.storage.setItem("debug",e):t.storage.removeItem("debug")}catch(e){}},t.load=function(){let e;try{e=t.storage.getItem("debug")}catch(e){}return!e&&void 0!==r&&"env"in r&&(e=r.env.DEBUG),e},t.useColors=function(){return!("undefined"==typeof window||!window.process||"renderer"!==window.process.type&&!window.process.__nwjs)||("undefined"==typeof navigator||!navigator.userAgent||!navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))&&("undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/))},t.storage=function(){try{return localStorage}catch(e){}}(),t.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),t.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],t.log=console.debug||console.log||(()=>{}),e.exports=n(447)(t);const{formatters:i}=e.exports;i.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}},447:(e,t,n)=>{e.exports=function(e){function t(e){let n,i=null;function o(...e){if(!o.enabled)return;const r=o,i=Number(new Date),s=i-(n||i);r.diff=s,r.prev=n,r.curr=i,n=i,e[0]=t.coerce(e[0]),"string"!=typeof e[0]&&e.unshift("%O");let a=0;e[0]=e[0].replace(/%([a-zA-Z%])/g,((n,i)=>{if("%%"===n)return"%";a++;const o=t.formatters[i];if("function"==typeof o){const t=e[a];n=o.call(r,t),e.splice(a,1),a--}return n})),t.formatArgs.call(r,e),(r.log||t.log).apply(r,e)}return o.namespace=e,o.useColors=t.useColors(),o.color=t.selectColor(e),o.extend=r,o.destroy=t.destroy,Object.defineProperty(o,"enabled",{enumerable:!0,configurable:!1,get:()=>null===i?t.enabled(e):i,set:e=>{i=e}}),"function"==typeof t.init&&t.init(o),o}function r(e,n){const r=t(this.namespace+(void 0===n?":":n)+e);return r.log=this.log,r}function i(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return t.debug=t,t.default=t,t.coerce=function(e){return e instanceof Error?e.stack||e.message:e},t.disable=function(){const e=[...t.names.map(i),...t.skips.map(i).map((e=>"-"+e))].join(",");return t.enable(""),e},t.enable=function(e){let n;t.save(e),t.names=[],t.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),i=r.length;for(n=0;n{t[n]=e[n]})),t.names=[],t.skips=[],t.formatters={},t.selectColor=function(e){let n=0;for(let t=0;te.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?n-1:0),i=1;i/gm),W=h(/^data-[\-\w.\u00B7-\uFFFF]/),G=h(/^aria-[\-\w]+$/),J=h(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|cid|xmpp):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),Z=h(/^(?:\w+script|data):/i),K=h(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),V=h(/^html$/i),Y=function(){return"undefined"==typeof window?null:window},X=function(t,n){if("object"!==e(t)||"function"!=typeof t.createPolicy)return null;var r=null,i="data-tt-policy-suffix";n.currentScript&&n.currentScript.hasAttribute(i)&&(r=n.currentScript.getAttribute(i));var o="dompurify"+(r?"#"+r:"");try{return t.createPolicy(o,{createHTML:function(e){return e}})}catch(e){return console.warn("TrustedTypes policy "+o+" could not be created."),null}};return function t(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Y(),r=function(e){return t(e)};if(r.version="2.3.8",r.removed=[],!n||!n.document||9!==n.document.nodeType)return r.isSupported=!1,r;var o=n.document,s=n.document,a=n.DocumentFragment,c=n.HTMLTemplateElement,l=n.Node,u=n.Element,h=n.NodeFilter,p=n.NamedNodeMap,f=void 0===p?n.NamedNodeMap||n.MozNamedAttrMap:p,g=n.HTMLFormElement,m=n.DOMParser,y=n.trustedTypes,k=u.prototype,Q=I(k,"cloneNode"),ee=I(k,"nextSibling"),te=I(k,"childNodes"),ne=I(k,"parentNode");if("function"==typeof c){var re=s.createElement("template");re.content&&re.content.ownerDocument&&(s=re.content.ownerDocument)}var ie=X(y,o),oe=ie?ie.createHTML(""):"",se=s,ae=se.implementation,ce=se.createNodeIterator,le=se.createDocumentFragment,ue=se.getElementsByTagName,de=o.importNode,he={};try{he=j(s).documentMode?s.documentMode:{}}catch(e){}var pe={};r.isSupported="function"==typeof ne&&ae&&void 0!==ae.createHTMLDocument&&9!==he;var fe,ge,me=q,ye=B,_e=W,be=G,ve=Z,we=K,xe=J,Ce=null,Se=T({},[].concat(i(L),i(N),i(M),i(F),i(D))),Ee=null,Oe=T({},[].concat(i(U),i($),i(z),i(H))),Ae=Object.seal(Object.create(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),ke=null,Te=null,je=!0,Ie=!0,Le=!1,Ne=!1,Me=!1,Re=!1,Fe=!1,Pe=!1,De=!1,Ue=!1,$e=!0,ze=!0,He=!1,qe={},Be=null,We=T({},["annotation-xml","audio","colgroup","desc","foreignobject","head","iframe","math","mi","mn","mo","ms","mtext","noembed","noframes","noscript","plaintext","script","style","svg","template","thead","title","video","xmp"]),Ge=null,Je=T({},["audio","video","img","source","image","track"]),Ze=null,Ke=T({},["alt","class","for","id","label","name","pattern","placeholder","role","summary","title","value","style","xmlns"]),Ve="http://www.w3.org/1998/Math/MathML",Ye="http://www.w3.org/2000/svg",Xe="http://www.w3.org/1999/xhtml",Qe=Xe,et=!1,tt=["application/xhtml+xml","text/html"],nt="text/html",rt=null,it=s.createElement("form"),ot=function(e){return e instanceof RegExp||e instanceof Function},st=function(t){rt&&rt===t||(t&&"object"===e(t)||(t={}),t=j(t),Ce="ALLOWED_TAGS"in t?T({},t.ALLOWED_TAGS):Se,Ee="ALLOWED_ATTR"in t?T({},t.ALLOWED_ATTR):Oe,Ze="ADD_URI_SAFE_ATTR"in t?T(j(Ke),t.ADD_URI_SAFE_ATTR):Ke,Ge="ADD_DATA_URI_TAGS"in t?T(j(Je),t.ADD_DATA_URI_TAGS):Je,Be="FORBID_CONTENTS"in t?T({},t.FORBID_CONTENTS):We,ke="FORBID_TAGS"in t?T({},t.FORBID_TAGS):{},Te="FORBID_ATTR"in t?T({},t.FORBID_ATTR):{},qe="USE_PROFILES"in t&&t.USE_PROFILES,je=!1!==t.ALLOW_ARIA_ATTR,Ie=!1!==t.ALLOW_DATA_ATTR,Le=t.ALLOW_UNKNOWN_PROTOCOLS||!1,Ne=t.SAFE_FOR_TEMPLATES||!1,Me=t.WHOLE_DOCUMENT||!1,Pe=t.RETURN_DOM||!1,De=t.RETURN_DOM_FRAGMENT||!1,Ue=t.RETURN_TRUSTED_TYPE||!1,Fe=t.FORCE_BODY||!1,$e=!1!==t.SANITIZE_DOM,ze=!1!==t.KEEP_CONTENT,He=t.IN_PLACE||!1,xe=t.ALLOWED_URI_REGEXP||xe,Qe=t.NAMESPACE||Xe,t.CUSTOM_ELEMENT_HANDLING&&ot(t.CUSTOM_ELEMENT_HANDLING.tagNameCheck)&&(Ae.tagNameCheck=t.CUSTOM_ELEMENT_HANDLING.tagNameCheck),t.CUSTOM_ELEMENT_HANDLING&&ot(t.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)&&(Ae.attributeNameCheck=t.CUSTOM_ELEMENT_HANDLING.attributeNameCheck),t.CUSTOM_ELEMENT_HANDLING&&"boolean"==typeof t.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements&&(Ae.allowCustomizedBuiltInElements=t.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements),fe=fe=-1===tt.indexOf(t.PARSER_MEDIA_TYPE)?nt:t.PARSER_MEDIA_TYPE,ge="application/xhtml+xml"===fe?function(e){return e}:w,Ne&&(Ie=!1),De&&(Pe=!0),qe&&(Ce=T({},i(D)),Ee=[],!0===qe.html&&(T(Ce,L),T(Ee,U)),!0===qe.svg&&(T(Ce,N),T(Ee,$),T(Ee,H)),!0===qe.svgFilters&&(T(Ce,M),T(Ee,$),T(Ee,H)),!0===qe.mathMl&&(T(Ce,F),T(Ee,z),T(Ee,H))),t.ADD_TAGS&&(Ce===Se&&(Ce=j(Ce)),T(Ce,t.ADD_TAGS)),t.ADD_ATTR&&(Ee===Oe&&(Ee=j(Ee)),T(Ee,t.ADD_ATTR)),t.ADD_URI_SAFE_ATTR&&T(Ze,t.ADD_URI_SAFE_ATTR),t.FORBID_CONTENTS&&(Be===We&&(Be=j(Be)),T(Be,t.FORBID_CONTENTS)),ze&&(Ce["#text"]=!0),Me&&T(Ce,["html","head","body"]),Ce.table&&(T(Ce,["tbody"]),delete ke.tbody),d&&d(t),rt=t)},at=T({},["mi","mo","mn","ms","mtext"]),ct=T({},["foreignobject","desc","title","annotation-xml"]),lt=T({},["title","style","font","a","script"]),ut=T({},N);T(ut,M),T(ut,R);var dt=T({},F);T(dt,P);var ht=function(e){var t=ne(e);t&&t.tagName||(t={namespaceURI:Xe,tagName:"template"});var n=w(e.tagName),r=w(t.tagName);return e.namespaceURI===Ye?t.namespaceURI===Xe?"svg"===n:t.namespaceURI===Ve?"svg"===n&&("annotation-xml"===r||at[r]):Boolean(ut[n]):e.namespaceURI===Ve?t.namespaceURI===Xe?"math"===n:t.namespaceURI===Ye?"math"===n&&ct[r]:Boolean(dt[n]):e.namespaceURI===Xe&&!(t.namespaceURI===Ye&&!ct[r])&&!(t.namespaceURI===Ve&&!at[r])&&!dt[n]&&(lt[n]||!ut[n])},pt=function(e){v(r.removed,{element:e});try{e.parentNode.removeChild(e)}catch(t){try{e.outerHTML=oe}catch(t){e.remove()}}},ft=function(e,t){try{v(r.removed,{attribute:t.getAttributeNode(e),from:t})}catch(e){v(r.removed,{attribute:null,from:t})}if(t.removeAttribute(e),"is"===e&&!Ee[e])if(Pe||De)try{pt(t)}catch(e){}else try{t.setAttribute(e,"")}catch(e){}},gt=function(e){var t,n;if(Fe)e=""+e;else{var r=x(e,/^[\r\n\t ]+/);n=r&&r[0]}"application/xhtml+xml"===fe&&(e=''+e+"");var i=ie?ie.createHTML(e):e;if(Qe===Xe)try{t=(new m).parseFromString(i,fe)}catch(e){}if(!t||!t.documentElement){t=ae.createDocument(Qe,"template",null);try{t.documentElement.innerHTML=et?"":i}catch(e){}}var o=t.body||t.documentElement;return e&&n&&o.insertBefore(s.createTextNode(n),o.childNodes[0]||null),Qe===Xe?ue.call(t,Me?"html":"body")[0]:Me?t.documentElement:o},mt=function(e){return ce.call(e.ownerDocument||e,e,h.SHOW_ELEMENT|h.SHOW_COMMENT|h.SHOW_TEXT,null,!1)},yt=function(e){return e instanceof g&&("string"!=typeof e.nodeName||"string"!=typeof e.textContent||"function"!=typeof e.removeChild||!(e.attributes instanceof f)||"function"!=typeof e.removeAttribute||"function"!=typeof e.setAttribute||"string"!=typeof e.namespaceURI||"function"!=typeof e.insertBefore)},_t=function(t){return"object"===e(l)?t instanceof l:t&&"object"===e(t)&&"number"==typeof t.nodeType&&"string"==typeof t.nodeName},bt=function(e,t,n){pe[e]&&_(pe[e],(function(e){e.call(r,t,n,rt)}))},vt=function(e){var t;if(bt("beforeSanitizeElements",e,null),yt(e))return pt(e),!0;if(O(/[\u0080-\uFFFF]/,e.nodeName))return pt(e),!0;var n=ge(e.nodeName);if(bt("uponSanitizeElement",e,{tagName:n,allowedTags:Ce}),e.hasChildNodes()&&!_t(e.firstElementChild)&&(!_t(e.content)||!_t(e.content.firstElementChild))&&O(/<[/\w]/g,e.innerHTML)&&O(/<[/\w]/g,e.textContent))return pt(e),!0;if("select"===n&&O(/