@alicloud/console-os-browser-vm 1.4.23 → 1.4.25-alpha.0
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/LICENSE +21 -0
- package/es/Context.js +3 -2
- package/es/Elements.js +1 -1
- package/es/Window.js +10 -0
- package/lib/Context.js +3 -2
- package/lib/Elements.js +1 -1
- package/lib/Window.js +10 -0
- package/package.json +11 -12
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
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.
|
package/es/Context.js
CHANGED
|
@@ -25,9 +25,10 @@ var Context = /*#__PURE__*/function () {
|
|
|
25
25
|
this.window = new Window(conf, this, frame, location);
|
|
26
26
|
this.allowResources = conf.allowResources || [];
|
|
27
27
|
var body = conf.body;
|
|
28
|
-
|
|
28
|
+
var disableBody = conf.disableBody;
|
|
29
|
+
if (disableBody) {
|
|
29
30
|
body = document.body;
|
|
30
|
-
} else if (!
|
|
31
|
+
} else if (!body) {
|
|
31
32
|
body = document.createElement('body');
|
|
32
33
|
document.documentElement.appendChild(body);
|
|
33
34
|
}
|
package/es/Elements.js
CHANGED
|
@@ -3,7 +3,7 @@ import injectScriptCallBack, { getJsonCallback } from './utils/injectScriptCallB
|
|
|
3
3
|
import { isSSR } from './utils/isSSR';
|
|
4
4
|
var makeElInjector = function makeElInjector(originMethod, methodName) {
|
|
5
5
|
return function (el) {
|
|
6
|
-
var notAllowed = el.ownerContext && el.ownerContext.allowResources.indexOf(el.src) === -1 && el.ownerContext.allowResources !== '*';
|
|
6
|
+
var notAllowed = el && el.ownerContext && el.ownerContext.allowResources.indexOf(el.src) === -1 && el.ownerContext.allowResources !== '*';
|
|
7
7
|
|
|
8
8
|
// 如果不在 BrowserVM 的白名单内,尝试通过 context 的 load script 通过 xhr 获取脚本内容,并在沙箱中执行
|
|
9
9
|
if (el && el._evalScriptInSandbox && el.ownerContext && el.nodeName === 'SCRIPT' && el.src && notAllowed && !getJsonCallback(el.src)) {
|
package/es/Window.js
CHANGED
|
@@ -7,6 +7,7 @@ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
|
7
7
|
import { addEventListener, removeEventListener } from './events';
|
|
8
8
|
import { isConstructable, isBoundedFunction } from './utils/common';
|
|
9
9
|
var globalFnName = ['setTimeout', 'setInterval', 'clearInterval', 'clearTimeout'];
|
|
10
|
+
var globalVars = ['location', 'history'];
|
|
10
11
|
var defaultExternals = ['requestAnimationFrame', 'webkitRequestAnimationFrame', 'mozRequestAnimationFrame', 'oRequestAnimationFrame', 'msRequestAnimationFrame', 'cancelAnimationFrame', 'webkitCancelAnimationFrame', 'mozCancelAnimationFrame', 'oCancelAnimationFrame', 'msCancelAnimationFrame', 'matchMedia'];
|
|
11
12
|
var Window = /*#__PURE__*/_createClass(function Window() {
|
|
12
13
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
@@ -15,12 +16,21 @@ var Window = /*#__PURE__*/_createClass(function Window() {
|
|
|
15
16
|
_classCallCheck(this, Window);
|
|
16
17
|
var externals = [].concat(defaultExternals, _toConsumableArray(options.externals || []));
|
|
17
18
|
var __CONSOLE_OS_GLOBAL_VARS_ = {};
|
|
19
|
+
|
|
20
|
+
// 拦截全局方法
|
|
18
21
|
globalFnName.forEach(function (name) {
|
|
19
22
|
if (externals.includes(name)) {
|
|
20
23
|
return;
|
|
21
24
|
}
|
|
22
25
|
__CONSOLE_OS_GLOBAL_VARS_[name] = frame.contentWindow[name].bind(frame.contentWindow);
|
|
23
26
|
});
|
|
27
|
+
|
|
28
|
+
// 通过拦截外置的全局变量,指向外部变量
|
|
29
|
+
globalVars.forEach(function (name) {
|
|
30
|
+
if (externals.includes(name)) {
|
|
31
|
+
__CONSOLE_OS_GLOBAL_VARS_[name] = window[name];
|
|
32
|
+
}
|
|
33
|
+
});
|
|
24
34
|
return new Proxy(frame.contentWindow, {
|
|
25
35
|
set: function set(target, name, value) {
|
|
26
36
|
target[name] = value;
|
package/lib/Context.js
CHANGED
|
@@ -30,9 +30,10 @@ var Context = /*#__PURE__*/function () {
|
|
|
30
30
|
this.window = new _Window.default(conf, this, frame, location);
|
|
31
31
|
this.allowResources = conf.allowResources || [];
|
|
32
32
|
var body = conf.body;
|
|
33
|
-
|
|
33
|
+
var disableBody = conf.disableBody;
|
|
34
|
+
if (disableBody) {
|
|
34
35
|
body = document.body;
|
|
35
|
-
} else if (!
|
|
36
|
+
} else if (!body) {
|
|
36
37
|
body = document.createElement('body');
|
|
37
38
|
document.documentElement.appendChild(body);
|
|
38
39
|
}
|
package/lib/Elements.js
CHANGED
|
@@ -9,7 +9,7 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
9
9
|
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; }
|
|
10
10
|
var makeElInjector = function makeElInjector(originMethod, methodName) {
|
|
11
11
|
return function (el) {
|
|
12
|
-
var notAllowed = el.ownerContext && el.ownerContext.allowResources.indexOf(el.src) === -1 && el.ownerContext.allowResources !== '*';
|
|
12
|
+
var notAllowed = el && el.ownerContext && el.ownerContext.allowResources.indexOf(el.src) === -1 && el.ownerContext.allowResources !== '*';
|
|
13
13
|
|
|
14
14
|
// 如果不在 BrowserVM 的白名单内,尝试通过 context 的 load script 通过 xhr 获取脚本内容,并在沙箱中执行
|
|
15
15
|
if (el && el._evalScriptInSandbox && el.ownerContext && el.nodeName === 'SCRIPT' && el.src && notAllowed && !(0, _injectScriptCallBack.getJsonCallback)(el.src)) {
|
package/lib/Window.js
CHANGED
|
@@ -15,6 +15,7 @@ var _common = require("./utils/common");
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
var globalFnName = ['setTimeout', 'setInterval', 'clearInterval', 'clearTimeout'];
|
|
18
|
+
var globalVars = ['location', 'history'];
|
|
18
19
|
var defaultExternals = ['requestAnimationFrame', 'webkitRequestAnimationFrame', 'mozRequestAnimationFrame', 'oRequestAnimationFrame', 'msRequestAnimationFrame', 'cancelAnimationFrame', 'webkitCancelAnimationFrame', 'mozCancelAnimationFrame', 'oCancelAnimationFrame', 'msCancelAnimationFrame', 'matchMedia'];
|
|
19
20
|
var Window = /*#__PURE__*/(0, _createClass2.default)(function Window() {
|
|
20
21
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
@@ -23,12 +24,21 @@ var Window = /*#__PURE__*/(0, _createClass2.default)(function Window() {
|
|
|
23
24
|
(0, _classCallCheck2.default)(this, Window);
|
|
24
25
|
var externals = [].concat(defaultExternals, (0, _toConsumableArray2.default)(options.externals || []));
|
|
25
26
|
var __CONSOLE_OS_GLOBAL_VARS_ = {};
|
|
27
|
+
|
|
28
|
+
// 拦截全局方法
|
|
26
29
|
globalFnName.forEach(function (name) {
|
|
27
30
|
if (externals.includes(name)) {
|
|
28
31
|
return;
|
|
29
32
|
}
|
|
30
33
|
__CONSOLE_OS_GLOBAL_VARS_[name] = frame.contentWindow[name].bind(frame.contentWindow);
|
|
31
34
|
});
|
|
35
|
+
|
|
36
|
+
// 通过拦截外置的全局变量,指向外部变量
|
|
37
|
+
globalVars.forEach(function (name) {
|
|
38
|
+
if (externals.includes(name)) {
|
|
39
|
+
__CONSOLE_OS_GLOBAL_VARS_[name] = window[name];
|
|
40
|
+
}
|
|
41
|
+
});
|
|
32
42
|
return new Proxy(frame.contentWindow, {
|
|
33
43
|
set: function set(target, name, value) {
|
|
34
44
|
target[name] = value;
|
package/package.json
CHANGED
|
@@ -1,19 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alicloud/console-os-browser-vm",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.25-alpha.0",
|
|
4
4
|
"description": "browser virtual machine",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "es/index.js",
|
|
7
7
|
"typings": "index.d.ts",
|
|
8
|
-
"scripts": {
|
|
9
|
-
"prepublishOnly": "npm run clean && npm run build && npm run babel && npm run babel:esm",
|
|
10
|
-
"babel": "breezr build --engine babel",
|
|
11
|
-
"babel:esm": "breezr build --engine babel --es-module",
|
|
12
|
-
"build": "breezr build --engine webpack",
|
|
13
|
-
"storybook": "breezr start-storybook",
|
|
14
|
-
"test": "breezr test:unit --coverage --env jsdom",
|
|
15
|
-
"clean": "rm -rf es build lib yarn.lock"
|
|
16
|
-
},
|
|
17
8
|
"author": "Boelroy",
|
|
18
9
|
"license": "ISC",
|
|
19
10
|
"devDependencies": {
|
|
@@ -30,5 +21,13 @@
|
|
|
30
21
|
"js-beautify": "^1.10.1",
|
|
31
22
|
"jsdom": "^16.2.2"
|
|
32
23
|
},
|
|
33
|
-
"gitHead": "9c6fffdb53e1b42c98b80e3f4eb896a3e2ee0c86"
|
|
34
|
-
|
|
24
|
+
"gitHead": "9c6fffdb53e1b42c98b80e3f4eb896a3e2ee0c86",
|
|
25
|
+
"scripts": {
|
|
26
|
+
"babel": "breezr build --engine babel",
|
|
27
|
+
"babel:esm": "breezr build --engine babel --es-module",
|
|
28
|
+
"build": "breezr build --engine webpack",
|
|
29
|
+
"storybook": "breezr start-storybook",
|
|
30
|
+
"test": "breezr test:unit --coverage --env jsdom",
|
|
31
|
+
"clean": "rm -rf es build lib yarn.lock"
|
|
32
|
+
}
|
|
33
|
+
}
|