@alicloud/console-os-browser-vm 1.4.24 → 1.4.25
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/es/Context.js +3 -2
- package/es/Location.js +7 -2
- package/es/Window.js +10 -0
- package/lib/Context.js +3 -2
- package/lib/Location.js +7 -2
- package/lib/Window.js +10 -0
- package/package.json +1 -1
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/Location.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
2
2
|
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
3
|
+
function isAboutBlank(loc) {
|
|
4
|
+
return loc && loc.href === 'about:blank';
|
|
5
|
+
}
|
|
3
6
|
var Location = /*#__PURE__*/_createClass(function Location(location) {
|
|
4
7
|
_classCallCheck(this, Location);
|
|
5
8
|
return new Proxy({}, {
|
|
@@ -23,9 +26,9 @@ var Location = /*#__PURE__*/_createClass(function Location(location) {
|
|
|
23
26
|
case 'toString':
|
|
24
27
|
return function () {
|
|
25
28
|
try {
|
|
26
|
-
return location.toString();
|
|
29
|
+
return isAboutBlank(location) ? window.location.toString() : location.toString();
|
|
27
30
|
} catch (e) {
|
|
28
|
-
return location.href;
|
|
31
|
+
return isAboutBlank(location) ? window.location.href : location.href;
|
|
29
32
|
}
|
|
30
33
|
};
|
|
31
34
|
default:
|
|
@@ -33,6 +36,8 @@ var Location = /*#__PURE__*/_createClass(function Location(location) {
|
|
|
33
36
|
}
|
|
34
37
|
if (typeof location[name] === 'function') {
|
|
35
38
|
return location[name].bind && location[name].bind(target);
|
|
39
|
+
} else if (isAboutBlank(location)) {
|
|
40
|
+
return window.location[name];
|
|
36
41
|
} else {
|
|
37
42
|
return location[name];
|
|
38
43
|
}
|
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/Location.js
CHANGED
|
@@ -7,6 +7,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.default = void 0;
|
|
8
8
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
9
9
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
10
|
+
function isAboutBlank(loc) {
|
|
11
|
+
return loc && loc.href === 'about:blank';
|
|
12
|
+
}
|
|
10
13
|
var Location = /*#__PURE__*/(0, _createClass2.default)(function Location(location) {
|
|
11
14
|
(0, _classCallCheck2.default)(this, Location);
|
|
12
15
|
return new Proxy({}, {
|
|
@@ -30,9 +33,9 @@ var Location = /*#__PURE__*/(0, _createClass2.default)(function Location(locatio
|
|
|
30
33
|
case 'toString':
|
|
31
34
|
return function () {
|
|
32
35
|
try {
|
|
33
|
-
return location.toString();
|
|
36
|
+
return isAboutBlank(location) ? window.location.toString() : location.toString();
|
|
34
37
|
} catch (e) {
|
|
35
|
-
return location.href;
|
|
38
|
+
return isAboutBlank(location) ? window.location.href : location.href;
|
|
36
39
|
}
|
|
37
40
|
};
|
|
38
41
|
default:
|
|
@@ -40,6 +43,8 @@ var Location = /*#__PURE__*/(0, _createClass2.default)(function Location(locatio
|
|
|
40
43
|
}
|
|
41
44
|
if (typeof location[name] === 'function') {
|
|
42
45
|
return location[name].bind && location[name].bind(target);
|
|
46
|
+
} else if (isAboutBlank(location)) {
|
|
47
|
+
return window.location[name];
|
|
43
48
|
} else {
|
|
44
49
|
return location[name];
|
|
45
50
|
}
|
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;
|