@openreplay/tracker 3.4.7 → 3.4.11
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/index.d.ts +7 -7
- package/cjs/app/index.js +20 -20
- package/cjs/app/logger.d.ts +0 -0
- package/cjs/app/logger.js +1 -0
- package/cjs/app/observer.d.ts +1 -1
- package/cjs/app/observer.js +24 -20
- package/cjs/app/sanitizer.d.ts +0 -0
- package/cjs/app/sanitizer.js +1 -0
- package/cjs/app/ticker.d.ts +1 -1
- package/cjs/index.d.ts +11 -10
- package/cjs/index.js +59 -56
- package/cjs/messages/index.d.ts +2 -2
- package/cjs/messages/message.d.ts +1 -1
- package/cjs/modules/connection.d.ts +1 -1
- package/cjs/modules/connection.js +2 -2
- package/cjs/modules/console.d.ts +1 -1
- package/cjs/modules/console.js +4 -4
- package/cjs/modules/cssrules.d.ts +1 -1
- package/cjs/modules/cssrules.js +4 -4
- package/cjs/modules/exception.d.ts +2 -2
- package/cjs/modules/exception.js +4 -4
- package/cjs/modules/img.d.ts +1 -1
- package/cjs/modules/img.js +6 -6
- package/cjs/modules/input.d.ts +1 -1
- package/cjs/modules/input.js +11 -11
- package/cjs/modules/longtasks.d.ts +1 -1
- package/cjs/modules/longtasks.js +2 -2
- package/cjs/modules/mouse.d.ts +1 -1
- package/cjs/modules/mouse.js +10 -10
- package/cjs/modules/performance.d.ts +1 -1
- package/cjs/modules/performance.js +5 -5
- package/cjs/modules/scroll.d.ts +1 -1
- package/cjs/modules/scroll.js +3 -3
- package/cjs/modules/timing.d.ts +1 -1
- package/cjs/modules/timing.js +6 -6
- package/cjs/modules/viewport.d.ts +1 -1
- package/cjs/modules/viewport.js +4 -4
- package/cjs/utils.js +1 -1
- package/lib/app/index.d.ts +7 -7
- package/lib/app/index.js +8 -8
- package/lib/app/logger.d.ts +0 -0
- package/lib/app/logger.js +1 -0
- package/lib/app/observer.d.ts +1 -1
- package/lib/app/observer.js +7 -3
- package/lib/app/sanitizer.d.ts +0 -0
- package/lib/app/sanitizer.js +1 -0
- package/lib/app/ticker.d.ts +1 -1
- package/lib/index.d.ts +11 -10
- package/lib/index.js +25 -22
- package/lib/messages/index.d.ts +2 -2
- package/lib/messages/message.d.ts +1 -1
- package/lib/messages/tsconfig.tsbuildinfo +1 -1
- package/lib/modules/connection.d.ts +1 -1
- package/lib/modules/connection.js +1 -1
- package/lib/modules/console.d.ts +1 -1
- package/lib/modules/console.js +2 -2
- package/lib/modules/cssrules.d.ts +1 -1
- package/lib/modules/cssrules.js +1 -1
- package/lib/modules/exception.d.ts +2 -2
- package/lib/modules/exception.js +1 -1
- package/lib/modules/img.d.ts +1 -1
- package/lib/modules/img.js +2 -2
- package/lib/modules/input.d.ts +1 -1
- package/lib/modules/input.js +2 -2
- package/lib/modules/longtasks.d.ts +1 -1
- package/lib/modules/longtasks.js +1 -1
- package/lib/modules/mouse.d.ts +1 -1
- package/lib/modules/mouse.js +3 -3
- package/lib/modules/performance.d.ts +1 -1
- package/lib/modules/performance.js +2 -2
- package/lib/modules/scroll.d.ts +1 -1
- package/lib/modules/scroll.js +1 -1
- package/lib/modules/timing.d.ts +1 -1
- package/lib/modules/timing.js +2 -2
- package/lib/modules/viewport.d.ts +1 -1
- package/lib/modules/viewport.js +1 -1
- package/package.json +2 -2
- package/tsconfig-base.json +1 -1
- package/cjs/app/observer/iframe_observer.d.ts +0 -4
- package/cjs/app/observer/iframe_observer.js +0 -21
- package/cjs/app/observer/observer.d.ts +0 -46
- package/cjs/app/observer/observer.js +0 -353
- package/cjs/app/observer/shadow_root_observer.d.ts +0 -4
- package/cjs/app/observer/shadow_root_observer.js +0 -21
- package/cjs/app/observer/top_observer.d.ts +0 -15
- package/cjs/app/observer/top_observer.js +0 -78
- package/lib/app/observer/iframe_observer.d.ts +0 -4
- package/lib/app/observer/iframe_observer.js +0 -18
- package/lib/app/observer/observer.d.ts +0 -46
- package/lib/app/observer/observer.js +0 -348
- package/lib/app/observer/shadow_root_observer.d.ts +0 -4
- package/lib/app/observer/shadow_root_observer.js +0 -18
- package/lib/app/observer/top_observer.d.ts +0 -15
- package/lib/app/observer/top_observer.js +0 -75
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import Observer from './observer';
|
|
2
|
-
import { CreateIFrameDocument, } from '../../messages';
|
|
3
|
-
export default class IFrameObserver extends Observer {
|
|
4
|
-
observe(iframe) {
|
|
5
|
-
const doc = iframe.contentDocument;
|
|
6
|
-
const frameID = this.app.nodes.getID(iframe);
|
|
7
|
-
if (!doc || frameID === undefined) {
|
|
8
|
-
return;
|
|
9
|
-
} //log TODO common app.logger
|
|
10
|
-
this.observeRoot(doc, (docID) => {
|
|
11
|
-
if (docID === undefined) {
|
|
12
|
-
console.log("OpenReplay: Document not bound");
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
this.app.send(CreateIFrameDocument(frameID, docID));
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import App from '../index';
|
|
2
|
-
export interface Window extends globalThis.Window {
|
|
3
|
-
HTMLInputElement: typeof HTMLInputElement;
|
|
4
|
-
HTMLLinkElement: typeof HTMLLinkElement;
|
|
5
|
-
HTMLStyleElement: typeof HTMLStyleElement;
|
|
6
|
-
SVGStyleElement: typeof SVGStyleElement;
|
|
7
|
-
HTMLIFrameElement: typeof HTMLIFrameElement;
|
|
8
|
-
Text: typeof Text;
|
|
9
|
-
Element: typeof Element;
|
|
10
|
-
ShadowRoot: typeof ShadowRoot;
|
|
11
|
-
}
|
|
12
|
-
declare type WindowConstructor = Document | Element | Text | ShadowRoot | HTMLInputElement | HTMLLinkElement | HTMLStyleElement | HTMLIFrameElement;
|
|
13
|
-
declare type Constructor<T> = {
|
|
14
|
-
new (...args: any[]): T;
|
|
15
|
-
name: string;
|
|
16
|
-
};
|
|
17
|
-
export declare function isInstance<T extends WindowConstructor>(node: Node, constr: Constructor<T>): node is T;
|
|
18
|
-
export interface Options {
|
|
19
|
-
obscureTextEmails: boolean;
|
|
20
|
-
obscureTextNumbers: boolean;
|
|
21
|
-
}
|
|
22
|
-
export default abstract class Observer<AdditionalOptions = {}> {
|
|
23
|
-
protected readonly app: App;
|
|
24
|
-
protected readonly context: Window;
|
|
25
|
-
private readonly observer;
|
|
26
|
-
private readonly commited;
|
|
27
|
-
private readonly recents;
|
|
28
|
-
private readonly indexes;
|
|
29
|
-
private readonly attributesList;
|
|
30
|
-
private readonly textSet;
|
|
31
|
-
private readonly textMasked;
|
|
32
|
-
protected readonly options: Options & AdditionalOptions;
|
|
33
|
-
constructor(app: App, options: Partial<Options> & AdditionalOptions, context?: Window);
|
|
34
|
-
private clear;
|
|
35
|
-
private sendNodeAttribute;
|
|
36
|
-
private sendNodeData;
|
|
37
|
-
private bindNode;
|
|
38
|
-
private bindTree;
|
|
39
|
-
private unbindNode;
|
|
40
|
-
private _commitNode;
|
|
41
|
-
private commitNode;
|
|
42
|
-
private commitNodes;
|
|
43
|
-
protected observeRoot(node: Node, beforeCommit: (id?: number) => unknown): void;
|
|
44
|
-
disconnect(): void;
|
|
45
|
-
}
|
|
46
|
-
export {};
|
|
@@ -1,348 +0,0 @@
|
|
|
1
|
-
import { stars, hasOpenreplayAttribute } from '../../utils';
|
|
2
|
-
import { CreateElementNode, CreateTextNode, SetNodeData, SetCSSDataURLBased, SetNodeAttribute, SetNodeAttributeURLBased, RemoveNodeAttribute, MoveNode, RemoveNode, } from '../../messages';
|
|
3
|
-
function isSVGElement(node) {
|
|
4
|
-
return node.namespaceURI === 'http://www.w3.org/2000/svg';
|
|
5
|
-
}
|
|
6
|
-
// TODO: we need a type expert here so we won't have to ignore the lines
|
|
7
|
-
// TODO: use it everywhere (static function; export from which file? <-- global Window typing required)
|
|
8
|
-
export function isInstance(node, constr) {
|
|
9
|
-
const doc = node.ownerDocument;
|
|
10
|
-
if (!doc) { // null if Document
|
|
11
|
-
return constr.name === 'Document';
|
|
12
|
-
}
|
|
13
|
-
let context =
|
|
14
|
-
// @ts-ignore (for EI, Safary)
|
|
15
|
-
doc.parentWindow ||
|
|
16
|
-
doc.defaultView; // TODO: smart global typing for Window object
|
|
17
|
-
while (context.parent && context.parent !== context) {
|
|
18
|
-
// @ts-ignore
|
|
19
|
-
if (node instanceof context[constr.name]) {
|
|
20
|
-
return true;
|
|
21
|
-
}
|
|
22
|
-
// @ts-ignore
|
|
23
|
-
context = context.parent;
|
|
24
|
-
}
|
|
25
|
-
// @ts-ignore
|
|
26
|
-
return node instanceof context[constr.name];
|
|
27
|
-
}
|
|
28
|
-
function isIgnored(node) {
|
|
29
|
-
if (isInstance(node, Text)) {
|
|
30
|
-
return false;
|
|
31
|
-
}
|
|
32
|
-
if (!isInstance(node, Element)) {
|
|
33
|
-
return true;
|
|
34
|
-
}
|
|
35
|
-
const tag = node.tagName.toUpperCase();
|
|
36
|
-
if (tag === 'LINK') {
|
|
37
|
-
const rel = node.getAttribute('rel');
|
|
38
|
-
const as = node.getAttribute('as');
|
|
39
|
-
return !((rel === null || rel === void 0 ? void 0 : rel.includes('stylesheet')) || as === "style" || as === "font");
|
|
40
|
-
}
|
|
41
|
-
return (tag === 'SCRIPT' ||
|
|
42
|
-
tag === 'NOSCRIPT' ||
|
|
43
|
-
tag === 'META' ||
|
|
44
|
-
tag === 'TITLE' ||
|
|
45
|
-
tag === 'BASE');
|
|
46
|
-
}
|
|
47
|
-
function isRootNode(node) {
|
|
48
|
-
return isInstance(node, Document) || isInstance(node, ShadowRoot);
|
|
49
|
-
}
|
|
50
|
-
function isObservable(node) {
|
|
51
|
-
if (isRootNode(node)) {
|
|
52
|
-
return true;
|
|
53
|
-
}
|
|
54
|
-
return !isIgnored(node);
|
|
55
|
-
}
|
|
56
|
-
export default class Observer {
|
|
57
|
-
constructor(app, options, context = window) {
|
|
58
|
-
this.app = app;
|
|
59
|
-
this.context = context;
|
|
60
|
-
this.options = Object.assign({
|
|
61
|
-
obscureTextEmails: true,
|
|
62
|
-
obscureTextNumbers: false,
|
|
63
|
-
}, options);
|
|
64
|
-
this.observer = new MutationObserver(this.app.safe((mutations) => {
|
|
65
|
-
for (const mutation of mutations) {
|
|
66
|
-
const target = mutation.target;
|
|
67
|
-
const type = mutation.type;
|
|
68
|
-
// TODO TODO TODO: move to iframe_observer/remove??? (check if )
|
|
69
|
-
// Special case
|
|
70
|
-
// 'childList' on Document might happen in case of iframe.
|
|
71
|
-
// TODO: generalize as much as possible
|
|
72
|
-
// if (isInstance(target, Document) // Also ShadowRoot can be here
|
|
73
|
-
// && type === 'childList'
|
|
74
|
-
// //&& new Array(mutation.addedNodes).some(node => isInstance(node, HTMLHtmlElement))
|
|
75
|
-
// ) {
|
|
76
|
-
// const parentFrame = target.defaultView?.frameElement
|
|
77
|
-
// if (!parentFrame) { continue }
|
|
78
|
-
// this.bindTree(target.documentElement)
|
|
79
|
-
// const frameID = this.app.nodes.getID(parentFrame)
|
|
80
|
-
// const docID = this.app.nodes.getID(target.documentElement)
|
|
81
|
-
// if (frameID === undefined || docID === undefined) { continue }
|
|
82
|
-
// this.app.send(CreateIFrameDocument(frameID, docID));
|
|
83
|
-
// continue;
|
|
84
|
-
// }
|
|
85
|
-
if (!isObservable(target) || !context.document.contains(target)) {
|
|
86
|
-
continue;
|
|
87
|
-
}
|
|
88
|
-
if (type === 'childList') {
|
|
89
|
-
for (let i = 0; i < mutation.removedNodes.length; i++) {
|
|
90
|
-
this.bindTree(mutation.removedNodes[i]);
|
|
91
|
-
}
|
|
92
|
-
for (let i = 0; i < mutation.addedNodes.length; i++) {
|
|
93
|
-
this.bindTree(mutation.addedNodes[i]);
|
|
94
|
-
}
|
|
95
|
-
continue;
|
|
96
|
-
}
|
|
97
|
-
const id = this.app.nodes.getID(target);
|
|
98
|
-
if (id === undefined) {
|
|
99
|
-
continue;
|
|
100
|
-
}
|
|
101
|
-
if (id >= this.recents.length) {
|
|
102
|
-
this.recents[id] = undefined;
|
|
103
|
-
}
|
|
104
|
-
if (type === 'attributes') {
|
|
105
|
-
const name = mutation.attributeName;
|
|
106
|
-
if (name === null) {
|
|
107
|
-
continue;
|
|
108
|
-
}
|
|
109
|
-
let attr = this.attributesList[id];
|
|
110
|
-
if (attr === undefined) {
|
|
111
|
-
this.attributesList[id] = attr = new Set();
|
|
112
|
-
}
|
|
113
|
-
attr.add(name);
|
|
114
|
-
continue;
|
|
115
|
-
}
|
|
116
|
-
if (type === 'characterData') {
|
|
117
|
-
this.textSet.add(id);
|
|
118
|
-
continue;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
this.commitNodes();
|
|
122
|
-
}));
|
|
123
|
-
this.commited = [];
|
|
124
|
-
this.recents = [];
|
|
125
|
-
this.indexes = [0];
|
|
126
|
-
this.attributesList = [];
|
|
127
|
-
this.textSet = new Set();
|
|
128
|
-
this.textMasked = new Set();
|
|
129
|
-
}
|
|
130
|
-
clear() {
|
|
131
|
-
this.commited.length = 0;
|
|
132
|
-
this.recents.length = 0;
|
|
133
|
-
this.indexes.length = 1;
|
|
134
|
-
this.attributesList.length = 0;
|
|
135
|
-
this.textSet.clear();
|
|
136
|
-
this.textMasked.clear();
|
|
137
|
-
}
|
|
138
|
-
sendNodeAttribute(id, node, name, value) {
|
|
139
|
-
if (isSVGElement(node)) {
|
|
140
|
-
if (name.substr(0, 6) === 'xlink:') {
|
|
141
|
-
name = name.substr(6);
|
|
142
|
-
}
|
|
143
|
-
if (value === null) {
|
|
144
|
-
this.app.send(new RemoveNodeAttribute(id, name));
|
|
145
|
-
}
|
|
146
|
-
else if (name === 'href') {
|
|
147
|
-
if (value.length > 1e5) {
|
|
148
|
-
value = '';
|
|
149
|
-
}
|
|
150
|
-
this.app.send(new SetNodeAttributeURLBased(id, name, value, this.app.getBaseHref()));
|
|
151
|
-
}
|
|
152
|
-
else {
|
|
153
|
-
this.app.send(new SetNodeAttribute(id, name, value));
|
|
154
|
-
}
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
if (name === 'src' ||
|
|
158
|
-
name === 'srcset' ||
|
|
159
|
-
name === 'integrity' ||
|
|
160
|
-
name === 'crossorigin' ||
|
|
161
|
-
name === 'autocomplete' ||
|
|
162
|
-
name.substr(0, 2) === 'on') {
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
if (name === 'value' &&
|
|
166
|
-
isInstance(node, HTMLInputElement) &&
|
|
167
|
-
node.type !== 'button' &&
|
|
168
|
-
node.type !== 'reset' &&
|
|
169
|
-
node.type !== 'submit') {
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
if (value === null) {
|
|
173
|
-
this.app.send(new RemoveNodeAttribute(id, name));
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
176
|
-
if (name === 'style' || name === 'href' && isInstance(node, HTMLLinkElement)) {
|
|
177
|
-
this.app.send(new SetNodeAttributeURLBased(id, name, value, this.app.getBaseHref()));
|
|
178
|
-
return;
|
|
179
|
-
}
|
|
180
|
-
if (name === 'href' || value.length > 1e5) {
|
|
181
|
-
value = '';
|
|
182
|
-
}
|
|
183
|
-
this.app.send(new SetNodeAttribute(id, name, value));
|
|
184
|
-
}
|
|
185
|
-
sendNodeData(id, parentElement, data) {
|
|
186
|
-
if (isInstance(parentElement, HTMLStyleElement) || isInstance(parentElement, SVGStyleElement)) {
|
|
187
|
-
this.app.send(new SetCSSDataURLBased(id, data, this.app.getBaseHref()));
|
|
188
|
-
return;
|
|
189
|
-
}
|
|
190
|
-
if (this.textMasked.has(id)) {
|
|
191
|
-
data = data.replace(/[^\f\n\r\t\v\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]/g, '█');
|
|
192
|
-
}
|
|
193
|
-
else {
|
|
194
|
-
if (this.options.obscureTextNumbers) {
|
|
195
|
-
data = data.replace(/\d/g, '0');
|
|
196
|
-
}
|
|
197
|
-
if (this.options.obscureTextEmails) {
|
|
198
|
-
data = data.replace(/([^\s]+)@([^\s]+)\.([^\s]+)/g, (...f) => stars(f[1]) + '@' + stars(f[2]) + '.' + stars(f[3]));
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
this.app.send(new SetNodeData(id, data));
|
|
202
|
-
}
|
|
203
|
-
bindNode(node) {
|
|
204
|
-
const r = this.app.nodes.registerNode(node);
|
|
205
|
-
const id = r[0];
|
|
206
|
-
this.recents[id] = r[1] || this.recents[id] || false;
|
|
207
|
-
}
|
|
208
|
-
bindTree(node) {
|
|
209
|
-
if (!isObservable(node)) {
|
|
210
|
-
return;
|
|
211
|
-
}
|
|
212
|
-
this.bindNode(node);
|
|
213
|
-
const walker = document.createTreeWalker(node, NodeFilter.SHOW_ELEMENT + NodeFilter.SHOW_TEXT, {
|
|
214
|
-
acceptNode: (node) => isIgnored(node) || this.app.nodes.getID(node) !== undefined
|
|
215
|
-
? NodeFilter.FILTER_REJECT
|
|
216
|
-
: NodeFilter.FILTER_ACCEPT,
|
|
217
|
-
}, false);
|
|
218
|
-
while (walker.nextNode()) {
|
|
219
|
-
this.bindNode(walker.currentNode);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
unbindNode(node) {
|
|
223
|
-
const id = this.app.nodes.unregisterNode(node);
|
|
224
|
-
if (id !== undefined && this.recents[id] === false) {
|
|
225
|
-
this.app.send(new RemoveNode(id));
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
_commitNode(id, node) {
|
|
229
|
-
if (isRootNode(node)) {
|
|
230
|
-
return true;
|
|
231
|
-
}
|
|
232
|
-
const parent = node.parentNode;
|
|
233
|
-
let parentID;
|
|
234
|
-
// if (isInstance(node, HTMLHtmlElement)) { // ?? TODO: get rid of "specia" cases
|
|
235
|
-
// this.indexes[id] = 0
|
|
236
|
-
// } else {
|
|
237
|
-
if (parent === null) {
|
|
238
|
-
this.unbindNode(node);
|
|
239
|
-
return false;
|
|
240
|
-
}
|
|
241
|
-
parentID = this.app.nodes.getID(parent);
|
|
242
|
-
if (parentID === undefined) {
|
|
243
|
-
this.unbindNode(node);
|
|
244
|
-
return false;
|
|
245
|
-
}
|
|
246
|
-
if (!this.commitNode(parentID)) {
|
|
247
|
-
this.unbindNode(node);
|
|
248
|
-
return false;
|
|
249
|
-
}
|
|
250
|
-
if (this.textMasked.has(parentID) ||
|
|
251
|
-
(isInstance(node, Element) && hasOpenreplayAttribute(node, 'masked'))) {
|
|
252
|
-
this.textMasked.add(id);
|
|
253
|
-
}
|
|
254
|
-
let sibling = node.previousSibling;
|
|
255
|
-
while (sibling !== null) {
|
|
256
|
-
const siblingID = this.app.nodes.getID(sibling);
|
|
257
|
-
if (siblingID !== undefined) {
|
|
258
|
-
this.commitNode(siblingID);
|
|
259
|
-
this.indexes[id] = this.indexes[siblingID] + 1;
|
|
260
|
-
break;
|
|
261
|
-
}
|
|
262
|
-
sibling = sibling.previousSibling;
|
|
263
|
-
}
|
|
264
|
-
if (sibling === null) {
|
|
265
|
-
this.indexes[id] = 0;
|
|
266
|
-
}
|
|
267
|
-
const isNew = this.recents[id];
|
|
268
|
-
const index = this.indexes[id];
|
|
269
|
-
if (index === undefined) {
|
|
270
|
-
throw 'commitNode: missing node index';
|
|
271
|
-
}
|
|
272
|
-
if (isNew === true) {
|
|
273
|
-
if (isInstance(node, Element)) {
|
|
274
|
-
if (parentID !== undefined) {
|
|
275
|
-
this.app.send(new CreateElementNode(id, parentID, index, node.tagName, isSVGElement(node)));
|
|
276
|
-
}
|
|
277
|
-
for (let i = 0; i < node.attributes.length; i++) {
|
|
278
|
-
const attr = node.attributes[i];
|
|
279
|
-
this.sendNodeAttribute(id, node, attr.nodeName, attr.value);
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
else if (isInstance(node, Text)) {
|
|
283
|
-
// for text node id != 0, hence parentID !== undefined and parent is Element
|
|
284
|
-
this.app.send(new CreateTextNode(id, parentID, index));
|
|
285
|
-
this.sendNodeData(id, parent, node.data);
|
|
286
|
-
}
|
|
287
|
-
return true;
|
|
288
|
-
}
|
|
289
|
-
if (isNew === false && parentID !== undefined) {
|
|
290
|
-
this.app.send(new MoveNode(id, parentID, index));
|
|
291
|
-
}
|
|
292
|
-
const attr = this.attributesList[id];
|
|
293
|
-
if (attr !== undefined) {
|
|
294
|
-
if (!isInstance(node, Element)) {
|
|
295
|
-
throw 'commitNode: node is not an element';
|
|
296
|
-
}
|
|
297
|
-
for (const name of attr) {
|
|
298
|
-
this.sendNodeAttribute(id, node, name, node.getAttribute(name));
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
if (this.textSet.has(id)) {
|
|
302
|
-
if (!isInstance(node, Text)) {
|
|
303
|
-
throw 'commitNode: node is not a text';
|
|
304
|
-
}
|
|
305
|
-
// for text node id != 0, hence parent is Element
|
|
306
|
-
this.sendNodeData(id, parent, node.data);
|
|
307
|
-
}
|
|
308
|
-
return true;
|
|
309
|
-
}
|
|
310
|
-
commitNode(id) {
|
|
311
|
-
const node = this.app.nodes.getNode(id);
|
|
312
|
-
if (node === undefined) {
|
|
313
|
-
return false;
|
|
314
|
-
}
|
|
315
|
-
const cmt = this.commited[id];
|
|
316
|
-
if (cmt !== undefined) {
|
|
317
|
-
return cmt;
|
|
318
|
-
}
|
|
319
|
-
return (this.commited[id] = this._commitNode(id, node));
|
|
320
|
-
}
|
|
321
|
-
commitNodes() {
|
|
322
|
-
let node;
|
|
323
|
-
for (let id = 0; id < this.recents.length; id++) {
|
|
324
|
-
this.commitNode(id);
|
|
325
|
-
if (this.recents[id] === true && (node = this.app.nodes.getNode(id))) {
|
|
326
|
-
this.app.nodes.callNodeCallbacks(node);
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
this.clear();
|
|
330
|
-
}
|
|
331
|
-
observeRoot(node, beforeCommit) {
|
|
332
|
-
this.observer.observe(node, {
|
|
333
|
-
childList: true,
|
|
334
|
-
attributes: true,
|
|
335
|
-
characterData: true,
|
|
336
|
-
subtree: true,
|
|
337
|
-
attributeOldValue: false,
|
|
338
|
-
characterDataOldValue: false,
|
|
339
|
-
});
|
|
340
|
-
this.bindTree(node);
|
|
341
|
-
beforeCommit(this.app.nodes.getID(node));
|
|
342
|
-
this.commitNodes();
|
|
343
|
-
}
|
|
344
|
-
disconnect() {
|
|
345
|
-
this.observer.disconnect();
|
|
346
|
-
this.clear();
|
|
347
|
-
}
|
|
348
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import Observer from './observer';
|
|
2
|
-
import { CreateIFrameDocument, } from '../../messages';
|
|
3
|
-
export default class ShadowRootObserver extends Observer {
|
|
4
|
-
observe(el) {
|
|
5
|
-
const shRoot = el.shadowRoot;
|
|
6
|
-
const hostID = this.app.nodes.getID(el);
|
|
7
|
-
if (!shRoot || hostID === undefined) {
|
|
8
|
-
return;
|
|
9
|
-
} // log
|
|
10
|
-
this.observeRoot(shRoot, (rootID) => {
|
|
11
|
-
if (rootID === undefined) {
|
|
12
|
-
console.log("OpenReplay: Shadow Root was not bound");
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
this.app.send(CreateIFrameDocument(hostID, rootID));
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import Observer from './observer';
|
|
2
|
-
import type { Options as BaseOptions } from './observer';
|
|
3
|
-
import type App from '../index';
|
|
4
|
-
export interface Options extends Partial<BaseOptions> {
|
|
5
|
-
captureIFrames: boolean;
|
|
6
|
-
}
|
|
7
|
-
export default class TopObserver extends Observer<Options> {
|
|
8
|
-
constructor(app: App, options: Partial<Options>);
|
|
9
|
-
private iframeObservers;
|
|
10
|
-
private handleIframe;
|
|
11
|
-
private shadowRootObservers;
|
|
12
|
-
private handleShadowRoot;
|
|
13
|
-
observe(): void;
|
|
14
|
-
disconnect(): void;
|
|
15
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import Observer, { isInstance } from './observer';
|
|
2
|
-
import IFrameObserver from './iframe_observer';
|
|
3
|
-
import ShadowRootObserver from './shadow_root_observer';
|
|
4
|
-
import { CreateDocument, } from '../../messages';
|
|
5
|
-
export default class TopObserver extends Observer {
|
|
6
|
-
constructor(app, options) {
|
|
7
|
-
super(app, Object.assign({
|
|
8
|
-
captureIFrames: false
|
|
9
|
-
}, options));
|
|
10
|
-
this.iframeObservers = [];
|
|
11
|
-
this.shadowRootObservers = [];
|
|
12
|
-
// IFrames
|
|
13
|
-
this.app.nodes.attachNodeCallback(node => {
|
|
14
|
-
if (isInstance(node, HTMLIFrameElement) &&
|
|
15
|
-
(this.options.captureIFrames || node.getAttribute("data-openreplay-capture"))) {
|
|
16
|
-
this.handleIframe(node);
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
// ShadowDOM
|
|
20
|
-
this.app.nodes.attachNodeCallback(node => {
|
|
21
|
-
if (isInstance(node, Element) && node.shadowRoot !== null) {
|
|
22
|
-
this.handleShadowRoot(node.shadowRoot);
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
const attachShadowNative = Element.prototype.attachShadow;
|
|
26
|
-
const observer = this;
|
|
27
|
-
Element.prototype.attachShadow = function () {
|
|
28
|
-
const shadow = attachShadowNative.apply(this, arguments);
|
|
29
|
-
if (app.active()) { // Is it necessary here?
|
|
30
|
-
// TODO: clearify logic - sub-observation should happen only during main observation.
|
|
31
|
-
// THat works well with node callbacks, but not here
|
|
32
|
-
observer.handleShadowRoot(shadow);
|
|
33
|
-
}
|
|
34
|
-
return shadow;
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
handleIframe(iframe) {
|
|
38
|
-
let context = null;
|
|
39
|
-
const handle = () => {
|
|
40
|
-
const id = this.app.nodes.getID(iframe);
|
|
41
|
-
if (id === undefined) {
|
|
42
|
-
return;
|
|
43
|
-
} //log
|
|
44
|
-
if (iframe.contentWindow === context) {
|
|
45
|
-
return;
|
|
46
|
-
} //Does this happen frequently?
|
|
47
|
-
context = iframe.contentWindow;
|
|
48
|
-
if (!context) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
const observer = new IFrameObserver(this.app, this.options, context);
|
|
52
|
-
this.iframeObservers.push(observer);
|
|
53
|
-
observer.observe(iframe);
|
|
54
|
-
};
|
|
55
|
-
this.app.attachEventListener(iframe, "load", handle);
|
|
56
|
-
handle();
|
|
57
|
-
}
|
|
58
|
-
handleShadowRoot(shRoot) {
|
|
59
|
-
const observer = new ShadowRootObserver(this.app, this.options, this.context);
|
|
60
|
-
this.shadowRootObservers.push(observer);
|
|
61
|
-
observer.observe(shRoot.host);
|
|
62
|
-
}
|
|
63
|
-
observe() {
|
|
64
|
-
this.observeRoot(this.context.document, () => {
|
|
65
|
-
this.app.send(new CreateDocument());
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
disconnect() {
|
|
69
|
-
this.iframeObservers.forEach(o => o.disconnect());
|
|
70
|
-
this.iframeObservers = [];
|
|
71
|
-
this.shadowRootObservers.forEach(o => o.disconnect());
|
|
72
|
-
this.shadowRootObservers = [];
|
|
73
|
-
super.disconnect();
|
|
74
|
-
}
|
|
75
|
-
}
|