@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.
- package/cjs/app/context.d.ts +18 -0
- package/cjs/app/context.js +48 -0
- package/cjs/app/index.d.ts +10 -5
- package/cjs/app/index.js +19 -8
- package/cjs/app/observer/observer.d.ts +2 -27
- package/cjs/app/observer/observer.js +18 -92
- package/cjs/app/observer/top_observer.d.ts +3 -3
- package/cjs/app/observer/top_observer.js +9 -7
- package/cjs/app/sanitizer.d.ts +16 -0
- package/cjs/app/sanitizer.js +46 -0
- package/cjs/index.d.ts +1 -0
- package/cjs/index.js +7 -1
- package/cjs/modules/img.js +15 -1
- package/cjs/modules/input.d.ts +3 -1
- package/cjs/modules/input.js +6 -3
- package/cjs/modules/mouse.js +1 -1
- package/lib/app/context.d.ts +18 -0
- package/lib/app/context.js +43 -0
- package/lib/app/index.d.ts +10 -5
- package/lib/app/index.js +19 -8
- package/lib/app/observer/observer.d.ts +2 -27
- package/lib/app/observer/observer.js +7 -79
- package/lib/app/observer/top_observer.d.ts +3 -3
- package/lib/app/observer/top_observer.js +8 -6
- package/lib/app/sanitizer.d.ts +16 -0
- package/lib/app/sanitizer.js +44 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +7 -1
- package/lib/modules/img.js +16 -2
- package/lib/modules/input.d.ts +3 -1
- package/lib/modules/input.js +6 -3
- package/lib/modules/mouse.js +1 -1
- package/package.json +1 -1
- package/cjs/app/observer.d.ts +0 -47
- package/cjs/app/observer.js +0 -395
- package/lib/app/observer.d.ts +0 -47
- package/lib/app/observer.js +0 -392
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface Window extends globalThis.Window {
|
|
2
|
+
HTMLInputElement: typeof HTMLInputElement;
|
|
3
|
+
HTMLLinkElement: typeof HTMLLinkElement;
|
|
4
|
+
HTMLStyleElement: typeof HTMLStyleElement;
|
|
5
|
+
SVGStyleElement: typeof SVGStyleElement;
|
|
6
|
+
HTMLIFrameElement: typeof HTMLIFrameElement;
|
|
7
|
+
Text: typeof Text;
|
|
8
|
+
Element: typeof Element;
|
|
9
|
+
ShadowRoot: typeof ShadowRoot;
|
|
10
|
+
}
|
|
11
|
+
declare type WindowConstructor = Document | Element | Text | ShadowRoot | HTMLInputElement | HTMLLinkElement | HTMLStyleElement | HTMLIFrameElement;
|
|
12
|
+
declare type Constructor<T> = {
|
|
13
|
+
new (...args: any[]): T;
|
|
14
|
+
name: string;
|
|
15
|
+
};
|
|
16
|
+
export declare function isInstance<T extends WindowConstructor>(node: Node, constr: Constructor<T>): node is T;
|
|
17
|
+
export declare function inDocument(node: Node): boolean;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.inDocument = exports.isInstance = void 0;
|
|
4
|
+
// TODO: we need a type expert here so we won't have to ignore the lines
|
|
5
|
+
// TODO: use it everywhere (static function; export from which file? <-- global Window typing required)
|
|
6
|
+
function isInstance(node, constr) {
|
|
7
|
+
const doc = node.ownerDocument;
|
|
8
|
+
if (!doc) { // null if Document
|
|
9
|
+
return constr.name === 'Document';
|
|
10
|
+
}
|
|
11
|
+
let context =
|
|
12
|
+
// @ts-ignore (for EI, Safary)
|
|
13
|
+
doc.parentWindow ||
|
|
14
|
+
doc.defaultView; // TODO: smart global typing for Window object
|
|
15
|
+
while (context.parent && context.parent !== context) {
|
|
16
|
+
// @ts-ignore
|
|
17
|
+
if (node instanceof context[constr.name]) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
// @ts-ignore
|
|
21
|
+
context = context.parent;
|
|
22
|
+
}
|
|
23
|
+
// @ts-ignore
|
|
24
|
+
return node instanceof context[constr.name];
|
|
25
|
+
}
|
|
26
|
+
exports.isInstance = isInstance;
|
|
27
|
+
function inDocument(node) {
|
|
28
|
+
const doc = node.ownerDocument;
|
|
29
|
+
if (!doc) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
if (doc.contains(node)) {
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
let context =
|
|
36
|
+
// @ts-ignore (for EI, Safary)
|
|
37
|
+
doc.parentWindow ||
|
|
38
|
+
doc.defaultView;
|
|
39
|
+
while (context.parent && context.parent !== context) {
|
|
40
|
+
if (context.document.contains(node)) {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
// @ts-ignore
|
|
44
|
+
context = context.parent;
|
|
45
|
+
}
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
exports.inDocument = inDocument;
|
package/cjs/app/index.d.ts
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import Message from "../messages/message.js";
|
|
2
2
|
import Nodes from "./nodes.js";
|
|
3
|
-
import
|
|
3
|
+
import Sanitizer from "./sanitizer.js";
|
|
4
4
|
import Ticker from "./ticker.js";
|
|
5
5
|
import type { Options as ObserverOptions } from "./observer/top_observer.js";
|
|
6
|
+
import type { Options as SanitizerOptions } from "./sanitizer.js";
|
|
6
7
|
import type { Options as WebworkerOptions } from "../messages/webworker.js";
|
|
7
8
|
export interface OnStartInfo {
|
|
8
9
|
sessionID: string;
|
|
9
10
|
sessionToken: string;
|
|
10
11
|
userUUID: string;
|
|
11
12
|
}
|
|
12
|
-
|
|
13
|
+
declare type AppOptions = {
|
|
13
14
|
revID: string;
|
|
14
15
|
node_id: string;
|
|
15
16
|
session_token_key: string;
|
|
16
17
|
session_pageno_key: string;
|
|
18
|
+
session_reset_key: string;
|
|
17
19
|
local_uuid_key: string;
|
|
18
20
|
ingestPoint: string;
|
|
19
21
|
resourceBaseHref: string | null;
|
|
@@ -21,7 +23,8 @@ export declare type Options = {
|
|
|
21
23
|
__debug_report_edp: string | null;
|
|
22
24
|
__debug_log: boolean;
|
|
23
25
|
onStart?: (info: OnStartInfo) => void;
|
|
24
|
-
} &
|
|
26
|
+
} & WebworkerOptions;
|
|
27
|
+
export declare type Options = AppOptions & ObserverOptions & SanitizerOptions;
|
|
25
28
|
declare type Callback = () => void;
|
|
26
29
|
declare type CommitCallback = (messages: Array<Message>) => void;
|
|
27
30
|
export declare const DEFAULT_INGEST_POINT = "https://api.openreplay.com/ingest";
|
|
@@ -29,8 +32,9 @@ export default class App {
|
|
|
29
32
|
readonly nodes: Nodes;
|
|
30
33
|
readonly ticker: Ticker;
|
|
31
34
|
readonly projectKey: string;
|
|
35
|
+
readonly sanitizer: Sanitizer;
|
|
32
36
|
private readonly messages;
|
|
33
|
-
readonly observer
|
|
37
|
+
private readonly observer;
|
|
34
38
|
private readonly startCallbacks;
|
|
35
39
|
private readonly stopCallbacks;
|
|
36
40
|
private readonly commitCallbacks;
|
|
@@ -40,7 +44,7 @@ export default class App {
|
|
|
40
44
|
private isActive;
|
|
41
45
|
private version;
|
|
42
46
|
private readonly worker?;
|
|
43
|
-
constructor(projectKey: string, sessionToken: string | null | undefined,
|
|
47
|
+
constructor(projectKey: string, sessionToken: string | null | undefined, options: Partial<Options>);
|
|
44
48
|
private _debug;
|
|
45
49
|
send(message: Message, urgent?: boolean): void;
|
|
46
50
|
private commit;
|
|
@@ -58,6 +62,7 @@ export default class App {
|
|
|
58
62
|
resolveResourceURL(resourceURL: string): string;
|
|
59
63
|
isServiceURL(url: string): boolean;
|
|
60
64
|
active(): boolean;
|
|
65
|
+
resetNextPageSession(flag: boolean): void;
|
|
61
66
|
private _start;
|
|
62
67
|
start(reset?: boolean): Promise<OnStartInfo>;
|
|
63
68
|
stop(): void;
|
package/cjs/app/index.js
CHANGED
|
@@ -5,41 +5,41 @@ const utils_js_1 = require("../utils.js");
|
|
|
5
5
|
const index_js_1 = require("../messages/index.js");
|
|
6
6
|
const nodes_js_1 = require("./nodes.js");
|
|
7
7
|
const top_observer_js_1 = require("./observer/top_observer.js");
|
|
8
|
+
const sanitizer_js_1 = require("./sanitizer.js");
|
|
8
9
|
const ticker_js_1 = require("./ticker.js");
|
|
9
10
|
const performance_js_1 = require("../modules/performance.js");
|
|
10
11
|
// TODO: use backendHost only
|
|
11
12
|
exports.DEFAULT_INGEST_POINT = 'https://api.openreplay.com/ingest';
|
|
12
13
|
class App {
|
|
13
|
-
constructor(projectKey, sessionToken,
|
|
14
|
+
constructor(projectKey, sessionToken, options) {
|
|
14
15
|
this.messages = [];
|
|
15
16
|
this.startCallbacks = [];
|
|
16
17
|
this.stopCallbacks = [];
|
|
17
18
|
this.commitCallbacks = [];
|
|
18
19
|
this._sessionID = null;
|
|
19
20
|
this.isActive = false;
|
|
20
|
-
this.version = '3.4.
|
|
21
|
+
this.version = '3.4.17-beta.0';
|
|
21
22
|
this.projectKey = projectKey;
|
|
22
23
|
this.options = Object.assign({
|
|
23
24
|
revID: '',
|
|
24
25
|
node_id: '__openreplay_id',
|
|
25
26
|
session_token_key: '__openreplay_token',
|
|
26
27
|
session_pageno_key: '__openreplay_pageno',
|
|
28
|
+
session_reset_key: '__openreplay_reset',
|
|
27
29
|
local_uuid_key: '__openreplay_uuid',
|
|
28
30
|
ingestPoint: exports.DEFAULT_INGEST_POINT,
|
|
29
31
|
resourceBaseHref: null,
|
|
30
32
|
__is_snippet: false,
|
|
31
33
|
__debug_report_edp: null,
|
|
32
34
|
__debug_log: false,
|
|
33
|
-
|
|
34
|
-
obscureTextNumbers: false,
|
|
35
|
-
captureIFrames: false,
|
|
36
|
-
}, opts);
|
|
35
|
+
}, options);
|
|
37
36
|
if (sessionToken != null) {
|
|
38
37
|
sessionStorage.setItem(this.options.session_token_key, sessionToken);
|
|
39
38
|
}
|
|
40
39
|
this.revID = this.options.revID;
|
|
40
|
+
this.sanitizer = new sanitizer_js_1.default(this, options);
|
|
41
41
|
this.nodes = new nodes_js_1.default(this.options.node_id);
|
|
42
|
-
this.observer = new top_observer_js_1.default(this,
|
|
42
|
+
this.observer = new top_observer_js_1.default(this, options);
|
|
43
43
|
this.ticker = new ticker_js_1.default(this);
|
|
44
44
|
this.ticker.attach(() => this.commit());
|
|
45
45
|
try {
|
|
@@ -181,6 +181,14 @@ class App {
|
|
|
181
181
|
active() {
|
|
182
182
|
return this.isActive;
|
|
183
183
|
}
|
|
184
|
+
resetNextPageSession(flag) {
|
|
185
|
+
if (flag) {
|
|
186
|
+
sessionStorage.setItem(this.options.session_reset_key, 't');
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
sessionStorage.removeItem(this.options.session_reset_key);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
184
192
|
_start(reset) {
|
|
185
193
|
if (!this.isActive) {
|
|
186
194
|
if (!this.worker) {
|
|
@@ -208,6 +216,8 @@ class App {
|
|
|
208
216
|
// if (tokenIsActive) {
|
|
209
217
|
// token = null
|
|
210
218
|
// }
|
|
219
|
+
const sReset = sessionStorage.getItem(this.options.session_reset_key);
|
|
220
|
+
sessionStorage.removeItem(this.options.session_reset_key);
|
|
211
221
|
return window.fetch(this.options.ingestPoint + '/v1/web/start', {
|
|
212
222
|
method: 'POST',
|
|
213
223
|
headers: {
|
|
@@ -223,7 +233,7 @@ class App {
|
|
|
223
233
|
isSnippet: this.options.__is_snippet,
|
|
224
234
|
deviceMemory: performance_js_1.deviceMemory,
|
|
225
235
|
jsHeapSizeLimit: performance_js_1.jsHeapSizeLimit,
|
|
226
|
-
reset,
|
|
236
|
+
reset: reset || sReset !== null,
|
|
227
237
|
}),
|
|
228
238
|
})
|
|
229
239
|
.then(r => {
|
|
@@ -301,6 +311,7 @@ class App {
|
|
|
301
311
|
if (this.worker) {
|
|
302
312
|
this.worker.postMessage("stop");
|
|
303
313
|
}
|
|
314
|
+
this.sanitizer.clear();
|
|
304
315
|
this.observer.disconnect();
|
|
305
316
|
this.nodes.clear();
|
|
306
317
|
this.ticker.stop();
|
|
@@ -1,25 +1,5 @@
|
|
|
1
1
|
import App from "../index.js";
|
|
2
|
-
export
|
|
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 = {}> {
|
|
2
|
+
export default abstract class Observer {
|
|
23
3
|
protected readonly app: App;
|
|
24
4
|
protected readonly context: Window;
|
|
25
5
|
private readonly observer;
|
|
@@ -29,14 +9,10 @@ export default abstract class Observer<AdditionalOptions = {}> {
|
|
|
29
9
|
private readonly indexes;
|
|
30
10
|
private readonly attributesList;
|
|
31
11
|
private readonly textSet;
|
|
32
|
-
private readonly textMasked;
|
|
33
|
-
protected readonly options: Options & AdditionalOptions;
|
|
34
12
|
private readonly inUpperContext;
|
|
35
|
-
constructor(app: App,
|
|
13
|
+
constructor(app: App, context?: Window);
|
|
36
14
|
private clear;
|
|
37
15
|
private sendNodeAttribute;
|
|
38
|
-
getInnerTextSecure(el: HTMLElement): string;
|
|
39
|
-
private checkObscure;
|
|
40
16
|
private sendNodeData;
|
|
41
17
|
private bindNode;
|
|
42
18
|
private bindTree;
|
|
@@ -47,4 +23,3 @@ export default abstract class Observer<AdditionalOptions = {}> {
|
|
|
47
23
|
protected observeRoot(node: Node, beforeCommit: (id?: number) => unknown, nodeToBind?: Node): void;
|
|
48
24
|
disconnect(): void;
|
|
49
25
|
}
|
|
50
|
-
export {};
|
|
@@ -1,39 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isInstance = void 0;
|
|
4
|
-
const utils_js_1 = require("../../utils.js");
|
|
5
3
|
const index_js_1 = require("../../messages/index.js");
|
|
4
|
+
const context_js_1 = require("../context.js");
|
|
6
5
|
function isSVGElement(node) {
|
|
7
6
|
return node.namespaceURI === 'http://www.w3.org/2000/svg';
|
|
8
7
|
}
|
|
9
|
-
// TODO: we need a type expert here so we won't have to ignore the lines
|
|
10
|
-
// TODO: use it everywhere (static function; export from which file? <-- global Window typing required)
|
|
11
|
-
function isInstance(node, constr) {
|
|
12
|
-
const doc = node.ownerDocument;
|
|
13
|
-
if (!doc) { // null if Document
|
|
14
|
-
return constr.name === 'Document';
|
|
15
|
-
}
|
|
16
|
-
let context =
|
|
17
|
-
// @ts-ignore (for EI, Safary)
|
|
18
|
-
doc.parentWindow ||
|
|
19
|
-
doc.defaultView; // TODO: smart global typing for Window object
|
|
20
|
-
while (context.parent && context.parent !== context) {
|
|
21
|
-
// @ts-ignore
|
|
22
|
-
if (node instanceof context[constr.name]) {
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
25
|
-
// @ts-ignore
|
|
26
|
-
context = context.parent;
|
|
27
|
-
}
|
|
28
|
-
// @ts-ignore
|
|
29
|
-
return node instanceof context[constr.name];
|
|
30
|
-
}
|
|
31
|
-
exports.isInstance = isInstance;
|
|
32
8
|
function isIgnored(node) {
|
|
33
|
-
if (isInstance(node, Text)) {
|
|
9
|
+
if ((0, context_js_1.isInstance)(node, Text)) {
|
|
34
10
|
return false;
|
|
35
11
|
}
|
|
36
|
-
if (!isInstance(node, Element)) {
|
|
12
|
+
if (!(0, context_js_1.isInstance)(node, Element)) {
|
|
37
13
|
return true;
|
|
38
14
|
}
|
|
39
15
|
const tag = node.tagName.toUpperCase();
|
|
@@ -49,7 +25,7 @@ function isIgnored(node) {
|
|
|
49
25
|
tag === 'BASE');
|
|
50
26
|
}
|
|
51
27
|
function isRootNode(node) {
|
|
52
|
-
return isInstance(node, Document) || isInstance(node, ShadowRoot);
|
|
28
|
+
return (0, context_js_1.isInstance)(node, Document) || (0, context_js_1.isInstance)(node, ShadowRoot);
|
|
53
29
|
}
|
|
54
30
|
function isObservable(node) {
|
|
55
31
|
if (isRootNode(node)) {
|
|
@@ -58,7 +34,7 @@ function isObservable(node) {
|
|
|
58
34
|
return !isIgnored(node);
|
|
59
35
|
}
|
|
60
36
|
class Observer {
|
|
61
|
-
constructor(app,
|
|
37
|
+
constructor(app, context = window) {
|
|
62
38
|
this.app = app;
|
|
63
39
|
this.context = context;
|
|
64
40
|
this.commited = [];
|
|
@@ -67,34 +43,12 @@ class Observer {
|
|
|
67
43
|
this.indexes = [];
|
|
68
44
|
this.attributesList = [];
|
|
69
45
|
this.textSet = new Set();
|
|
70
|
-
this.
|
|
71
|
-
this.options = Object.assign({
|
|
72
|
-
obscureTextEmails: true,
|
|
73
|
-
obscureTextNumbers: false,
|
|
74
|
-
}, options);
|
|
75
|
-
this.inUpperContext = context.parent === context;
|
|
46
|
+
this.inUpperContext = context.parent === context; //TODO: get rid of context here
|
|
76
47
|
this.observer = new MutationObserver(this.app.safe((mutations) => {
|
|
77
48
|
for (const mutation of mutations) {
|
|
78
49
|
const target = mutation.target;
|
|
79
50
|
const type = mutation.type;
|
|
80
|
-
|
|
81
|
-
// Special case
|
|
82
|
-
// 'childList' on Document might happen in case of iframe.
|
|
83
|
-
// TODO: generalize as much as possible
|
|
84
|
-
// if (isInstance(target, Document) // Also ShadowRoot can be here
|
|
85
|
-
// && type === 'childList'
|
|
86
|
-
// //&& new Array(mutation.addedNodes).some(node => isInstance(node, HTMLHtmlElement))
|
|
87
|
-
// ) {
|
|
88
|
-
// const parentFrame = target.defaultView?.frameElement
|
|
89
|
-
// if (!parentFrame) { continue }
|
|
90
|
-
// this.bindTree(target.documentElement)
|
|
91
|
-
// const frameID = this.app.nodes.getID(parentFrame)
|
|
92
|
-
// const docID = this.app.nodes.getID(target.documentElement)
|
|
93
|
-
// if (frameID === undefined || docID === undefined) { continue }
|
|
94
|
-
// this.app.send(CreateIFrameDocument(frameID, docID));
|
|
95
|
-
// continue;
|
|
96
|
-
// }
|
|
97
|
-
if (!isObservable(target) || !context.document.contains(target)) {
|
|
51
|
+
if (!isObservable(target) || !(0, context_js_1.inDocument)(target)) {
|
|
98
52
|
continue;
|
|
99
53
|
}
|
|
100
54
|
if (type === 'childList') {
|
|
@@ -139,7 +93,6 @@ class Observer {
|
|
|
139
93
|
this.indexes.length = 1;
|
|
140
94
|
this.attributesList.length = 0;
|
|
141
95
|
this.textSet.clear();
|
|
142
|
-
//this.textMasked.clear();
|
|
143
96
|
}
|
|
144
97
|
sendNodeAttribute(id, node, name, value) {
|
|
145
98
|
if (isSVGElement(node)) {
|
|
@@ -169,7 +122,7 @@ class Observer {
|
|
|
169
122
|
return;
|
|
170
123
|
}
|
|
171
124
|
if (name === 'value' &&
|
|
172
|
-
isInstance(node, HTMLInputElement) &&
|
|
125
|
+
(0, context_js_1.isInstance)(node, HTMLInputElement) &&
|
|
173
126
|
node.type !== 'button' &&
|
|
174
127
|
node.type !== 'reset' &&
|
|
175
128
|
node.type !== 'submit') {
|
|
@@ -179,7 +132,7 @@ class Observer {
|
|
|
179
132
|
this.app.send(new index_js_1.RemoveNodeAttribute(id, name));
|
|
180
133
|
return;
|
|
181
134
|
}
|
|
182
|
-
if (name === 'style' || name === 'href' && isInstance(node, HTMLLinkElement)) {
|
|
135
|
+
if (name === 'style' || name === 'href' && (0, context_js_1.isInstance)(node, HTMLLinkElement)) {
|
|
183
136
|
this.app.send(new index_js_1.SetNodeAttributeURLBased(id, name, value, this.app.getBaseHref()));
|
|
184
137
|
return;
|
|
185
138
|
}
|
|
@@ -188,35 +141,14 @@ class Observer {
|
|
|
188
141
|
}
|
|
189
142
|
this.app.send(new index_js_1.SetNodeAttribute(id, name, value));
|
|
190
143
|
}
|
|
191
|
-
/* TODO: abstract sanitation */
|
|
192
|
-
getInnerTextSecure(el) {
|
|
193
|
-
const id = this.app.nodes.getID(el);
|
|
194
|
-
if (!id) {
|
|
195
|
-
return '';
|
|
196
|
-
}
|
|
197
|
-
return this.checkObscure(id, el.innerText);
|
|
198
|
-
}
|
|
199
|
-
checkObscure(id, data) {
|
|
200
|
-
if (this.textMasked.has(id)) {
|
|
201
|
-
return data.replace(/[^\f\n\r\t\v\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]/g, '█');
|
|
202
|
-
}
|
|
203
|
-
if (this.options.obscureTextNumbers) {
|
|
204
|
-
data = data.replace(/\d/g, '0');
|
|
205
|
-
}
|
|
206
|
-
if (this.options.obscureTextEmails) {
|
|
207
|
-
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]));
|
|
208
|
-
}
|
|
209
|
-
return data;
|
|
210
|
-
}
|
|
211
144
|
sendNodeData(id, parentElement, data) {
|
|
212
|
-
if (isInstance(parentElement, HTMLStyleElement) || isInstance(parentElement, SVGStyleElement)) {
|
|
145
|
+
if ((0, context_js_1.isInstance)(parentElement, HTMLStyleElement) || (0, context_js_1.isInstance)(parentElement, SVGStyleElement)) {
|
|
213
146
|
this.app.send(new index_js_1.SetCSSDataURLBased(id, data, this.app.getBaseHref()));
|
|
214
147
|
return;
|
|
215
148
|
}
|
|
216
|
-
data = this.
|
|
149
|
+
data = this.app.sanitizer.sanitize(id, data);
|
|
217
150
|
this.app.send(new index_js_1.SetNodeData(id, data));
|
|
218
151
|
}
|
|
219
|
-
/* end TODO: abstract sanitation */
|
|
220
152
|
bindNode(node) {
|
|
221
153
|
const r = this.app.nodes.registerNode(node);
|
|
222
154
|
const id = r[0];
|
|
@@ -254,7 +186,7 @@ class Observer {
|
|
|
254
186
|
// Disable parent check for the upper context HTMLHtmlElement, because it is root there... (before)
|
|
255
187
|
// TODO: get rid of "special" cases (there is an issue with CreateDocument altered behaviour though)
|
|
256
188
|
// TODO: Clean the logic (though now it workd fine)
|
|
257
|
-
if (!isInstance(node, HTMLHtmlElement) || !this.inUpperContext) {
|
|
189
|
+
if (!(0, context_js_1.isInstance)(node, HTMLHtmlElement) || !this.inUpperContext) {
|
|
258
190
|
if (parent === null) {
|
|
259
191
|
this.unbindNode(node);
|
|
260
192
|
return false;
|
|
@@ -268,10 +200,7 @@ class Observer {
|
|
|
268
200
|
this.unbindNode(node);
|
|
269
201
|
return false;
|
|
270
202
|
}
|
|
271
|
-
|
|
272
|
-
(isInstance(node, Element) && (0, utils_js_1.hasOpenreplayAttribute)(node, 'masked'))) {
|
|
273
|
-
this.textMasked.add(id);
|
|
274
|
-
}
|
|
203
|
+
this.app.sanitizer.handleNode(id, parentID, node);
|
|
275
204
|
}
|
|
276
205
|
let sibling = node.previousSibling;
|
|
277
206
|
while (sibling !== null) {
|
|
@@ -292,7 +221,7 @@ class Observer {
|
|
|
292
221
|
throw 'commitNode: missing node index';
|
|
293
222
|
}
|
|
294
223
|
if (isNew === true) {
|
|
295
|
-
if (isInstance(node, Element)) {
|
|
224
|
+
if ((0, context_js_1.isInstance)(node, Element)) {
|
|
296
225
|
if (parentID !== undefined) {
|
|
297
226
|
this.app.send(new index_js_1.CreateElementNode(id, parentID, index, node.tagName, isSVGElement(node)));
|
|
298
227
|
}
|
|
@@ -301,7 +230,7 @@ class Observer {
|
|
|
301
230
|
this.sendNodeAttribute(id, node, attr.nodeName, attr.value);
|
|
302
231
|
}
|
|
303
232
|
}
|
|
304
|
-
else if (isInstance(node, Text)) {
|
|
233
|
+
else if ((0, context_js_1.isInstance)(node, Text)) {
|
|
305
234
|
// for text node id != 0, hence parentID !== undefined and parent is Element
|
|
306
235
|
this.app.send(new index_js_1.CreateTextNode(id, parentID, index));
|
|
307
236
|
this.sendNodeData(id, parent, node.data);
|
|
@@ -313,7 +242,7 @@ class Observer {
|
|
|
313
242
|
}
|
|
314
243
|
const attr = this.attributesList[id];
|
|
315
244
|
if (attr !== undefined) {
|
|
316
|
-
if (!isInstance(node, Element)) {
|
|
245
|
+
if (!(0, context_js_1.isInstance)(node, Element)) {
|
|
317
246
|
throw 'commitNode: node is not an element';
|
|
318
247
|
}
|
|
319
248
|
for (const name of attr) {
|
|
@@ -321,7 +250,7 @@ class Observer {
|
|
|
321
250
|
}
|
|
322
251
|
}
|
|
323
252
|
if (this.textSet.has(id)) {
|
|
324
|
-
if (!isInstance(node, Text)) {
|
|
253
|
+
if (!(0, context_js_1.isInstance)(node, Text)) {
|
|
325
254
|
throw 'commitNode: node is not a text';
|
|
326
255
|
}
|
|
327
256
|
// for text node id != 0, hence parent is Element
|
|
@@ -344,8 +273,7 @@ class Observer {
|
|
|
344
273
|
let node;
|
|
345
274
|
for (let id = 0; id < this.recents.length; id++) {
|
|
346
275
|
// TODO: make things/logic nice here.
|
|
347
|
-
// commit required in any case if recents[id] true or false (in case of unbinding).
|
|
348
|
-
// ???!?!?R@TW:$HKJ$WLKn
|
|
276
|
+
// commit required in any case if recents[id] true or false (in case of unbinding) or undefined (in case of attr change).
|
|
349
277
|
if (!this.myNodes[id]) {
|
|
350
278
|
continue;
|
|
351
279
|
}
|
|
@@ -373,8 +301,6 @@ class Observer {
|
|
|
373
301
|
disconnect() {
|
|
374
302
|
this.observer.disconnect();
|
|
375
303
|
this.clear();
|
|
376
|
-
// to sanitizer
|
|
377
|
-
this.textMasked.clear();
|
|
378
304
|
this.myNodes.length = 0;
|
|
379
305
|
}
|
|
380
306
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import Observer from "./observer.js";
|
|
2
|
-
import type { Options as BaseOptions } from "./observer.js";
|
|
3
2
|
import App from "../index.js";
|
|
4
|
-
export interface Options
|
|
3
|
+
export interface Options {
|
|
5
4
|
captureIFrames: boolean;
|
|
6
5
|
}
|
|
7
|
-
export default class TopObserver extends Observer
|
|
6
|
+
export default class TopObserver extends Observer {
|
|
7
|
+
private readonly options;
|
|
8
8
|
constructor(app: App, options: Partial<Options>);
|
|
9
9
|
private iframeObservers;
|
|
10
10
|
private handleIframe;
|
|
@@ -1,27 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const observer_js_1 = require("./observer.js");
|
|
4
|
+
const context_js_1 = require("../context.js");
|
|
4
5
|
const iframe_observer_js_1 = require("./iframe_observer.js");
|
|
5
6
|
const shadow_root_observer_js_1 = require("./shadow_root_observer.js");
|
|
6
7
|
const index_js_1 = require("../../messages/index.js");
|
|
7
8
|
const attachShadowNativeFn = Element.prototype.attachShadow;
|
|
8
9
|
class TopObserver extends observer_js_1.default {
|
|
9
10
|
constructor(app, options) {
|
|
10
|
-
super(app
|
|
11
|
-
captureIFrames: false
|
|
12
|
-
}, options));
|
|
11
|
+
super(app);
|
|
13
12
|
this.iframeObservers = [];
|
|
14
13
|
this.shadowRootObservers = [];
|
|
14
|
+
this.options = Object.assign({
|
|
15
|
+
captureIFrames: false
|
|
16
|
+
}, options);
|
|
15
17
|
// IFrames
|
|
16
18
|
this.app.nodes.attachNodeCallback(node => {
|
|
17
|
-
if ((0,
|
|
19
|
+
if ((0, context_js_1.isInstance)(node, HTMLIFrameElement) &&
|
|
18
20
|
(this.options.captureIFrames || node.getAttribute("data-openreplay-capture"))) {
|
|
19
21
|
this.handleIframe(node);
|
|
20
22
|
}
|
|
21
23
|
});
|
|
22
24
|
// ShadowDOM
|
|
23
25
|
this.app.nodes.attachNodeCallback(node => {
|
|
24
|
-
if ((0,
|
|
26
|
+
if ((0, context_js_1.isInstance)(node, Element) && node.shadowRoot !== null) {
|
|
25
27
|
this.handleShadowRoot(node.shadowRoot);
|
|
26
28
|
}
|
|
27
29
|
});
|
|
@@ -40,7 +42,7 @@ class TopObserver extends observer_js_1.default {
|
|
|
40
42
|
if (!context) {
|
|
41
43
|
return;
|
|
42
44
|
}
|
|
43
|
-
const observer = new iframe_observer_js_1.default(this.app,
|
|
45
|
+
const observer = new iframe_observer_js_1.default(this.app, context);
|
|
44
46
|
this.iframeObservers.push(observer);
|
|
45
47
|
observer.observe(iframe);
|
|
46
48
|
});
|
|
@@ -48,7 +50,7 @@ class TopObserver extends observer_js_1.default {
|
|
|
48
50
|
handle();
|
|
49
51
|
}
|
|
50
52
|
handleShadowRoot(shRoot) {
|
|
51
|
-
const observer = new shadow_root_observer_js_1.default(this.app, this.
|
|
53
|
+
const observer = new shadow_root_observer_js_1.default(this.app, this.context);
|
|
52
54
|
this.shadowRootObservers.push(observer);
|
|
53
55
|
observer.observe(shRoot.host);
|
|
54
56
|
}
|
package/cjs/app/sanitizer.d.ts
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import App from "./index.js";
|
|
2
|
+
export interface Options {
|
|
3
|
+
obscureTextEmails: boolean;
|
|
4
|
+
obscureTextNumbers: boolean;
|
|
5
|
+
}
|
|
6
|
+
export default class Sanitizer {
|
|
7
|
+
private readonly app;
|
|
8
|
+
private readonly masked;
|
|
9
|
+
private readonly options;
|
|
10
|
+
constructor(app: App, options: Partial<Options>);
|
|
11
|
+
handleNode(id: number, parentID: number, node: Node): void;
|
|
12
|
+
sanitize(id: number, data: string): string;
|
|
13
|
+
isMasked(id: number): boolean;
|
|
14
|
+
getInnerTextSecure(el: HTMLElement): string;
|
|
15
|
+
clear(): void;
|
|
16
|
+
}
|
package/cjs/app/sanitizer.js
CHANGED
|
@@ -1 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const utils_js_1 = require("../utils.js");
|
|
4
|
+
const context_js_1 = require("./context.js");
|
|
5
|
+
class Sanitizer {
|
|
6
|
+
constructor(app, options) {
|
|
7
|
+
this.app = app;
|
|
8
|
+
this.masked = new Set();
|
|
9
|
+
this.options = Object.assign({
|
|
10
|
+
obscureTextEmails: true,
|
|
11
|
+
obscureTextNumbers: false,
|
|
12
|
+
}, options);
|
|
13
|
+
}
|
|
14
|
+
handleNode(id, parentID, node) {
|
|
15
|
+
if (this.masked.has(parentID) ||
|
|
16
|
+
((0, context_js_1.isInstance)(node, Element) && (0, utils_js_1.hasOpenreplayAttribute)(node, 'masked'))) {
|
|
17
|
+
this.masked.add(id);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
sanitize(id, data) {
|
|
21
|
+
if (this.masked.has(id)) {
|
|
22
|
+
// TODO: is it the best place to put trim() ? Might trimmed spaces be considered in layout in certain cases?
|
|
23
|
+
return data.trim().replace(/[^\f\n\r\t\v\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]/g, '█');
|
|
24
|
+
}
|
|
25
|
+
if (this.options.obscureTextNumbers) {
|
|
26
|
+
data = data.replace(/\d/g, '0');
|
|
27
|
+
}
|
|
28
|
+
if (this.options.obscureTextEmails) {
|
|
29
|
+
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]));
|
|
30
|
+
}
|
|
31
|
+
return data;
|
|
32
|
+
}
|
|
33
|
+
isMasked(id) {
|
|
34
|
+
return this.masked.has(id);
|
|
35
|
+
}
|
|
36
|
+
getInnerTextSecure(el) {
|
|
37
|
+
const id = this.app.nodes.getID(el);
|
|
38
|
+
if (!id) {
|
|
39
|
+
return '';
|
|
40
|
+
}
|
|
41
|
+
return this.sanitize(id, el.innerText);
|
|
42
|
+
}
|
|
43
|
+
clear() {
|
|
44
|
+
this.masked.clear();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.default = Sanitizer;
|
package/cjs/index.d.ts
CHANGED
package/cjs/index.js
CHANGED
|
@@ -115,7 +115,7 @@ class API {
|
|
|
115
115
|
// no-cors issue only with text/plain or not-set Content-Type
|
|
116
116
|
// req.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
|
|
117
117
|
req.send(JSON.stringify({
|
|
118
|
-
trackerVersion: '3.4.
|
|
118
|
+
trackerVersion: '3.4.17-beta.0',
|
|
119
119
|
projectKey: options.projectKey,
|
|
120
120
|
doNotTrack,
|
|
121
121
|
// TODO: add precise reason (an exact API missing)
|
|
@@ -223,5 +223,11 @@ class API {
|
|
|
223
223
|
this.app.send(new index_js_3.CustomIssue(key, payload));
|
|
224
224
|
}
|
|
225
225
|
}
|
|
226
|
+
resetNextPageSession(flag) {
|
|
227
|
+
if (typeof flag !== 'boolean' || !this.app) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
this.app.resetNextPageSession(flag);
|
|
231
|
+
}
|
|
226
232
|
}
|
|
227
233
|
exports.default = API;
|