@openreplay/tracker 5.0.2-beta → 5.0.2
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/cjs/app/guards.d.ts +21 -0
- package/cjs/app/guards.js +37 -0
- package/cjs/app/index.d.ts +118 -0
- package/cjs/app/index.js +438 -0
- package/cjs/app/logger.d.ts +26 -0
- package/cjs/app/logger.js +45 -0
- package/cjs/app/messages.gen.d.ts +63 -0
- package/cjs/app/messages.gen.js +551 -0
- package/cjs/app/nodes.d.ts +18 -0
- package/cjs/app/nodes.js +82 -0
- package/cjs/app/observer/iframe_observer.d.ts +4 -0
- package/cjs/app/observer/iframe_observer.js +23 -0
- package/cjs/app/observer/iframe_offsets.d.ts +8 -0
- package/cjs/app/observer/iframe_offsets.js +59 -0
- package/cjs/app/observer/observer.d.ts +23 -0
- package/cjs/app/observer/observer.js +340 -0
- package/cjs/app/observer/shadow_root_observer.d.ts +4 -0
- package/cjs/app/observer/shadow_root_observer.js +21 -0
- package/cjs/app/observer/top_observer.d.ts +24 -0
- package/cjs/app/observer/top_observer.js +113 -0
- package/cjs/app/sanitizer.d.ts +24 -0
- package/cjs/app/sanitizer.js +76 -0
- package/cjs/app/session.d.ts +38 -0
- package/cjs/app/session.js +114 -0
- package/cjs/app/ticker.d.ts +12 -0
- package/cjs/app/ticker.js +42 -0
- package/cjs/common/interaction.d.ts +24 -0
- package/cjs/common/interaction.js +2 -0
- package/cjs/common/messages.gen.d.ts +427 -0
- package/cjs/common/messages.gen.js +4 -0
- package/cjs/index.d.ts +47 -0
- package/cjs/index.js +254 -0
- package/cjs/modules/connection.d.ts +2 -0
- package/cjs/modules/connection.js +15 -0
- package/cjs/modules/console.d.ts +6 -0
- package/cjs/modules/console.js +119 -0
- package/cjs/modules/constructedStyleSheets.d.ts +4 -0
- package/cjs/modules/constructedStyleSheets.js +131 -0
- package/cjs/modules/cssrules.d.ts +2 -0
- package/cjs/modules/cssrules.js +99 -0
- package/cjs/modules/exception.d.ts +16 -0
- package/cjs/modules/exception.js +77 -0
- package/cjs/modules/focus.d.ts +2 -0
- package/cjs/modules/focus.js +45 -0
- package/cjs/modules/fonts.d.ts +2 -0
- package/cjs/modules/fonts.js +57 -0
- package/cjs/modules/img.d.ts +2 -0
- package/cjs/modules/img.js +110 -0
- package/cjs/modules/input.d.ts +16 -0
- package/cjs/modules/input.js +163 -0
- package/cjs/modules/mouse.d.ts +2 -0
- package/cjs/modules/mouse.js +148 -0
- package/cjs/modules/network.d.ts +28 -0
- package/cjs/modules/network.js +203 -0
- package/cjs/modules/performance.d.ts +7 -0
- package/cjs/modules/performance.js +53 -0
- package/cjs/modules/scroll.d.ts +2 -0
- package/cjs/modules/scroll.js +79 -0
- package/cjs/modules/timing.d.ts +7 -0
- package/cjs/modules/timing.js +160 -0
- package/cjs/modules/viewport.d.ts +2 -0
- package/cjs/modules/viewport.js +43 -0
- package/cjs/package.json +1 -0
- package/cjs/utils.d.ts +13 -0
- package/cjs/utils.js +71 -0
- package/cjs/vendors/finder/finder.d.ts +12 -0
- package/cjs/vendors/finder/finder.js +352 -0
- package/lib/app/guards.d.ts +21 -0
- package/lib/app/guards.js +26 -0
- package/lib/app/index.d.ts +118 -0
- package/lib/app/index.js +434 -0
- package/lib/app/logger.d.ts +26 -0
- package/lib/app/logger.js +41 -0
- package/lib/app/messages.gen.d.ts +63 -0
- package/lib/app/messages.gen.js +486 -0
- package/lib/app/nodes.d.ts +18 -0
- package/lib/app/nodes.js +79 -0
- package/lib/app/observer/iframe_observer.d.ts +4 -0
- package/lib/app/observer/iframe_observer.js +20 -0
- package/lib/app/observer/iframe_offsets.d.ts +8 -0
- package/lib/app/observer/iframe_offsets.js +56 -0
- package/lib/app/observer/observer.d.ts +23 -0
- package/lib/app/observer/observer.js +337 -0
- package/lib/app/observer/shadow_root_observer.d.ts +4 -0
- package/lib/app/observer/shadow_root_observer.js +18 -0
- package/lib/app/observer/top_observer.d.ts +24 -0
- package/lib/app/observer/top_observer.js +110 -0
- package/lib/app/sanitizer.d.ts +24 -0
- package/lib/app/sanitizer.js +72 -0
- package/lib/app/session.d.ts +38 -0
- package/lib/app/session.js +111 -0
- package/lib/app/ticker.d.ts +12 -0
- package/lib/app/ticker.js +39 -0
- package/lib/common/interaction.d.ts +24 -0
- package/lib/common/interaction.js +1 -0
- package/lib/common/messages.gen.d.ts +427 -0
- package/lib/common/messages.gen.js +3 -0
- package/lib/common/tsconfig.tsbuildinfo +1 -0
- package/lib/index.d.ts +47 -0
- package/lib/index.js +248 -0
- package/lib/modules/connection.d.ts +2 -0
- package/lib/modules/connection.js +12 -0
- package/lib/modules/console.d.ts +6 -0
- package/lib/modules/console.js +116 -0
- package/lib/modules/constructedStyleSheets.d.ts +4 -0
- package/lib/modules/constructedStyleSheets.js +126 -0
- package/lib/modules/cssrules.d.ts +2 -0
- package/lib/modules/cssrules.js +97 -0
- package/lib/modules/exception.d.ts +16 -0
- package/lib/modules/exception.js +71 -0
- package/lib/modules/focus.d.ts +2 -0
- package/lib/modules/focus.js +42 -0
- package/lib/modules/fonts.d.ts +2 -0
- package/lib/modules/fonts.js +54 -0
- package/lib/modules/img.d.ts +2 -0
- package/lib/modules/img.js +107 -0
- package/lib/modules/input.d.ts +16 -0
- package/lib/modules/input.js +158 -0
- package/lib/modules/mouse.d.ts +2 -0
- package/lib/modules/mouse.js +145 -0
- package/lib/modules/network.d.ts +28 -0
- package/lib/modules/network.js +200 -0
- package/lib/modules/performance.d.ts +7 -0
- package/lib/modules/performance.js +49 -0
- package/lib/modules/scroll.d.ts +2 -0
- package/lib/modules/scroll.js +76 -0
- package/lib/modules/timing.d.ts +7 -0
- package/lib/modules/timing.js +157 -0
- package/lib/modules/viewport.d.ts +2 -0
- package/lib/modules/viewport.js +40 -0
- package/lib/utils.d.ts +13 -0
- package/lib/utils.js +61 -0
- package/lib/vendors/finder/finder.d.ts +12 -0
- package/lib/vendors/finder/finder.js +348 -0
- package/package.json +1 -1
package/cjs/app/nodes.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class Nodes {
|
|
4
|
+
constructor(node_id) {
|
|
5
|
+
this.node_id = node_id;
|
|
6
|
+
this.nodes = [];
|
|
7
|
+
this.nodeCallbacks = [];
|
|
8
|
+
this.elementListeners = new Map();
|
|
9
|
+
}
|
|
10
|
+
// Attached once per Tracker instance
|
|
11
|
+
attachNodeCallback(nodeCallback) {
|
|
12
|
+
this.nodeCallbacks.push(nodeCallback);
|
|
13
|
+
}
|
|
14
|
+
attachNodeListener(node, type, listener, useCapture = true) {
|
|
15
|
+
const id = this.getID(node);
|
|
16
|
+
if (id === undefined) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
node.addEventListener(type, listener, useCapture);
|
|
20
|
+
let listeners = this.elementListeners.get(id);
|
|
21
|
+
if (listeners === undefined) {
|
|
22
|
+
listeners = [];
|
|
23
|
+
this.elementListeners.set(id, listeners);
|
|
24
|
+
}
|
|
25
|
+
listeners.push([type, listener, useCapture]);
|
|
26
|
+
}
|
|
27
|
+
registerNode(node) {
|
|
28
|
+
let id = node[this.node_id];
|
|
29
|
+
const isNew = id === undefined;
|
|
30
|
+
if (isNew) {
|
|
31
|
+
id = this.nodes.length;
|
|
32
|
+
this.nodes[id] = node;
|
|
33
|
+
node[this.node_id] = id;
|
|
34
|
+
}
|
|
35
|
+
return [id, isNew];
|
|
36
|
+
}
|
|
37
|
+
unregisterNode(node) {
|
|
38
|
+
const id = node[this.node_id];
|
|
39
|
+
if (id !== undefined) {
|
|
40
|
+
delete node[this.node_id];
|
|
41
|
+
delete this.nodes[id];
|
|
42
|
+
const listeners = this.elementListeners.get(id);
|
|
43
|
+
if (listeners !== undefined) {
|
|
44
|
+
this.elementListeners.delete(id);
|
|
45
|
+
listeners.forEach((listener) => node.removeEventListener(listener[0], listener[1], listener[2]));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return id;
|
|
49
|
+
}
|
|
50
|
+
cleanTree() {
|
|
51
|
+
// sadly we keep empty items in array here resulting in some memory still being used
|
|
52
|
+
// but its still better than keeping dead nodes or undef elements
|
|
53
|
+
// plus we keep our index positions for new/alive nodes
|
|
54
|
+
// performance test: 3ms for 30k nodes with 17k dead ones
|
|
55
|
+
for (let i = 0; i < this.nodes.length; i++) {
|
|
56
|
+
const node = this.nodes[i];
|
|
57
|
+
if (node && !document.contains(node)) {
|
|
58
|
+
this.unregisterNode(node);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
callNodeCallbacks(node, isStart) {
|
|
63
|
+
this.nodeCallbacks.forEach((cb) => cb(node, isStart));
|
|
64
|
+
}
|
|
65
|
+
getID(node) {
|
|
66
|
+
return node[this.node_id];
|
|
67
|
+
}
|
|
68
|
+
getNode(id) {
|
|
69
|
+
return this.nodes[id];
|
|
70
|
+
}
|
|
71
|
+
clear() {
|
|
72
|
+
for (let id = 0; id < this.nodes.length; id++) {
|
|
73
|
+
const node = this.nodes[id];
|
|
74
|
+
if (node === undefined) {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
this.unregisterNode(node);
|
|
78
|
+
}
|
|
79
|
+
this.nodes.length = 0;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.default = Nodes;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const observer_js_1 = require("./observer.js");
|
|
4
|
+
const messages_gen_js_1 = require("../messages.gen.js");
|
|
5
|
+
class IFrameObserver extends observer_js_1.default {
|
|
6
|
+
observe(iframe) {
|
|
7
|
+
const doc = iframe.contentDocument;
|
|
8
|
+
const hostID = this.app.nodes.getID(iframe);
|
|
9
|
+
if (!doc || hostID === undefined) {
|
|
10
|
+
return;
|
|
11
|
+
} //log TODO common app.logger
|
|
12
|
+
// Have to observe document, because the inner <html> might be changed
|
|
13
|
+
this.observeRoot(doc, (docID) => {
|
|
14
|
+
//MBTODO: do not send if empty (send on load? it might be in-place iframe, like our replayer, which does not get loaded)
|
|
15
|
+
if (docID === undefined) {
|
|
16
|
+
console.log('OpenReplay: Iframe document not bound');
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
this.app.send((0, messages_gen_js_1.CreateIFrameDocument)(hostID, docID));
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.default = IFrameObserver;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Le truc - for defining an absolute offset for (nested) iframe documents. (To track mouse movments)
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
class IFrameOffsets {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.states = new Map();
|
|
7
|
+
}
|
|
8
|
+
calcOffset(state) {
|
|
9
|
+
let parLeft = 0, parTop = 0;
|
|
10
|
+
if (state.parent) {
|
|
11
|
+
;
|
|
12
|
+
[parLeft, parTop] = this.calcOffset(state.parent);
|
|
13
|
+
}
|
|
14
|
+
if (!state.offset) {
|
|
15
|
+
const { left, top } = state.iFrame.getBoundingClientRect();
|
|
16
|
+
state.offset = [left, top];
|
|
17
|
+
}
|
|
18
|
+
const [left, top] = state.offset;
|
|
19
|
+
return [parLeft + left, parTop + top]; // TODO: store absolute sum, invalidate whole subtree. Otherwise it is summated on each mousemove
|
|
20
|
+
}
|
|
21
|
+
getDocumentOffset(doc) {
|
|
22
|
+
const state = this.states.get(doc);
|
|
23
|
+
if (!state) {
|
|
24
|
+
return [0, 0];
|
|
25
|
+
} // topmost doc
|
|
26
|
+
return this.calcOffset(state);
|
|
27
|
+
}
|
|
28
|
+
observe(iFrame) {
|
|
29
|
+
var _a;
|
|
30
|
+
const doc = iFrame.contentDocument;
|
|
31
|
+
if (!doc) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const parentDoc = iFrame.ownerDocument;
|
|
35
|
+
const parentState = this.states.get(parentDoc);
|
|
36
|
+
const state = {
|
|
37
|
+
offset: null,
|
|
38
|
+
iFrame,
|
|
39
|
+
parent: parentState || null,
|
|
40
|
+
clear: () => {
|
|
41
|
+
var _a;
|
|
42
|
+
parentDoc.removeEventListener('scroll', invalidateOffset);
|
|
43
|
+
(_a = parentDoc.defaultView) === null || _a === void 0 ? void 0 : _a.removeEventListener('resize', invalidateOffset);
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
const invalidateOffset = () => {
|
|
47
|
+
state.offset = null;
|
|
48
|
+
};
|
|
49
|
+
// anything more reliable? This does not cover all cases (layout changes are ignored, for ex.)
|
|
50
|
+
parentDoc.addEventListener('scroll', invalidateOffset);
|
|
51
|
+
(_a = parentDoc.defaultView) === null || _a === void 0 ? void 0 : _a.addEventListener('resize', invalidateOffset);
|
|
52
|
+
this.states.set(doc, state);
|
|
53
|
+
}
|
|
54
|
+
clear() {
|
|
55
|
+
this.states.forEach((s) => s.clear());
|
|
56
|
+
this.states.clear();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.default = IFrameOffsets;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import App from '../index.js';
|
|
2
|
+
export default abstract class Observer {
|
|
3
|
+
protected readonly app: App;
|
|
4
|
+
protected readonly isTopContext: boolean;
|
|
5
|
+
private readonly observer;
|
|
6
|
+
private readonly commited;
|
|
7
|
+
private readonly recents;
|
|
8
|
+
private readonly indexes;
|
|
9
|
+
private readonly attributesMap;
|
|
10
|
+
private readonly textSet;
|
|
11
|
+
constructor(app: App, isTopContext?: boolean);
|
|
12
|
+
private clear;
|
|
13
|
+
private sendNodeAttribute;
|
|
14
|
+
private sendNodeData;
|
|
15
|
+
private bindNode;
|
|
16
|
+
private bindTree;
|
|
17
|
+
private unbindTree;
|
|
18
|
+
private _commitNode;
|
|
19
|
+
private commitNode;
|
|
20
|
+
private commitNodes;
|
|
21
|
+
protected observeRoot(node: Node, beforeCommit: (id?: number) => unknown, nodeToBind?: Node): void;
|
|
22
|
+
disconnect(): void;
|
|
23
|
+
}
|
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const messages_gen_js_1 = require("../messages.gen.js");
|
|
4
|
+
const guards_js_1 = require("../guards.js");
|
|
5
|
+
function isIgnored(node) {
|
|
6
|
+
if ((0, guards_js_1.isCommentNode)(node)) {
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
if ((0, guards_js_1.isTextNode)(node)) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
if (!(0, guards_js_1.isElementNode)(node)) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
const tag = node.tagName.toUpperCase();
|
|
16
|
+
if (tag === 'LINK') {
|
|
17
|
+
const rel = node.getAttribute('rel');
|
|
18
|
+
const as = node.getAttribute('as');
|
|
19
|
+
return !((rel === null || rel === void 0 ? void 0 : rel.includes('stylesheet')) || as === 'style' || as === 'font');
|
|
20
|
+
}
|
|
21
|
+
return (tag === 'SCRIPT' || tag === 'NOSCRIPT' || tag === 'META' || tag === 'TITLE' || tag === 'BASE');
|
|
22
|
+
}
|
|
23
|
+
function isObservable(node) {
|
|
24
|
+
if ((0, guards_js_1.isRootNode)(node)) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
return !isIgnored(node);
|
|
28
|
+
}
|
|
29
|
+
/*
|
|
30
|
+
TODO:
|
|
31
|
+
- fix unbinding logic + send all removals first (ensure sequence is correct)
|
|
32
|
+
- use document as a 0-node in the upper context (should be updated in player at first)
|
|
33
|
+
*/
|
|
34
|
+
var RecentsType;
|
|
35
|
+
(function (RecentsType) {
|
|
36
|
+
RecentsType[RecentsType["New"] = 0] = "New";
|
|
37
|
+
RecentsType[RecentsType["Removed"] = 1] = "Removed";
|
|
38
|
+
RecentsType[RecentsType["Changed"] = 2] = "Changed";
|
|
39
|
+
})(RecentsType || (RecentsType = {}));
|
|
40
|
+
class Observer {
|
|
41
|
+
constructor(app, isTopContext = false) {
|
|
42
|
+
this.app = app;
|
|
43
|
+
this.isTopContext = isTopContext;
|
|
44
|
+
this.commited = [];
|
|
45
|
+
this.recents = new Map();
|
|
46
|
+
this.indexes = [];
|
|
47
|
+
this.attributesMap = new Map();
|
|
48
|
+
this.textSet = new Set();
|
|
49
|
+
this.observer = new MutationObserver(this.app.safe((mutations) => {
|
|
50
|
+
for (const mutation of mutations) {
|
|
51
|
+
// mutations order is sequential
|
|
52
|
+
const target = mutation.target;
|
|
53
|
+
const type = mutation.type;
|
|
54
|
+
if (!isObservable(target)) {
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if (type === 'childList') {
|
|
58
|
+
for (let i = 0; i < mutation.removedNodes.length; i++) {
|
|
59
|
+
// Should be the same as bindTree(mutation.removedNodes[i]), but logic needs to be be untied
|
|
60
|
+
if (isObservable(mutation.removedNodes[i])) {
|
|
61
|
+
this.bindNode(mutation.removedNodes[i]);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
for (let i = 0; i < mutation.addedNodes.length; i++) {
|
|
65
|
+
this.bindTree(mutation.addedNodes[i]);
|
|
66
|
+
}
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
const id = this.app.nodes.getID(target);
|
|
70
|
+
if (id === undefined) {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (!this.recents.has(id)) {
|
|
74
|
+
this.recents.set(id, RecentsType.Changed); // TODO only when altered
|
|
75
|
+
}
|
|
76
|
+
if (type === 'attributes') {
|
|
77
|
+
const name = mutation.attributeName;
|
|
78
|
+
if (name === null) {
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
let attr = this.attributesMap.get(id);
|
|
82
|
+
if (attr === undefined) {
|
|
83
|
+
this.attributesMap.set(id, (attr = new Set()));
|
|
84
|
+
}
|
|
85
|
+
attr.add(name);
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
if (type === 'characterData') {
|
|
89
|
+
this.textSet.add(id);
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
this.commitNodes();
|
|
94
|
+
}));
|
|
95
|
+
}
|
|
96
|
+
clear() {
|
|
97
|
+
this.commited.length = 0;
|
|
98
|
+
this.recents.clear();
|
|
99
|
+
this.indexes.length = 1;
|
|
100
|
+
this.attributesMap.clear();
|
|
101
|
+
this.textSet.clear();
|
|
102
|
+
}
|
|
103
|
+
sendNodeAttribute(id, node, name, value) {
|
|
104
|
+
if ((0, guards_js_1.isSVGElement)(node)) {
|
|
105
|
+
if (name.substr(0, 6) === 'xlink:') {
|
|
106
|
+
name = name.substr(6);
|
|
107
|
+
}
|
|
108
|
+
if (value === null) {
|
|
109
|
+
this.app.send((0, messages_gen_js_1.RemoveNodeAttribute)(id, name));
|
|
110
|
+
}
|
|
111
|
+
else if (name === 'href') {
|
|
112
|
+
if (value.length > 1e5) {
|
|
113
|
+
value = '';
|
|
114
|
+
}
|
|
115
|
+
this.app.send((0, messages_gen_js_1.SetNodeAttributeURLBased)(id, name, value, this.app.getBaseHref()));
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
this.app.send((0, messages_gen_js_1.SetNodeAttribute)(id, name, value));
|
|
119
|
+
}
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
if (name === 'src' ||
|
|
123
|
+
name === 'srcset' ||
|
|
124
|
+
name === 'integrity' ||
|
|
125
|
+
name === 'crossorigin' ||
|
|
126
|
+
name === 'autocomplete' ||
|
|
127
|
+
name.substr(0, 2) === 'on') {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
if (name === 'value' &&
|
|
131
|
+
(0, guards_js_1.hasTag)(node, 'input') &&
|
|
132
|
+
node.type !== 'button' &&
|
|
133
|
+
node.type !== 'reset' &&
|
|
134
|
+
node.type !== 'submit') {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
if (value === null) {
|
|
138
|
+
this.app.send((0, messages_gen_js_1.RemoveNodeAttribute)(id, name));
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
if (name === 'style' || (name === 'href' && (0, guards_js_1.hasTag)(node, 'link'))) {
|
|
142
|
+
this.app.send((0, messages_gen_js_1.SetNodeAttributeURLBased)(id, name, value, this.app.getBaseHref()));
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
if (name === 'href' || value.length > 1e5) {
|
|
146
|
+
value = '';
|
|
147
|
+
}
|
|
148
|
+
this.app.send((0, messages_gen_js_1.SetNodeAttribute)(id, name, value));
|
|
149
|
+
}
|
|
150
|
+
sendNodeData(id, parentElement, data) {
|
|
151
|
+
if ((0, guards_js_1.hasTag)(parentElement, 'style')) {
|
|
152
|
+
this.app.send((0, messages_gen_js_1.SetCSSDataURLBased)(id, data, this.app.getBaseHref()));
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
data = this.app.sanitizer.sanitize(id, data);
|
|
156
|
+
this.app.send((0, messages_gen_js_1.SetNodeData)(id, data));
|
|
157
|
+
}
|
|
158
|
+
bindNode(node) {
|
|
159
|
+
const [id, isNew] = this.app.nodes.registerNode(node);
|
|
160
|
+
if (isNew) {
|
|
161
|
+
this.recents.set(id, RecentsType.New);
|
|
162
|
+
}
|
|
163
|
+
else if (this.recents.get(id) !== RecentsType.New) {
|
|
164
|
+
this.recents.set(id, RecentsType.Removed);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
bindTree(node) {
|
|
168
|
+
if (!isObservable(node)) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
this.bindNode(node);
|
|
172
|
+
const walker = document.createTreeWalker(node, NodeFilter.SHOW_ELEMENT + NodeFilter.SHOW_TEXT, {
|
|
173
|
+
acceptNode: (node) => isIgnored(node) || this.app.nodes.getID(node) !== undefined
|
|
174
|
+
? NodeFilter.FILTER_REJECT
|
|
175
|
+
: NodeFilter.FILTER_ACCEPT,
|
|
176
|
+
},
|
|
177
|
+
// @ts-ignore
|
|
178
|
+
false);
|
|
179
|
+
while (walker.nextNode()) {
|
|
180
|
+
this.bindNode(walker.currentNode);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
unbindTree(node) {
|
|
184
|
+
const id = this.app.nodes.unregisterNode(node);
|
|
185
|
+
if (id !== undefined && this.recents.get(id) === RecentsType.Removed) {
|
|
186
|
+
// Sending RemoveNode only for parent to maintain
|
|
187
|
+
this.app.send((0, messages_gen_js_1.RemoveNode)(id));
|
|
188
|
+
// Unregistering all the children in order to clear the memory
|
|
189
|
+
const walker = document.createTreeWalker(node, NodeFilter.SHOW_ELEMENT + NodeFilter.SHOW_TEXT, {
|
|
190
|
+
acceptNode: (node) => isIgnored(node) || this.app.nodes.getID(node) === undefined
|
|
191
|
+
? NodeFilter.FILTER_REJECT
|
|
192
|
+
: NodeFilter.FILTER_ACCEPT,
|
|
193
|
+
},
|
|
194
|
+
// @ts-ignore
|
|
195
|
+
false);
|
|
196
|
+
while (walker.nextNode()) {
|
|
197
|
+
this.app.nodes.unregisterNode(walker.currentNode);
|
|
198
|
+
}
|
|
199
|
+
// MBTODO: count and send RemovedNodesCount (for the page crash detection in heuristics)
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
// A top-consumption function on the infinite lists test. (~1% of performance resources)
|
|
203
|
+
_commitNode(id, node) {
|
|
204
|
+
if ((0, guards_js_1.isRootNode)(node)) {
|
|
205
|
+
return true;
|
|
206
|
+
}
|
|
207
|
+
const parent = node.parentNode;
|
|
208
|
+
let parentID;
|
|
209
|
+
// Disable parent check for the upper context HTMLHtmlElement, because it is root there... (before)
|
|
210
|
+
// TODO: get rid of "special" cases (there is an issue with CreateDocument altered behaviour though)
|
|
211
|
+
// TODO: Clean the logic (though now it workd fine)
|
|
212
|
+
if (!(0, guards_js_1.hasTag)(node, 'html') || !this.isTopContext) {
|
|
213
|
+
if (parent === null) {
|
|
214
|
+
// Sometimes one observation contains attribute mutations for the removimg node, which gets ignored here.
|
|
215
|
+
// That shouldn't affect the visual rendering ( should it? maybe when transition applied? )
|
|
216
|
+
this.unbindTree(node);
|
|
217
|
+
return false;
|
|
218
|
+
}
|
|
219
|
+
parentID = this.app.nodes.getID(parent);
|
|
220
|
+
if (parentID === undefined) {
|
|
221
|
+
this.unbindTree(node);
|
|
222
|
+
return false;
|
|
223
|
+
}
|
|
224
|
+
if (!this.commitNode(parentID)) {
|
|
225
|
+
this.unbindTree(node);
|
|
226
|
+
return false;
|
|
227
|
+
}
|
|
228
|
+
this.app.sanitizer.handleNode(id, parentID, node);
|
|
229
|
+
if (this.app.sanitizer.isHidden(parentID)) {
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
// From here parentID === undefined if node is top context HTML node
|
|
234
|
+
let sibling = node.previousSibling;
|
|
235
|
+
while (sibling !== null) {
|
|
236
|
+
const siblingID = this.app.nodes.getID(sibling);
|
|
237
|
+
if (siblingID !== undefined) {
|
|
238
|
+
this.commitNode(siblingID);
|
|
239
|
+
this.indexes[id] = this.indexes[siblingID] + 1;
|
|
240
|
+
break;
|
|
241
|
+
}
|
|
242
|
+
sibling = sibling.previousSibling;
|
|
243
|
+
}
|
|
244
|
+
if (sibling === null) {
|
|
245
|
+
this.indexes[id] = 0;
|
|
246
|
+
}
|
|
247
|
+
const recentsType = this.recents.get(id);
|
|
248
|
+
const isNew = recentsType === RecentsType.New;
|
|
249
|
+
const index = this.indexes[id];
|
|
250
|
+
if (index === undefined) {
|
|
251
|
+
throw 'commitNode: missing node index';
|
|
252
|
+
}
|
|
253
|
+
if (isNew) {
|
|
254
|
+
if ((0, guards_js_1.isElementNode)(node)) {
|
|
255
|
+
let el = node;
|
|
256
|
+
if (parentID !== undefined) {
|
|
257
|
+
if (this.app.sanitizer.isHidden(id)) {
|
|
258
|
+
const width = el.clientWidth;
|
|
259
|
+
const height = el.clientHeight;
|
|
260
|
+
el = node.cloneNode();
|
|
261
|
+
el.style.width = `${width}px`;
|
|
262
|
+
el.style.height = `${height}px`;
|
|
263
|
+
}
|
|
264
|
+
this.app.send((0, messages_gen_js_1.CreateElementNode)(id, parentID, index, el.tagName, (0, guards_js_1.isSVGElement)(node)));
|
|
265
|
+
}
|
|
266
|
+
for (let i = 0; i < el.attributes.length; i++) {
|
|
267
|
+
const attr = el.attributes[i];
|
|
268
|
+
this.sendNodeAttribute(id, el, attr.nodeName, attr.value);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
else if ((0, guards_js_1.isTextNode)(node)) {
|
|
272
|
+
// for text node id != 0, hence parentID !== undefined and parent is Element
|
|
273
|
+
this.app.send((0, messages_gen_js_1.CreateTextNode)(id, parentID, index));
|
|
274
|
+
this.sendNodeData(id, parent, node.data);
|
|
275
|
+
}
|
|
276
|
+
return true;
|
|
277
|
+
}
|
|
278
|
+
if (recentsType === RecentsType.Removed && parentID !== undefined) {
|
|
279
|
+
this.app.send((0, messages_gen_js_1.MoveNode)(id, parentID, index));
|
|
280
|
+
}
|
|
281
|
+
const attr = this.attributesMap.get(id);
|
|
282
|
+
if (attr !== undefined) {
|
|
283
|
+
if (!(0, guards_js_1.isElementNode)(node)) {
|
|
284
|
+
throw 'commitNode: node is not an element';
|
|
285
|
+
}
|
|
286
|
+
for (const name of attr) {
|
|
287
|
+
this.sendNodeAttribute(id, node, name, node.getAttribute(name));
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
if (this.textSet.has(id)) {
|
|
291
|
+
if (!(0, guards_js_1.isTextNode)(node)) {
|
|
292
|
+
throw 'commitNode: node is not a text';
|
|
293
|
+
}
|
|
294
|
+
// for text node id != 0, hence parent is Element
|
|
295
|
+
this.sendNodeData(id, parent, node.data);
|
|
296
|
+
}
|
|
297
|
+
return true;
|
|
298
|
+
}
|
|
299
|
+
commitNode(id) {
|
|
300
|
+
const node = this.app.nodes.getNode(id);
|
|
301
|
+
if (node === undefined) {
|
|
302
|
+
return false;
|
|
303
|
+
}
|
|
304
|
+
const cmt = this.commited[id];
|
|
305
|
+
if (cmt !== undefined) {
|
|
306
|
+
return cmt;
|
|
307
|
+
}
|
|
308
|
+
return (this.commited[id] = this._commitNode(id, node));
|
|
309
|
+
}
|
|
310
|
+
commitNodes(isStart = false) {
|
|
311
|
+
let node;
|
|
312
|
+
this.recents.forEach((type, id) => {
|
|
313
|
+
this.commitNode(id);
|
|
314
|
+
if (type === RecentsType.New && (node = this.app.nodes.getNode(id))) {
|
|
315
|
+
this.app.nodes.callNodeCallbacks(node, isStart);
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
this.clear();
|
|
319
|
+
}
|
|
320
|
+
// ISSSUE (nodeToBinde should be the same as node in all cases. Look at the comment about 0-node at the beginning of the file.)
|
|
321
|
+
// TODO: use one observer instance for all iframes/shadowRoots (composition instiad of inheritance)
|
|
322
|
+
observeRoot(node, beforeCommit, nodeToBind = node) {
|
|
323
|
+
this.observer.observe(node, {
|
|
324
|
+
childList: true,
|
|
325
|
+
attributes: true,
|
|
326
|
+
characterData: true,
|
|
327
|
+
subtree: true,
|
|
328
|
+
attributeOldValue: false,
|
|
329
|
+
characterDataOldValue: false,
|
|
330
|
+
});
|
|
331
|
+
this.bindTree(nodeToBind);
|
|
332
|
+
beforeCommit(this.app.nodes.getID(node));
|
|
333
|
+
this.commitNodes(true);
|
|
334
|
+
}
|
|
335
|
+
disconnect() {
|
|
336
|
+
this.observer.disconnect();
|
|
337
|
+
this.clear();
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
exports.default = Observer;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const observer_js_1 = require("./observer.js");
|
|
4
|
+
const messages_gen_js_1 = require("../messages.gen.js");
|
|
5
|
+
class ShadowRootObserver extends observer_js_1.default {
|
|
6
|
+
observe(el) {
|
|
7
|
+
const shRoot = el.shadowRoot;
|
|
8
|
+
const hostID = this.app.nodes.getID(el);
|
|
9
|
+
if (!shRoot || hostID === undefined) {
|
|
10
|
+
return;
|
|
11
|
+
} // log
|
|
12
|
+
this.observeRoot(shRoot, (rootID) => {
|
|
13
|
+
if (rootID === undefined) {
|
|
14
|
+
console.log('OpenReplay: Shadow Root was not bound');
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
this.app.send((0, messages_gen_js_1.CreateIFrameDocument)(hostID, rootID));
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.default = ShadowRootObserver;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import Observer from './observer.js';
|
|
2
|
+
import { Offset } from './iframe_offsets.js';
|
|
3
|
+
import App from '../index.js';
|
|
4
|
+
export interface Options {
|
|
5
|
+
captureIFrames: boolean;
|
|
6
|
+
}
|
|
7
|
+
type Context = Window & typeof globalThis;
|
|
8
|
+
type ContextCallback = (context: Context) => void;
|
|
9
|
+
export default class TopObserver extends Observer {
|
|
10
|
+
private readonly options;
|
|
11
|
+
private readonly iframeOffsets;
|
|
12
|
+
constructor(app: App, options: Partial<Options>);
|
|
13
|
+
private readonly contextCallbacks;
|
|
14
|
+
private readonly contextsSet;
|
|
15
|
+
attachContextCallback(cb: ContextCallback): void;
|
|
16
|
+
getDocumentOffset(doc: Document): Offset;
|
|
17
|
+
private iframeObservers;
|
|
18
|
+
private handleIframe;
|
|
19
|
+
private shadowRootObservers;
|
|
20
|
+
private handleShadowRoot;
|
|
21
|
+
observe(): void;
|
|
22
|
+
disconnect(): void;
|
|
23
|
+
}
|
|
24
|
+
export {};
|