@highlight-run/rrweb 1.2.1 → 2.0.4

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.
Files changed (191) hide show
  1. package/dist/plugins/console-record.js +454 -0
  2. package/dist/plugins/console-record.min.js +12 -15
  3. package/dist/plugins/console-record.min.js.map +1 -1
  4. package/dist/plugins/console-replay.js +164 -0
  5. package/dist/plugins/console-replay.min.js +5 -0
  6. package/dist/plugins/console-replay.min.js.map +1 -0
  7. package/dist/plugins/sequential-id-record.js +30 -0
  8. package/dist/plugins/sequential-id-record.min.js +2 -0
  9. package/dist/plugins/sequential-id-record.min.js.map +1 -0
  10. package/dist/plugins/sequential-id-replay.js +33 -0
  11. package/dist/plugins/sequential-id-replay.min.js +2 -0
  12. package/dist/plugins/sequential-id-replay.min.js.map +1 -0
  13. package/dist/record/rrweb-record-pack.js +664 -0
  14. package/dist/record/rrweb-record-pack.min.js +4 -0
  15. package/dist/record/rrweb-record-pack.min.js.map +1 -0
  16. package/dist/record/rrweb-record.js +3202 -0
  17. package/dist/record/rrweb-record.min.js +5 -0
  18. package/dist/record/rrweb-record.min.js.map +1 -0
  19. package/dist/replay/rrweb-replay-unpack.js +4926 -0
  20. package/dist/replay/rrweb-replay-unpack.min.js +18 -0
  21. package/dist/replay/rrweb-replay-unpack.min.js.map +1 -0
  22. package/dist/replay/rrweb-replay.js +4518 -0
  23. package/dist/replay/rrweb-replay.min.js +18 -0
  24. package/dist/replay/rrweb-replay.min.js.map +1 -0
  25. package/dist/rrweb-all.js +8889 -0
  26. package/dist/rrweb-all.min.js +29 -0
  27. package/dist/rrweb-all.min.js.map +1 -0
  28. package/dist/rrweb.js +7558 -0
  29. package/dist/rrweb.min.js +6 -17
  30. package/dist/rrweb.min.js.map +1 -1
  31. package/es/rrweb/_virtual/_rollup-plugin-web-worker-loader__helper__auto__createBase64WorkerFactory.js +12 -0
  32. package/es/rrweb/_virtual/_rollup-plugin-web-worker-loader__helper__auto__isNodeJS.js +7 -0
  33. package/es/rrweb/_virtual/_rollup-plugin-web-worker-loader__helper__browser__createBase64WorkerFactory.js +31 -0
  34. package/es/rrweb/_virtual/_rollup-plugin-web-worker-loader__helper__node__WorkerClass.js +11 -0
  35. package/es/rrweb/_virtual/_rollup-plugin-web-worker-loader__helper__node__createBase64WorkerFactory.js +18 -0
  36. package/es/rrweb/_virtual/image-bitmap-data-url-worker.js +6 -0
  37. package/es/rrweb/ext/@xstate/fsm/es/index.js +17 -0
  38. package/es/rrweb/ext/base64-arraybuffer/dist/base64-arraybuffer.es5.js +49 -0
  39. package/es/rrweb/ext/fflate/esm/browser.js +777 -0
  40. package/es/rrweb/ext/mitt/dist/mitt.es.js +63 -0
  41. package/es/rrweb/ext/tslib/tslib.es6.js +38 -0
  42. package/es/rrweb/packages/rrdom/es/virtual-dom.js +1099 -0
  43. package/es/rrweb/packages/rrweb/src/entries/all.js +13 -0
  44. package/es/rrweb/packages/rrweb/src/index.js +14 -0
  45. package/es/rrweb/packages/rrweb/src/packer/base.js +3 -0
  46. package/es/rrweb/packages/rrweb/src/packer/pack.js +9 -0
  47. package/es/rrweb/packages/rrweb/src/packer/unpack.js +29 -0
  48. package/es/rrweb/packages/rrweb/src/plugins/console/record/error-stack-parser.js +178 -0
  49. package/es/rrweb/packages/rrweb/src/plugins/console/record/index.js +115 -0
  50. package/es/rrweb/packages/rrweb/src/plugins/console/record/stringify.js +128 -0
  51. package/es/rrweb/packages/rrweb/src/plugins/console/replay/index.js +94 -0
  52. package/es/rrweb/packages/rrweb/src/plugins/sequential-id/record/index.js +22 -0
  53. package/es/rrweb/packages/rrweb/src/plugins/sequential-id/replay/index.js +28 -0
  54. package/es/rrweb/packages/rrweb/src/record/iframe-manager.js +31 -0
  55. package/es/rrweb/packages/rrweb/src/record/index.js +356 -0
  56. package/es/rrweb/packages/rrweb/src/record/mutation.js +491 -0
  57. package/es/rrweb/packages/rrweb/src/record/observer.js +590 -0
  58. package/es/rrweb/packages/rrweb/src/record/observers/canvas/2d.js +49 -0
  59. package/es/rrweb/packages/rrweb/src/record/observers/canvas/canvas-manager.js +172 -0
  60. package/es/rrweb/packages/rrweb/src/record/observers/canvas/canvas.js +25 -0
  61. package/es/rrweb/packages/rrweb/src/record/observers/canvas/serialize-args.js +123 -0
  62. package/es/rrweb/packages/rrweb/src/record/observers/canvas/webgl.js +59 -0
  63. package/es/rrweb/packages/rrweb/src/record/shadow-dom-manager.js +43 -0
  64. package/es/rrweb/packages/rrweb/src/record/stylesheet-manager.js +31 -0
  65. package/es/rrweb/packages/rrweb/src/replay/canvas/2d.js +29 -0
  66. package/es/rrweb/packages/rrweb/src/replay/canvas/deserialize-args.js +67 -0
  67. package/es/rrweb/packages/rrweb/src/replay/canvas/index.js +43 -0
  68. package/es/rrweb/packages/rrweb/src/replay/canvas/webgl.js +62 -0
  69. package/es/rrweb/packages/rrweb/src/replay/index.js +1555 -0
  70. package/es/rrweb/packages/rrweb/src/replay/machine.js +281 -0
  71. package/es/rrweb/packages/rrweb/src/replay/smoothscroll.js +219 -0
  72. package/es/rrweb/packages/rrweb/src/replay/styles/inject-style.js +8 -0
  73. package/es/rrweb/packages/rrweb/src/replay/timer.js +92 -0
  74. package/es/rrweb/packages/rrweb/src/types.js +75 -0
  75. package/es/rrweb/packages/rrweb/src/utils.js +315 -0
  76. package/es/rrweb/packages/rrweb-snapshot/es/rrweb-snapshot.js +1821 -0
  77. package/lib/plugins/console-record.js +492 -0
  78. package/lib/plugins/console-replay.js +218 -0
  79. package/lib/plugins/sequential-id-record.js +27 -0
  80. package/lib/plugins/sequential-id-replay.js +32 -0
  81. package/lib/record/rrweb-record-pack.js +787 -0
  82. package/lib/record/rrweb-record.js +3363 -0
  83. package/lib/replay/rrweb-replay-unpack.js +5075 -0
  84. package/lib/replay/rrweb-replay.js +4665 -0
  85. package/lib/rrweb-all.js +9181 -0
  86. package/lib/rrweb.js +7814 -0
  87. package/package.json +41 -42
  88. package/typings/entries/all.d.ts +6 -0
  89. package/{dist → typings}/entries/record-pack.d.ts +0 -0
  90. package/{dist → typings}/entries/replay-unpack.d.ts +0 -0
  91. package/{dist → typings}/index.d.ts +1 -2
  92. package/{dist → typings}/packer/base.d.ts +1 -1
  93. package/{dist → typings}/packer/index.d.ts +0 -0
  94. package/{dist → typings}/packer/pack.d.ts +0 -0
  95. package/{dist → typings}/packer/unpack.d.ts +0 -0
  96. package/{dist → typings}/plugins/console/record/error-stack-parser.d.ts +0 -0
  97. package/{dist → typings}/plugins/console/record/index.d.ts +4 -3
  98. package/{dist → typings}/plugins/console/record/stringify.d.ts +1 -1
  99. package/{dist → typings}/plugins/console/replay/index.d.ts +2 -2
  100. package/{dist → typings}/plugins/sequential-id/record/index.d.ts +1 -1
  101. package/{dist → typings}/plugins/sequential-id/replay/index.d.ts +1 -1
  102. package/{dist → typings}/record/iframe-manager.d.ts +3 -3
  103. package/{dist/plugins → typings}/record/index.d.ts +9 -9
  104. package/{dist → typings}/record/mutation.d.ts +6 -8
  105. package/typings/record/observer.d.ts +7 -0
  106. package/{dist/plugins → typings}/record/observers/canvas/2d.d.ts +3 -2
  107. package/{dist → typings}/record/observers/canvas/canvas-manager.d.ts +5 -2
  108. package/{dist/plugins → typings}/record/observers/canvas/canvas.d.ts +2 -2
  109. package/typings/record/observers/canvas/serialize-args.d.ts +6 -0
  110. package/{dist/plugins → typings}/record/observers/canvas/webgl.d.ts +3 -2
  111. package/typings/record/observers/canvas/webgl2.d.ts +2 -0
  112. package/typings/record/shadow-dom-manager.d.ts +22 -0
  113. package/typings/record/stylesheet-manager.d.ts +12 -0
  114. package/typings/record/workers/image-bitmap-data-url-worker.d.ts +5 -0
  115. package/{dist → typings}/replay/canvas/2d.d.ts +3 -3
  116. package/typings/replay/canvas/deserialize-args.d.ts +7 -0
  117. package/{dist/plugins → typings}/replay/canvas/index.d.ts +10 -9
  118. package/typings/replay/canvas/webgl.d.ts +9 -0
  119. package/{dist → typings}/replay/index.d.ts +7 -9
  120. package/{dist → typings}/replay/machine.d.ts +0 -0
  121. package/{dist → typings}/replay/smoothscroll.d.ts +0 -0
  122. package/{dist → typings}/replay/styles/inject-style.d.ts +0 -0
  123. package/{dist → typings}/replay/timer.d.ts +0 -0
  124. package/{dist → typings}/rrdom/index.d.ts +0 -0
  125. package/{dist → typings}/rrdom/tree-node.d.ts +0 -0
  126. package/{dist/plugins → typings}/types.d.ts +536 -509
  127. package/typings/utils.d.ts +43 -0
  128. package/CHANGELOG.md +0 -26
  129. package/README.md +0 -124
  130. package/README.zh_CN.md +0 -122
  131. package/dist/entries/all.d.ts +0 -4
  132. package/dist/index.css +0 -82
  133. package/dist/index.css.map +0 -1
  134. package/dist/index.js +0 -3
  135. package/dist/index.js.LICENSE.txt +0 -14
  136. package/dist/index.js.map +0 -1
  137. package/dist/plugins/entries/all.d.ts +0 -4
  138. package/dist/plugins/entries/record-pack.d.ts +0 -2
  139. package/dist/plugins/entries/replay-unpack.d.ts +0 -2
  140. package/dist/plugins/index.d.ts +0 -9
  141. package/dist/plugins/packer/base.d.ts +0 -7
  142. package/dist/plugins/packer/index.d.ts +0 -2
  143. package/dist/plugins/packer/pack.d.ts +0 -2
  144. package/dist/plugins/packer/unpack.d.ts +0 -2
  145. package/dist/plugins/plugins/console/record/error-stack-parser.d.ts +0 -37
  146. package/dist/plugins/plugins/console/record/index.d.ts +0 -41
  147. package/dist/plugins/plugins/console/record/stringify.d.ts +0 -2
  148. package/dist/plugins/plugins/console/replay/index.d.ts +0 -9
  149. package/dist/plugins/plugins/sequential-id/record/index.d.ts +0 -6
  150. package/dist/plugins/plugins/sequential-id/replay/index.d.ts +0 -7
  151. package/dist/plugins/record/iframe-manager.d.ts +0 -13
  152. package/dist/plugins/record/mutation.d.ts +0 -45
  153. package/dist/plugins/record/observer.d.ts +0 -11
  154. package/dist/plugins/record/observers/canvas/canvas-manager.d.ts +0 -32
  155. package/dist/plugins/record/observers/canvas/serialize-args.d.ts +0 -6
  156. package/dist/plugins/record/shadow-dom-manager.d.ts +0 -34
  157. package/dist/plugins/replay/canvas/2d.d.ts +0 -9
  158. package/dist/plugins/replay/canvas/webgl.d.ts +0 -11
  159. package/dist/plugins/replay/index.d.ts +0 -82
  160. package/dist/plugins/replay/machine.d.ts +0 -85
  161. package/dist/plugins/replay/smoothscroll.d.ts +0 -1
  162. package/dist/plugins/replay/styles/inject-style.d.ts +0 -2
  163. package/dist/plugins/replay/timer.d.ts +0 -19
  164. package/dist/plugins/replay/virtual-styles.d.ts +0 -43
  165. package/dist/plugins/rrdom/index.d.ts +0 -1
  166. package/dist/plugins/rrdom/tree-node.d.ts +0 -20
  167. package/dist/plugins/snapshot/css.d.ts +0 -92
  168. package/dist/plugins/snapshot/index.d.ts +0 -5
  169. package/dist/plugins/snapshot/rebuild.d.ts +0 -19
  170. package/dist/plugins/snapshot/snapshot.d.ts +0 -49
  171. package/dist/plugins/snapshot/types.d.ts +0 -99
  172. package/dist/plugins/snapshot/utils.d.ts +0 -11
  173. package/dist/plugins/utils.d.ts +0 -71
  174. package/dist/record/index.d.ts +0 -9
  175. package/dist/record/observer.d.ts +0 -11
  176. package/dist/record/observers/canvas/2d.d.ts +0 -2
  177. package/dist/record/observers/canvas/canvas.d.ts +0 -2
  178. package/dist/record/observers/canvas/serialize-args.d.ts +0 -6
  179. package/dist/record/observers/canvas/webgl.d.ts +0 -2
  180. package/dist/record/shadow-dom-manager.d.ts +0 -34
  181. package/dist/replay/canvas/index.d.ts +0 -9
  182. package/dist/replay/canvas/webgl.d.ts +0 -11
  183. package/dist/replay/virtual-styles.d.ts +0 -43
  184. package/dist/snapshot/css.d.ts +0 -92
  185. package/dist/snapshot/index.d.ts +0 -5
  186. package/dist/snapshot/rebuild.d.ts +0 -19
  187. package/dist/snapshot/snapshot.d.ts +0 -49
  188. package/dist/snapshot/types.d.ts +0 -99
  189. package/dist/snapshot/utils.d.ts +0 -11
  190. package/dist/types.d.ts +0 -509
  191. package/dist/utils.d.ts +0 -71
