@alicloud/console-os-browser-vm 1.4.29 → 1.4.31

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 ADDED
@@ -0,0 +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){n=n(2)();t.exports=n;try{regeneratorRuntime=n}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=n:Function("r","regeneratorRuntime = r")(n)}},function(t,e,n){t.exports=n(4)},function(P,t,e){var k=e(3).default;function n(){"use strict";/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */P.exports=function(){return a},P.exports.__esModule=!0,P.exports.default=P.exports;var u,a={},t=Object.prototype,s=t.hasOwnProperty,l=Object.defineProperty||function(t,e,n){t[e]=n.value},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(u){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 m?e:m,e=Object.create(e.prototype),r=new L(r||[]);return l(e,"_invoke",{value:(o=t,i=n,a=r,c=p,function(t,e){if(c===h)throw Error("Generator is already running");if(c===y){if("throw"===t)throw e;return{value:u,done:!0}}for(a.method=t,a.arg=e;;){var n=a.delegate;if(n){n=function t(e,n){var r=n.method,o=e.iterator[r];if(o===u)return n.delegate=null,"throw"===r&&e.iterator.return&&(n.method="return",n.arg=u,t(e,n),"throw"===n.method)||"return"!==r&&(n.method="throw",n.arg=new TypeError("The iterator does not provide a '"+r+"' method")),v;r=f(o,e.iterator,n.arg);if("throw"===r.type)return n.method="throw",n.arg=r.arg,n.delegate=null,v;o=r.arg;return o?o.done?(n[e.resultName]=o.value,n.next=e.nextLoc,"return"!==n.method&&(n.method="next",n.arg=u),n.delegate=null,v):o:(n.method="throw",n.arg=new TypeError("iterator result is not an object"),n.delegate=null,v)}(n,a);if(n){if(n===v)continue;return n}}if("next"===a.method)a.sent=a._sent=a.arg;else if("throw"===a.method){if(c===p)throw c=y,a.arg;a.dispatchException(a.arg)}else"return"===a.method&&a.abrupt("return",a.arg);c=h;n=f(o,i,a);if("normal"===n.type){if(c=a.done?y:d,n.arg===v)continue;return{value:n.arg,done:a.done}}"throw"===n.type&&(c=y,a.method="throw",a.arg=n.arg)}})}),e}function f(t,e,n){try{return{type:"normal",arg:t.call(e,n)}}catch(t){return{type:"throw",arg:t}}}a.wrap=c;var p="suspendedStart",d="suspendedYield",h="executing",y="completed",v={};function m(){}function w(){}function b(){}var e={},g=(i(e,r,function(){return this}),Object.getPrototypeOf),g=g&&g(g(j([]))),x=(g&&g!==t&&s.call(g,r)&&(e=g),b.prototype=m.prototype=Object.create(e));function O(t){["next","throw","return"].forEach(function(e){i(t,e,function(t){return this._invoke(e,t)})})}function S(a,c){var e;l(this,"_invoke",{value:function(n,r){function t(){return new c(function(t,e){!function e(t,n,r,o){var i,t=f(a[t],a,n);if("throw"!==t.type)return i=t.arg,n=i.value,n&&"object"==k(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 E(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 _(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function L(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(E,this),this.reset(!0)}function j(e){if(e||""===e){var n,t=e[r];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length))return 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},t.next=t}throw new TypeError(k(e)+" is not iterable")}return w.prototype=b,l(x,"constructor",{value:b,configurable:!0}),l(b,"constructor",{value:w,configurable:!0}),w.displayName=i(b,o,"GeneratorFunction"),a.isGeneratorFunction=function(t){t="function"==typeof t&&t.constructor;return!!t&&(t===w||"GeneratorFunction"===(t.displayName||t.name))},a.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,b):(t.__proto__=b,i(t,o,"GeneratorFunction")),t.prototype=Object.create(x),t},a.awrap=function(t){return{__await:t}},O(S.prototype),i(S.prototype,n,function(){return this}),a.AsyncIterator=S,a.async=function(t,e,n,r,o){void 0===o&&(o=Promise);var i=new S(c(t,e,n,r),o);return a.isGeneratorFunction(e)?i:i.next().then(function(t){return t.done?t.value:i.next()})},O(x),i(x,o,"Generator"),i(x,r,function(){return this}),i(x,"toString",function(){return"[object Generator]"}),a.keys=function(t){var e,n=Object(t),r=[];for(e in n)r.push(e);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=j,L.prototype={constructor:L,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(_),!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].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 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,v):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),v},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),_(n),v}},catch:function(t){for(var e=this.tryEntries.length-1;0<=e;--e){var n,r,o=this.tryEntries[e];if(o.tryLoc===t)return n=o.completion,"throw"===n.type&&(r=n.arg,_(o)),r}throw Error("illegal catch attempt")},delegateYield:function(t,e,n){return this.delegate={iterator:j(t),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=u),v}},a}P.exports=n,P.exports.__esModule=!0,P.exports.default=P.exports},function(e,t){function n(t){return e.exports=n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},e.exports.__esModule=!0,e.exports.default=e.exports,n(t)}e.exports=n,e.exports.__esModule=!0,e.exports.default=e.exports},function(R,t,e){"use strict";function r(t){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},r(t)}function o(t){t=function(t,e){if("object"!=r(t)||!t)return t;var n=t[Symbol.toPrimitive];if(void 0===n)return("string"===e?String:Number)(t);if(n=n.call(t,e||"default"),"object"!=r(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}(t,"string");return"symbol"==r(t)?t:t+""}function a(t,e,n){e=o(e),e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n}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 i(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)})}}e.r(t),e.d(t,"createContext",function(){return W}),e.d(t,"removeContext",function(){return U}),e.d(t,"evalScripts",function(){return V});var t=e(0),c=e.n(t);function s(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 l(t){return function(t){if(Array.isArray(t))return s(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){var n;if(t)return"string"==typeof t?s(t,e):(n=Object.prototype.toString.call(t).slice(8,-1),"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)?s(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.")}()}function f(t){var e;try{e=new URL(t)}catch(t){return}return t=e.searchParams,t?t.get("callback")||t.get("cb"):null}function n(){return"undefined"==typeof document}var p=function(t){setTimeout(function(){var e,n;t.src&&(e=t.ownerContext.window,n=f(t.src),n)&&"function"==typeof e[n]&&(window[n]=function(){var t=e[n].apply(e,arguments);return window[n]=null,t})},0)};if(!n()&&"function"==typeof window.Element)for(var d=0,h=["appendChild","insertBefore","append"];d<h.length;d++){var y=h[d],v=window.Element.prototype[y];window.Element.prototype[y]=function(i,a){return function(n){var e=n&&n.ownerContext&&-1===n.ownerContext.allowResources.indexOf(n.src)&&"*"!==n.ownerContext.allowResources;if(n&&n._evalScriptInSandbox&&n.ownerContext&&"SCRIPT"===n.nodeName&&n.src&&e&&!f(n.src))return n.ownerContext.loadScripts(n.src).then(function(){var t=n._listenerMap.get("load"),t=(t&&t.forEach(function(t){t()}),new Event("load"));n.onload&&n.onload(t)}).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&&p(n),n&&n.scriptText&&n.ownerContext.evalScript(n.scriptText);for(var t=arguments.length,r=new Array(1<t?t-1:0),o=1;o<t;o++)r[o-1]=arguments[o];e=("append"===a&&void 0===n?[]:[n]).concat(r);try{return i.call.apply(i,[this].concat(l(e)))}catch(t){return i.apply(this,e)}}}(v,y)}function m(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function w(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,o(r.key),r)}}function b(t,e,n){return e&&w(t.prototype,e),n&&w(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}var g=n()?function(){}:window.addEventListener,x=n()?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 S(t){t=t.prototype&&t.prototype.constructor===t&&1<Object.getOwnPropertyNames(t.prototype).length||/^class\b/.test(t.toString());return t}function E(t){t=0===t.name.indexOf("bound ")&&!t.hasOwnProperty("prototype");return t}function _(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(l(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])}),e._evalScriptInSandbox||(A.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})}),e._evalScriptInSandbox=!0)}var L=["setTimeout","setInterval","clearInterval","clearTimeout"],j=["location","history"],P=["requestAnimationFrame","webkitRequestAnimationFrame","mozRequestAnimationFrame","oRequestAnimationFrame","msRequestAnimationFrame","cancelAnimationFrame","webkitCancelAnimationFrame","mozCancelAnimationFrame","oCancelAnimationFrame","msCancelAnimationFrame","matchMedia","getSelection","open"],e=b(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,u=(m(this,t),[].concat(P,l(e.externals||[]))),s={};return L.forEach(function(t){u.includes(t)||(s[t]=n.contentWindow[t].bind(n.contentWindow))}),j.forEach(function(t){u.includes(t)&&(s[t]=window[t])}),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||E(n)||S(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(l(r),[e])),-1===O.indexOf(t)?a.baseFrame.addEventListener.apply(a.baseFrame.contentWindow,[t,e,n]):g.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]):x.apply(window,[t,e,n])}}var i,a;return s[e]||(e=t[e],"function"!=typeof e||E(e)||S(e)?e:e.bind&&e.bind(t))}})}),k=e,A=["innerHTML","text","innerText"],t=b(function t(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},n=1<arguments.length?arguments[1]:void 0,o=(m(this,t),[]);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),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(){for(var t=0,e=o;t<e.length;t++){var n=e[t];r.removeEventListener.apply(r,l(n))}}}return"function"==typeof r[t]?r[t].bind&&r[t].bind(r):r[t]}})}),I=t;function C(t){return t&&"about:blank"===t.href}var e=b(function t(r){return m(this,t),new Proxy({},{set:function(t,e,n){return"href"!==e&&(r[e]=n),!0},get:function(t,e){switch(e){case"reload":return function(){return window.location.reload()};case"replace":return function(){};case"toString":return function(){try{return(C(r)?window.location:r).toString()}catch(t){return(C(r)?window.location:r).href}}}return"function"==typeof r[e]?r[e].bind&&r[e].bind(t):(C(r)?window.location:r)[e]}})}),G=e,t=b(function t(e,o){if(m(this,t),!e)return o.history;function i(){o.postMessage({type:"".concat(e,":history-change"),data:JSON.parse(JSON.stringify(o.location))},"*")}try{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}catch(t){}}),B=t;function D(t){return t.includes("console.aliyun.com")||t.includes("console.alibabacloud.com")||function(t,e){try{var n=new URL(t);return n.origin===e}catch(t){}try{var r=new URL(t,e);return r.origin===e}catch(t){}}(t,location&&location.origin)?"include":"omit"}function T(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 F(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?T(Object(n),!0).forEach(function(t){a(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):T(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}var e=function(){function o(t,e){m(this,o),this.location=new G(e.contentWindow.location),this.history=new B(t.id,e.contentWindow),this.window=new k(t,this,e,location),this.allowResources=t.allowResources||[];var n=t.body,r=t.disableBody;r?n=document.body:n||(n=document.createElement("body"),document.documentElement.appendChild(n)),this.body=n,this.document=new I(F({enableScriptEscape:!0},t),this,e,location),this.baseFrame=e,this._listenerMap=new Map,this.window.__IS_CONSOLE_OS_CONTEXT__=!0}var e,n;return b(o,[{key:"loadScripts",value:(n=i(c.a.mark(function t(e){var n;return c.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,fetch(e,{credentials:D(e)});case 2:return n=t.sent,t.next=5,n.text();case 5:n=t.sent,this.evalScript(n,e);case 7:case"end":return t.stop()}},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]:"",t=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));t().call(this.window,F({},this))}},{key:"updateBody",value:function(t){!t&&this.body||(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(r){var o=this;return new Promise(function(t){var e=document.createElement("iframe"),n=(e.setAttribute("src",r.url||"/api.json"),e.style.cssText="position: absolute; top: -20000px; width: 1px; height: 1px;",r.id&&e.setAttribute("data-id",r.id),(null==(n=document.documentElement)?void 0:n.getElementsByTagName("body")[0])||document.body);if(n.appendChild(e),"about:blank"===r.url)return t(new o(r,e));e.onload=function(){t(new o(r,e))}})}},{key:"remove",value:(e=i(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)})}]),o}(),M=e;function N(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 W=function(){var t=i(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,M.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)}}(),U=function(){var e=i(c.a.mark(function t(e){return c.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,M.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)}}(),V=function(){var e=i(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,M.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?N(Object(n),!0).forEach(function(t){a(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):N(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){var e;return(r[t]||(e=r[t]={i:t,l:!1,exports:{}},n[t].call(e.exports,e,e.exports,o),e.l=!0,e)).exports}var n,r});
package/es/Context.js CHANGED
@@ -5,17 +5,11 @@ import _createClass from "@babel/runtime/helpers/esm/createClass";
5
5
  import _regeneratorRuntime from "@babel/runtime/regenerator";
6
6
  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; }
7
7
  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; }
8
- /**
9
- * Context
10
- * @lastModified 2019086
11
- * @forwardCompatibleTo 2019086
12
- * @createAt 2019086
13
- */
14
-
15
8
  import Window from './Window';
16
9
  import Document from './Document';
17
10
  import Location from './Location';
18
11
  import History from './History';
12
+ import { getFetchCredentials } from './utils/credentials';
19
13
  var Context = /*#__PURE__*/function () {
20
14
  function Context(conf, frame) {
21
15
  _classCallCheck(this, Context);
@@ -48,7 +42,9 @@ var Context = /*#__PURE__*/function () {
48
42
  while (1) switch (_context.prev = _context.next) {
49
43
  case 0:
50
44
  _context.next = 2;
51
- return fetch(url);
45
+ return fetch(url, {
46
+ credentials: getFetchCredentials(url)
47
+ });
52
48
  case 2:
53
49
  resp = _context.sent;
54
50
  _context.next = 5;
@@ -1,3 +1,28 @@
1
+ function isSameOriginUrl(str, origin) {
2
+ try {
3
+ // str 的格式可以被解析成 url
4
+ var url = new URL(str);
5
+ return url.origin === origin;
6
+ } catch (e) {/**/}
7
+ try {
8
+ // str 是相对路径或绝对路径,无法被解析成 url
9
+ var _url = new URL(str, origin);
10
+ return _url.origin === origin;
11
+ } catch (e) {
12
+ return false;
13
+ }
14
+ }
15
+
16
+ // 某些情况下,请求静态资源需要带 cookie
1
17
  export var getFetchCredentials = function getFetchCredentials(url) {
2
- return url.includes('console.aliyun.com') ? 'include' : 'omit';
18
+ // 兼容历史逻辑
19
+ if (url.includes('console.aliyun.com') || url.includes('console.alibabacloud.com')) {
20
+ return 'include';
21
+ }
22
+
23
+ // 同域请求
24
+ if (isSameOriginUrl(url, location && location.origin)) {
25
+ return 'include';
26
+ }
27
+ return 'omit';
3
28
  };
package/lib/Context.js CHANGED
@@ -14,13 +14,9 @@ var _Window = _interopRequireDefault(require("./Window"));
14
14
  var _Document = _interopRequireDefault(require("./Document"));
15
15
  var _Location = _interopRequireDefault(require("./Location"));
16
16
  var _History = _interopRequireDefault(require("./History"));
17
+ var _credentials = require("./utils/credentials");
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; }
18
- 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; } /**
19
- * Context
20
- * @lastModified 2019086
21
- * @forwardCompatibleTo 2019086
22
- * @createAt 2019086
23
- */
19
+ 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; }
24
20
  var Context = /*#__PURE__*/function () {
25
21
  function Context(conf, frame) {
26
22
  (0, _classCallCheck2.default)(this, Context);
@@ -53,7 +49,9 @@ var Context = /*#__PURE__*/function () {
53
49
  while (1) switch (_context.prev = _context.next) {
54
50
  case 0:
55
51
  _context.next = 2;
56
- return fetch(url);
52
+ return fetch(url, {
53
+ credentials: (0, _credentials.getFetchCredentials)(url)
54
+ });
57
55
  case 2:
58
56
  resp = _context.sent;
59
57
  _context.next = 5;
@@ -4,7 +4,32 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getFetchCredentials = void 0;
7
+ function isSameOriginUrl(str, origin) {
8
+ try {
9
+ // str 的格式可以被解析成 url
10
+ var url = new URL(str);
11
+ return url.origin === origin;
12
+ } catch (e) {/**/}
13
+ try {
14
+ // str 是相对路径或绝对路径,无法被解析成 url
15
+ var _url = new URL(str, origin);
16
+ return _url.origin === origin;
17
+ } catch (e) {
18
+ return false;
19
+ }
20
+ }
21
+
22
+ // 某些情况下,请求静态资源需要带 cookie
7
23
  var getFetchCredentials = function getFetchCredentials(url) {
8
- return url.includes('console.aliyun.com') ? 'include' : 'omit';
24
+ // 兼容历史逻辑
25
+ if (url.includes('console.aliyun.com') || url.includes('console.alibabacloud.com')) {
26
+ return 'include';
27
+ }
28
+
29
+ // 同域请求
30
+ if (isSameOriginUrl(url, location && location.origin)) {
31
+ return 'include';
32
+ }
33
+ return 'omit';
9
34
  };
10
35
  exports.getFetchCredentials = getFetchCredentials;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alicloud/console-os-browser-vm",
3
- "version": "1.4.29",
3
+ "version": "1.4.31",
4
4
  "description": "browser virtual machine",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -20,6 +20,9 @@
20
20
  "js-beautify": "^1.10.1",
21
21
  "jsdom": "^16.2.2"
22
22
  },
23
+ "dependencies": {
24
+ "@babel/runtime": "^7.24.1"
25
+ },
23
26
  "scripts": {
24
27
  "babel": "breezr build --engine babel",
25
28
  "babel:esm": "breezr build --engine babel --es-module",