wu-framework 1.1.14 → 1.1.16
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 +39 -39
- package/README.md +408 -408
- package/dist/wu-framework.cjs.js.map +1 -1
- package/dist/wu-framework.dev.js +15151 -15151
- package/dist/wu-framework.dev.js.map +1 -1
- package/dist/wu-framework.esm.js.map +1 -1
- package/dist/wu-framework.umd.js.map +1 -1
- package/integrations/astro/README.md +127 -127
- package/integrations/astro/WuApp.astro +63 -63
- package/integrations/astro/WuShell.astro +39 -39
- package/integrations/astro/index.js +68 -68
- package/integrations/astro/package.json +38 -38
- package/integrations/astro/types.d.ts +53 -53
- package/package.json +161 -161
- package/src/adapters/angular/ai.js +30 -30
- package/src/adapters/angular/index.d.ts +154 -154
- package/src/adapters/angular/index.js +932 -932
- package/src/adapters/angular.d.ts +3 -3
- package/src/adapters/angular.js +3 -3
- package/src/adapters/index.js +168 -168
- package/src/adapters/lit/ai.js +20 -20
- package/src/adapters/lit/index.d.ts +120 -120
- package/src/adapters/lit/index.js +721 -721
- package/src/adapters/lit.d.ts +3 -3
- package/src/adapters/lit.js +3 -3
- package/src/adapters/preact/ai.js +33 -33
- package/src/adapters/preact/index.d.ts +108 -108
- package/src/adapters/preact/index.js +661 -661
- package/src/adapters/preact.d.ts +3 -3
- package/src/adapters/preact.js +3 -3
- package/src/adapters/react/index.js +48 -54
- package/src/adapters/react.d.ts +3 -3
- package/src/adapters/react.js +3 -3
- package/src/adapters/shared.js +64 -64
- package/src/adapters/solid/ai.js +32 -32
- package/src/adapters/solid/index.d.ts +101 -101
- package/src/adapters/solid/index.js +586 -586
- package/src/adapters/solid.d.ts +3 -3
- package/src/adapters/solid.js +3 -3
- package/src/adapters/svelte/ai.js +31 -31
- package/src/adapters/svelte/index.d.ts +166 -166
- package/src/adapters/svelte/index.js +798 -798
- package/src/adapters/svelte.d.ts +3 -3
- package/src/adapters/svelte.js +3 -3
- package/src/adapters/vanilla/ai.js +30 -30
- package/src/adapters/vanilla/index.d.ts +179 -179
- package/src/adapters/vanilla/index.js +785 -785
- package/src/adapters/vanilla.d.ts +3 -3
- package/src/adapters/vanilla.js +3 -3
- package/src/adapters/vue/ai.js +52 -52
- package/src/adapters/vue/index.d.ts +299 -299
- package/src/adapters/vue/index.js +610 -610
- package/src/adapters/vue.d.ts +3 -3
- package/src/adapters/vue.js +3 -3
- package/src/ai/wu-ai-actions.js +261 -261
- package/src/ai/wu-ai-agent.js +546 -546
- package/src/ai/wu-ai-browser-primitives.js +354 -354
- package/src/ai/wu-ai-browser.js +380 -380
- package/src/ai/wu-ai-context.js +332 -332
- package/src/ai/wu-ai-conversation.js +613 -613
- package/src/ai/wu-ai-orchestrate.js +1021 -1021
- package/src/ai/wu-ai-permissions.js +381 -381
- package/src/ai/wu-ai-provider.js +700 -700
- package/src/ai/wu-ai-schema.js +225 -225
- package/src/ai/wu-ai-triggers.js +396 -396
- package/src/ai/wu-ai.js +804 -804
- package/src/core/wu-app.js +236 -236
- package/src/core/wu-cache.js +477 -477
- package/src/core/wu-core.js +1398 -1398
- package/src/core/wu-error-boundary.js +382 -382
- package/src/core/wu-event-bus.js +348 -348
- package/src/core/wu-hooks.js +350 -350
- package/src/core/wu-html-parser.js +190 -190
- package/src/core/wu-iframe-sandbox.js +328 -328
- package/src/core/wu-loader.js +272 -272
- package/src/core/wu-logger.js +134 -134
- package/src/core/wu-manifest.js +509 -509
- package/src/core/wu-mcp-bridge.js +432 -432
- package/src/core/wu-overrides.js +510 -510
- package/src/core/wu-performance.js +228 -228
- package/src/core/wu-plugin.js +348 -348
- package/src/core/wu-prefetch.js +414 -414
- package/src/core/wu-proxy-sandbox.js +476 -476
- package/src/core/wu-sandbox.js +779 -779
- package/src/core/wu-script-executor.js +113 -113
- package/src/core/wu-snapshot-sandbox.js +227 -227
- package/src/core/wu-strategies.js +256 -256
- package/src/core/wu-style-bridge.js +477 -477
- package/src/index.js +224 -224
- package/src/utils/dependency-resolver.js +327 -327
|
@@ -1,227 +1,227 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WU-SNAPSHOT-SANDBOX: JavaScript Isolation via Snapshots
|
|
3
|
-
* Fallback for browsers without Proxy support.
|
|
4
|
-
*
|
|
5
|
-
* Takes a snapshot of window state before mount,
|
|
6
|
-
* restores original state on deactivate.
|
|
7
|
-
* Also tracks timers and event listeners for cleanup.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { logger } from './wu-logger.js';
|
|
11
|
-
|
|
12
|
-
export class WuSnapshotSandbox {
|
|
13
|
-
constructor(appName) {
|
|
14
|
-
this.appName = appName;
|
|
15
|
-
this.proxy = window;
|
|
16
|
-
this.snapshot = new Map();
|
|
17
|
-
this.modifiedKeys = new Set();
|
|
18
|
-
this.active = false;
|
|
19
|
-
|
|
20
|
-
// Side-effect tracking (same as ProxySandbox)
|
|
21
|
-
this._timers = new Set();
|
|
22
|
-
this._intervals = new Set();
|
|
23
|
-
this._rafs = new Set();
|
|
24
|
-
this._eventListeners = [];
|
|
25
|
-
|
|
26
|
-
// Window patching state
|
|
27
|
-
this._patched = false;
|
|
28
|
-
this._originals = null;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Activate sandbox - capture window snapshot and start tracking.
|
|
33
|
-
*/
|
|
34
|
-
activate() {
|
|
35
|
-
if (this.active) return this.proxy;
|
|
36
|
-
|
|
37
|
-
this.snapshot.clear();
|
|
38
|
-
this.modifiedKeys.clear();
|
|
39
|
-
|
|
40
|
-
// Capture current window state
|
|
41
|
-
for (const key in window) {
|
|
42
|
-
try {
|
|
43
|
-
this.snapshot.set(key, window[key]);
|
|
44
|
-
} catch {
|
|
45
|
-
// Some properties may be inaccessible
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
this.active = true;
|
|
50
|
-
logger.wuDebug(`[SnapshotSandbox] Activated for ${this.appName} (${this.snapshot.size} props)`);
|
|
51
|
-
return this.proxy;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Deactivate sandbox - restore snapshot AND clean side effects.
|
|
56
|
-
*/
|
|
57
|
-
deactivate() {
|
|
58
|
-
if (!this.active) return;
|
|
59
|
-
|
|
60
|
-
// Unpatch window if patched
|
|
61
|
-
this.unpatchWindow();
|
|
62
|
-
|
|
63
|
-
// --- Clean tracked timers ---
|
|
64
|
-
for (const id of this._timers) {
|
|
65
|
-
try { clearTimeout(id); } catch {}
|
|
66
|
-
}
|
|
67
|
-
for (const id of this._intervals) {
|
|
68
|
-
try { clearInterval(id); } catch {}
|
|
69
|
-
}
|
|
70
|
-
for (const id of this._rafs) {
|
|
71
|
-
try { cancelAnimationFrame(id); } catch {}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const timerCount = this._timers.size + this._intervals.size + this._rafs.size;
|
|
75
|
-
this._timers.clear();
|
|
76
|
-
this._intervals.clear();
|
|
77
|
-
this._rafs.clear();
|
|
78
|
-
|
|
79
|
-
// --- Clean tracked event listeners ---
|
|
80
|
-
const listenerCount = this._eventListeners.length;
|
|
81
|
-
for (const { target, event, handler, options } of this._eventListeners) {
|
|
82
|
-
try { target.removeEventListener(event, handler, options); } catch {}
|
|
83
|
-
}
|
|
84
|
-
this._eventListeners = [];
|
|
85
|
-
|
|
86
|
-
// --- Restore window snapshot ---
|
|
87
|
-
let restoredCount = 0;
|
|
88
|
-
let deletedCount = 0;
|
|
89
|
-
|
|
90
|
-
for (const key in window) {
|
|
91
|
-
try {
|
|
92
|
-
const currentValue = window[key];
|
|
93
|
-
const originalValue = this.snapshot.get(key);
|
|
94
|
-
|
|
95
|
-
if (currentValue !== originalValue) {
|
|
96
|
-
if (this.snapshot.has(key)) {
|
|
97
|
-
window[key] = originalValue;
|
|
98
|
-
restoredCount++;
|
|
99
|
-
} else {
|
|
100
|
-
try {
|
|
101
|
-
delete window[key];
|
|
102
|
-
deletedCount++;
|
|
103
|
-
} catch {}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
} catch {}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
this.snapshot.clear();
|
|
110
|
-
this.modifiedKeys.clear();
|
|
111
|
-
this.active = false;
|
|
112
|
-
|
|
113
|
-
if (timerCount > 0 || listenerCount > 0) {
|
|
114
|
-
logger.wuDebug(
|
|
115
|
-
`[SnapshotSandbox] ${this.appName} cleanup: ${timerCount} timers, ${listenerCount} listeners, ${restoredCount} restored, ${deletedCount} deleted`
|
|
116
|
-
);
|
|
117
|
-
}
|
|
118
|
-
logger.wuDebug(`[SnapshotSandbox] Deactivated for ${this.appName}`);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// ================================================================
|
|
122
|
-
// WINDOW PATCHING - same interface as ProxySandbox
|
|
123
|
-
// ================================================================
|
|
124
|
-
|
|
125
|
-
patchWindow() {
|
|
126
|
-
if (this._patched) return;
|
|
127
|
-
|
|
128
|
-
const self = this;
|
|
129
|
-
|
|
130
|
-
// Capture in local closure — survives unpatch safely
|
|
131
|
-
const originals = {
|
|
132
|
-
setTimeout: window.setTimeout,
|
|
133
|
-
clearTimeout: window.clearTimeout,
|
|
134
|
-
setInterval: window.setInterval,
|
|
135
|
-
clearInterval: window.clearInterval,
|
|
136
|
-
requestAnimationFrame: window.requestAnimationFrame,
|
|
137
|
-
cancelAnimationFrame: window.cancelAnimationFrame,
|
|
138
|
-
addEventListener: window.addEventListener,
|
|
139
|
-
removeEventListener: window.removeEventListener
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
this._originals = originals;
|
|
143
|
-
|
|
144
|
-
window.setTimeout = function(fn, delay, ...args) {
|
|
145
|
-
const id = originals.setTimeout.call(window, fn, delay, ...args);
|
|
146
|
-
if (self._patched) self._timers.add(id);
|
|
147
|
-
return id;
|
|
148
|
-
};
|
|
149
|
-
window.clearTimeout = function(id) {
|
|
150
|
-
self._timers.delete(id);
|
|
151
|
-
return originals.clearTimeout.call(window, id);
|
|
152
|
-
};
|
|
153
|
-
window.setInterval = function(fn, delay, ...args) {
|
|
154
|
-
const id = originals.setInterval.call(window, fn, delay, ...args);
|
|
155
|
-
if (self._patched) self._intervals.add(id);
|
|
156
|
-
return id;
|
|
157
|
-
};
|
|
158
|
-
window.clearInterval = function(id) {
|
|
159
|
-
self._intervals.delete(id);
|
|
160
|
-
return originals.clearInterval.call(window, id);
|
|
161
|
-
};
|
|
162
|
-
window.requestAnimationFrame = function(fn) {
|
|
163
|
-
const id = originals.requestAnimationFrame.call(window, fn);
|
|
164
|
-
if (self._patched) self._rafs.add(id);
|
|
165
|
-
return id;
|
|
166
|
-
};
|
|
167
|
-
window.cancelAnimationFrame = function(id) {
|
|
168
|
-
self._rafs.delete(id);
|
|
169
|
-
return originals.cancelAnimationFrame.call(window, id);
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
window.addEventListener = function(event, handler, options) {
|
|
173
|
-
if (self._patched) self._eventListeners.push({ target: window, event, handler, options });
|
|
174
|
-
return originals.addEventListener.call(window, event, handler, options);
|
|
175
|
-
};
|
|
176
|
-
window.removeEventListener = function(event, handler, options) {
|
|
177
|
-
self._eventListeners = self._eventListeners.filter(
|
|
178
|
-
l => !(l.target === window && l.event === event && l.handler === handler)
|
|
179
|
-
);
|
|
180
|
-
return originals.removeEventListener.call(window, event, handler, options);
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
this._patched = true;
|
|
184
|
-
logger.wuDebug(`[SnapshotSandbox] Window patched for ${this.appName}`);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
unpatchWindow() {
|
|
188
|
-
if (!this._patched || !this._originals) return;
|
|
189
|
-
|
|
190
|
-
window.setTimeout = this._originals.setTimeout;
|
|
191
|
-
window.clearTimeout = this._originals.clearTimeout;
|
|
192
|
-
window.setInterval = this._originals.setInterval;
|
|
193
|
-
window.clearInterval = this._originals.clearInterval;
|
|
194
|
-
window.requestAnimationFrame = this._originals.requestAnimationFrame;
|
|
195
|
-
window.cancelAnimationFrame = this._originals.cancelAnimationFrame;
|
|
196
|
-
window.addEventListener = this._originals.addEventListener;
|
|
197
|
-
window.removeEventListener = this._originals.removeEventListener;
|
|
198
|
-
|
|
199
|
-
this._patched = false;
|
|
200
|
-
logger.wuDebug(`[SnapshotSandbox] Window unpatched for ${this.appName}`);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
// ================================================================
|
|
204
|
-
// UTILITIES
|
|
205
|
-
// ================================================================
|
|
206
|
-
|
|
207
|
-
getProxy() {
|
|
208
|
-
return this.active ? this.proxy : null;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
isActive() {
|
|
212
|
-
return this.active;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
getStats() {
|
|
216
|
-
return {
|
|
217
|
-
appName: this.appName,
|
|
218
|
-
active: this.active,
|
|
219
|
-
patched: this._patched,
|
|
220
|
-
snapshotSize: this.snapshot.size,
|
|
221
|
-
trackedTimers: this._timers.size,
|
|
222
|
-
trackedIntervals: this._intervals.size,
|
|
223
|
-
trackedRAFs: this._rafs.size,
|
|
224
|
-
trackedEventListeners: this._eventListeners.length
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* WU-SNAPSHOT-SANDBOX: JavaScript Isolation via Snapshots
|
|
3
|
+
* Fallback for browsers without Proxy support.
|
|
4
|
+
*
|
|
5
|
+
* Takes a snapshot of window state before mount,
|
|
6
|
+
* restores original state on deactivate.
|
|
7
|
+
* Also tracks timers and event listeners for cleanup.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { logger } from './wu-logger.js';
|
|
11
|
+
|
|
12
|
+
export class WuSnapshotSandbox {
|
|
13
|
+
constructor(appName) {
|
|
14
|
+
this.appName = appName;
|
|
15
|
+
this.proxy = window;
|
|
16
|
+
this.snapshot = new Map();
|
|
17
|
+
this.modifiedKeys = new Set();
|
|
18
|
+
this.active = false;
|
|
19
|
+
|
|
20
|
+
// Side-effect tracking (same as ProxySandbox)
|
|
21
|
+
this._timers = new Set();
|
|
22
|
+
this._intervals = new Set();
|
|
23
|
+
this._rafs = new Set();
|
|
24
|
+
this._eventListeners = [];
|
|
25
|
+
|
|
26
|
+
// Window patching state
|
|
27
|
+
this._patched = false;
|
|
28
|
+
this._originals = null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Activate sandbox - capture window snapshot and start tracking.
|
|
33
|
+
*/
|
|
34
|
+
activate() {
|
|
35
|
+
if (this.active) return this.proxy;
|
|
36
|
+
|
|
37
|
+
this.snapshot.clear();
|
|
38
|
+
this.modifiedKeys.clear();
|
|
39
|
+
|
|
40
|
+
// Capture current window state
|
|
41
|
+
for (const key in window) {
|
|
42
|
+
try {
|
|
43
|
+
this.snapshot.set(key, window[key]);
|
|
44
|
+
} catch {
|
|
45
|
+
// Some properties may be inaccessible
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
this.active = true;
|
|
50
|
+
logger.wuDebug(`[SnapshotSandbox] Activated for ${this.appName} (${this.snapshot.size} props)`);
|
|
51
|
+
return this.proxy;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Deactivate sandbox - restore snapshot AND clean side effects.
|
|
56
|
+
*/
|
|
57
|
+
deactivate() {
|
|
58
|
+
if (!this.active) return;
|
|
59
|
+
|
|
60
|
+
// Unpatch window if patched
|
|
61
|
+
this.unpatchWindow();
|
|
62
|
+
|
|
63
|
+
// --- Clean tracked timers ---
|
|
64
|
+
for (const id of this._timers) {
|
|
65
|
+
try { clearTimeout(id); } catch {}
|
|
66
|
+
}
|
|
67
|
+
for (const id of this._intervals) {
|
|
68
|
+
try { clearInterval(id); } catch {}
|
|
69
|
+
}
|
|
70
|
+
for (const id of this._rafs) {
|
|
71
|
+
try { cancelAnimationFrame(id); } catch {}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const timerCount = this._timers.size + this._intervals.size + this._rafs.size;
|
|
75
|
+
this._timers.clear();
|
|
76
|
+
this._intervals.clear();
|
|
77
|
+
this._rafs.clear();
|
|
78
|
+
|
|
79
|
+
// --- Clean tracked event listeners ---
|
|
80
|
+
const listenerCount = this._eventListeners.length;
|
|
81
|
+
for (const { target, event, handler, options } of this._eventListeners) {
|
|
82
|
+
try { target.removeEventListener(event, handler, options); } catch {}
|
|
83
|
+
}
|
|
84
|
+
this._eventListeners = [];
|
|
85
|
+
|
|
86
|
+
// --- Restore window snapshot ---
|
|
87
|
+
let restoredCount = 0;
|
|
88
|
+
let deletedCount = 0;
|
|
89
|
+
|
|
90
|
+
for (const key in window) {
|
|
91
|
+
try {
|
|
92
|
+
const currentValue = window[key];
|
|
93
|
+
const originalValue = this.snapshot.get(key);
|
|
94
|
+
|
|
95
|
+
if (currentValue !== originalValue) {
|
|
96
|
+
if (this.snapshot.has(key)) {
|
|
97
|
+
window[key] = originalValue;
|
|
98
|
+
restoredCount++;
|
|
99
|
+
} else {
|
|
100
|
+
try {
|
|
101
|
+
delete window[key];
|
|
102
|
+
deletedCount++;
|
|
103
|
+
} catch {}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
} catch {}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
this.snapshot.clear();
|
|
110
|
+
this.modifiedKeys.clear();
|
|
111
|
+
this.active = false;
|
|
112
|
+
|
|
113
|
+
if (timerCount > 0 || listenerCount > 0) {
|
|
114
|
+
logger.wuDebug(
|
|
115
|
+
`[SnapshotSandbox] ${this.appName} cleanup: ${timerCount} timers, ${listenerCount} listeners, ${restoredCount} restored, ${deletedCount} deleted`
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
logger.wuDebug(`[SnapshotSandbox] Deactivated for ${this.appName}`);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// ================================================================
|
|
122
|
+
// WINDOW PATCHING - same interface as ProxySandbox
|
|
123
|
+
// ================================================================
|
|
124
|
+
|
|
125
|
+
patchWindow() {
|
|
126
|
+
if (this._patched) return;
|
|
127
|
+
|
|
128
|
+
const self = this;
|
|
129
|
+
|
|
130
|
+
// Capture in local closure — survives unpatch safely
|
|
131
|
+
const originals = {
|
|
132
|
+
setTimeout: window.setTimeout,
|
|
133
|
+
clearTimeout: window.clearTimeout,
|
|
134
|
+
setInterval: window.setInterval,
|
|
135
|
+
clearInterval: window.clearInterval,
|
|
136
|
+
requestAnimationFrame: window.requestAnimationFrame,
|
|
137
|
+
cancelAnimationFrame: window.cancelAnimationFrame,
|
|
138
|
+
addEventListener: window.addEventListener,
|
|
139
|
+
removeEventListener: window.removeEventListener
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
this._originals = originals;
|
|
143
|
+
|
|
144
|
+
window.setTimeout = function(fn, delay, ...args) {
|
|
145
|
+
const id = originals.setTimeout.call(window, fn, delay, ...args);
|
|
146
|
+
if (self._patched) self._timers.add(id);
|
|
147
|
+
return id;
|
|
148
|
+
};
|
|
149
|
+
window.clearTimeout = function(id) {
|
|
150
|
+
self._timers.delete(id);
|
|
151
|
+
return originals.clearTimeout.call(window, id);
|
|
152
|
+
};
|
|
153
|
+
window.setInterval = function(fn, delay, ...args) {
|
|
154
|
+
const id = originals.setInterval.call(window, fn, delay, ...args);
|
|
155
|
+
if (self._patched) self._intervals.add(id);
|
|
156
|
+
return id;
|
|
157
|
+
};
|
|
158
|
+
window.clearInterval = function(id) {
|
|
159
|
+
self._intervals.delete(id);
|
|
160
|
+
return originals.clearInterval.call(window, id);
|
|
161
|
+
};
|
|
162
|
+
window.requestAnimationFrame = function(fn) {
|
|
163
|
+
const id = originals.requestAnimationFrame.call(window, fn);
|
|
164
|
+
if (self._patched) self._rafs.add(id);
|
|
165
|
+
return id;
|
|
166
|
+
};
|
|
167
|
+
window.cancelAnimationFrame = function(id) {
|
|
168
|
+
self._rafs.delete(id);
|
|
169
|
+
return originals.cancelAnimationFrame.call(window, id);
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
window.addEventListener = function(event, handler, options) {
|
|
173
|
+
if (self._patched) self._eventListeners.push({ target: window, event, handler, options });
|
|
174
|
+
return originals.addEventListener.call(window, event, handler, options);
|
|
175
|
+
};
|
|
176
|
+
window.removeEventListener = function(event, handler, options) {
|
|
177
|
+
self._eventListeners = self._eventListeners.filter(
|
|
178
|
+
l => !(l.target === window && l.event === event && l.handler === handler)
|
|
179
|
+
);
|
|
180
|
+
return originals.removeEventListener.call(window, event, handler, options);
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
this._patched = true;
|
|
184
|
+
logger.wuDebug(`[SnapshotSandbox] Window patched for ${this.appName}`);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
unpatchWindow() {
|
|
188
|
+
if (!this._patched || !this._originals) return;
|
|
189
|
+
|
|
190
|
+
window.setTimeout = this._originals.setTimeout;
|
|
191
|
+
window.clearTimeout = this._originals.clearTimeout;
|
|
192
|
+
window.setInterval = this._originals.setInterval;
|
|
193
|
+
window.clearInterval = this._originals.clearInterval;
|
|
194
|
+
window.requestAnimationFrame = this._originals.requestAnimationFrame;
|
|
195
|
+
window.cancelAnimationFrame = this._originals.cancelAnimationFrame;
|
|
196
|
+
window.addEventListener = this._originals.addEventListener;
|
|
197
|
+
window.removeEventListener = this._originals.removeEventListener;
|
|
198
|
+
|
|
199
|
+
this._patched = false;
|
|
200
|
+
logger.wuDebug(`[SnapshotSandbox] Window unpatched for ${this.appName}`);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// ================================================================
|
|
204
|
+
// UTILITIES
|
|
205
|
+
// ================================================================
|
|
206
|
+
|
|
207
|
+
getProxy() {
|
|
208
|
+
return this.active ? this.proxy : null;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
isActive() {
|
|
212
|
+
return this.active;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
getStats() {
|
|
216
|
+
return {
|
|
217
|
+
appName: this.appName,
|
|
218
|
+
active: this.active,
|
|
219
|
+
patched: this._patched,
|
|
220
|
+
snapshotSize: this.snapshot.size,
|
|
221
|
+
trackedTimers: this._timers.size,
|
|
222
|
+
trackedIntervals: this._intervals.size,
|
|
223
|
+
trackedRAFs: this._rafs.size,
|
|
224
|
+
trackedEventListeners: this._eventListeners.length
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
}
|