@alicloud/console-os-browser-vm 1.3.0 → 1.3.1-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.aliOSBrowserVM=e():t.aliOSBrowserVM=e()}(window,function(){return n=[function(t,e,n){t.exports=n(2)},function(t,e,n){t.exports=n(3)},function(e,t,n){e=function(a){"use strict";var u,t=Object.prototype,s=t.hasOwnProperty,e="function"==typeof Symbol?Symbol:{},r=e.iterator||"@@iterator",n=e.asyncIterator||"@@asyncIterator",o=e.toStringTag||"@@toStringTag";function i(t,e,n){return Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{i({},"")}catch(t){i=function(t,e,n){return t[e]=n}}function c(t,e,n,r){var o,i,a,c,e=e&&e.prototype instanceof v?e:v,e=Object.create(e.prototype),r=new _(r||[]);return e._invoke=(o=t,i=n,a=r,c=f,function(t,e){if(c===h)throw new Error("Generator is already running");if(c===d){if("throw"===t)throw e;return j()}for(a.method=t,a.arg=e;;){var n=a.delegate;if(n){var r=function t(e,n){var r=e.iterator[n.method];if(r===u){if(n.delegate=null,"throw"===n.method){if(e.iterator.return&&(n.method="return",n.arg=u,t(e,n),"throw"===n.method))return y;n.method="throw",n.arg=new TypeError("The iterator does not provide a 'throw' method")}return y}var r=l(r,e.iterator,n.arg);if("throw"===r.type)return n.method="throw",n.arg=r.arg,n.delegate=null,y;r=r.arg;if(!r)return n.method="throw",n.arg=new TypeError("iterator result is not an object"),n.delegate=null,y;{if(!r.done)return r;n[e.resultName]=r.value,n.next=e.nextLoc,"return"!==n.method&&(n.method="next",n.arg=u)}n.delegate=null;return y}(n,a);if(r){if(r===y)continue;return r}}if("next"===a.method)a.sent=a._sent=a.arg;else if("throw"===a.method){if(c===f)throw c=d,a.arg;a.dispatchException(a.arg)}else"return"===a.method&&a.abrupt("return",a.arg);c=h;r=l(o,i,a);if("normal"===r.type){if(c=a.done?d:p,r.arg!==y)return{value:r.arg,done:a.done}}else"throw"===r.type&&(c=d,a.method="throw",a.arg=r.arg)}}),e}function l(t,e,n){try{return{type:"normal",arg:t.call(e,n)}}catch(t){return{type:"throw",arg:t}}}a.wrap=c;var f="suspendedStart",p="suspendedYield",h="executing",d="completed",y={};function v(){}function m(){}function w(){}var b={};i(b,r,function(){return this});e=Object.getPrototypeOf,e=e&&e(e(L([])));e&&e!==t&&s.call(e,r)&&(b=e);var g=w.prototype=v.prototype=Object.create(b);function O(t){["next","throw","return"].forEach(function(e){i(t,e,function(t){return this._invoke(e,t)})})}function x(a,c){var e;this._invoke=function(n,r){function t(){return new c(function(t,e){!function e(t,n,r,o){t=l(a[t],a,n);if("throw"!==t.type){var i=t.arg,n=i.value;return n&&"object"==typeof n&&s.call(n,"__await")?c.resolve(n.__await).then(function(t){e("next",t,r,o)},function(t){e("throw",t,r,o)}):c.resolve(n).then(function(t){i.value=t,r(i)},function(t){return e("throw",t,r,o)})}o(t.arg)}(n,r,t,e)})}return e=e?e.then(t,t):t()}}function S(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function E(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function _(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(S,this),this.reset(!0)}function L(e){if(e){var t=e[r];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,t=function t(){for(;++n<e.length;)if(s.call(e,n))return t.value=e[n],t.done=!1,t;return t.value=u,t.done=!0,t};return t.next=t}}return{next:j}}function j(){return{value:u,done:!0}}return m.prototype=w,i(g,"constructor",w),i(w,"constructor",m),m.displayName=i(w,o,"GeneratorFunction"),a.isGeneratorFunction=function(t){t="function"==typeof t&&t.constructor;return!!t&&(t===m||"GeneratorFunction"===(t.displayName||t.name))},a.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,w):(t.__proto__=w,i(t,o,"GeneratorFunction")),t.prototype=Object.create(g),t},a.awrap=function(t){return{__await:t}},O(x.prototype),i(x.prototype,n,function(){return this}),a.AsyncIterator=x,a.async=function(t,e,n,r,o){void 0===o&&(o=Promise);var i=new x(c(t,e,n,r),o);return a.isGeneratorFunction(e)?i:i.next().then(function(t){return t.done?t.value:i.next()})},O(g),i(g,o,"Generator"),i(g,r,function(){return this}),i(g,"toString",function(){return"[object Generator]"}),a.keys=function(n){var t,r=[];for(t in n)r.push(t);return r.reverse(),function t(){for(;r.length;){var e=r.pop();if(e in n)return t.value=e,t.done=!1,t}return t.done=!0,t}},a.values=L,_.prototype={constructor:_,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=u,this.done=!1,this.delegate=null,this.method="next",this.arg=u,this.tryEntries.forEach(E),!t)for(var e in this)"t"===e.charAt(0)&&s.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=u)},stop:function(){this.done=!0;var t=this.tryEntries[0],t=t.completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(n){if(this.done)throw n;var r=this;function t(t,e){return i.type="throw",i.arg=n,r.next=t,e&&(r.method="next",r.arg=u),!!e}for(var e=this.tryEntries.length-1;0<=e;--e){var o=this.tryEntries[e],i=o.completion;if("root"===o.tryLoc)return t("end");if(o.tryLoc<=this.prev){var a=s.call(o,"catchLoc"),c=s.call(o,"finallyLoc");if(a&&c){if(this.prev<o.catchLoc)return t(o.catchLoc,!0);if(this.prev<o.finallyLoc)return t(o.finallyLoc)}else if(a){if(this.prev<o.catchLoc)return t(o.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return t(o.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;0<=n;--n){var r=this.tryEntries[n];if(r.tryLoc<=this.prev&&s.call(r,"finallyLoc")&&this.prev<r.finallyLoc){var o=r;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var i=o?o.completion:{};return i.type=t,i.arg=e,o?(this.method="next",this.next=o.finallyLoc,y):this.complete(i)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),y},finish:function(t){for(var e=this.tryEntries.length-1;0<=e;--e){var n=this.tryEntries[e];if(n.finallyLoc===t)return this.complete(n.completion,n.afterLoc),E(n),y}},catch:function(t){for(var e=this.tryEntries.length-1;0<=e;--e){var n=this.tryEntries[e];if(n.tryLoc===t){var r,o=n.completion;return"throw"===o.type&&(r=o.arg,E(n)),r}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,n){return this.delegate={iterator:L(t),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=u),y}},a}(e.exports);try{regeneratorRuntime=e}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=e:Function("r","regeneratorRuntime = r")(e)}},function(t,e,n){"use strict";function a(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function u(t,e,n,r,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void n(t)}c.done?e(u):Promise.resolve(u).then(r,o)}function o(c){return function(){var t=this,a=arguments;return new Promise(function(e,n){var r=c.apply(t,a);function o(t){u(r,e,n,o,i,"next",t)}function i(t){u(r,e,n,o,i,"throw",t)}o(void 0)})}}n.r(e),n.d(e,"createContext",function(){return G}),n.d(e,"removeContext",function(){return B}),n.d(e,"evalScripts",function(){return D});function i(t){try{e=new URL(t)}catch(t){return}var e=e.searchParams;return e?e.get("callback")||e.get("cb"):null}function r(){return"undefined"==typeof document}var e=n(0),c=n.n(e),s=function(t){setTimeout(function(){var e,n;t.src&&(e=t.ownerContext.window,n=i(t.src),n&&"function"==typeof e[n]&&(window[n]=function(){var t=e[n].apply(e,arguments);return window[n]=null,t}))},0)};if(!r()&&"function"==typeof window.Element)for(var l=0,f=["appendChild","insertBefore","append"];l<f.length;l++){var p=f[l],h=window.Element.prototype[p];window.Element.prototype[p]=function(o){return function(n){if(n&&n._evalScriptInSandbox&&n.ownerContext&&"SCRIPT"===n.nodeName&&n.src&&-1===n.ownerContext.allowResources.indexOf(n.src)&&!i(n.src))return n.ownerContext.loadScripts(n.src).then(function(){var t=n._listenerMap.get("load");t&&t.forEach(function(t){t()}),n.onload&&n.onload()}).catch(function(e){console.error(e);var t=n._listenerMap.get("error");t&&t.forEach(function(t){t(e)}),n.onerror&&n.onerror(e)});n&&"SCRIPT"===n.nodeName&&n.ownerContext&&s(n),n&&n.scriptText&&n.ownerContext.evalScript(n.scriptText);for(var t=arguments.length,e=new Array(1<t?t-1:0),r=1;r<t;r++)e[r-1]=arguments[r];try{return o.call.apply(o,[this,n].concat(e))}catch(t){return o.apply(this,[n].concat(e))}}}(h)}function d(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function y(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function v(t,e,n){return e&&y(t.prototype,e),n&&y(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function m(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function w(t){return function(t){if(Array.isArray(t))return m(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(t){if("string"==typeof t)return m(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?m(t,e):void 0}}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var b=r()?function(){}:window.addEventListener,g=r()?function(){}:window.removeEventListener,O=["webkitmouseforcedown","webkitmouseforcewillbegin","visibilitychange","error","mousemove","mousedown","mouseup","touchcancel","touchend","touchstart","auxclick","dblclick","pointercancel","pointerdown","pointerup","dragend","dragstart","drop","compositionend","compositionstart","keydown","keypress","keyup","input","textInput","close","cancel","copy","cut","paste","click","change","contextmenu","reset","submit","resize","scroll","foucs","blur"];function x(t){t=t.prototype&&t.prototype.constructor===t&&1<Object.getOwnPropertyNames(t.prototype).length||/^class\b/.test(t.toString());return t}function S(t){t=0===t.name.indexOf("bound ")&&!t.hasOwnProperty("prototype");return t}function E(e){var o,i,a,c;e._listenerMap=new Map,e.addEventListener=(o=e,i=e.addEventListener,function(t,e,n){var r=o._listenerMap.get(t)||[];return o._listenerMap.set(t,[].concat(w(r),[e])),i.apply(o,[t,e,n])}),e.removeEventListener=(a=e,c=e.removeEventListener,function(t,e,n){var r=a._listenerMap.get(t);return r&&r.length&&-1!==r.indexOf(e)&&r.splice(r.indexOf(e),1),c.apply(a,[t,e,n])}),P.forEach(function(t){Object.defineProperty(e,t,{get:function(){return this.scriptText||""},set:function(t){this.scriptText=t,e.parentNode&&this.ownerContext.evalScript&&e.ownerContext.evalScript(t.toString())},enumerable:!1})})}var _=["setTimeout","setInterval","clearInterval","clearTimeout"],L=["requestAnimationFrame","webkitRequestAnimationFrame","mozRequestAnimationFrame","oRequestAnimationFrame","msRequestAnimationFrame","cancelAnimationFrame","webkitCancelAnimationFrame","mozCancelAnimationFrame","oCancelAnimationFrame","msCancelAnimationFrame"],e=v(function t(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},c=1<arguments.length?arguments[1]:void 0,n=2<arguments.length?arguments[2]:void 0;d(this,t);var u=[].concat(L,w(e.externals||[])),s={};return _.forEach(function(t){u.includes(t)||(s[t]=n.contentWindow[t].bind(n.contentWindow))}),new Proxy(n.contentWindow,{set:function(t,e,n){return t[e]=n,s[e]=n,!0},get:function(t,e){if(u.includes(e)){var n=window[e];if("function"!=typeof n||S(n)||x(n))return n;var r,o=n.bind(window);for(r in n)o[r]=n[r];return o}switch(e){case"document":return c.document;case"location":return c.location;case"history":return c.history;case"__CONSOLE_OS_GLOBAL_VARS_":return s;case"addEventListener":return a=c,function(t,e,n){var r=a._listenerMap.get(t)||[];return a._listenerMap.set(t,[].concat(w(r),[e])),-1===O.indexOf(t)?a.baseFrame.addEventListener.apply(a.baseFrame.contentWindow,[t,e,n]):b.apply(window,[t,e,n])};case"removeEventListener":return i=c,function(t,e,n){var r=i._listenerMap.get(t);return r&&r.length&&-1!==r.indexOf(e)&&r.splice(r.indexOf(e),1),-1===O.indexOf(t)?i.baseFrame.removeEventListener.apply(i.baseFrame.contentWindow,[t,e,n]):g.apply(window,[t,e,n])}}var i,a;if(s[e])return s[e];e=t[e];return"function"!=typeof e||S(e)||x(e)?e:e.bind&&e.bind(t)}})}),j=e,P=["innerHTML","text","innerText"];function k(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return A(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?A(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0,e=function(){};return{s:e,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:e}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,i=!0,a=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return i=t.done,t},e:function(t){a=!0,o=t},f:function(){try{i||null==n.return||n.return()}finally{if(a)throw o}}}}function A(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}var e=v(function t(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},n=1<arguments.length?arguments[1]:void 0;d(this,t);var o=[];return new Proxy(document,{set:function(t,e,n){return"cookie"===e?document.cookie=n:t[e]=n,!0},get:function(r,t){switch(t){case"body":return n.body;case"location":return n.location;case"defaultView":return n.window;case"write":case"writeln":return function(){};case"createElement":return function(){var t=(t=document).createElement.apply(t,arguments);return t.ownerContext=n,t.appId=e.id,"SCRIPT"!==t.tagName||e.enableScriptEscape||(t._evalScriptInSandbox=!0,E(t)),t};case"addEventListener":return function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];return o.push(e),r.addEventListener.apply(r,e)};case"removeEventListeners":return function(){var t,e=k(o);try{for(e.s();!(t=e.n()).done;){var n=t.value;r.removeEventListener.apply(r,w(n))}}catch(t){e.e(t)}finally{e.f()}}}return"function"==typeof r[t]?r[t].bind&&r[t].bind(r):r[t]}})}),C=e,e=v(function t(r){return d(this,t),new Proxy({},{set:function(t,e,n){return"href"===e||(r[e]=n),!0},get:function(t,e){switch(e){case"reload":case"replace":return function(){};case"toString":return function(){try{return r.toString()}catch(t){return r.href}}}return"function"==typeof r[e]?r[e].bind&&r[e].bind(t):r[e]}})}),F=e,e=v(function t(e,o){if(d(this,t),!e)return o.history;function i(){o.postMessage({type:"".concat(e,":history-change"),data:JSON.parse(JSON.stringify(o.location))},"*")}var a=o.history.pushState,c=o.history.replaceState;return o.history.pushState=function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];var r=a.apply(o.history,[].concat(e));return i(),r},o.history.replaceState=function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];var r=c.apply(o.history,[].concat(e));return i(),r},o.history}),T=e;function M(e,t){var n,r=Object.keys(e);return Object.getOwnPropertySymbols&&(n=Object.getOwnPropertySymbols(e),t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)),r}function N(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?M(Object(n),!0).forEach(function(t){a(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):M(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}var e=function(){function r(t,e){d(this,r),this.location=new F(e.contentWindow.location),this.history=new T(t.id,e.contentWindow),this.window=new j(t,this,e,location),this.allowResources=t.allowResources||[];var n=t.body;t.disableBody?n=document.body:t.body||(n=document.createElement("body"),document.documentElement.appendChild(n)),this.body=n,this.document=new C(N({enableScriptEscape:!0},t),this,e,location),this.baseFrame=e,this._listenerMap=new Map,this.window.__IS_CONSOLE_OS_CONTEXT__=!0}var e,n;return v(r,[{key:"loadScripts",value:(n=o(c.a.mark(function t(n){var r;return c.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,fetch(n,{credentials:(e=n,e.includes("console.aliyun.com")?"include":"omit")});case 2:return r=t.sent,t.next=5,r.text();case 5:r=t.sent,this.evalScript(r,n);case 7:case"end":return t.stop()}var e},t,this)})),function(t){return n.apply(this,arguments)})},{key:"evalScript",value:function(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"",e=new Function("\n return function ({window, location, history, document}){ \n with(window.__CONSOLE_OS_GLOBAL_VARS_) {\n try {\n ".concat(t,"\n }\n catch(e) {\n console.log(e)\n }\n }\n }//@ sourceMappingURL=").concat(e));e().call(this.window,N({},this))}},{key:"updateBody",value:function(t){this.body=t}},{key:"remove",value:function(){this.document.removeEventListeners(),this.baseFrame&&(this.baseFrame.parentNode?this.baseFrame.parentNode.removeChild(this.baseFrame):this.baseFrame.setAttribute("src","about:blank"))}}],[{key:"create",value:function(n){var r=this;return new Promise(function(t){var e=document.createElement("iframe");if(e.setAttribute("src",n.url||"/api.json"),e.style.cssText="position: absolute; top: -20000px; width: 100%; height: 1px;",document.body.appendChild(e),"about:blank"===n.url)return t(new r(n,e));e.onload=function(){t(new r(n,e))}})}},{key:"remove",value:(e=o(c.a.mark(function t(e){return c.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:e.remove&&e.remove();case 1:case"end":return t.stop()}},t)})),function(t){return e.apply(this,arguments)})}]),r}(),I=e;function R(e,t){var n,r=Object.keys(e);return Object.getOwnPropertySymbols&&(n=Object.getOwnPropertySymbols(e),t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)),r}var G=function(){var t=o(c.a.mark(function t(){var e,n=arguments;return c.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return e=0<n.length&&void 0!==n[0]?n[0]:{},t.next=3,I.create(e);case 3:return t.abrupt("return",t.sent);case 4:case"end":return t.stop()}},t)}));return function(){return t.apply(this,arguments)}}(),B=function(){var e=o(c.a.mark(function t(e){return c.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,I.remove(e);case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}},t)}));return function(t){return e.apply(this,arguments)}}(),D=function(){var e=o(c.a.mark(function t(e){var n,r,o,i=arguments;return c.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return n=1<i.length&&void 0!==i[1]?i[1]:{},t.next=3,I.create(n);case 3:return r=t.sent,o=new Function("\n return function({window, location, history, document}){ \n with(window.__CONSOLE_OS_GLOBAL_VARS_) { \n ".concat(e,"\n }\n }//@sourceURL=").concat(n.name)),t.abrupt("return",o(function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?R(Object(n),!0).forEach(function(t){a(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):R(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}({},r)));case 6:case"end":return t.stop()}},t)}));return function(t){return e.apply(this,arguments)}}()}],r={},o.m=n,o.c=r,o.d=function(t,e,n){o.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},o.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},o.t=function(e,t){if(1&t&&(e=o(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(o.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)o.d(n,r,function(t){return e[t]}.bind(null,r));return n},o.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return o.d(e,"a",e),e},o.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},o.p="/",o(o.s=1);function o(t){if(r[t])return r[t].exports;var e=r[t]={i:t,l:!1,exports:{}};return n[t].call(e.exports,e,e.exports,o),e.l=!0,e.exports}var n,r});
1
+ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.aliOSBrowserVM=e():t.aliOSBrowserVM=e()}(window,function(){return n=[function(t,e,n){t.exports=n(2)},function(t,e,n){t.exports=n(3)},function(e,t,n){e=function(a){"use strict";var u,t=Object.prototype,s=t.hasOwnProperty,e="function"==typeof Symbol?Symbol:{},r=e.iterator||"@@iterator",n=e.asyncIterator||"@@asyncIterator",o=e.toStringTag||"@@toStringTag";function i(t,e,n){return Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{i({},"")}catch(t){i=function(t,e,n){return t[e]=n}}function c(t,e,n,r){var o,i,a,c,e=e&&e.prototype instanceof v?e:v,e=Object.create(e.prototype),r=new _(r||[]);return e._invoke=(o=t,i=n,a=r,c=f,function(t,e){if(c===h)throw new Error("Generator is already running");if(c===d){if("throw"===t)throw e;return j()}for(a.method=t,a.arg=e;;){var n=a.delegate;if(n){var r=function t(e,n){var r=e.iterator[n.method];if(r===u){if(n.delegate=null,"throw"===n.method){if(e.iterator.return&&(n.method="return",n.arg=u,t(e,n),"throw"===n.method))return y;n.method="throw",n.arg=new TypeError("The iterator does not provide a 'throw' method")}return y}var r=l(r,e.iterator,n.arg);if("throw"===r.type)return n.method="throw",n.arg=r.arg,n.delegate=null,y;r=r.arg;if(!r)return n.method="throw",n.arg=new TypeError("iterator result is not an object"),n.delegate=null,y;{if(!r.done)return r;n[e.resultName]=r.value,n.next=e.nextLoc,"return"!==n.method&&(n.method="next",n.arg=u)}n.delegate=null;return y}(n,a);if(r){if(r===y)continue;return r}}if("next"===a.method)a.sent=a._sent=a.arg;else if("throw"===a.method){if(c===f)throw c=d,a.arg;a.dispatchException(a.arg)}else"return"===a.method&&a.abrupt("return",a.arg);c=h;r=l(o,i,a);if("normal"===r.type){if(c=a.done?d:p,r.arg!==y)return{value:r.arg,done:a.done}}else"throw"===r.type&&(c=d,a.method="throw",a.arg=r.arg)}}),e}function l(t,e,n){try{return{type:"normal",arg:t.call(e,n)}}catch(t){return{type:"throw",arg:t}}}a.wrap=c;var f="suspendedStart",p="suspendedYield",h="executing",d="completed",y={};function v(){}function m(){}function w(){}var b={};i(b,r,function(){return this});e=Object.getPrototypeOf,e=e&&e(e(L([])));e&&e!==t&&s.call(e,r)&&(b=e);var g=w.prototype=v.prototype=Object.create(b);function O(t){["next","throw","return"].forEach(function(e){i(t,e,function(t){return this._invoke(e,t)})})}function x(a,c){var e;this._invoke=function(n,r){function t(){return new c(function(t,e){!function e(t,n,r,o){t=l(a[t],a,n);if("throw"!==t.type){var i=t.arg,n=i.value;return n&&"object"==typeof n&&s.call(n,"__await")?c.resolve(n.__await).then(function(t){e("next",t,r,o)},function(t){e("throw",t,r,o)}):c.resolve(n).then(function(t){i.value=t,r(i)},function(t){return e("throw",t,r,o)})}o(t.arg)}(n,r,t,e)})}return e=e?e.then(t,t):t()}}function S(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function E(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function _(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(S,this),this.reset(!0)}function L(e){if(e){var t=e[r];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,t=function t(){for(;++n<e.length;)if(s.call(e,n))return t.value=e[n],t.done=!1,t;return t.value=u,t.done=!0,t};return t.next=t}}return{next:j}}function j(){return{value:u,done:!0}}return m.prototype=w,i(g,"constructor",w),i(w,"constructor",m),m.displayName=i(w,o,"GeneratorFunction"),a.isGeneratorFunction=function(t){t="function"==typeof t&&t.constructor;return!!t&&(t===m||"GeneratorFunction"===(t.displayName||t.name))},a.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,w):(t.__proto__=w,i(t,o,"GeneratorFunction")),t.prototype=Object.create(g),t},a.awrap=function(t){return{__await:t}},O(x.prototype),i(x.prototype,n,function(){return this}),a.AsyncIterator=x,a.async=function(t,e,n,r,o){void 0===o&&(o=Promise);var i=new x(c(t,e,n,r),o);return a.isGeneratorFunction(e)?i:i.next().then(function(t){return t.done?t.value:i.next()})},O(g),i(g,o,"Generator"),i(g,r,function(){return this}),i(g,"toString",function(){return"[object Generator]"}),a.keys=function(n){var t,r=[];for(t in n)r.push(t);return r.reverse(),function t(){for(;r.length;){var e=r.pop();if(e in n)return t.value=e,t.done=!1,t}return t.done=!0,t}},a.values=L,_.prototype={constructor:_,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=u,this.done=!1,this.delegate=null,this.method="next",this.arg=u,this.tryEntries.forEach(E),!t)for(var e in this)"t"===e.charAt(0)&&s.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=u)},stop:function(){this.done=!0;var t=this.tryEntries[0],t=t.completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(n){if(this.done)throw n;var r=this;function t(t,e){return i.type="throw",i.arg=n,r.next=t,e&&(r.method="next",r.arg=u),!!e}for(var e=this.tryEntries.length-1;0<=e;--e){var o=this.tryEntries[e],i=o.completion;if("root"===o.tryLoc)return t("end");if(o.tryLoc<=this.prev){var a=s.call(o,"catchLoc"),c=s.call(o,"finallyLoc");if(a&&c){if(this.prev<o.catchLoc)return t(o.catchLoc,!0);if(this.prev<o.finallyLoc)return t(o.finallyLoc)}else if(a){if(this.prev<o.catchLoc)return t(o.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return t(o.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;0<=n;--n){var r=this.tryEntries[n];if(r.tryLoc<=this.prev&&s.call(r,"finallyLoc")&&this.prev<r.finallyLoc){var o=r;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var i=o?o.completion:{};return i.type=t,i.arg=e,o?(this.method="next",this.next=o.finallyLoc,y):this.complete(i)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),y},finish:function(t){for(var e=this.tryEntries.length-1;0<=e;--e){var n=this.tryEntries[e];if(n.finallyLoc===t)return this.complete(n.completion,n.afterLoc),E(n),y}},catch:function(t){for(var e=this.tryEntries.length-1;0<=e;--e){var n=this.tryEntries[e];if(n.tryLoc===t){var r,o=n.completion;return"throw"===o.type&&(r=o.arg,E(n)),r}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,n){return this.delegate={iterator:L(t),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=u),y}},a}(e.exports);try{regeneratorRuntime=e}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=e:Function("r","regeneratorRuntime = r")(e)}},function(t,e,n){"use strict";function a(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function u(t,e,n,r,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void n(t)}c.done?e(u):Promise.resolve(u).then(r,o)}function o(c){return function(){var t=this,a=arguments;return new Promise(function(e,n){var r=c.apply(t,a);function o(t){u(r,e,n,o,i,"next",t)}function i(t){u(r,e,n,o,i,"throw",t)}o(void 0)})}}n.r(e),n.d(e,"createContext",function(){return G}),n.d(e,"removeContext",function(){return B}),n.d(e,"evalScripts",function(){return D});function i(t){try{e=new URL(t)}catch(t){return}var e=e.searchParams;return e?e.get("callback")||e.get("cb"):null}function r(){return"undefined"==typeof document}var e=n(0),c=n.n(e),s=function(t){setTimeout(function(){var e,n;t.src&&(e=t.ownerContext.window,n=i(t.src),n&&"function"==typeof e[n]&&(window[n]=function(){var t=e[n].apply(e,arguments);return window[n]=null,t}))},0)};if(!r()&&"function"==typeof window.Element)for(var l=0,f=["appendChild","insertBefore","append"];l<f.length;l++){var p=f[l],h=window.Element.prototype[p];window.Element.prototype[p]=function(o){return function(n){if(n&&n._evalScriptInSandbox&&n.ownerContext&&"SCRIPT"===n.nodeName&&n.src&&-1===n.ownerContext.allowResources.indexOf(n.src)&&!i(n.src))return n.ownerContext.loadScripts(n.src).then(function(){var t=n._listenerMap.get("load");t&&t.forEach(function(t){t()}),n.onload&&n.onload()}).catch(function(e){console.error(e);var t=n._listenerMap.get("error");t&&t.forEach(function(t){t(e)}),n.onerror&&n.onerror(e)});n&&"SCRIPT"===n.nodeName&&n.ownerContext&&s(n),n&&n.scriptText&&n.ownerContext.evalScript(n.scriptText);for(var t=arguments.length,e=new Array(1<t?t-1:0),r=1;r<t;r++)e[r-1]=arguments[r];try{return o.call.apply(o,[this,n].concat(e))}catch(t){return o.apply(this,[n].concat(e))}}}(h)}function d(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function y(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function v(t,e,n){return e&&y(t.prototype,e),n&&y(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function m(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function w(t){return function(t){if(Array.isArray(t))return m(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(t){if("string"==typeof t)return m(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?m(t,e):void 0}}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var b=r()?function(){}:window.addEventListener,g=r()?function(){}:window.removeEventListener,O=["webkitmouseforcedown","webkitmouseforcewillbegin","visibilitychange","error","mousemove","mousedown","mouseup","touchcancel","touchend","touchstart","auxclick","dblclick","pointercancel","pointerdown","pointerup","dragend","dragstart","drop","compositionend","compositionstart","keydown","keypress","keyup","input","textInput","close","cancel","copy","cut","paste","click","change","contextmenu","reset","submit","resize","scroll","foucs","blur"];function x(t){t=t.prototype&&t.prototype.constructor===t&&1<Object.getOwnPropertyNames(t.prototype).length||/^class\b/.test(t.toString());return t}function S(t){t=0===t.name.indexOf("bound ")&&!t.hasOwnProperty("prototype");return t}function E(e){var o,i,a,c;e._listenerMap=new Map,e.addEventListener=(o=e,i=e.addEventListener,function(t,e,n){var r=o._listenerMap.get(t)||[];return o._listenerMap.set(t,[].concat(w(r),[e])),i.apply(o,[t,e,n])}),e.removeEventListener=(a=e,c=e.removeEventListener,function(t,e,n){var r=a._listenerMap.get(t);return r&&r.length&&-1!==r.indexOf(e)&&r.splice(r.indexOf(e),1),c.apply(a,[t,e,n])}),P.forEach(function(t){Object.defineProperty(e,t,{get:function(){return this.scriptText||""},set:function(t){this.scriptText=t,e.parentNode&&this.ownerContext.evalScript&&e.ownerContext.evalScript(t.toString())},enumerable:!1})})}var _=["setTimeout","setInterval","clearInterval","clearTimeout"],L=["requestAnimationFrame","webkitRequestAnimationFrame","mozRequestAnimationFrame","oRequestAnimationFrame","msRequestAnimationFrame","cancelAnimationFrame","webkitCancelAnimationFrame","mozCancelAnimationFrame","oCancelAnimationFrame","msCancelAnimationFrame"],e=v(function t(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},u=1<arguments.length?arguments[1]:void 0,s=2<arguments.length?arguments[2]:void 0;d(this,t);var l=[].concat(L,w(e.externals||[])),f={},p=new Proxy(s.contentWindow,{set:function(t,e,n){return f[e]=n,!0},get:function(t,e){if(l.includes(e)){var n=window[e];if("function"!=typeof n||S(n)||x(n))return n;var r,o=n.bind(window);for(r in n)o[r]=n[r];return o}switch(e){case"window":return p;case"document":return u.document;case"location":return u.location;case"history":return u.history;case"__CONSOLE_OS_GLOBAL_VARS_":return p;case"addEventListener":return a=u,function(t,e,n){var r=a._listenerMap.get(t)||[];return a._listenerMap.set(t,[].concat(w(r),[e])),-1===O.indexOf(t)?a.baseFrame.addEventListener.apply(a.baseFrame.contentWindow,[t,e,n]):b.apply(window,[t,e,n])};case"removeEventListener":return i=u,function(t,e,n){var r=i._listenerMap.get(t);return r&&r.length&&-1!==r.indexOf(e)&&r.splice(r.indexOf(e),1),-1===O.indexOf(t)?i.baseFrame.removeEventListener.apply(i.baseFrame.contentWindow,[t,e,n]):g.apply(window,[t,e,n])}}var i,a,c;if(c=f[e],null!=c)return f[e];if(c=e,"string"==typeof c&&c in s.contentWindow){e=window[e];return"function"!=typeof e||S(e)||x(e)?e:e.bind&&e.bind(window)}}});return _.forEach(function(t){l.includes(t)||(p[t]=s.contentWindow[t].bind(s.contentWindow))}),p}),j=e,P=["innerHTML","text","innerText"];function k(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return A(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?A(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0,e=function(){};return{s:e,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:e}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,i=!0,a=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return i=t.done,t},e:function(t){a=!0,o=t},f:function(){try{i||null==n.return||n.return()}finally{if(a)throw o}}}}function A(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}var e=v(function t(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},n=1<arguments.length?arguments[1]:void 0;d(this,t);var o=[];return new Proxy(document,{set:function(t,e,n){return"cookie"===e?document.cookie=n:t[e]=n,!0},get:function(r,t){switch(t){case"body":return n.body;case"location":return n.location;case"defaultView":return n.window;case"write":case"writeln":return function(){};case"createElement":return function(){var t=(t=document).createElement.apply(t,arguments);return t.ownerContext=n,t.appId=e.id,"SCRIPT"!==t.tagName||e.enableScriptEscape||(t._evalScriptInSandbox=!0,E(t)),t};case"addEventListener":return function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];return o.push(e),r.addEventListener.apply(r,e)};case"removeEventListeners":return function(){var t,e=k(o);try{for(e.s();!(t=e.n()).done;){var n=t.value;r.removeEventListener.apply(r,w(n))}}catch(t){e.e(t)}finally{e.f()}}}return"function"==typeof r[t]?r[t].bind&&r[t].bind(r):r[t]}})}),C=e,e=v(function t(r){return d(this,t),new Proxy({},{set:function(t,e,n){return"href"===e||(r[e]=n),!0},get:function(t,e){switch(e){case"reload":case"replace":return function(){};case"toString":return function(){try{return r.toString()}catch(t){return r.href}}}return"function"==typeof r[e]?r[e].bind&&r[e].bind(t):r[e]}})}),F=e,e=v(function t(e,o){if(d(this,t),!e)return o.history;function i(){o.postMessage({type:"".concat(e,":history-change"),data:JSON.parse(JSON.stringify(o.location))},"*")}var a=o.history.pushState,c=o.history.replaceState;return o.history.pushState=function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];var r=a.apply(o.history,[].concat(e));return i(),r},o.history.replaceState=function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];var r=c.apply(o.history,[].concat(e));return i(),r},o.history}),T=e;function M(e,t){var n,r=Object.keys(e);return Object.getOwnPropertySymbols&&(n=Object.getOwnPropertySymbols(e),t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)),r}function N(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?M(Object(n),!0).forEach(function(t){a(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):M(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}var e=function(){function r(t,e){d(this,r),this.location=new F(e.contentWindow.location),this.history=new T(t.id,e.contentWindow),this.window=new j(t,this,e,location),this.allowResources=t.allowResources||[];var n=t.body;t.disableBody?n=document.body:t.body||(n=document.createElement("body"),document.documentElement.appendChild(n)),this.body=n,this.document=new C(N({enableScriptEscape:!0},t),this,e,location),this.baseFrame=e,this._listenerMap=new Map,this.window.__IS_CONSOLE_OS_CONTEXT__=!0}var e,n;return v(r,[{key:"loadScripts",value:(n=o(c.a.mark(function t(n){var r;return c.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,fetch(n,{credentials:(e=n,e.includes("console.aliyun.com")?"include":"omit")});case 2:return r=t.sent,t.next=5,r.text();case 5:r=t.sent,this.evalScript(r,n);case 7:case"end":return t.stop()}var e},t,this)})),function(t){return n.apply(this,arguments)})},{key:"evalScript",value:function(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"",e=new Function("\n return function ({window, location, history, document}){ \n with(window.__CONSOLE_OS_GLOBAL_VARS_) {\n try {\n ".concat(t,"\n }\n catch(e) {\n console.log(e)\n }\n }\n }//@ sourceMappingURL=").concat(e));e().call(this.window,N({},this))}},{key:"updateBody",value:function(t){this.body=t}},{key:"remove",value:function(){this.document.removeEventListeners(),this.baseFrame&&(this.baseFrame.parentNode?this.baseFrame.parentNode.removeChild(this.baseFrame):this.baseFrame.setAttribute("src","about:blank"))}}],[{key:"create",value:function(n){var r=this;return new Promise(function(t){var e=document.createElement("iframe");if(e.setAttribute("src",n.url||"/api.json"),e.style.cssText="position: absolute; top: -20000px; width: 100%; height: 1px;",document.body.appendChild(e),"about:blank"===n.url)return t(new r(n,e));e.onload=function(){t(new r(n,e))}})}},{key:"remove",value:(e=o(c.a.mark(function t(e){return c.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:e.remove&&e.remove();case 1:case"end":return t.stop()}},t)})),function(t){return e.apply(this,arguments)})}]),r}(),I=e;function R(e,t){var n,r=Object.keys(e);return Object.getOwnPropertySymbols&&(n=Object.getOwnPropertySymbols(e),t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)),r}var G=function(){var t=o(c.a.mark(function t(){var e,n=arguments;return c.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return e=0<n.length&&void 0!==n[0]?n[0]:{},t.next=3,I.create(e);case 3:return t.abrupt("return",t.sent);case 4:case"end":return t.stop()}},t)}));return function(){return t.apply(this,arguments)}}(),B=function(){var e=o(c.a.mark(function t(e){return c.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,I.remove(e);case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}},t)}));return function(t){return e.apply(this,arguments)}}(),D=function(){var e=o(c.a.mark(function t(e){var n,r,o,i=arguments;return c.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return n=1<i.length&&void 0!==i[1]?i[1]:{},t.next=3,I.create(n);case 3:return r=t.sent,o=new Function("\n return function({window, location, history, document}){ \n with(window.__CONSOLE_OS_GLOBAL_VARS_) { \n ".concat(e,"\n }\n }//@sourceURL=").concat(n.name)),t.abrupt("return",o(function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?R(Object(n),!0).forEach(function(t){a(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):R(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}({},r)));case 6:case"end":return t.stop()}},t)}));return function(t){return e.apply(this,arguments)}}()}],r={},o.m=n,o.c=r,o.d=function(t,e,n){o.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},o.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},o.t=function(e,t){if(1&t&&(e=o(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(o.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)o.d(n,r,function(t){return e[t]}.bind(null,r));return n},o.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return o.d(e,"a",e),e},o.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},o.p="/",o(o.s=1);function o(t){if(r[t])return r[t].exports;var e=r[t]={i:t,l:!1,exports:{}};return n[t].call(e.exports,e,e.exports,o),e.l=!0,e.exports}var n,r});
package/es/Context.js CHANGED
@@ -86,7 +86,7 @@ var Context = /*#__PURE__*/function () {
86
86
  }, {
87
87
  key: "evalScript",
88
88
  value: function evalScript(code) {
89
- var url = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "";
89
+ var url = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
90
90
  var resolver = new Function("\n return function ({window, location, history, document}){ \n with(window.__CONSOLE_OS_GLOBAL_VARS_) {\n try {\n ".concat(code, "\n }\n catch(e) {\n console.log(e)\n }\n }\n }//@ sourceMappingURL=").concat(url));
91
91
  resolver().call(this.window, _objectSpread({}, this));
92
92
  }
package/es/Window.js CHANGED
@@ -10,6 +10,15 @@ import { isConstructable, isBoundedFunction } from './utils/common';
10
10
  var globalFnName = ['setTimeout', 'setInterval', 'clearInterval', 'clearTimeout'];
11
11
  var defaultExternals = ['requestAnimationFrame', 'webkitRequestAnimationFrame', 'mozRequestAnimationFrame', 'oRequestAnimationFrame', 'msRequestAnimationFrame', 'cancelAnimationFrame', 'webkitCancelAnimationFrame', 'mozCancelAnimationFrame', 'oCancelAnimationFrame', 'msCancelAnimationFrame'];
12
12
 
13
+ var isExist = function isExist(value) {
14
+ return typeof value !== 'undefined' && value !== null;
15
+ }; // 1. if var in externals, read it from window
16
+ // 2. if var in hack list, read it from iframe's window
17
+ // 3. if var in cache which wrote by micro app, read it from cache
18
+ // 4. if var is native, read it from window
19
+ // 5. otherwise return undefined
20
+
21
+
13
22
  var Window = /*#__PURE__*/_createClass(function Window() {
14
23
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
15
24
  var context = arguments.length > 1 ? arguments[1] : undefined;
@@ -17,19 +26,17 @@ var Window = /*#__PURE__*/_createClass(function Window() {
17
26
 
18
27
  _classCallCheck(this, Window);
19
28
 
20
- var externals = [].concat(defaultExternals, _toConsumableArray(options.externals || []));
21
- var __CONSOLE_OS_GLOBAL_VARS_ = {};
22
- globalFnName.forEach(function (name) {
23
- if (externals.includes(name)) {
24
- return;
25
- }
29
+ var externals = [].concat(defaultExternals, _toConsumableArray(options.externals || [])); // if the var is native in context
26
30
 
27
- __CONSOLE_OS_GLOBAL_VARS_[name] = frame.contentWindow[name].bind(frame.contentWindow);
28
- });
29
- return new Proxy(frame.contentWindow, {
31
+ var isNative = function isNative(variable) {
32
+ return typeof variable === 'string' && variable in frame.contentWindow;
33
+ };
34
+
35
+ var cache = {};
36
+
37
+ var __CONSOLE_OS_GLOBAL_VARS_ = new Proxy(frame.contentWindow, {
30
38
  set: function set(target, name, value) {
31
- target[name] = value;
32
- __CONSOLE_OS_GLOBAL_VARS_[name] = value;
39
+ cache[name] = value;
33
40
  return true;
34
41
  },
35
42
  get: function get(target, name) {
@@ -47,9 +54,13 @@ var Window = /*#__PURE__*/_createClass(function Window() {
47
54
  } else {
48
55
  return windowValue;
49
56
  }
50
- }
57
+ } // hack
58
+
51
59
 
52
60
  switch (name) {
61
+ case 'window':
62
+ return __CONSOLE_OS_GLOBAL_VARS_;
63
+
53
64
  case 'document':
54
65
  return context.document;
55
66
 
@@ -69,19 +80,32 @@ var Window = /*#__PURE__*/_createClass(function Window() {
69
80
  return removeEventListener(context);
70
81
  }
71
82
 
72
- if (__CONSOLE_OS_GLOBAL_VARS_[name]) {
73
- return __CONSOLE_OS_GLOBAL_VARS_[name];
83
+ if (isExist(cache[name])) {
84
+ return cache[name];
74
85
  }
75
86
 
76
- var value = target[name];
87
+ if (isNative(name)) {
88
+ var value = window[name];
89
+
90
+ if (typeof value === 'function' && !isBoundedFunction(value) && !isConstructable(value)) {
91
+ return value.bind && value.bind(window);
92
+ }
77
93
 
78
- if (typeof value === 'function' && !isBoundedFunction(value) && !isConstructable(value)) {
79
- return value.bind && value.bind(target);
80
- } else {
81
94
  return value;
82
95
  }
96
+
97
+ return undefined;
98
+ }
99
+ });
100
+
101
+ globalFnName.forEach(function (name) {
102
+ if (externals.includes(name)) {
103
+ return;
83
104
  }
105
+
106
+ __CONSOLE_OS_GLOBAL_VARS_[name] = frame.contentWindow[name].bind(frame.contentWindow);
84
107
  });
108
+ return __CONSOLE_OS_GLOBAL_VARS_;
85
109
  });
86
110
 
87
111
  export default Window;
@@ -1,9 +1,3 @@
1
- /**
2
- * injectScriptCallBack
3
- * @lastModified 20190821
4
- * @forwardCompatibleTo 20190821
5
- * @createAt 20190821
6
- */
7
1
  export var getJsonCallback = function getJsonCallback(src) {
8
2
  var u;
9
3
 
@@ -1,9 +1,3 @@
1
- /**
2
- * Not implemented
3
- * @lastModified 2019086
4
- * @forwardCompatibleTo 2019086
5
- * @createAt 2019086
6
- */
7
1
  export default (function (nameForErrorMessage) {
8
2
  console.error("Not implemented: ".concat(nameForErrorMessage));
9
3
  });
File without changes
@@ -0,0 +1,65 @@
1
+ import injectScriptCallBack, { getJsonCallback } from './utils/injectScriptCallBack';
2
+ import { isSSR } from './utils/isSSR';
3
+
4
+ var makeElInjector = function makeElInjector(originMethod) {
5
+ return function (el) {
6
+ // 如果不在 BrowserVM 的白名单内,尝试通过 context 的 load script 通过 xhr 获取脚本内容,并在沙箱中执行
7
+ if (el && el._evalScriptInSandbox && el.ownerContext && el.nodeName === 'SCRIPT' && el.src && el.ownerContext.allowResources.indexOf(el.src) === -1 && !getJsonCallback(el.src)) {
8
+ return el.ownerContext.loadScripts(el.src).then(function () {
9
+ var fns = el._listenerMap.get('load');
10
+
11
+ if (fns) {
12
+ fns.forEach(function (fn) {
13
+ fn();
14
+ });
15
+ }
16
+
17
+ el.onload && el.onload();
18
+ }).catch(function (e) {
19
+ console.error(e);
20
+
21
+ var fns = el._listenerMap.get('error');
22
+
23
+ if (fns) {
24
+ fns.forEach(function (fn) {
25
+ fn(e);
26
+ });
27
+ }
28
+
29
+ el.onerror && el.onerror(e);
30
+ });
31
+ }
32
+
33
+ if (el && el.nodeName === 'SCRIPT' && el.ownerContext) {
34
+ injectScriptCallBack(el);
35
+ } // 如果有 scriptText, 证明在 append 之前被设置了 text
36
+ // 所以直接执行这个 script
37
+
38
+
39
+ if (el && el.scriptText) {
40
+ el.ownerContext.evalScript(el.scriptText);
41
+ } // fix: babel 会把 fn.call 转义成 fn.call.apply 造成 chrome 50 的几个版本报错
42
+ // 这里 尝试 try catch 如果报错 直接调用 fn.apply
43
+
44
+
45
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
46
+ args[_key - 1] = arguments[_key];
47
+ }
48
+
49
+ try {
50
+ return originMethod.call.apply(originMethod, [this, el].concat(args));
51
+ } catch (_unused) {
52
+ return originMethod.apply(this, [el].concat(args));
53
+ }
54
+ };
55
+ };
56
+
57
+ if (!isSSR() && typeof window.Element === 'function') {
58
+ var mountElementMethods = ['appendChild', 'insertBefore', 'append'];
59
+
60
+ for (var _i = 0, _mountElementMethods = mountElementMethods; _i < _mountElementMethods.length; _i++) {
61
+ var method = _mountElementMethods[_i];
62
+ var originMethod = window.Element.prototype[method];
63
+ window.Element.prototype[method] = makeElInjector(originMethod);
64
+ }
65
+ }
package/es/v2/index.js CHANGED
@@ -1,11 +1,25 @@
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
1
2
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
+
4
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
5
+
6
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
7
+
2
8
  import _regeneratorRuntime from "@babel/runtime/regenerator";
9
+ import Context from './Context';
3
10
  export var createContext = /*#__PURE__*/function () {
4
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
11
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(conf) {
5
12
  return _regeneratorRuntime.wrap(function _callee$(_context) {
6
13
  while (1) {
7
14
  switch (_context.prev = _context.next) {
8
15
  case 0:
16
+ _context.next = 2;
17
+ return Context.create(conf);
18
+
19
+ case 2:
20
+ return _context.abrupt("return", _context.sent);
21
+
22
+ case 3:
9
23
  case "end":
10
24
  return _context.stop();
11
25
  }
@@ -13,16 +27,23 @@ export var createContext = /*#__PURE__*/function () {
13
27
  }, _callee);
14
28
  }));
15
29
 
16
- return function createContext() {
30
+ return function createContext(_x) {
17
31
  return _ref.apply(this, arguments);
18
32
  };
19
33
  }();
20
34
  export var removeContext = /*#__PURE__*/function () {
21
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
35
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(context) {
22
36
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
23
37
  while (1) {
24
38
  switch (_context2.prev = _context2.next) {
25
39
  case 0:
40
+ _context2.next = 2;
41
+ return Context.remove(context);
42
+
43
+ case 2:
44
+ return _context2.abrupt("return", _context2.sent);
45
+
46
+ case 3:
26
47
  case "end":
27
48
  return _context2.stop();
28
49
  }
@@ -30,7 +51,39 @@ export var removeContext = /*#__PURE__*/function () {
30
51
  }, _callee2);
31
52
  }));
32
53
 
33
- return function removeContext() {
54
+ return function removeContext(_x2) {
34
55
  return _ref2.apply(this, arguments);
35
56
  };
57
+ }();
58
+ export var evalScripts = /*#__PURE__*/function () {
59
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(code) {
60
+ var conf,
61
+ ctx,
62
+ resolver,
63
+ _args3 = arguments;
64
+ return _regeneratorRuntime.wrap(function _callee3$(_context3) {
65
+ while (1) {
66
+ switch (_context3.prev = _context3.next) {
67
+ case 0:
68
+ conf = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : {};
69
+ _context3.next = 3;
70
+ return Context.create(conf);
71
+
72
+ case 3:
73
+ ctx = _context3.sent;
74
+ // eslint-disable-next-line no-new-func
75
+ resolver = new Function("\n return function({window, location, history, document}){ \n with(window.__CONSOLE_OS_GLOBAL_VARS_) { \n ".concat(code, "\n }\n }//@sourceURL=").concat(conf.name));
76
+ return _context3.abrupt("return", resolver(_objectSpread({}, ctx)));
77
+
78
+ case 6:
79
+ case "end":
80
+ return _context3.stop();
81
+ }
82
+ }
83
+ }, _callee3);
84
+ }));
85
+
86
+ return function evalScripts(_x3) {
87
+ return _ref3.apply(this, arguments);
88
+ };
36
89
  }();
package/lib/Context.js CHANGED
@@ -96,7 +96,7 @@ var Context = /*#__PURE__*/function () {
96
96
  }, {
97
97
  key: "evalScript",
98
98
  value: function evalScript(code) {
99
- var url = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "";
99
+ var url = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
100
100
  var resolver = new Function("\n return function ({window, location, history, document}){ \n with(window.__CONSOLE_OS_GLOBAL_VARS_) {\n try {\n ".concat(code, "\n }\n catch(e) {\n console.log(e)\n }\n }\n }//@ sourceMappingURL=").concat(url));
101
101
  resolver().call(this.window, _objectSpread({}, this));
102
102
  }
package/lib/Window.js CHANGED
@@ -22,24 +22,32 @@ var _common = require("./utils/common");
22
22
  */
23
23
  var globalFnName = ['setTimeout', 'setInterval', 'clearInterval', 'clearTimeout'];
24
24
  var defaultExternals = ['requestAnimationFrame', 'webkitRequestAnimationFrame', 'mozRequestAnimationFrame', 'oRequestAnimationFrame', 'msRequestAnimationFrame', 'cancelAnimationFrame', 'webkitCancelAnimationFrame', 'mozCancelAnimationFrame', 'oCancelAnimationFrame', 'msCancelAnimationFrame'];
25
+
26
+ var isExist = function isExist(value) {
27
+ return typeof value !== 'undefined' && value !== null;
28
+ }; // 1. if var in externals, read it from window
29
+ // 2. if var in hack list, read it from iframe's window
30
+ // 3. if var in cache which wrote by micro app, read it from cache
31
+ // 4. if var is native, read it from window
32
+ // 5. otherwise return undefined
33
+
34
+
25
35
  var Window = /*#__PURE__*/(0, _createClass2.default)(function Window() {
26
36
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
27
37
  var context = arguments.length > 1 ? arguments[1] : undefined;
28
38
  var frame = arguments.length > 2 ? arguments[2] : undefined;
29
39
  (0, _classCallCheck2.default)(this, Window);
30
- var externals = [].concat(defaultExternals, (0, _toConsumableArray2.default)(options.externals || []));
31
- var __CONSOLE_OS_GLOBAL_VARS_ = {};
32
- globalFnName.forEach(function (name) {
33
- if (externals.includes(name)) {
34
- return;
35
- }
40
+ var externals = [].concat(defaultExternals, (0, _toConsumableArray2.default)(options.externals || [])); // if the var is native in context
36
41
 
37
- __CONSOLE_OS_GLOBAL_VARS_[name] = frame.contentWindow[name].bind(frame.contentWindow);
38
- });
39
- return new Proxy(frame.contentWindow, {
42
+ var isNative = function isNative(variable) {
43
+ return typeof variable === 'string' && variable in frame.contentWindow;
44
+ };
45
+
46
+ var cache = {};
47
+
48
+ var __CONSOLE_OS_GLOBAL_VARS_ = new Proxy(frame.contentWindow, {
40
49
  set: function set(target, name, value) {
41
- target[name] = value;
42
- __CONSOLE_OS_GLOBAL_VARS_[name] = value;
50
+ cache[name] = value;
43
51
  return true;
44
52
  },
45
53
  get: function get(target, name) {
@@ -57,9 +65,13 @@ var Window = /*#__PURE__*/(0, _createClass2.default)(function Window() {
57
65
  } else {
58
66
  return windowValue;
59
67
  }
60
- }
68
+ } // hack
69
+
61
70
 
62
71
  switch (name) {
72
+ case 'window':
73
+ return __CONSOLE_OS_GLOBAL_VARS_;
74
+
63
75
  case 'document':
64
76
  return context.document;
65
77
 
@@ -79,19 +91,32 @@ var Window = /*#__PURE__*/(0, _createClass2.default)(function Window() {
79
91
  return (0, _events.removeEventListener)(context);
80
92
  }
81
93
 
82
- if (__CONSOLE_OS_GLOBAL_VARS_[name]) {
83
- return __CONSOLE_OS_GLOBAL_VARS_[name];
94
+ if (isExist(cache[name])) {
95
+ return cache[name];
84
96
  }
85
97
 
86
- var value = target[name];
98
+ if (isNative(name)) {
99
+ var value = window[name];
100
+
101
+ if (typeof value === 'function' && !(0, _common.isBoundedFunction)(value) && !(0, _common.isConstructable)(value)) {
102
+ return value.bind && value.bind(window);
103
+ }
87
104
 
88
- if (typeof value === 'function' && !(0, _common.isBoundedFunction)(value) && !(0, _common.isConstructable)(value)) {
89
- return value.bind && value.bind(target);
90
- } else {
91
105
  return value;
92
106
  }
107
+
108
+ return undefined;
93
109
  }
94
110
  });
111
+
112
+ globalFnName.forEach(function (name) {
113
+ if (externals.includes(name)) {
114
+ return;
115
+ }
116
+
117
+ __CONSOLE_OS_GLOBAL_VARS_[name] = frame.contentWindow[name].bind(frame.contentWindow);
118
+ });
119
+ return __CONSOLE_OS_GLOBAL_VARS_;
95
120
  });
96
121
  var _default = Window;
97
122
  exports.default = _default;
@@ -5,12 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.getJsonCallback = exports.default = void 0;
7
7
 
8
- /**
9
- * injectScriptCallBack
10
- * @lastModified 20190821
11
- * @forwardCompatibleTo 20190821
12
- * @createAt 20190821
13
- */
14
8
  var getJsonCallback = function getJsonCallback(src) {
15
9
  var u;
16
10
 
@@ -5,12 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
- /**
9
- * Not implemented
10
- * @lastModified 2019086
11
- * @forwardCompatibleTo 2019086
12
- * @createAt 2019086
13
- */
14
8
  var _default = function _default(nameForErrorMessage) {
15
9
  console.error("Not implemented: ".concat(nameForErrorMessage));
16
10
  };
File without changes
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+
3
+ var _typeof = require("@babel/runtime/helpers/typeof");
4
+
5
+ var _injectScriptCallBack = _interopRequireWildcard(require("./utils/injectScriptCallBack"));
6
+
7
+ var _isSSR = require("./utils/isSSR");
8
+
9
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
10
+
11
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
12
+
13
+ var makeElInjector = function makeElInjector(originMethod) {
14
+ return function (el) {
15
+ // 如果不在 BrowserVM 的白名单内,尝试通过 context 的 load script 通过 xhr 获取脚本内容,并在沙箱中执行
16
+ if (el && el._evalScriptInSandbox && el.ownerContext && el.nodeName === 'SCRIPT' && el.src && el.ownerContext.allowResources.indexOf(el.src) === -1 && !(0, _injectScriptCallBack.getJsonCallback)(el.src)) {
17
+ return el.ownerContext.loadScripts(el.src).then(function () {
18
+ var fns = el._listenerMap.get('load');
19
+
20
+ if (fns) {
21
+ fns.forEach(function (fn) {
22
+ fn();
23
+ });
24
+ }
25
+
26
+ el.onload && el.onload();
27
+ }).catch(function (e) {
28
+ console.error(e);
29
+
30
+ var fns = el._listenerMap.get('error');
31
+
32
+ if (fns) {
33
+ fns.forEach(function (fn) {
34
+ fn(e);
35
+ });
36
+ }
37
+
38
+ el.onerror && el.onerror(e);
39
+ });
40
+ }
41
+
42
+ if (el && el.nodeName === 'SCRIPT' && el.ownerContext) {
43
+ (0, _injectScriptCallBack.default)(el);
44
+ } // 如果有 scriptText, 证明在 append 之前被设置了 text
45
+ // 所以直接执行这个 script
46
+
47
+
48
+ if (el && el.scriptText) {
49
+ el.ownerContext.evalScript(el.scriptText);
50
+ } // fix: babel 会把 fn.call 转义成 fn.call.apply 造成 chrome 50 的几个版本报错
51
+ // 这里 尝试 try catch 如果报错 直接调用 fn.apply
52
+
53
+
54
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
55
+ args[_key - 1] = arguments[_key];
56
+ }
57
+
58
+ try {
59
+ return originMethod.call.apply(originMethod, [this, el].concat(args));
60
+ } catch (_unused) {
61
+ return originMethod.apply(this, [el].concat(args));
62
+ }
63
+ };
64
+ };
65
+
66
+ if (!(0, _isSSR.isSSR)() && typeof window.Element === 'function') {
67
+ var mountElementMethods = ['appendChild', 'insertBefore', 'append'];
68
+
69
+ for (var _i = 0, _mountElementMethods = mountElementMethods; _i < _mountElementMethods.length; _i++) {
70
+ var method = _mountElementMethods[_i];
71
+ var originMethod = window.Element.prototype[method];
72
+ window.Element.prototype[method] = makeElInjector(originMethod);
73
+ }
74
+ }
package/lib/v2/index.js CHANGED
@@ -5,18 +5,33 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.removeContext = exports.createContext = void 0;
8
+ exports.removeContext = exports.evalScripts = exports.createContext = void 0;
9
9
 
10
10
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
11
 
12
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
+
12
14
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
13
15
 
16
+ var _Context = _interopRequireDefault(require("./Context"));
17
+
18
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
19
+
20
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
21
+
14
22
  var createContext = /*#__PURE__*/function () {
15
- var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
23
+ var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(conf) {
16
24
  return _regenerator.default.wrap(function _callee$(_context) {
17
25
  while (1) {
18
26
  switch (_context.prev = _context.next) {
19
27
  case 0:
28
+ _context.next = 2;
29
+ return _Context.default.create(conf);
30
+
31
+ case 2:
32
+ return _context.abrupt("return", _context.sent);
33
+
34
+ case 3:
20
35
  case "end":
21
36
  return _context.stop();
22
37
  }
@@ -24,7 +39,7 @@ var createContext = /*#__PURE__*/function () {
24
39
  }, _callee);
25
40
  }));
26
41
 
27
- return function createContext() {
42
+ return function createContext(_x) {
28
43
  return _ref.apply(this, arguments);
29
44
  };
30
45
  }();
@@ -32,11 +47,18 @@ var createContext = /*#__PURE__*/function () {
32
47
  exports.createContext = createContext;
33
48
 
34
49
  var removeContext = /*#__PURE__*/function () {
35
- var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() {
50
+ var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(context) {
36
51
  return _regenerator.default.wrap(function _callee2$(_context2) {
37
52
  while (1) {
38
53
  switch (_context2.prev = _context2.next) {
39
54
  case 0:
55
+ _context2.next = 2;
56
+ return _Context.default.remove(context);
57
+
58
+ case 2:
59
+ return _context2.abrupt("return", _context2.sent);
60
+
61
+ case 3:
40
62
  case "end":
41
63
  return _context2.stop();
42
64
  }
@@ -44,9 +66,44 @@ var removeContext = /*#__PURE__*/function () {
44
66
  }, _callee2);
45
67
  }));
46
68
 
47
- return function removeContext() {
69
+ return function removeContext(_x2) {
48
70
  return _ref2.apply(this, arguments);
49
71
  };
50
72
  }();
51
73
 
52
- exports.removeContext = removeContext;
74
+ exports.removeContext = removeContext;
75
+
76
+ var evalScripts = /*#__PURE__*/function () {
77
+ var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(code) {
78
+ var conf,
79
+ ctx,
80
+ resolver,
81
+ _args3 = arguments;
82
+ return _regenerator.default.wrap(function _callee3$(_context3) {
83
+ while (1) {
84
+ switch (_context3.prev = _context3.next) {
85
+ case 0:
86
+ conf = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : {};
87
+ _context3.next = 3;
88
+ return _Context.default.create(conf);
89
+
90
+ case 3:
91
+ ctx = _context3.sent;
92
+ // eslint-disable-next-line no-new-func
93
+ resolver = new Function("\n return function({window, location, history, document}){ \n with(window.__CONSOLE_OS_GLOBAL_VARS_) { \n ".concat(code, "\n }\n }//@sourceURL=").concat(conf.name));
94
+ return _context3.abrupt("return", resolver(_objectSpread({}, ctx)));
95
+
96
+ case 6:
97
+ case "end":
98
+ return _context3.stop();
99
+ }
100
+ }
101
+ }, _callee3);
102
+ }));
103
+
104
+ return function evalScripts(_x3) {
105
+ return _ref3.apply(this, arguments);
106
+ };
107
+ }();
108
+
109
+ exports.evalScripts = evalScripts;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alicloud/console-os-browser-vm",
3
- "version": "1.3.0",
3
+ "version": "1.3.1-alpha.3",
4
4
  "description": "browser virtual machine",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -30,5 +30,5 @@
30
30
  "js-beautify": "^1.10.1",
31
31
  "jsdom": "^16.2.2"
32
32
  },
33
- "gitHead": "fd4e97a8b7802616641e61a6572492c90a480c30"
33
+ "gitHead": "43925181e0a3e489559b7ab1bb6c68e59e00d58e"
34
34
  }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2019 Alibaba Cloud
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.