@alicloud/console-os-browser-vm 1.4.21-alpha.0 → 1.4.23
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 +31 -53
- package/es/Document.js +8 -40
- package/es/Elements.js +8 -18
- package/es/History.js +2 -11
- package/es/Location.js +0 -9
- package/es/Window.js +1 -19
- package/es/events.js +0 -6
- package/es/index.js +37 -54
- package/es/utils/HTMLScriptElement.js +4 -7
- package/es/utils/injectScriptCallBack.js +0 -8
- package/lib/Context.js +36 -62
- package/lib/Document.js +13 -41
- package/lib/Elements.js +8 -24
- package/lib/History.js +2 -13
- package/lib/Location.js +0 -10
- package/lib/Window.js +2 -21
- package/lib/events.js +0 -14
- package/lib/index.js +42 -65
- package/lib/utils/HTMLScriptElement.js +4 -15
- package/lib/utils/common.js +0 -2
- package/lib/utils/credentials.js +0 -2
- package/lib/utils/injectScriptCallBack.js +0 -10
- package/lib/utils/isSSR.js +0 -2
- package/lib/utils/not-implemented.js +0 -2
- package/package.json +2 -2
- package/dist/index.js +0 -1
package/es/Context.js
CHANGED
|
@@ -3,40 +3,34 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
|
3
3
|
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
4
4
|
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
5
5
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
6
|
-
|
|
7
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; }
|
|
8
|
-
|
|
9
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; }
|
|
10
|
-
|
|
11
8
|
/**
|
|
12
9
|
* Context
|
|
13
10
|
* @lastModified 2019086
|
|
14
11
|
* @forwardCompatibleTo 2019086
|
|
15
12
|
* @createAt 2019086
|
|
16
13
|
*/
|
|
14
|
+
|
|
17
15
|
import Window from './Window';
|
|
18
16
|
import Document from './Document';
|
|
19
17
|
import Location from './Location';
|
|
20
18
|
import History from './History';
|
|
21
19
|
import { getFetchCredentials } from './utils/credentials';
|
|
22
|
-
|
|
23
20
|
var Context = /*#__PURE__*/function () {
|
|
24
21
|
function Context(conf, frame) {
|
|
25
22
|
_classCallCheck(this, Context);
|
|
26
|
-
|
|
27
23
|
this.location = new Location(frame.contentWindow.location);
|
|
28
24
|
this.history = new History(conf.id, frame.contentWindow);
|
|
29
25
|
this.window = new Window(conf, this, frame, location);
|
|
30
26
|
this.allowResources = conf.allowResources || [];
|
|
31
27
|
var body = conf.body;
|
|
32
|
-
|
|
33
28
|
if (conf.disableBody) {
|
|
34
29
|
body = document.body;
|
|
35
30
|
} else if (!conf.body) {
|
|
36
31
|
body = document.createElement('body');
|
|
37
32
|
document.documentElement.appendChild(body);
|
|
38
33
|
}
|
|
39
|
-
|
|
40
34
|
this.body = body;
|
|
41
35
|
this.document = new Document(_objectSpread({
|
|
42
36
|
enableScriptEscape: true
|
|
@@ -45,42 +39,34 @@ var Context = /*#__PURE__*/function () {
|
|
|
45
39
|
this._listenerMap = new Map();
|
|
46
40
|
this.window.__IS_CONSOLE_OS_CONTEXT__ = true;
|
|
47
41
|
}
|
|
48
|
-
|
|
49
42
|
_createClass(Context, [{
|
|
50
43
|
key: "loadScripts",
|
|
51
44
|
value: function () {
|
|
52
45
|
var _loadScripts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(url) {
|
|
53
46
|
var resp, code;
|
|
54
47
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
55
|
-
while (1) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
case 7:
|
|
73
|
-
case "end":
|
|
74
|
-
return _context.stop();
|
|
75
|
-
}
|
|
48
|
+
while (1) switch (_context.prev = _context.next) {
|
|
49
|
+
case 0:
|
|
50
|
+
_context.next = 2;
|
|
51
|
+
return fetch(url, {
|
|
52
|
+
credentials: getFetchCredentials(url)
|
|
53
|
+
});
|
|
54
|
+
case 2:
|
|
55
|
+
resp = _context.sent;
|
|
56
|
+
_context.next = 5;
|
|
57
|
+
return resp.text();
|
|
58
|
+
case 5:
|
|
59
|
+
code = _context.sent;
|
|
60
|
+
this.evalScript(code, url);
|
|
61
|
+
case 7:
|
|
62
|
+
case "end":
|
|
63
|
+
return _context.stop();
|
|
76
64
|
}
|
|
77
65
|
}, _callee, this);
|
|
78
66
|
}));
|
|
79
|
-
|
|
80
67
|
function loadScripts(_x) {
|
|
81
68
|
return _loadScripts.apply(this, arguments);
|
|
82
69
|
}
|
|
83
|
-
|
|
84
70
|
return loadScripts;
|
|
85
71
|
}()
|
|
86
72
|
}, {
|
|
@@ -101,7 +87,6 @@ var Context = /*#__PURE__*/function () {
|
|
|
101
87
|
key: "remove",
|
|
102
88
|
value: function remove() {
|
|
103
89
|
this.document.removeEventListeners();
|
|
104
|
-
|
|
105
90
|
if (this.baseFrame) {
|
|
106
91
|
if (this.baseFrame.parentNode) {
|
|
107
92
|
this.baseFrame.parentNode.removeChild(this.baseFrame);
|
|
@@ -114,23 +99,23 @@ var Context = /*#__PURE__*/function () {
|
|
|
114
99
|
key: "create",
|
|
115
100
|
value: function create(conf) {
|
|
116
101
|
var _this = this;
|
|
117
|
-
|
|
118
102
|
return new Promise(function (resolve) {
|
|
119
103
|
var _document$documentEle;
|
|
104
|
+
var iframe = document.createElement('iframe');
|
|
120
105
|
|
|
121
|
-
|
|
122
|
-
|
|
106
|
+
// TODO: change src to a reasonable value.
|
|
123
107
|
iframe.setAttribute('src', conf.url ? conf.url : '/api.json');
|
|
124
108
|
iframe.style.cssText = 'position: absolute; top: -20000px; width: 1px; height: 1px;';
|
|
125
|
-
if (conf.id) iframe.setAttribute('data-id', conf.id);
|
|
109
|
+
if (conf.id) iframe.setAttribute('data-id', conf.id);
|
|
126
110
|
|
|
111
|
+
// body will be hijacked in sandbox, so get body from html
|
|
127
112
|
var topBody = ((_document$documentEle = document.documentElement) === null || _document$documentEle === void 0 ? void 0 : _document$documentEle.getElementsByTagName('body')[0]) || document.body;
|
|
128
|
-
topBody.appendChild(iframe);
|
|
113
|
+
topBody.appendChild(iframe);
|
|
129
114
|
|
|
115
|
+
// the onload will no trigger when src is about:blank
|
|
130
116
|
if (conf.url === 'about:blank') {
|
|
131
117
|
return resolve(new _this(conf, iframe));
|
|
132
118
|
}
|
|
133
|
-
|
|
134
119
|
iframe.onload = function () {
|
|
135
120
|
resolve(new _this(conf, iframe));
|
|
136
121
|
};
|
|
@@ -141,30 +126,23 @@ var Context = /*#__PURE__*/function () {
|
|
|
141
126
|
value: function () {
|
|
142
127
|
var _remove = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(context) {
|
|
143
128
|
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
144
|
-
while (1) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
case "end":
|
|
153
|
-
return _context2.stop();
|
|
154
|
-
}
|
|
129
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
130
|
+
case 0:
|
|
131
|
+
if (context.remove) {
|
|
132
|
+
context.remove();
|
|
133
|
+
}
|
|
134
|
+
case 1:
|
|
135
|
+
case "end":
|
|
136
|
+
return _context2.stop();
|
|
155
137
|
}
|
|
156
138
|
}, _callee2);
|
|
157
139
|
}));
|
|
158
|
-
|
|
159
140
|
function remove(_x2) {
|
|
160
141
|
return _remove.apply(this, arguments);
|
|
161
142
|
}
|
|
162
|
-
|
|
163
143
|
return remove;
|
|
164
144
|
}()
|
|
165
145
|
}]);
|
|
166
|
-
|
|
167
146
|
return Context;
|
|
168
147
|
}();
|
|
169
|
-
|
|
170
148
|
export default Context;
|
package/es/Document.js
CHANGED
|
@@ -1,28 +1,19 @@
|
|
|
1
1
|
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
2
|
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
3
|
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
4
|
-
|
|
5
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
6
|
-
|
|
7
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
8
|
-
|
|
9
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
10
|
-
|
|
11
4
|
/**
|
|
12
5
|
* Document.js
|
|
13
6
|
* @lastModified 2019085
|
|
14
7
|
* @forwardCompatibleTo 2019085
|
|
15
8
|
* @createAt 2019085
|
|
16
9
|
*/
|
|
17
|
-
import { injectHTMLScriptElement } from './utils/HTMLScriptElement';
|
|
18
10
|
|
|
11
|
+
import { injectHTMLScriptElement } from './utils/HTMLScriptElement';
|
|
19
12
|
var Document = /*#__PURE__*/_createClass(function Document() {
|
|
20
13
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
21
14
|
var context = arguments.length > 1 ? arguments[1] : undefined;
|
|
22
15
|
var frame = arguments.length > 2 ? arguments[2] : undefined;
|
|
23
|
-
|
|
24
16
|
_classCallCheck(this, Document);
|
|
25
|
-
|
|
26
17
|
var eventListeners = [];
|
|
27
18
|
return new Proxy(document, {
|
|
28
19
|
set: function set(target, name, value) {
|
|
@@ -30,75 +21,53 @@ var Document = /*#__PURE__*/_createClass(function Document() {
|
|
|
30
21
|
case 'cookie':
|
|
31
22
|
document.cookie = value;
|
|
32
23
|
break;
|
|
33
|
-
|
|
34
24
|
default:
|
|
35
25
|
target[name] = value;
|
|
36
26
|
}
|
|
37
|
-
|
|
38
27
|
return true;
|
|
39
28
|
},
|
|
40
29
|
get: function get(target, name) {
|
|
41
30
|
switch (name) {
|
|
42
31
|
case 'body':
|
|
43
32
|
return context.body;
|
|
44
|
-
|
|
45
33
|
case 'location':
|
|
46
34
|
return context.location;
|
|
47
|
-
|
|
48
35
|
case 'defaultView':
|
|
49
36
|
return context.window;
|
|
50
|
-
|
|
51
37
|
case 'write':
|
|
52
38
|
case 'writeln':
|
|
53
39
|
return function () {};
|
|
54
|
-
|
|
55
40
|
case 'createElement':
|
|
56
41
|
return function () {
|
|
57
42
|
var _document;
|
|
58
|
-
|
|
59
43
|
var el = (_document = document).createElement.apply(_document, arguments);
|
|
60
|
-
|
|
61
44
|
el.ownerContext = context;
|
|
62
|
-
el.appId = options.id;
|
|
63
|
-
|
|
45
|
+
el.appId = options.id;
|
|
46
|
+
// 对于 script 标签如果开启防逃逸,就直接 hack script 标签
|
|
64
47
|
if (el.tagName === 'SCRIPT' && !options.enableScriptEscape) {
|
|
65
48
|
injectHTMLScriptElement(el);
|
|
66
49
|
}
|
|
67
|
-
|
|
68
50
|
return el;
|
|
69
51
|
};
|
|
70
|
-
|
|
71
52
|
case 'addEventListener':
|
|
72
53
|
return function () {
|
|
73
54
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
74
55
|
args[_key] = arguments[_key];
|
|
75
56
|
}
|
|
76
|
-
|
|
77
57
|
eventListeners.push(args);
|
|
78
58
|
return target.addEventListener.apply(target, args);
|
|
79
59
|
};
|
|
80
|
-
|
|
81
60
|
case 'removeEventListeners':
|
|
82
61
|
return function () {
|
|
83
|
-
var
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
try {
|
|
87
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
88
|
-
var args = _step.value;
|
|
89
|
-
target.removeEventListener.apply(target, _toConsumableArray(args));
|
|
90
|
-
}
|
|
91
|
-
} catch (err) {
|
|
92
|
-
_iterator.e(err);
|
|
93
|
-
} finally {
|
|
94
|
-
_iterator.f();
|
|
62
|
+
for (var _i = 0, _eventListeners = eventListeners; _i < _eventListeners.length; _i++) {
|
|
63
|
+
var args = _eventListeners[_i];
|
|
64
|
+
target.removeEventListener.apply(target, _toConsumableArray(args));
|
|
95
65
|
}
|
|
96
66
|
};
|
|
97
|
-
|
|
98
67
|
default:
|
|
99
|
-
}
|
|
100
|
-
|
|
68
|
+
}
|
|
101
69
|
|
|
70
|
+
// TODO: hijack document.getElementsByTagName('body')
|
|
102
71
|
if (typeof target[name] === 'function') {
|
|
103
72
|
return target[name].bind && target[name].bind(target);
|
|
104
73
|
} else {
|
|
@@ -107,5 +76,4 @@ var Document = /*#__PURE__*/_createClass(function Document() {
|
|
|
107
76
|
}
|
|
108
77
|
});
|
|
109
78
|
});
|
|
110
|
-
|
|
111
79
|
export default Document;
|
package/es/Elements.js
CHANGED
|
@@ -1,57 +1,49 @@
|
|
|
1
1
|
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
2
|
import injectScriptCallBack, { getJsonCallback } from './utils/injectScriptCallBack';
|
|
3
3
|
import { isSSR } from './utils/isSSR';
|
|
4
|
-
|
|
5
4
|
var makeElInjector = function makeElInjector(originMethod, methodName) {
|
|
6
5
|
return function (el) {
|
|
7
|
-
var notAllowed = el.ownerContext && el.ownerContext.allowResources.indexOf(el.src) === -1 && el.ownerContext.allowResources !== '*';
|
|
6
|
+
var notAllowed = el.ownerContext && el.ownerContext.allowResources.indexOf(el.src) === -1 && el.ownerContext.allowResources !== '*';
|
|
8
7
|
|
|
8
|
+
// 如果不在 BrowserVM 的白名单内,尝试通过 context 的 load script 通过 xhr 获取脚本内容,并在沙箱中执行
|
|
9
9
|
if (el && el._evalScriptInSandbox && el.ownerContext && el.nodeName === 'SCRIPT' && el.src && notAllowed && !getJsonCallback(el.src)) {
|
|
10
10
|
return el.ownerContext.loadScripts(el.src).then(function () {
|
|
11
11
|
var fns = el._listenerMap.get('load');
|
|
12
|
-
|
|
13
12
|
if (fns) {
|
|
14
13
|
fns.forEach(function (fn) {
|
|
15
14
|
fn();
|
|
16
15
|
});
|
|
17
16
|
}
|
|
18
|
-
|
|
19
17
|
var e = new Event('load');
|
|
20
18
|
el.onload && el.onload(e);
|
|
21
19
|
}).catch(function (e) {
|
|
22
20
|
console.error(e);
|
|
23
|
-
|
|
24
21
|
var fns = el._listenerMap.get('error');
|
|
25
|
-
|
|
26
22
|
if (fns) {
|
|
27
23
|
fns.forEach(function (fn) {
|
|
28
24
|
fn(e);
|
|
29
25
|
});
|
|
30
26
|
}
|
|
31
|
-
|
|
32
27
|
el.onerror && el.onerror(e);
|
|
33
28
|
});
|
|
34
29
|
}
|
|
35
|
-
|
|
36
30
|
if (el && el.nodeName === 'SCRIPT' && el.ownerContext) {
|
|
37
31
|
injectScriptCallBack(el);
|
|
38
|
-
}
|
|
39
|
-
// 所以直接执行这个 script
|
|
40
|
-
|
|
32
|
+
}
|
|
41
33
|
|
|
34
|
+
// 如果有 scriptText, 证明在 append 之前被设置了 text
|
|
35
|
+
// 所以直接执行这个 script
|
|
42
36
|
if (el && el.scriptText) {
|
|
43
37
|
el.ownerContext.evalScript(el.scriptText);
|
|
44
|
-
}
|
|
45
|
-
// 这里 尝试 try catch 如果报错 直接调用 fn.apply
|
|
46
|
-
|
|
38
|
+
}
|
|
47
39
|
|
|
40
|
+
// fix: babel 会把 fn.call 转义成 fn.call.apply 造成 chrome 50 的几个版本报错
|
|
41
|
+
// 这里 尝试 try catch 如果报错 直接调用 fn.apply
|
|
48
42
|
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
49
43
|
args[_key - 1] = arguments[_key];
|
|
50
44
|
}
|
|
51
|
-
|
|
52
45
|
var methodArgs = methodName === 'append' && el === undefined // 修复 append 的过程中 append() 为一个没参数的状态。应为 append 的函数签名为 append(param1, param2, /* ... ,*/ paramN)
|
|
53
46
|
? [].concat(args) : [el].concat(args);
|
|
54
|
-
|
|
55
47
|
try {
|
|
56
48
|
return originMethod.call.apply(originMethod, [this].concat(_toConsumableArray(methodArgs)));
|
|
57
49
|
} catch (_unused) {
|
|
@@ -59,10 +51,8 @@ var makeElInjector = function makeElInjector(originMethod, methodName) {
|
|
|
59
51
|
}
|
|
60
52
|
};
|
|
61
53
|
};
|
|
62
|
-
|
|
63
54
|
if (!isSSR() && typeof window.Element === 'function') {
|
|
64
55
|
var mountElementMethods = ['appendChild', 'insertBefore', 'append'];
|
|
65
|
-
|
|
66
56
|
for (var _i = 0, _mountElementMethods = mountElementMethods; _i < _mountElementMethods.length; _i++) {
|
|
67
57
|
var method = _mountElementMethods[_i];
|
|
68
58
|
var originMethod = window.Element.prototype[method];
|
package/es/History.js
CHANGED
|
@@ -1,49 +1,40 @@
|
|
|
1
1
|
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
2
2
|
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
3
|
-
|
|
4
3
|
var History = /*#__PURE__*/_createClass(function History(id, frame) {
|
|
5
4
|
_classCallCheck(this, History);
|
|
6
|
-
|
|
7
5
|
if (!id) {
|
|
8
6
|
return frame.history;
|
|
9
7
|
}
|
|
10
|
-
|
|
11
8
|
var postMessage = function postMessage() {
|
|
12
9
|
frame.postMessage({
|
|
13
10
|
type: "".concat(id, ":history-change"),
|
|
14
11
|
data: JSON.parse(JSON.stringify(frame.location))
|
|
15
12
|
}, '*');
|
|
16
|
-
};
|
|
17
|
-
|
|
13
|
+
};
|
|
18
14
|
|
|
15
|
+
// throw error when iframe src is about:blank
|
|
19
16
|
try {
|
|
20
17
|
var originalPushStatus = frame.history.pushState;
|
|
21
18
|
var originalReplaceStatus = frame.history.replaceState;
|
|
22
|
-
|
|
23
19
|
frame.history.pushState = function () {
|
|
24
20
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
25
21
|
args[_key] = arguments[_key];
|
|
26
22
|
}
|
|
27
|
-
|
|
28
23
|
var returnValue = originalPushStatus.apply(frame.history, [].concat(args));
|
|
29
24
|
postMessage();
|
|
30
25
|
return returnValue;
|
|
31
26
|
};
|
|
32
|
-
|
|
33
27
|
frame.history.replaceState = function () {
|
|
34
28
|
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
35
29
|
args[_key2] = arguments[_key2];
|
|
36
30
|
}
|
|
37
|
-
|
|
38
31
|
var returnValue = originalReplaceStatus.apply(frame.history, [].concat(args));
|
|
39
32
|
postMessage();
|
|
40
33
|
return returnValue;
|
|
41
34
|
};
|
|
42
|
-
|
|
43
35
|
return frame.history;
|
|
44
36
|
} catch (e) {
|
|
45
37
|
return undefined;
|
|
46
38
|
}
|
|
47
39
|
});
|
|
48
|
-
|
|
49
40
|
export default History;
|
package/es/Location.js
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
1
|
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
2
2
|
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
3
|
-
|
|
4
3
|
var Location = /*#__PURE__*/_createClass(function Location(location) {
|
|
5
4
|
_classCallCheck(this, Location);
|
|
6
|
-
|
|
7
5
|
return new Proxy({}, {
|
|
8
6
|
set: function set(target, name, value) {
|
|
9
7
|
switch (name) {
|
|
10
8
|
case 'href':
|
|
11
9
|
break;
|
|
12
|
-
|
|
13
10
|
default:
|
|
14
11
|
location[name] = value;
|
|
15
12
|
}
|
|
16
|
-
|
|
17
13
|
return true;
|
|
18
14
|
},
|
|
19
15
|
get: function get(target, name) {
|
|
@@ -22,10 +18,8 @@ var Location = /*#__PURE__*/_createClass(function Location(location) {
|
|
|
22
18
|
return function () {
|
|
23
19
|
return window.location.reload();
|
|
24
20
|
};
|
|
25
|
-
|
|
26
21
|
case 'replace':
|
|
27
22
|
return function () {};
|
|
28
|
-
|
|
29
23
|
case 'toString':
|
|
30
24
|
return function () {
|
|
31
25
|
try {
|
|
@@ -34,11 +28,9 @@ var Location = /*#__PURE__*/_createClass(function Location(location) {
|
|
|
34
28
|
return location.href;
|
|
35
29
|
}
|
|
36
30
|
};
|
|
37
|
-
|
|
38
31
|
default:
|
|
39
32
|
break;
|
|
40
33
|
}
|
|
41
|
-
|
|
42
34
|
if (typeof location[name] === 'function') {
|
|
43
35
|
return location[name].bind && location[name].bind(target);
|
|
44
36
|
} else {
|
|
@@ -47,5 +39,4 @@ var Location = /*#__PURE__*/_createClass(function Location(location) {
|
|
|
47
39
|
}
|
|
48
40
|
});
|
|
49
41
|
});
|
|
50
|
-
|
|
51
42
|
export default Location;
|
package/es/Window.js
CHANGED
|
@@ -1,29 +1,24 @@
|
|
|
1
1
|
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
2
|
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
3
|
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
4
|
-
|
|
5
4
|
/**
|
|
6
5
|
* Window.js
|
|
7
6
|
*/
|
|
8
7
|
import { addEventListener, removeEventListener } from './events';
|
|
9
8
|
import { isConstructable, isBoundedFunction } from './utils/common';
|
|
10
9
|
var globalFnName = ['setTimeout', 'setInterval', 'clearInterval', 'clearTimeout'];
|
|
11
|
-
var defaultExternals = ['requestAnimationFrame', 'webkitRequestAnimationFrame', 'mozRequestAnimationFrame', 'oRequestAnimationFrame', 'msRequestAnimationFrame', 'cancelAnimationFrame', 'webkitCancelAnimationFrame', 'mozCancelAnimationFrame', 'oCancelAnimationFrame', 'msCancelAnimationFrame'];
|
|
12
|
-
|
|
10
|
+
var defaultExternals = ['requestAnimationFrame', 'webkitRequestAnimationFrame', 'mozRequestAnimationFrame', 'oRequestAnimationFrame', 'msRequestAnimationFrame', 'cancelAnimationFrame', 'webkitCancelAnimationFrame', 'mozCancelAnimationFrame', 'oCancelAnimationFrame', 'msCancelAnimationFrame', 'matchMedia'];
|
|
13
11
|
var Window = /*#__PURE__*/_createClass(function Window() {
|
|
14
12
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
15
13
|
var context = arguments.length > 1 ? arguments[1] : undefined;
|
|
16
14
|
var frame = arguments.length > 2 ? arguments[2] : undefined;
|
|
17
|
-
|
|
18
15
|
_classCallCheck(this, Window);
|
|
19
|
-
|
|
20
16
|
var externals = [].concat(defaultExternals, _toConsumableArray(options.externals || []));
|
|
21
17
|
var __CONSOLE_OS_GLOBAL_VARS_ = {};
|
|
22
18
|
globalFnName.forEach(function (name) {
|
|
23
19
|
if (externals.includes(name)) {
|
|
24
20
|
return;
|
|
25
21
|
}
|
|
26
|
-
|
|
27
22
|
__CONSOLE_OS_GLOBAL_VARS_[name] = frame.contentWindow[name].bind(frame.contentWindow);
|
|
28
23
|
});
|
|
29
24
|
return new Proxy(frame.contentWindow, {
|
|
@@ -35,46 +30,34 @@ var Window = /*#__PURE__*/_createClass(function Window() {
|
|
|
35
30
|
get: function get(target, name) {
|
|
36
31
|
if (externals.includes(name)) {
|
|
37
32
|
var windowValue = window[name];
|
|
38
|
-
|
|
39
33
|
if (typeof windowValue === 'function' && !isBoundedFunction(windowValue) && !isConstructable(windowValue)) {
|
|
40
34
|
var bindFn = windowValue.bind(window);
|
|
41
|
-
|
|
42
35
|
for (var key in windowValue) {
|
|
43
36
|
bindFn[key] = windowValue[key];
|
|
44
37
|
}
|
|
45
|
-
|
|
46
38
|
return bindFn;
|
|
47
39
|
} else {
|
|
48
40
|
return windowValue;
|
|
49
41
|
}
|
|
50
42
|
}
|
|
51
|
-
|
|
52
43
|
switch (name) {
|
|
53
44
|
case 'document':
|
|
54
45
|
return context.document;
|
|
55
|
-
|
|
56
46
|
case 'location':
|
|
57
47
|
return context.location;
|
|
58
|
-
|
|
59
48
|
case 'history':
|
|
60
49
|
return context.history;
|
|
61
|
-
|
|
62
50
|
case '__CONSOLE_OS_GLOBAL_VARS_':
|
|
63
51
|
return __CONSOLE_OS_GLOBAL_VARS_;
|
|
64
|
-
|
|
65
52
|
case 'addEventListener':
|
|
66
53
|
return addEventListener(context);
|
|
67
|
-
|
|
68
54
|
case 'removeEventListener':
|
|
69
55
|
return removeEventListener(context);
|
|
70
56
|
}
|
|
71
|
-
|
|
72
57
|
if (__CONSOLE_OS_GLOBAL_VARS_[name]) {
|
|
73
58
|
return __CONSOLE_OS_GLOBAL_VARS_[name];
|
|
74
59
|
}
|
|
75
|
-
|
|
76
60
|
var value = target[name];
|
|
77
|
-
|
|
78
61
|
if (typeof value === 'function' && !isBoundedFunction(value) && !isConstructable(value)) {
|
|
79
62
|
return value.bind && value.bind(target);
|
|
80
63
|
} else {
|
|
@@ -83,5 +66,4 @@ var Window = /*#__PURE__*/_createClass(function Window() {
|
|
|
83
66
|
}
|
|
84
67
|
});
|
|
85
68
|
});
|
|
86
|
-
|
|
87
69
|
export default Window;
|
package/es/events.js
CHANGED
|
@@ -7,28 +7,22 @@ export var domEventsListeningTo = ['webkitmouseforcedown', 'webkitmouseforcewill
|
|
|
7
7
|
export var addEventListener = function addEventListener(context) {
|
|
8
8
|
return function (type, listener, options) {
|
|
9
9
|
var listeners = context._listenerMap.get(type) || [];
|
|
10
|
-
|
|
11
10
|
context._listenerMap.set(type, [].concat(_toConsumableArray(listeners), [listener]));
|
|
12
|
-
|
|
13
11
|
if (domEventsListeningTo.indexOf(type) === -1) {
|
|
14
12
|
return context.baseFrame.addEventListener.apply(context.baseFrame.contentWindow, [type, listener, options]);
|
|
15
13
|
}
|
|
16
|
-
|
|
17
14
|
return rawAddEventListener.apply(window, [type, listener, options]);
|
|
18
15
|
};
|
|
19
16
|
};
|
|
20
17
|
export var removeEventListener = function removeEventListener(context) {
|
|
21
18
|
return function (type, listener, options) {
|
|
22
19
|
var storedTypeListeners = context._listenerMap.get(type);
|
|
23
|
-
|
|
24
20
|
if (storedTypeListeners && storedTypeListeners.length && storedTypeListeners.indexOf(listener) !== -1) {
|
|
25
21
|
storedTypeListeners.splice(storedTypeListeners.indexOf(listener), 1);
|
|
26
22
|
}
|
|
27
|
-
|
|
28
23
|
if (domEventsListeningTo.indexOf(type) === -1) {
|
|
29
24
|
return context.baseFrame.removeEventListener.apply(context.baseFrame.contentWindow, [type, listener, options]);
|
|
30
25
|
}
|
|
31
|
-
|
|
32
26
|
return rawRemoveEventListener.apply(window, [type, listener, options]);
|
|
33
27
|
};
|
|
34
28
|
};
|