@openreplay/tracker 3.4.16 → 3.4.17-beta.0

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.
@@ -1,6 +1,17 @@
1
1
  import { timestamp, isURL } from "../utils.js";
2
- import { ResourceTiming, SetNodeAttributeURLBased } from "../messages/index.js";
2
+ import { ResourceTiming, SetNodeAttributeURLBased, SetNodeAttribute } from "../messages/index.js";
3
+ const PLACEHOLDER_SRC = "https://static.openreplay.com/tracker/placeholder.jpeg";
3
4
  export default function (app) {
5
+ function sendPlaceholder(id, node) {
6
+ app.send(new SetNodeAttribute(id, "src", PLACEHOLDER_SRC));
7
+ const { width, height } = node.getBoundingClientRect();
8
+ if (!node.hasAttribute("width")) {
9
+ app.send(new SetNodeAttribute(id, "width", String(width)));
10
+ }
11
+ if (!node.hasAttribute("height")) {
12
+ app.send(new SetNodeAttribute(id, "height", String(height)));
13
+ }
14
+ }
4
15
  const sendImgSrc = app.safe(function () {
5
16
  const id = app.nodes.getID(this);
6
17
  if (id === undefined) {
@@ -15,7 +26,10 @@ export default function (app) {
15
26
  app.send(new ResourceTiming(timestamp(), 0, 0, 0, 0, 0, src, 'img'));
16
27
  }
17
28
  }
18
- else if (src.length < 1e5) {
29
+ else if (src.length >= 1e5 || app.sanitizer.isMasked(id)) {
30
+ sendPlaceholder(id, this);
31
+ }
32
+ else {
19
33
  app.send(new SetNodeAttributeURLBased(id, 'src', src, app.getBaseHref()));
20
34
  }
21
35
  });
@@ -1,5 +1,6 @@
1
1
  import App from "../app/index.js";
2
- export declare function getInputLabel(node: HTMLInputElement): string;
2
+ declare type TextEditableElement = HTMLInputElement | HTMLTextAreaElement;
3
+ export declare function getInputLabel(node: TextEditableElement): string;
3
4
  export declare const enum InputMode {
4
5
  Plain = 0,
5
6
  Obscured = 1,
@@ -11,3 +12,4 @@ export interface Options {
11
12
  defaultInputMode: InputMode;
12
13
  }
13
14
  export default function (app: App, opts: Partial<Options>): void;
15
+ export {};
@@ -1,6 +1,9 @@
1
1
  import { normSpaces, IN_BROWSER, getLabelAttribute, hasOpenreplayAttribute } from "../utils.js";
2
2
  import { SetInputTarget, SetInputValue, SetInputChecked } from "../messages/index.js";
3
- function isInput(node) {
3
+ function isTextEditable(node) {
4
+ if (node instanceof HTMLTextAreaElement) {
5
+ return true;
6
+ }
4
7
  if (!(node instanceof HTMLInputElement)) {
5
8
  return false;
6
9
  }
@@ -107,7 +110,7 @@ export default function (app, opts) {
107
110
  app.ticker.attach(() => {
108
111
  inputValues.forEach((value, id) => {
109
112
  const node = app.nodes.getNode(id);
110
- if (!isInput(node)) {
113
+ if (!isTextEditable(node)) {
111
114
  inputValues.delete(id);
112
115
  return;
113
116
  }
@@ -138,7 +141,7 @@ export default function (app, opts) {
138
141
  if (id === undefined) {
139
142
  return;
140
143
  }
141
- if (isInput(node)) {
144
+ if (isTextEditable(node)) {
142
145
  inputValues.set(id, node.value);
143
146
  sendInputValue(id, node);
144
147
  return;
@@ -83,7 +83,7 @@ export default function (app) {
83
83
  tag === 'LI' ||
84
84
  target.onclick != null ||
85
85
  target.getAttribute('role') === 'button') {
86
- const label = app.observer.getInnerTextSecure(target);
86
+ const label = app.sanitizer.getInnerTextSecure(target);
87
87
  return normSpaces(label).slice(0, 100);
88
88
  }
89
89
  return '';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@openreplay/tracker",
3
3
  "description": "The OpenReplay tracker main package",
4
- "version": "3.4.16",
4
+ "version": "3.4.17-beta.0",
5
5
  "keywords": [
6
6
  "logging",
7
7
  "replay"
@@ -1,47 +0,0 @@
1
- import App from "./index.js";
2
- interface Window extends WindowProxy {
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
- }
11
- export interface Options {
12
- obscureTextEmails: boolean;
13
- obscureTextNumbers: boolean;
14
- captureIFrames: boolean;
15
- }
16
- export default class Observer {
17
- private readonly app;
18
- private readonly options;
19
- private readonly context;
20
- private readonly observer;
21
- private readonly commited;
22
- private readonly recents;
23
- private readonly indexes;
24
- private readonly attributesList;
25
- private readonly textSet;
26
- private readonly textMasked;
27
- constructor(app: App, options: Options, context?: Window);
28
- private clear;
29
- private isInstance;
30
- private isIgnored;
31
- private sendNodeAttribute;
32
- getInnerTextSecure(el: HTMLElement): string;
33
- private checkObscure;
34
- private sendNodeData;
35
- private bindNode;
36
- private bindTree;
37
- private unbindNode;
38
- private _commitNode;
39
- private commitNode;
40
- private commitNodes;
41
- private iframeObservers;
42
- private handleIframe;
43
- private observeIframe;
44
- observe(): void;
45
- disconnect(): void;
46
- }
47
- export {};
@@ -1,395 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const utils_js_1 = require("../utils.js");
4
- const index_js_1 = require("../messages/index.js");
5
- function isSVGElement(node) {
6
- return node.namespaceURI === 'http://www.w3.org/2000/svg';
7
- }
8
- class Observer {
9
- constructor(app, options, context = window) {
10
- this.app = app;
11
- this.options = options;
12
- this.context = context;
13
- this.iframeObservers = [];
14
- this.observer = new MutationObserver(this.app.safe((mutations) => {
15
- var _a;
16
- for (const mutation of mutations) {
17
- const target = mutation.target;
18
- const type = mutation.type;
19
- // Special case
20
- // Document 'childList' might happen in case of iframe.
21
- // TODO: generalize as much as possible
22
- if (this.isInstance(target, Document)
23
- && type === 'childList'
24
- //&& new Array(mutation.addedNodes).some(node => this.isInstance(node, HTMLHtmlElement))
25
- ) {
26
- const parentFrame = (_a = target.defaultView) === null || _a === void 0 ? void 0 : _a.frameElement;
27
- if (!parentFrame) {
28
- continue;
29
- }
30
- this.bindTree(target.documentElement);
31
- const frameID = this.app.nodes.getID(parentFrame);
32
- const docID = this.app.nodes.getID(target.documentElement);
33
- if (frameID === undefined || docID === undefined) {
34
- continue;
35
- }
36
- this.app.send((0, index_js_1.CreateIFrameDocument)(frameID, docID));
37
- continue;
38
- }
39
- if (this.isIgnored(target) || !context.document.contains(target)) {
40
- continue;
41
- }
42
- if (type === 'childList') {
43
- for (let i = 0; i < mutation.removedNodes.length; i++) {
44
- this.bindTree(mutation.removedNodes[i]);
45
- }
46
- for (let i = 0; i < mutation.addedNodes.length; i++) {
47
- this.bindTree(mutation.addedNodes[i]);
48
- }
49
- continue;
50
- }
51
- const id = this.app.nodes.getID(target);
52
- if (id === undefined) {
53
- continue;
54
- }
55
- if (id >= this.recents.length) {
56
- this.recents[id] = undefined;
57
- }
58
- if (type === 'attributes') {
59
- const name = mutation.attributeName;
60
- if (name === null) {
61
- continue;
62
- }
63
- let attr = this.attributesList[id];
64
- if (attr === undefined) {
65
- this.attributesList[id] = attr = new Set();
66
- }
67
- attr.add(name);
68
- continue;
69
- }
70
- if (type === 'characterData') {
71
- this.textSet.add(id);
72
- continue;
73
- }
74
- }
75
- this.commitNodes();
76
- }));
77
- this.commited = [];
78
- this.recents = [];
79
- this.indexes = [0];
80
- this.attributesList = [];
81
- this.textSet = new Set();
82
- this.textMasked = new Set();
83
- }
84
- clear() {
85
- this.commited.length = 0;
86
- this.recents.length = 0;
87
- this.indexes.length = 1;
88
- this.attributesList.length = 0;
89
- this.textSet.clear();
90
- this.textMasked.clear();
91
- }
92
- // TODO: we need a type expert here so we won't have to ignore the lines
93
- isInstance(node, constr) {
94
- let context = this.context;
95
- while (context.parent && context.parent !== context) {
96
- // @ts-ignore
97
- if (node instanceof context[constr.name]) {
98
- return true;
99
- }
100
- // @ts-ignore
101
- context = context.parent;
102
- }
103
- // @ts-ignore
104
- return node instanceof context[constr.name];
105
- }
106
- isIgnored(node) {
107
- if (this.isInstance(node, Text)) {
108
- return false;
109
- }
110
- if (!this.isInstance(node, Element)) {
111
- return true;
112
- }
113
- const tag = node.tagName.toUpperCase();
114
- if (tag === 'LINK') {
115
- const rel = node.getAttribute('rel');
116
- const as = node.getAttribute('as');
117
- return !((rel === null || rel === void 0 ? void 0 : rel.includes('stylesheet')) || as === "style" || as === "font");
118
- }
119
- return (tag === 'SCRIPT' ||
120
- tag === 'NOSCRIPT' ||
121
- tag === 'META' ||
122
- tag === 'TITLE' ||
123
- tag === 'BASE');
124
- }
125
- sendNodeAttribute(id, node, name, value) {
126
- if (isSVGElement(node)) {
127
- if (name.substr(0, 6) === 'xlink:') {
128
- name = name.substr(6);
129
- }
130
- if (value === null) {
131
- this.app.send(new index_js_1.RemoveNodeAttribute(id, name));
132
- }
133
- else if (name === 'href') {
134
- if (value.length > 1e5) {
135
- value = '';
136
- }
137
- this.app.send(new index_js_1.SetNodeAttributeURLBased(id, name, value, this.app.getBaseHref()));
138
- }
139
- else {
140
- this.app.send(new index_js_1.SetNodeAttribute(id, name, value));
141
- }
142
- return;
143
- }
144
- if (name === 'src' ||
145
- name === 'srcset' ||
146
- name === 'integrity' ||
147
- name === 'crossorigin' ||
148
- name === 'autocomplete' ||
149
- name.substr(0, 2) === 'on') {
150
- return;
151
- }
152
- if (name === 'value' &&
153
- this.isInstance(node, HTMLInputElement) &&
154
- node.type !== 'button' &&
155
- node.type !== 'reset' &&
156
- node.type !== 'submit') {
157
- return;
158
- }
159
- if (value === null) {
160
- this.app.send(new index_js_1.RemoveNodeAttribute(id, name));
161
- return;
162
- }
163
- if (name === 'style' || name === 'href' && this.isInstance(node, HTMLLinkElement)) {
164
- this.app.send(new index_js_1.SetNodeAttributeURLBased(id, name, value, this.app.getBaseHref()));
165
- return;
166
- }
167
- if (name === 'href' || value.length > 1e5) {
168
- value = '';
169
- }
170
- this.app.send(new index_js_1.SetNodeAttribute(id, name, value));
171
- }
172
- /* TODO: abstract sanitation */
173
- getInnerTextSecure(el) {
174
- const id = this.app.nodes.getID(el);
175
- if (!id) {
176
- return '';
177
- }
178
- return this.checkObscure(id, el.innerText);
179
- }
180
- checkObscure(id, data) {
181
- if (this.textMasked.has(id)) {
182
- return data.replace(/[^\f\n\r\t\v\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]/g, '█');
183
- }
184
- if (this.options.obscureTextNumbers) {
185
- data = data.replace(/\d/g, '0');
186
- }
187
- if (this.options.obscureTextEmails) {
188
- data = data.replace(/([^\s]+)@([^\s]+)\.([^\s]+)/g, (...f) => (0, utils_js_1.stars)(f[1]) + '@' + (0, utils_js_1.stars)(f[2]) + '.' + (0, utils_js_1.stars)(f[3]));
189
- }
190
- return data;
191
- }
192
- sendNodeData(id, parentElement, data) {
193
- if (this.isInstance(parentElement, HTMLStyleElement) || this.isInstance(parentElement, SVGStyleElement)) {
194
- this.app.send(new index_js_1.SetCSSDataURLBased(id, data, this.app.getBaseHref()));
195
- return;
196
- }
197
- data = this.checkObscure(id, data);
198
- this.app.send(new index_js_1.SetNodeData(id, data));
199
- }
200
- /* end TODO: abstract sanitation */
201
- bindNode(node) {
202
- const r = this.app.nodes.registerNode(node);
203
- const id = r[0];
204
- this.recents[id] = r[1] || this.recents[id] || false;
205
- }
206
- bindTree(node) {
207
- if (this.isIgnored(node)) {
208
- return;
209
- }
210
- this.bindNode(node);
211
- const walker = document.createTreeWalker(node, NodeFilter.SHOW_ELEMENT + NodeFilter.SHOW_TEXT, {
212
- acceptNode: (node) => this.isIgnored(node) || this.app.nodes.getID(node) !== undefined
213
- ? NodeFilter.FILTER_REJECT
214
- : NodeFilter.FILTER_ACCEPT,
215
- },
216
- // @ts-ignore
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 index_js_1.RemoveNode(id));
226
- }
227
- }
228
- _commitNode(id, node) {
229
- const parent = node.parentNode;
230
- let parentID;
231
- if (this.isInstance(node, HTMLHtmlElement)) {
232
- this.indexes[id] = 0;
233
- }
234
- else {
235
- if (parent === null) {
236
- this.unbindNode(node);
237
- return false;
238
- }
239
- parentID = this.app.nodes.getID(parent);
240
- if (parentID === undefined) {
241
- this.unbindNode(node);
242
- return false;
243
- }
244
- if (!this.commitNode(parentID)) {
245
- this.unbindNode(node);
246
- return false;
247
- }
248
- if (this.textMasked.has(parentID) ||
249
- (this.isInstance(node, Element) && (0, utils_js_1.hasOpenreplayAttribute)(node, 'masked'))) {
250
- this.textMasked.add(id);
251
- }
252
- let sibling = node.previousSibling;
253
- while (sibling !== null) {
254
- const siblingID = this.app.nodes.getID(sibling);
255
- if (siblingID !== undefined) {
256
- this.commitNode(siblingID);
257
- this.indexes[id] = this.indexes[siblingID] + 1;
258
- break;
259
- }
260
- sibling = sibling.previousSibling;
261
- }
262
- if (sibling === null) {
263
- this.indexes[id] = 0;
264
- }
265
- }
266
- const isNew = this.recents[id];
267
- const index = this.indexes[id];
268
- if (index === undefined) {
269
- throw 'commitNode: missing node index';
270
- }
271
- if (isNew === true) {
272
- if (this.isInstance(node, Element)) {
273
- if (parentID !== undefined) {
274
- this.app.send(new index_js_1.CreateElementNode(id, parentID, index, node.tagName, isSVGElement(node)));
275
- }
276
- for (let i = 0; i < node.attributes.length; i++) {
277
- const attr = node.attributes[i];
278
- this.sendNodeAttribute(id, node, attr.nodeName, attr.value);
279
- }
280
- if (this.isInstance(node, HTMLIFrameElement) &&
281
- (this.options.captureIFrames || node.getAttribute("data-openreplay-capture"))) {
282
- this.handleIframe(node);
283
- }
284
- }
285
- else if (this.isInstance(node, Text)) {
286
- // for text node id != 0, hence parentID !== undefined and parent is Element
287
- this.app.send(new index_js_1.CreateTextNode(id, parentID, index));
288
- this.sendNodeData(id, parent, node.data);
289
- }
290
- return true;
291
- }
292
- if (isNew === false && parentID !== undefined) {
293
- this.app.send(new index_js_1.MoveNode(id, parentID, index));
294
- }
295
- const attr = this.attributesList[id];
296
- if (attr !== undefined) {
297
- if (!this.isInstance(node, Element)) {
298
- throw 'commitNode: node is not an element';
299
- }
300
- for (const name of attr) {
301
- this.sendNodeAttribute(id, node, name, node.getAttribute(name));
302
- }
303
- }
304
- if (this.textSet.has(id)) {
305
- if (!this.isInstance(node, Text)) {
306
- throw 'commitNode: node is not a text';
307
- }
308
- // for text node id != 0, hence parent is Element
309
- this.sendNodeData(id, parent, node.data);
310
- }
311
- return true;
312
- }
313
- commitNode(id) {
314
- const node = this.app.nodes.getNode(id);
315
- if (node === undefined) {
316
- return false;
317
- }
318
- const cmt = this.commited[id];
319
- if (cmt !== undefined) {
320
- return cmt;
321
- }
322
- return (this.commited[id] = this._commitNode(id, node));
323
- }
324
- commitNodes() {
325
- let node;
326
- for (let id = 0; id < this.recents.length; id++) {
327
- this.commitNode(id);
328
- if (this.recents[id] === true && (node = this.app.nodes.getNode(id))) {
329
- this.app.nodes.callNodeCallbacks(node);
330
- }
331
- }
332
- this.clear();
333
- }
334
- handleIframe(iframe) {
335
- let context = null;
336
- const handle = this.app.safe(() => {
337
- const id = this.app.nodes.getID(iframe);
338
- if (id === undefined) {
339
- return;
340
- }
341
- if (iframe.contentWindow === context) {
342
- return;
343
- }
344
- context = iframe.contentWindow;
345
- if (!context) {
346
- return;
347
- }
348
- const observer = new Observer(this.app, this.options, context);
349
- this.iframeObservers.push(observer);
350
- observer.observeIframe(id, context);
351
- });
352
- this.app.attachEventListener(iframe, "load", handle);
353
- handle();
354
- }
355
- // TODO: abstract common functionality, separate FrameObserver
356
- observeIframe(id, context) {
357
- const doc = context.document;
358
- this.observer.observe(doc, {
359
- childList: true,
360
- attributes: true,
361
- characterData: true,
362
- subtree: true,
363
- attributeOldValue: false,
364
- characterDataOldValue: false,
365
- });
366
- this.bindTree(doc.documentElement);
367
- const docID = this.app.nodes.getID(doc.documentElement);
368
- if (docID === undefined) {
369
- console.log("Wrong");
370
- return;
371
- }
372
- this.app.send((0, index_js_1.CreateIFrameDocument)(id, docID));
373
- this.commitNodes();
374
- }
375
- observe() {
376
- this.observer.observe(this.context.document, {
377
- childList: true,
378
- attributes: true,
379
- characterData: true,
380
- subtree: true,
381
- attributeOldValue: false,
382
- characterDataOldValue: false,
383
- });
384
- this.app.send(new index_js_1.CreateDocument());
385
- this.bindTree(this.context.document.documentElement);
386
- this.commitNodes();
387
- }
388
- disconnect() {
389
- this.iframeObservers.forEach(o => o.disconnect());
390
- this.iframeObservers = [];
391
- this.observer.disconnect();
392
- this.clear();
393
- }
394
- }
395
- exports.default = Observer;
@@ -1,47 +0,0 @@
1
- import App from "./index.js";
2
- interface Window extends WindowProxy {
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
- }
11
- export interface Options {
12
- obscureTextEmails: boolean;
13
- obscureTextNumbers: boolean;
14
- captureIFrames: boolean;
15
- }
16
- export default class Observer {
17
- private readonly app;
18
- private readonly options;
19
- private readonly context;
20
- private readonly observer;
21
- private readonly commited;
22
- private readonly recents;
23
- private readonly indexes;
24
- private readonly attributesList;
25
- private readonly textSet;
26
- private readonly textMasked;
27
- constructor(app: App, options: Options, context?: Window);
28
- private clear;
29
- private isInstance;
30
- private isIgnored;
31
- private sendNodeAttribute;
32
- getInnerTextSecure(el: HTMLElement): string;
33
- private checkObscure;
34
- private sendNodeData;
35
- private bindNode;
36
- private bindTree;
37
- private unbindNode;
38
- private _commitNode;
39
- private commitNode;
40
- private commitNodes;
41
- private iframeObservers;
42
- private handleIframe;
43
- private observeIframe;
44
- observe(): void;
45
- disconnect(): void;
46
- }
47
- export {};