@@ -0,0 +1,172 @@
1
+ import { __rest, __awaiter } from './../../../../../../ext/tslib/tslib.es6.js';
2
+ import { CanvasContext } from '../../../types.js';
3
+ import initCanvas2DMutationObserver from './2d.js';
4
+ import initCanvasContextObserver from './canvas.js';
5
+ import initCanvasWebGLMutationObserver from './webgl.js';
6
+ import WorkerFactory from '../../../../../../_virtual/image-bitmap-data-url-worker.js';
7
+
8
+ class CanvasManager {
9
+ constructor(options) {
10
+ this.pendingCanvasMutations = new Map();
11
+ this.rafStamps = { latestId: 0, invokeId: null };
12
+ this.frozen = false;
13
+ this.locked = false;
14
+ this.processMutation = function (target, mutation) {
15
+ const newFrame = this.rafStamps.invokeId &&
16
+ this.rafStamps.latestId !== this.rafStamps.invokeId;
17
+ if (newFrame || !this.rafStamps.invokeId)
18
+ this.rafStamps.invokeId = this.rafStamps.latestId;
19
+ if (!this.pendingCanvasMutations.has(target)) {
20
+ this.pendingCanvasMutations.set(target, []);
21
+ }
22
+ this.pendingCanvasMutations.get(target).push(mutation);
23
+ };
24
+ const { sampling = 'all', win, blockClass, recordCanvas } = options;
25
+ this.mutationCb = options.mutationCb;
26
+ this.mirror = options.mirror;
27
+ if (recordCanvas && sampling === 'all')
28
+ this.initCanvasMutationObserver(win, blockClass);
29
+ if (recordCanvas && typeof sampling === 'number')
30
+ this.initCanvasFPSObserver(sampling, win, blockClass);
31
+ }
32
+ reset() {
33
+ this.pendingCanvasMutations.clear();
34
+ this.resetObservers && this.resetObservers();
35
+ }
36
+ freeze() {
37
+ this.frozen = true;
38
+ }
39
+ unfreeze() {
40
+ this.frozen = false;
41
+ }
42
+ lock() {
43
+ this.locked = true;
44
+ }
45
+ unlock() {
46
+ this.locked = false;
47
+ }
48
+ initCanvasFPSObserver(fps, win, blockClass) {
49
+ const canvasContextReset = initCanvasContextObserver(win, blockClass);
50
+ const snapshotInProgressMap = new Map();
51
+ const worker = new WorkerFactory();
52
+ worker.onmessage = (e) => {
53
+ const { id } = e.data;
54
+ snapshotInProgressMap.set(id, false);
55
+ if (!('base64' in e.data))
56
+ return;
57
+ const { base64, type, width, height } = e.data;
58
+ this.mutationCb({
59
+ id,
60
+ type: CanvasContext['2D'],
61
+ commands: [
62
+ {
63
+ property: 'clearRect',
64
+ args: [0, 0, width, height],
65
+ },
66
+ {
67
+ property: 'drawImage',
68
+ args: [
69
+ {
70
+ rr_type: 'ImageBitmap',
71
+ args: [
72
+ {
73
+ rr_type: 'Blob',
74
+ data: [{ rr_type: 'ArrayBuffer', base64 }],
75
+ type,
76
+ },
77
+ ],
78
+ },
79
+ 0,
80
+ 0,
81
+ ],
82
+ },
83
+ ],
84
+ });
85
+ };
86
+ const timeBetweenSnapshots = 1000 / fps;
87
+ let lastSnapshotTime = 0;
88
+ let rafId;
89
+ const takeCanvasSnapshots = (timestamp) => {
90
+ if (lastSnapshotTime &&
91
+ timestamp - lastSnapshotTime < timeBetweenSnapshots) {
92
+ rafId = requestAnimationFrame(takeCanvasSnapshots);
93
+ return;
94
+ }
95
+ lastSnapshotTime = timestamp;
96
+ win.document
97
+ .querySelectorAll(`canvas:not(.${blockClass} *)`)
98
+ .forEach((canvas) => __awaiter(this, void 0, void 0, function* () {
99
+ var _a;
100
+ const id = this.mirror.getId(canvas);
101
+ if (snapshotInProgressMap.get(id))
102
+ return;
103
+ snapshotInProgressMap.set(id, true);
104
+ if (['webgl', 'webgl2'].includes(canvas.__context)) {
105
+ const context = canvas.getContext(canvas.__context);
106
+ if (((_a = context === null || context === void 0 ? void 0 : context.getContextAttributes()) === null || _a === void 0 ? void 0 : _a.preserveDrawingBuffer) === false) {
107
+ context === null || context === void 0 ? void 0 : context.clear(context.COLOR_BUFFER_BIT);
108
+ }
109
+ }
110
+ const bitmap = yield createImageBitmap(canvas);
111
+ worker.postMessage({
112
+ id,
113
+ bitmap,
114
+ width: canvas.width,
115
+ height: canvas.height,
116
+ }, [bitmap]);
117
+ }));
118
+ rafId = requestAnimationFrame(takeCanvasSnapshots);
119
+ };
120
+ rafId = requestAnimationFrame(takeCanvasSnapshots);
121
+ this.resetObservers = () => {
122
+ canvasContextReset();
123
+ cancelAnimationFrame(rafId);
124
+ };
125
+ }
126
+ initCanvasMutationObserver(win, blockClass) {
127
+ this.startRAFTimestamping();
128
+ this.startPendingCanvasMutationFlusher();
129
+ const canvasContextReset = initCanvasContextObserver(win, blockClass);
130
+ const canvas2DReset = initCanvas2DMutationObserver(this.processMutation.bind(this), win, blockClass, this.mirror);
131
+ const canvasWebGL1and2Reset = initCanvasWebGLMutationObserver(this.processMutation.bind(this), win, blockClass, this.mirror);
132
+ this.resetObservers = () => {
133
+ canvasContextReset();
134
+ canvas2DReset();
135
+ canvasWebGL1and2Reset();
136
+ };
137
+ }
138
+ startPendingCanvasMutationFlusher() {
139
+ requestAnimationFrame(() => this.flushPendingCanvasMutations());
140
+ }
141
+ startRAFTimestamping() {
142
+ const setLatestRAFTimestamp = (timestamp) => {
143
+ this.rafStamps.latestId = timestamp;
144
+ requestAnimationFrame(setLatestRAFTimestamp);
145
+ };
146
+ requestAnimationFrame(setLatestRAFTimestamp);
147
+ }
148
+ flushPendingCanvasMutations() {
149
+ this.pendingCanvasMutations.forEach((values, canvas) => {
150
+ const id = this.mirror.getId(canvas);
151
+ this.flushPendingCanvasMutationFor(canvas, id);
152
+ });
153
+ requestAnimationFrame(() => this.flushPendingCanvasMutations());
154
+ }
155
+ flushPendingCanvasMutationFor(canvas, id) {
156
+ if (this.frozen || this.locked) {
157
+ return;
158
+ }
159
+ const valuesWithType = this.pendingCanvasMutations.get(canvas);
160
+ if (!valuesWithType || id === -1)
161
+ return;
162
+ const values = valuesWithType.map((value) => {
163
+ const rest = __rest(value, ["type"]);
164
+ return rest;
165
+ });
166
+ const { type } = valuesWithType[0];
167
+ this.mutationCb({ id, type, commands: values });
168
+ this.pendingCanvasMutations.delete(canvas);
169
+ }
170
+ }
171
+
172
+ export { CanvasManager };
@@ -0,0 +1,25 @@
1
+ import { patch, isBlocked } from '../../../utils.js';
2
+
3
+ function initCanvasContextObserver(win, blockClass) {
4
+ const handlers = [];
5
+ try {
6
+ const restoreHandler = patch(win.HTMLCanvasElement.prototype, 'getContext', function (original) {
7
+ return function (contextType, ...args) {
8
+ if (!isBlocked(this, blockClass)) {
9
+ if (!('__context' in this))
10
+ (this).__context = contextType;
11
+ }
12
+ return original.apply(this, [contextType, ...args]);
13
+ };
14
+ });
15
+ handlers.push(restoreHandler);
16
+ }
17
+ catch (_a) {
18
+ console.error('failed to patch HTMLCanvasElement.prototype.getContext');
19
+ }
20
+ return () => {
21
+ handlers.forEach((h) => h());
22
+ };
23
+ }
24
+
25
+ export { initCanvasContextObserver as default };
@@ -0,0 +1,123 @@
1
+ import { encode } from './../../../../../../ext/base64-arraybuffer/dist/base64-arraybuffer.es5.js';
2
+
3
+ const canvasVarMap = new Map();
4
+ function variableListFor(ctx, ctor) {
5
+ let contextMap = canvasVarMap.get(ctx);
6
+ if (!contextMap) {
7
+ contextMap = new Map();
8
+ canvasVarMap.set(ctx, contextMap);
9
+ }
10
+ if (!contextMap.has(ctor)) {
11
+ contextMap.set(ctor, []);
12
+ }
13
+ return contextMap.get(ctor);
14
+ }
15
+ const saveWebGLVar = (value, win, ctx) => {
16
+ if (!value ||
17
+ !(isInstanceOfWebGLObject(value, win) || typeof value === 'object'))
18
+ return;
19
+ const name = value.constructor.name;
20
+ const list = variableListFor(ctx, name);
21
+ let index = list.indexOf(value);
22
+ if (index === -1) {
23
+ index = list.length;
24
+ list.push(value);
25
+ }
26
+ return index;
27
+ };
28
+ function serializeArg(value, win, ctx) {
29
+ if (value instanceof Array) {
30
+ return value.map((arg) => serializeArg(arg, win, ctx));
31
+ }
32
+ else if (value === null) {
33
+ return value;
34
+ }
35
+ else if (value instanceof Float32Array ||
36
+ value instanceof Float64Array ||
37
+ value instanceof Int32Array ||
38
+ value instanceof Uint32Array ||
39
+ value instanceof Uint8Array ||
40
+ value instanceof Uint16Array ||
41
+ value instanceof Int16Array ||
42
+ value instanceof Int8Array ||
43
+ value instanceof Uint8ClampedArray) {
44
+ const name = value.constructor.name;
45
+ return {
46
+ rr_type: name,
47
+ args: [Object.values(value)],
48
+ };
49
+ }
50
+ else if (value instanceof ArrayBuffer) {
51
+ const name = value.constructor.name;
52
+ const base64 = encode(value);
53
+ return {
54
+ rr_type: name,
55
+ base64,
56
+ };
57
+ }
58
+ else if (value instanceof DataView) {
59
+ const name = value.constructor.name;
60
+ return {
61
+ rr_type: name,
62
+ args: [
63
+ serializeArg(value.buffer, win, ctx),
64
+ value.byteOffset,
65
+ value.byteLength,
66
+ ],
67
+ };
68
+ }
69
+ else if (value instanceof HTMLImageElement) {
70
+ const name = value.constructor.name;
71
+ const { src } = value;
72
+ return {
73
+ rr_type: name,
74
+ src,
75
+ };
76
+ }
77
+ else if (value instanceof HTMLCanvasElement) {
78
+ const name = 'HTMLImageElement';
79
+ const src = value.toDataURL();
80
+ return {
81
+ rr_type: name,
82
+ src,
83
+ };
84
+ }
85
+ else if (value instanceof ImageData) {
86
+ const name = value.constructor.name;
87
+ return {
88
+ rr_type: name,
89
+ args: [serializeArg(value.data, win, ctx), value.width, value.height],
90
+ };
91
+ }
92
+ else if (isInstanceOfWebGLObject(value, win) || typeof value === 'object') {
93
+ const name = value.constructor.name;
94
+ const index = saveWebGLVar(value, win, ctx);
95
+ return {
96
+ rr_type: name,
97
+ index: index,
98
+ };
99
+ }
100
+ return value;
101
+ }
102
+ const serializeArgs = (args, win, ctx) => {
103
+ return [...args].map((arg) => serializeArg(arg, win, ctx));
104
+ };
105
+ const isInstanceOfWebGLObject = (value, win) => {
106
+ const webGLConstructorNames = [
107
+ 'WebGLActiveInfo',
108
+ 'WebGLBuffer',
109
+ 'WebGLFramebuffer',
110
+ 'WebGLProgram',
111
+ 'WebGLRenderbuffer',
112
+ 'WebGLShader',
113
+ 'WebGLShaderPrecisionFormat',
114
+ 'WebGLTexture',
115
+ 'WebGLUniformLocation',
116
+ 'WebGLVertexArrayObject',
117
+ 'WebGLVertexArrayObjectOES',
118
+ ];
119
+ const supportedWebGLConstructorNames = webGLConstructorNames.filter((name) => typeof win[name] === 'function');
120
+ return Boolean(supportedWebGLConstructorNames.find((name) => value instanceof win[name]));
121
+ };
122
+
123
+ export { isInstanceOfWebGLObject, saveWebGLVar, serializeArg, serializeArgs, variableListFor };
@@ -0,0 +1,59 @@
1
+ import { CanvasContext } from '../../../types.js';
2
+ import { patch, isBlocked, hookSetter } from '../../../utils.js';
3
+ import { saveWebGLVar, serializeArgs } from './serialize-args.js';
4
+
5
+ function patchGLPrototype(prototype, type, cb, blockClass, mirror, win) {
6
+ const handlers = [];
7
+ const props = Object.getOwnPropertyNames(prototype);
8
+ for (const prop of props) {
9
+ try {
10
+ if (typeof prototype[prop] !== 'function') {
11
+ continue;
12
+ }
13
+ const restoreHandler = patch(prototype, prop, function (original) {
14
+ return function (...args) {
15
+ const result = original.apply(this, args);
16
+ saveWebGLVar(result, win, prototype);
17
+ if (!isBlocked(this.canvas, blockClass)) {
18
+ const id = mirror.getId(this.canvas);
19
+ const recordArgs = serializeArgs([...args], win, prototype);
20
+ const mutation = {
21
+ type,
22
+ property: prop,
23
+ args: recordArgs,
24
+ };
25
+ cb(this.canvas, mutation);
26
+ }
27
+ return result;
28
+ };
29
+ });
30
+ handlers.push(restoreHandler);
31
+ }
32
+ catch (_a) {
33
+ const hookHandler = hookSetter(prototype, prop, {
34
+ set(v) {
35
+ cb(this.canvas, {
36
+ type,
37
+ property: prop,
38
+ args: [v],
39
+ setter: true,
40
+ });
41
+ },
42
+ });
43
+ handlers.push(hookHandler);
44
+ }
45
+ }
46
+ return handlers;
47
+ }
48
+ function initCanvasWebGLMutationObserver(cb, win, blockClass, mirror) {
49
+ const handlers = [];
50
+ handlers.push(...patchGLPrototype(win.WebGLRenderingContext.prototype, CanvasContext.WebGL, cb, blockClass, mirror, win));
51
+ if (typeof win.WebGL2RenderingContext !== 'undefined') {
52
+ handlers.push(...patchGLPrototype(win.WebGL2RenderingContext.prototype, CanvasContext.WebGL2, cb, blockClass, mirror, win));
53
+ }
54
+ return () => {
55
+ handlers.forEach((h) => h());
56
+ };
57
+ }
58
+
59
+ export { initCanvasWebGLMutationObserver as default };
@@ -0,0 +1,43 @@
1
+ import { initMutationObserver, initScrollObserver } from './observer.js';
2
+ import { patch } from '../utils.js';
3
+
4
+ class ShadowDomManager {
5
+ constructor(options) {
6
+ this.restorePatches = [];
7
+ this.mutationCb = options.mutationCb;
8
+ this.scrollCb = options.scrollCb;
9
+ this.bypassOptions = options.bypassOptions;
10
+ this.mirror = options.mirror;
11
+ const manager = this;
12
+ this.restorePatches.push(patch(HTMLElement.prototype, 'attachShadow', function (original) {
13
+ return function () {
14
+ const shadowRoot = original.apply(this, arguments);
15
+ if (this.shadowRoot)
16
+ manager.addShadowRoot(this.shadowRoot, this.ownerDocument);
17
+ return shadowRoot;
18
+ };
19
+ }));
20
+ }
21
+ addShadowRoot(shadowRoot, doc) {
22
+ initMutationObserver(Object.assign(Object.assign({}, this.bypassOptions), { doc, mutationCb: this.mutationCb, mirror: this.mirror, shadowDomManager: this }), shadowRoot);
23
+ initScrollObserver(Object.assign(Object.assign({}, this.bypassOptions), { scrollCb: this.scrollCb, doc: shadowRoot, mirror: this.mirror }));
24
+ }
25
+ observeAttachShadow(iframeElement) {
26
+ if (iframeElement.contentWindow) {
27
+ const manager = this;
28
+ this.restorePatches.push(patch(iframeElement.contentWindow.HTMLElement.prototype, 'attachShadow', function (original) {
29
+ return function () {
30
+ const shadowRoot = original.apply(this, arguments);
31
+ if (this.shadowRoot)
32
+ manager.addShadowRoot(this.shadowRoot, iframeElement.contentDocument);
33
+ return shadowRoot;
34
+ };
35
+ }));
36
+ }
37
+ }
38
+ reset() {
39
+ this.restorePatches.forEach((restorePatch) => restorePatch());
40
+ }
41
+ }
42
+
43
+ export { ShadowDomManager };
@@ -0,0 +1,31 @@
1
+ class StylesheetManager {
2
+ constructor(options) {
3
+ this.trackedStylesheets = new WeakSet();
4
+ this.mutationCb = options.mutationCb;
5
+ }
6
+ addStylesheet(linkEl) {
7
+ if (this.trackedStylesheets.has(linkEl))
8
+ return;
9
+ this.trackedStylesheets.add(linkEl);
10
+ this.trackStylesheet(linkEl);
11
+ }
12
+ trackStylesheet(linkEl) {
13
+ }
14
+ attachStylesheet(linkEl, childSn, mirror) {
15
+ this.mutationCb({
16
+ adds: [
17
+ {
18
+ parentId: mirror.getId(linkEl),
19
+ nextId: null,
20
+ node: childSn,
21
+ },
22
+ ],
23
+ removes: [],
24
+ texts: [],
25
+ attributes: [],
26
+ });
27
+ this.addStylesheet(linkEl);
28
+ }
29
+ }
30
+
31
+ export { StylesheetManager };
@@ -0,0 +1,29 @@
1
+ import { __awaiter } from './../../../../../ext/tslib/tslib.es6.js';
2
+ import { deserializeArg } from './deserialize-args.js';
3
+
4
+ function canvasMutation({ event, mutation, target, imageMap, errorHandler, }) {
5
+ return __awaiter(this, void 0, void 0, function* () {
6
+ try {
7
+ const ctx = target.getContext('2d');
8
+ if (mutation.setter) {
9
+ ctx[mutation.property] = mutation.args[0];
10
+ return;
11
+ }
12
+ const original = ctx[mutation.property];
13
+ if (mutation.property === 'drawImage' &&
14
+ typeof mutation.args[0] === 'string') {
15
+ const image = imageMap.get(event);
16
+ original.apply(ctx, mutation.args);
17
+ }
18
+ else {
19
+ const args = yield Promise.all(mutation.args.map(deserializeArg(imageMap, ctx)));
20
+ original.apply(ctx, args);
21
+ }
22
+ }
23
+ catch (error) {
24
+ errorHandler(mutation, error);
25
+ }
26
+ });
27
+ }
28
+
29
+ export { canvasMutation as default };
@@ -0,0 +1,67 @@
1
+ import { __awaiter } from './../../../../../ext/tslib/tslib.es6.js';
2
+ import { decode } from './../../../../../ext/base64-arraybuffer/dist/base64-arraybuffer.es5.js';
3
+
4
+ const webGLVarMap = new Map();
5
+ function variableListFor(ctx, ctor) {
6
+ let contextMap = webGLVarMap.get(ctx);
7
+ if (!contextMap) {
8
+ contextMap = new Map();
9
+ webGLVarMap.set(ctx, contextMap);
10
+ }
11
+ if (!contextMap.has(ctor)) {
12
+ contextMap.set(ctor, []);
13
+ }
14
+ return contextMap.get(ctor);
15
+ }
16
+ function deserializeArg(imageMap, ctx, preload) {
17
+ return (arg) => __awaiter(this, void 0, void 0, function* () {
18
+ if (arg && typeof arg === 'object' && 'rr_type' in arg) {
19
+ if (preload)
20
+ preload.isUnchanged = false;
21
+ if (arg.rr_type === 'ImageBitmap' && 'args' in arg) {
22
+ const args = yield deserializeArg(imageMap, ctx, preload)(arg.args);
23
+ return yield createImageBitmap.apply(null, args);
24
+ }
25
+ else if ('index' in arg) {
26
+ if (preload || ctx === null)
27
+ return arg;
28
+ const { rr_type: name, index } = arg;
29
+ return variableListFor(ctx, name)[index];
30
+ }
31
+ else if ('args' in arg) {
32
+ const { rr_type: name, args } = arg;
33
+ const ctor = window[name];
34
+ return new ctor(...(yield Promise.all(args.map(deserializeArg(imageMap, ctx, preload)))));
35
+ }
36
+ else if ('base64' in arg) {
37
+ return decode(arg.base64);
38
+ }
39
+ else if ('src' in arg) {
40
+ const image = imageMap.get(arg.src);
41
+ if (image) {
42
+ return image;
43
+ }
44
+ else {
45
+ const image = new Image();
46
+ image.src = arg.src;
47
+ imageMap.set(arg.src, image);
48
+ return image;
49
+ }
50
+ }
51
+ else if ('data' in arg && arg.rr_type === 'Blob') {
52
+ const blobContents = yield Promise.all(arg.data.map(deserializeArg(imageMap, ctx, preload)));
53
+ const blob = new Blob(blobContents, {
54
+ type: arg.type,
55
+ });
56
+ return blob;
57
+ }
58
+ }
59
+ else if (Array.isArray(arg)) {
60
+ const result = yield Promise.all(arg.map(deserializeArg(imageMap, ctx, preload)));
61
+ return result;
62
+ }
63
+ return arg;
64
+ });
65
+ }
66
+
67
+ export { deserializeArg, variableListFor };
@@ -0,0 +1,43 @@
1
+ import { __awaiter } from './../../../../../ext/tslib/tslib.es6.js';
2
+ import { CanvasContext } from '../../types.js';
3
+ import webglMutation from './webgl.js';
4
+ import canvasMutation$1 from './2d.js';
5
+
6
+ function canvasMutation({ event, mutation, target, imageMap, canvasEventMap, errorHandler, }) {
7
+ return __awaiter(this, void 0, void 0, function* () {
8
+ try {
9
+ const precomputedMutation = canvasEventMap.get(event) || mutation;
10
+ const commands = 'commands' in precomputedMutation
11
+ ? precomputedMutation.commands
12
+ : [precomputedMutation];
13
+ if ([CanvasContext.WebGL, CanvasContext.WebGL2].includes(mutation.type)) {
14
+ for (let i = 0; i < commands.length; i++) {
15
+ const command = commands[i];
16
+ yield webglMutation({
17
+ mutation: command,
18
+ type: mutation.type,
19
+ target,
20
+ imageMap,
21
+ errorHandler,
22
+ });
23
+ }
24
+ return;
25
+ }
26
+ for (let i = 0; i < commands.length; i++) {
27
+ const command = commands[i];
28
+ yield canvasMutation$1({
29
+ event,
30
+ mutation: command,
31
+ target,
32
+ imageMap,
33
+ errorHandler,
34
+ });
35
+ }
36
+ }
37
+ catch (error) {
38
+ errorHandler(mutation, error);
39
+ }
40
+ });
41
+ }
42
+
43
+ export { canvasMutation as default };
@@ -0,0 +1,62 @@
1
+ import { __awaiter } from './../../../../../ext/tslib/tslib.es6.js';
2
+ import { CanvasContext } from '../../types.js';
3
+ import { deserializeArg, variableListFor } from './deserialize-args.js';
4
+
5
+ function getContext(target, type) {
6
+ try {
7
+ if (type === CanvasContext.WebGL) {
8
+ return (target.getContext('webgl') ||
9
+ target.getContext('experimental-webgl'));
10
+ }
11
+ return target.getContext('webgl2');
12
+ }
13
+ catch (e) {
14
+ return null;
15
+ }
16
+ }
17
+ const WebGLVariableConstructorsNames = [
18
+ 'WebGLActiveInfo',
19
+ 'WebGLBuffer',
20
+ 'WebGLFramebuffer',
21
+ 'WebGLProgram',
22
+ 'WebGLRenderbuffer',
23
+ 'WebGLShader',
24
+ 'WebGLShaderPrecisionFormat',
25
+ 'WebGLTexture',
26
+ 'WebGLUniformLocation',
27
+ 'WebGLVertexArrayObject',
28
+ ];
29
+ function saveToWebGLVarMap(ctx, result) {
30
+ if (!(result === null || result === void 0 ? void 0 : result.constructor))
31
+ return;
32
+ const { name } = result.constructor;
33
+ if (!WebGLVariableConstructorsNames.includes(name))
34
+ return;
35
+ const variables = variableListFor(ctx, name);
36
+ if (!variables.includes(result))
37
+ variables.push(result);
38
+ }
39
+ function webglMutation({ mutation, target, type, imageMap, errorHandler, }) {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ try {
42
+ const ctx = getContext(target, type);
43
+ if (!ctx)
44
+ return;
45
+ if (mutation.setter) {
46
+ ctx[mutation.property] = mutation.args[0];
47
+ return;
48
+ }
49
+ const original = ctx[mutation.property];
50
+ const args = yield Promise.all(mutation.args.map(deserializeArg(imageMap, ctx)));
51
+ const result = original.apply(ctx, args);
52
+ saveToWebGLVarMap(ctx, result);
53
+ const debugMode = false;
54
+ if (debugMode) ;
55
+ }
56
+ catch (error) {
57
+ errorHandler(mutation, error);
58
+ }
59
+ });
60
+ }
61
+
62
+ export { webglMutation as default };