@openreplay/tracker 3.4.16 → 3.5.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/README.md +8 -1
- package/cjs/app/context.d.ts +18 -0
- package/cjs/app/context.js +48 -0
- package/cjs/app/index.d.ts +39 -9
- package/cjs/app/index.js +155 -121
- package/cjs/app/logger.d.ts +27 -0
- package/cjs/app/logger.js +42 -0
- 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 +11 -8
- package/cjs/app/sanitizer.d.ts +16 -0
- package/cjs/app/sanitizer.js +46 -0
- package/cjs/index.d.ts +10 -9
- package/cjs/index.js +32 -21
- package/cjs/modules/console.js +1 -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 +3 -1
- package/cjs/utils.d.ts +0 -8
- package/cjs/utils.js +3 -4
- package/lib/app/context.d.ts +18 -0
- package/lib/app/context.js +43 -0
- package/lib/app/index.d.ts +39 -9
- package/lib/app/index.js +156 -122
- package/lib/app/logger.d.ts +27 -0
- package/lib/app/logger.js +39 -1
- 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 +10 -7
- package/lib/app/sanitizer.d.ts +16 -0
- package/lib/app/sanitizer.js +44 -1
- package/lib/index.d.ts +10 -9
- package/lib/index.js +32 -21
- package/lib/modules/console.js +1 -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 +3 -1
- package/lib/utils.d.ts +0 -8
- package/lib/utils.js +2 -3
- 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
package/README.md
CHANGED
|
@@ -18,7 +18,14 @@ import Tracker from '@openreplay/tracker';
|
|
|
18
18
|
const tracker = new Tracker({
|
|
19
19
|
projectKey: YOUR_PROJECT_KEY,
|
|
20
20
|
});
|
|
21
|
-
tracker.start(
|
|
21
|
+
tracker.start({
|
|
22
|
+
userID: "Mr.Smith",
|
|
23
|
+
metadata: {
|
|
24
|
+
version: "3.5.0",
|
|
25
|
+
balance: "10M",
|
|
26
|
+
role: "admin",
|
|
27
|
+
}
|
|
28
|
+
});
|
|
22
29
|
```
|
|
23
30
|
|
|
24
31
|
Then you can use OpenReplay JavaScript API anywhere in your code.
|
|
@@ -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,55 +1,84 @@
|
|
|
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
|
+
import Logger from "./logger.js";
|
|
5
6
|
import type { Options as ObserverOptions } from "./observer/top_observer.js";
|
|
7
|
+
import type { Options as SanitizerOptions } from "./sanitizer.js";
|
|
8
|
+
import type { Options as LoggerOptions } from "./logger.js";
|
|
6
9
|
import type { Options as WebworkerOptions } from "../messages/webworker.js";
|
|
7
10
|
export interface OnStartInfo {
|
|
8
11
|
sessionID: string;
|
|
9
12
|
sessionToken: string;
|
|
10
13
|
userUUID: string;
|
|
11
14
|
}
|
|
12
|
-
export
|
|
15
|
+
export interface StartOptions {
|
|
16
|
+
userID?: string;
|
|
17
|
+
metadata?: Record<string, string>;
|
|
18
|
+
forceNew: boolean;
|
|
19
|
+
}
|
|
20
|
+
declare type AppOptions = {
|
|
13
21
|
revID: string;
|
|
14
22
|
node_id: string;
|
|
15
23
|
session_token_key: string;
|
|
16
24
|
session_pageno_key: string;
|
|
25
|
+
session_reset_key: string;
|
|
17
26
|
local_uuid_key: string;
|
|
18
27
|
ingestPoint: string;
|
|
19
28
|
resourceBaseHref: string | null;
|
|
29
|
+
verbose: boolean;
|
|
20
30
|
__is_snippet: boolean;
|
|
21
31
|
__debug_report_edp: string | null;
|
|
22
|
-
|
|
32
|
+
__debug__?: LoggerOptions;
|
|
23
33
|
onStart?: (info: OnStartInfo) => void;
|
|
24
|
-
} &
|
|
34
|
+
} & WebworkerOptions;
|
|
35
|
+
export declare type Options = AppOptions & ObserverOptions & SanitizerOptions;
|
|
25
36
|
declare type Callback = () => void;
|
|
26
37
|
declare type CommitCallback = (messages: Array<Message>) => void;
|
|
38
|
+
export declare const CANCELED = "canceled";
|
|
27
39
|
export declare const DEFAULT_INGEST_POINT = "https://api.openreplay.com/ingest";
|
|
28
40
|
export default class App {
|
|
29
41
|
readonly nodes: Nodes;
|
|
30
42
|
readonly ticker: Ticker;
|
|
31
43
|
readonly projectKey: string;
|
|
44
|
+
readonly sanitizer: Sanitizer;
|
|
45
|
+
readonly debug: Logger;
|
|
46
|
+
readonly notify: Logger;
|
|
32
47
|
private readonly messages;
|
|
33
|
-
readonly observer
|
|
48
|
+
private readonly observer;
|
|
34
49
|
private readonly startCallbacks;
|
|
35
50
|
private readonly stopCallbacks;
|
|
36
51
|
private readonly commitCallbacks;
|
|
37
52
|
private readonly options;
|
|
38
53
|
private readonly revID;
|
|
39
54
|
private _sessionID;
|
|
40
|
-
private
|
|
55
|
+
private _userID;
|
|
56
|
+
private _metadata;
|
|
57
|
+
private activityState;
|
|
41
58
|
private version;
|
|
42
59
|
private readonly worker?;
|
|
43
|
-
constructor(projectKey: string, sessionToken: string | null | undefined,
|
|
60
|
+
constructor(projectKey: string, sessionToken: string | null | undefined, options: Partial<Options>);
|
|
44
61
|
private _debug;
|
|
45
62
|
send(message: Message, urgent?: boolean): void;
|
|
46
63
|
private commit;
|
|
47
64
|
attachCommitCallback(cb: CommitCallback): void;
|
|
48
|
-
addCommitCallback(cb: CommitCallback): void;
|
|
49
65
|
safe<T extends (...args: any[]) => void>(fn: T): T;
|
|
50
66
|
attachStartCallback(cb: Callback): void;
|
|
51
67
|
attachStopCallback(cb: Callback): void;
|
|
52
68
|
attachEventListener(target: EventTarget, type: string, listener: EventListener, useSafe?: boolean, useCapture?: boolean): void;
|
|
69
|
+
checkRequiredVersion(version: string): boolean;
|
|
70
|
+
private getStartInfo;
|
|
71
|
+
getSessionInfo(): {
|
|
72
|
+
userUUID: string | null;
|
|
73
|
+
projectKey: string;
|
|
74
|
+
revID: string;
|
|
75
|
+
timestamp: number;
|
|
76
|
+
trackerVersion: string;
|
|
77
|
+
userID: string | null;
|
|
78
|
+
isSnippet: boolean;
|
|
79
|
+
sessionID: string | null;
|
|
80
|
+
metadata: Record<string, string>;
|
|
81
|
+
};
|
|
53
82
|
getSessionToken(): string | undefined;
|
|
54
83
|
getSessionID(): string | undefined;
|
|
55
84
|
getHost(): string;
|
|
@@ -58,8 +87,9 @@ export default class App {
|
|
|
58
87
|
resolveResourceURL(resourceURL: string): string;
|
|
59
88
|
isServiceURL(url: string): boolean;
|
|
60
89
|
active(): boolean;
|
|
90
|
+
resetNextPageSession(flag: boolean): void;
|
|
61
91
|
private _start;
|
|
62
|
-
start(
|
|
92
|
+
start(options?: StartOptions): Promise<OnStartInfo>;
|
|
63
93
|
stop(): void;
|
|
64
94
|
}
|
|
65
95
|
export {};
|
package/cjs/app/index.js
CHANGED
|
@@ -1,49 +1,64 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_INGEST_POINT = void 0;
|
|
3
|
+
exports.DEFAULT_INGEST_POINT = exports.CANCELED = void 0;
|
|
4
4
|
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");
|
|
10
|
+
const logger_js_1 = require("./logger.js");
|
|
9
11
|
const performance_js_1 = require("../modules/performance.js");
|
|
12
|
+
var ActivityState;
|
|
13
|
+
(function (ActivityState) {
|
|
14
|
+
ActivityState[ActivityState["NotActive"] = 0] = "NotActive";
|
|
15
|
+
ActivityState[ActivityState["Starting"] = 1] = "Starting";
|
|
16
|
+
ActivityState[ActivityState["Active"] = 2] = "Active";
|
|
17
|
+
})(ActivityState || (ActivityState = {}));
|
|
18
|
+
exports.CANCELED = "canceled";
|
|
10
19
|
// TODO: use backendHost only
|
|
11
20
|
exports.DEFAULT_INGEST_POINT = 'https://api.openreplay.com/ingest';
|
|
12
21
|
class App {
|
|
13
|
-
constructor(projectKey, sessionToken,
|
|
22
|
+
constructor(projectKey, sessionToken, options) {
|
|
23
|
+
// if (options.onStart !== undefined) {
|
|
24
|
+
// deprecationWarn("'onStart' option", "tracker.start().then(/* handle session info */)")
|
|
25
|
+
// } ?? maybe onStart is good
|
|
14
26
|
this.messages = [];
|
|
15
27
|
this.startCallbacks = [];
|
|
16
28
|
this.stopCallbacks = [];
|
|
17
29
|
this.commitCallbacks = [];
|
|
18
30
|
this._sessionID = null;
|
|
19
|
-
this.
|
|
20
|
-
this.
|
|
31
|
+
this._userID = null;
|
|
32
|
+
this._metadata = {};
|
|
33
|
+
this.activityState = ActivityState.NotActive;
|
|
34
|
+
this.version = '3.5.0'; // TODO: version compatability check inside each plugin.
|
|
21
35
|
this.projectKey = projectKey;
|
|
22
36
|
this.options = Object.assign({
|
|
23
37
|
revID: '',
|
|
24
38
|
node_id: '__openreplay_id',
|
|
25
39
|
session_token_key: '__openreplay_token',
|
|
26
40
|
session_pageno_key: '__openreplay_pageno',
|
|
41
|
+
session_reset_key: '__openreplay_reset',
|
|
27
42
|
local_uuid_key: '__openreplay_uuid',
|
|
28
43
|
ingestPoint: exports.DEFAULT_INGEST_POINT,
|
|
29
44
|
resourceBaseHref: null,
|
|
45
|
+
verbose: false,
|
|
30
46
|
__is_snippet: false,
|
|
31
47
|
__debug_report_edp: null,
|
|
32
|
-
|
|
33
|
-
obscureTextEmails: true,
|
|
34
|
-
obscureTextNumbers: false,
|
|
35
|
-
captureIFrames: false,
|
|
36
|
-
}, opts);
|
|
48
|
+
}, options);
|
|
37
49
|
if (sessionToken != null) {
|
|
38
50
|
sessionStorage.setItem(this.options.session_token_key, sessionToken);
|
|
39
51
|
}
|
|
40
52
|
this.revID = this.options.revID;
|
|
53
|
+
this.sanitizer = new sanitizer_js_1.default(this, options);
|
|
41
54
|
this.nodes = new nodes_js_1.default(this.options.node_id);
|
|
42
|
-
this.observer = new top_observer_js_1.default(this,
|
|
55
|
+
this.observer = new top_observer_js_1.default(this, options);
|
|
43
56
|
this.ticker = new ticker_js_1.default(this);
|
|
44
57
|
this.ticker.attach(() => this.commit());
|
|
58
|
+
this.debug = new logger_js_1.default(this.options.__debug__);
|
|
59
|
+
this.notify = new logger_js_1.default(this.options.verbose ? logger_js_1.LogLevel.Warnings : logger_js_1.LogLevel.Silent);
|
|
45
60
|
try {
|
|
46
|
-
this.worker = new Worker(URL.createObjectURL(new Blob([`"use strict";function t(t){function s(...s){return new t(...s)}return s.prototype=t.prototype,s}const s=new Map;const i=t(class{constructor(t,s,i){this.pageNo=t,this.firstIndex=s,this.timestamp=i,this._id=80}encode(t){return t.uint(80)&&t.uint(this.pageNo)&&t.uint(this.firstIndex)&&t.int(this.timestamp)}});s.set(80,i);const n=t(class{constructor(t){this.timestamp=t,this._id=0}encode(t){return t.uint(0)&&t.uint(this.timestamp)}});s.set(0,n);const e=t(class{constructor(t,s,i){this.url=t,this.referrer=s,this.navigationStart=i,this._id=4}encode(t){return t.uint(4)&&t.string(this.url)&&t.string(this.referrer)&&t.uint(this.navigationStart)}});s.set(4,e);const r=t(class{constructor(t,s){this.width=t,this.height=s,this._id=5}encode(t){return t.uint(5)&&t.uint(this.width)&&t.uint(this.height)}});s.set(5,r);const o=t(class{constructor(t,s){this.x=t,this.y=s,this._id=6}encode(t){return t.uint(6)&&t.int(this.x)&&t.int(this.y)}});s.set(6,o);const h=t(class{constructor(){this._id=7}encode(t){return t.uint(7)}});s.set(7,h);const c=t(class{constructor(t,s,i,n,e){this.id=t,this.parentID=s,this.index=i,this.tag=n,this.svg=e,this._id=8}encode(t){return t.uint(8)&&t.uint(this.id)&&t.uint(this.parentID)&&t.uint(this.index)&&t.string(this.tag)&&t.boolean(this.svg)}});s.set(8,c);const u=t(class{constructor(t,s,i){this.id=t,this.parentID=s,this.index=i,this._id=9}encode(t){return t.uint(9)&&t.uint(this.id)&&t.uint(this.parentID)&&t.uint(this.index)}});s.set(9,u);const a=t(class{constructor(t,s,i){this.id=t,this.parentID=s,this.index=i,this._id=10}encode(t){return t.uint(10)&&t.uint(this.id)&&t.uint(this.parentID)&&t.uint(this.index)}});s.set(10,a);const d=t(class{constructor(t){this.id=t,this._id=11}encode(t){return t.uint(11)&&t.uint(this.id)}});s.set(11,d);const l=t(class{constructor(t,s,i){this.id=t,this.name=s,this.value=i,this._id=12}encode(t){return t.uint(12)&&t.uint(this.id)&&t.string(this.name)&&t.string(this.value)}});s.set(12,l);const g=t(class{constructor(t,s){this.id=t,this.name=s,this._id=13}encode(t){return t.uint(13)&&t.uint(this.id)&&t.string(this.name)}});s.set(13,g);const f=t(class{constructor(t,s){this.id=t,this.data=s,this._id=14}encode(t){return t.uint(14)&&t.uint(this.id)&&t.string(this.data)}});s.set(14,f);const p=t(class{constructor(t,s,i){this.id=t,this.x=s,this.y=i,this._id=16}encode(t){return t.uint(16)&&t.uint(this.id)&&t.int(this.x)&&t.int(this.y)}});s.set(16,p);const m=t(class{constructor(t,s){this.id=t,this.label=s,this._id=17}encode(t){return t.uint(17)&&t.uint(this.id)&&t.string(this.label)}});s.set(17,m);const _=t(class{constructor(t,s,i){this.id=t,this.value=s,this.mask=i,this._id=18}encode(t){return t.uint(18)&&t.uint(this.id)&&t.string(this.value)&&t.int(this.mask)}});s.set(18,_);const y=t(class{constructor(t,s){this.id=t,this.checked=s,this._id=19}encode(t){return t.uint(19)&&t.uint(this.id)&&t.boolean(this.checked)}});s.set(19,y);const v=t(class{constructor(t,s){this.x=t,this.y=s,this._id=20}encode(t){return t.uint(20)&&t.uint(this.x)&&t.uint(this.y)}});s.set(20,v);const S=t(class{constructor(t,s){this.level=t,this.value=s,this._id=22}encode(t){return t.uint(22)&&t.string(this.level)&&t.string(this.value)}});s.set(22,S);const b=t(class{constructor(t,s,i,n,e,r,o,h,c){this.requestStart=t,this.responseStart=s,this.responseEnd=i,this.domContentLoadedEventStart=n,this.domContentLoadedEventEnd=e,this.loadEventStart=r,this.loadEventEnd=o,this.firstPaint=h,this.firstContentfulPaint=c,this._id=23}encode(t){return t.uint(23)&&t.uint(this.requestStart)&&t.uint(this.responseStart)&&t.uint(this.responseEnd)&&t.uint(this.domContentLoadedEventStart)&&t.uint(this.domContentLoadedEventEnd)&&t.uint(this.loadEventStart)&&t.uint(this.loadEventEnd)&&t.uint(this.firstPaint)&&t.uint(this.firstContentfulPaint)}});s.set(23,b);const x=t(class{constructor(t,s,i){this.speedIndex=t,this.visuallyComplete=s,this.timeToInteractive=i,this._id=24}encode(t){return t.uint(24)&&t.uint(this.speedIndex)&&t.uint(this.visuallyComplete)&&t.uint(this.timeToInteractive)}});s.set(24,x);const E=t(class{constructor(t,s,i){this.name=t,this.message=s,this.payload=i,this._id=25}encode(t){return t.uint(25)&&t.string(this.name)&&t.string(this.message)&&t.string(this.payload)}});s.set(25,E);const k=t(class{constructor(t,s){this.name=t,this.payload=s,this._id=27}encode(t){return t.uint(27)&&t.string(this.name)&&t.string(this.payload)}});s.set(27,k);const I=t(class{constructor(t){this.id=t,this._id=28}encode(t){return t.uint(28)&&t.string(this.id)}});s.set(28,I);const z=t(class{constructor(t){this.id=t,this._id=29}encode(t){return t.uint(29)&&t.string(this.id)}});s.set(29,z);const w=t(class{constructor(t,s){this.key=t,this.value=s,this._id=30}encode(t){return t.uint(30)&&t.string(this.key)&&t.string(this.value)}});s.set(30,w);const T=t(class{constructor(t,s,i){this.id=t,this.rule=s,this.index=i,this._id=37}encode(t){return t.uint(37)&&t.uint(this.id)&&t.string(this.rule)&&t.uint(this.index)}});s.set(37,T);const L=t(class{constructor(t,s){this.id=t,this.index=s,this._id=38}encode(t){return t.uint(38)&&t.uint(this.id)&&t.uint(this.index)}});s.set(38,L);const A=t(class{constructor(t,s,i,n,e,r,o){this.method=t,this.url=s,this.request=i,this.response=n,this.status=e,this.timestamp=r,this.duration=o,this._id=39}encode(t){return t.uint(39)&&t.string(this.method)&&t.string(this.url)&&t.string(this.request)&&t.string(this.response)&&t.uint(this.status)&&t.uint(this.timestamp)&&t.uint(this.duration)}});s.set(39,A);const C=t(class{constructor(t,s,i,n){this.name=t,this.duration=s,this.args=i,this.result=n,this._id=40}encode(t){return t.uint(40)&&t.string(this.name)&&t.uint(this.duration)&&t.string(this.args)&&t.string(this.result)}});s.set(40,C);const M=t(class{constructor(t,s){this.key=t,this.value=s,this._id=41}encode(t){return t.uint(41)&&t.string(this.key)&&t.string(this.value)}});s.set(41,M);const R=t(class{constructor(t){this.type=t,this._id=42}encode(t){return t.uint(42)&&t.string(this.type)}});s.set(42,R);const N=t(class{constructor(t,s,i){this.action=t,this.state=s,this.duration=i,this._id=44}encode(t){return t.uint(44)&&t.string(this.action)&&t.string(this.state)&&t.uint(this.duration)}});s.set(44,N);const D=t(class{constructor(t,s){this.mutation=t,this.state=s,this._id=45}encode(t){return t.uint(45)&&t.string(this.mutation)&&t.string(this.state)}});s.set(45,D);const U=t(class{constructor(t,s){this.type=t,this.payload=s,this._id=46}encode(t){return t.uint(46)&&t.string(this.type)&&t.string(this.payload)}});s.set(46,U);const O=t(class{constructor(t,s,i){this.action=t,this.state=s,this.duration=i,this._id=47}encode(t){return t.uint(47)&&t.string(this.action)&&t.string(this.state)&&t.uint(this.duration)}});s.set(47,O);const q=t(class{constructor(t,s,i,n){this.operationKind=t,this.operationName=s,this.variables=i,this.response=n,this._id=48}encode(t){return t.uint(48)&&t.string(this.operationKind)&&t.string(this.operationName)&&t.string(this.variables)&&t.string(this.response)}});s.set(48,q);const H=t(class{constructor(t,s,i,n){this.frames=t,this.ticks=s,this.totalJSHeapSize=i,this.usedJSHeapSize=n,this._id=49}encode(t){return t.uint(49)&&t.int(this.frames)&&t.int(this.ticks)&&t.uint(this.totalJSHeapSize)&&t.uint(this.usedJSHeapSize)}});s.set(49,H);const P=t(class{constructor(t,s,i,n,e,r,o,h){this.timestamp=t,this.duration=s,this.ttfb=i,this.headerSize=n,this.encodedBodySize=e,this.decodedBodySize=r,this.url=o,this.initiator=h,this._id=53}encode(t){return t.uint(53)&&t.uint(this.timestamp)&&t.uint(this.duration)&&t.uint(this.ttfb)&&t.uint(this.headerSize)&&t.uint(this.encodedBodySize)&&t.uint(this.decodedBodySize)&&t.string(this.url)&&t.string(this.initiator)}});s.set(53,P);const B=t(class{constructor(t,s){this.downlink=t,this.type=s,this._id=54}encode(t){return t.uint(54)&&t.uint(this.downlink)&&t.string(this.type)}});s.set(54,B);const J=t(class{constructor(t){this.hidden=t,this._id=55}encode(t){return t.uint(55)&&t.boolean(this.hidden)}});s.set(55,J);const j=t(class{constructor(t,s,i,n,e,r,o){this.timestamp=t,this.duration=s,this.context=i,this.containerType=n,this.containerSrc=e,this.containerId=r,this.containerName=o,this._id=59}encode(t){return t.uint(59)&&t.uint(this.timestamp)&&t.uint(this.duration)&&t.uint(this.context)&&t.uint(this.containerType)&&t.string(this.containerSrc)&&t.string(this.containerId)&&t.string(this.containerName)}});s.set(59,j);const G=t(class{constructor(t,s,i,n){this.id=t,this.name=s,this.value=i,this.baseURL=n,this._id=60}encode(t){return t.uint(60)&&t.uint(this.id)&&t.string(this.name)&&t.string(this.value)&&t.string(this.baseURL)}});s.set(60,G);const K=t(class{constructor(t,s,i){this.id=t,this.data=s,this.baseURL=i,this._id=61}encode(t){return t.uint(61)&&t.uint(this.id)&&t.string(this.data)&&t.string(this.baseURL)}});s.set(61,K);const X=t(class{constructor(t,s){this.type=t,this.value=s,this._id=63}encode(t){return t.uint(63)&&t.string(this.type)&&t.string(this.value)}});s.set(63,X);const F=t(class{constructor(t,s){this.name=t,this.payload=s,this._id=64}encode(t){return t.uint(64)&&t.string(this.name)&&t.string(this.payload)}});s.set(64,F);const Q=t(class{constructor(){this._id=65}encode(t){return t.uint(65)}});s.set(65,Q);const V=t(class{constructor(t,s,i,n){this.id=t,this.rule=s,this.index=i,this.baseURL=n,this._id=67}encode(t){return t.uint(67)&&t.uint(this.id)&&t.string(this.rule)&&t.uint(this.index)&&t.string(this.baseURL)}});s.set(67,V);const W=t(class{constructor(t,s,i,n){this.id=t,this.hesitationTime=s,this.label=i,this.selector=n,this._id=69}encode(t){return t.uint(69)&&t.uint(this.id)&&t.uint(this.hesitationTime)&&t.string(this.label)&&t.string(this.selector)}});s.set(69,W);const Y=t(class{constructor(t,s){this.frameID=t,this.id=s,this._id=70}encode(t){return t.uint(70)&&t.uint(this.frameID)&&t.uint(this.id)}});s.set(70,Y);const Z="function"==typeof TextEncoder?new TextEncoder:{encode(t){const s=t.length,i=new Uint8Array(3*s);let n=-1;for(var e=0,r=0,o=0;o!==s;){if(e=t.charCodeAt(o),o+=1,e>=55296&&e<=56319){if(o===s){i[n+=1]=239,i[n+=1]=191,i[n+=1]=189;break}if(!((r=t.charCodeAt(o))>=56320&&r<=57343)){i[n+=1]=239,i[n+=1]=191,i[n+=1]=189;continue}if(o+=1,(e=1024*(e-55296)+r-56320+65536)>65535){i[n+=1]=240|e>>>18,i[n+=1]=128|e>>>12&63,i[n+=1]=128|e>>>6&63,i[n+=1]=128|63&e;continue}}e<=127?i[n+=1]=0|e:e<=2047?(i[n+=1]=192|e>>>6,i[n+=1]=128|63&e):(i[n+=1]=224|e>>>12,i[n+=1]=128|e>>>6&63,i[n+=1]=128|63&e)}return i.subarray(0,n+1)}};class tt{constructor(t){this.size=t,this.offset=0,this.checkpointOffset=0,this.data=new Uint8Array(t)}checkpoint(){this.checkpointOffset=this.offset}isEmpty(){return 0===this.offset}boolean(t){return this.data[this.offset++]=+t,this.offset<=this.size}uint(t){for((t<0||t>Number.MAX_SAFE_INTEGER)&&(t=0);t>=128;)this.data[this.offset++]=t%256|128,t=Math.floor(t/128);return this.data[this.offset++]=t,this.offset<=this.size}int(t){return t=Math.round(t),this.uint(t>=0?2*t:-2*t-1)}string(t){const s=Z.encode(t),i=s.byteLength;return!(!this.uint(i)||this.offset+i>this.size)&&(this.data.set(s,this.offset),this.offset+=i,!0)}reset(){this.offset=0,this.checkpointOffset=0}flush(){const t=this.data.slice(0,this.checkpointOffset);return this.reset(),t}}let st=1e6,it=2e5,nt=new tt(it),et="",rt="",ot=0,ht=0,ct=0,ut=0,at=!0;function dt(){return new i(ot,ut,ht).encode(nt)}let lt=null;const gt=[];let ft,pt=!1,mt=0,_t=8e3,yt=10;function vt(){if(at||""===rt||""===et)return;const t=nt.flush();pt?gt.push(t):(pt=!0,function t(s){const i=new XMLHttpRequest;i.open("POST",et+"/v1/web/i",!1),i.setRequestHeader("Authorization","Bearer "+rt),i.onreadystatechange=function(){if(4===this.readyState){if(0==this.status)return;if(this.status>=400)return St(),gt.length=0,401===this.status?void self.postMessage("restart"):void self.postMessage(null);const s=gt.shift();s?t(s):pt=!1}},i.onerror=function(i){if(mt>=yt)return St(),void self.postMessage(null);mt++,setTimeout(()=>t(s),_t)},i.send(s.buffer)}(t)),at=!0,dt()}function St(){et="",rt="",null!==lt&&(clearInterval(lt),lt=null),nt.reset()}self.onmessage=({data:t})=>{if(null!==t)return"stop"===t?(vt(),void St()):Array.isArray(t)?void t.forEach(t=>{const i=new(s.get(t._id));if(Object.assign(i,t),i instanceof n?ht=i.timestamp:i instanceof J&&(i.hidden?ft=setTimeout(()=>self.postMessage("restart"),18e5):clearTimeout(ft)),nt.checkpoint(),!i.encode(nt)&&(vt(),!i.encode(nt)))for(;!i.encode(nt);){if(it===st)return console.warn("OpenReplay: beacon size overflow."),nt.reset(),void dt();it=Math.min(2*it,st),nt=new tt(it),dt()}ut++,at=!1}):(et=t.ingestPoint||et,rt=t.token||rt,ot=t.pageNo||ot,ht=t.startTimestamp||ht,ct=t.timeAdjustment||ct,yt=t.connAttemptCount||yt,_t=t.connAttemptGap||_t,st=t.beaconSizeLimit||st,it=Math.min(st,t.beaconSize||it),nt.isEmpty()&&dt(),void(null===lt&&(lt=setInterval(vt,1e4))));vt()};
|
|
61
|
+
this.worker = new Worker(URL.createObjectURL(new Blob([`"use strict";function t(t){function s(...s){return new t(...s)}return s.prototype=t.prototype,s}const s=new Map;const i=t(class{constructor(t,s,i){this.pageNo=t,this.firstIndex=s,this.timestamp=i,this._id=80}encode(t){return t.uint(80)&&t.uint(this.pageNo)&&t.uint(this.firstIndex)&&t.int(this.timestamp)}});s.set(80,i);const n=t(class{constructor(t){this.timestamp=t,this._id=0}encode(t){return t.uint(0)&&t.uint(this.timestamp)}});s.set(0,n);const e=t(class{constructor(t,s,i){this.url=t,this.referrer=s,this.navigationStart=i,this._id=4}encode(t){return t.uint(4)&&t.string(this.url)&&t.string(this.referrer)&&t.uint(this.navigationStart)}});s.set(4,e);const r=t(class{constructor(t,s){this.width=t,this.height=s,this._id=5}encode(t){return t.uint(5)&&t.uint(this.width)&&t.uint(this.height)}});s.set(5,r);const o=t(class{constructor(t,s){this.x=t,this.y=s,this._id=6}encode(t){return t.uint(6)&&t.int(this.x)&&t.int(this.y)}});s.set(6,o);const h=t(class{constructor(){this._id=7}encode(t){return t.uint(7)}});s.set(7,h);const c=t(class{constructor(t,s,i,n,e){this.id=t,this.parentID=s,this.index=i,this.tag=n,this.svg=e,this._id=8}encode(t){return t.uint(8)&&t.uint(this.id)&&t.uint(this.parentID)&&t.uint(this.index)&&t.string(this.tag)&&t.boolean(this.svg)}});s.set(8,c);const u=t(class{constructor(t,s,i){this.id=t,this.parentID=s,this.index=i,this._id=9}encode(t){return t.uint(9)&&t.uint(this.id)&&t.uint(this.parentID)&&t.uint(this.index)}});s.set(9,u);const a=t(class{constructor(t,s,i){this.id=t,this.parentID=s,this.index=i,this._id=10}encode(t){return t.uint(10)&&t.uint(this.id)&&t.uint(this.parentID)&&t.uint(this.index)}});s.set(10,a);const d=t(class{constructor(t){this.id=t,this._id=11}encode(t){return t.uint(11)&&t.uint(this.id)}});s.set(11,d);const l=t(class{constructor(t,s,i){this.id=t,this.name=s,this.value=i,this._id=12}encode(t){return t.uint(12)&&t.uint(this.id)&&t.string(this.name)&&t.string(this.value)}});s.set(12,l);const g=t(class{constructor(t,s){this.id=t,this.name=s,this._id=13}encode(t){return t.uint(13)&&t.uint(this.id)&&t.string(this.name)}});s.set(13,g);const f=t(class{constructor(t,s){this.id=t,this.data=s,this._id=14}encode(t){return t.uint(14)&&t.uint(this.id)&&t.string(this.data)}});s.set(14,f);const p=t(class{constructor(t,s,i){this.id=t,this.x=s,this.y=i,this._id=16}encode(t){return t.uint(16)&&t.uint(this.id)&&t.int(this.x)&&t.int(this.y)}});s.set(16,p);const m=t(class{constructor(t,s){this.id=t,this.label=s,this._id=17}encode(t){return t.uint(17)&&t.uint(this.id)&&t.string(this.label)}});s.set(17,m);const _=t(class{constructor(t,s,i){this.id=t,this.value=s,this.mask=i,this._id=18}encode(t){return t.uint(18)&&t.uint(this.id)&&t.string(this.value)&&t.int(this.mask)}});s.set(18,_);const y=t(class{constructor(t,s){this.id=t,this.checked=s,this._id=19}encode(t){return t.uint(19)&&t.uint(this.id)&&t.boolean(this.checked)}});s.set(19,y);const v=t(class{constructor(t,s){this.x=t,this.y=s,this._id=20}encode(t){return t.uint(20)&&t.uint(this.x)&&t.uint(this.y)}});s.set(20,v);const S=t(class{constructor(t,s){this.level=t,this.value=s,this._id=22}encode(t){return t.uint(22)&&t.string(this.level)&&t.string(this.value)}});s.set(22,S);const b=t(class{constructor(t,s,i,n,e,r,o,h,c){this.requestStart=t,this.responseStart=s,this.responseEnd=i,this.domContentLoadedEventStart=n,this.domContentLoadedEventEnd=e,this.loadEventStart=r,this.loadEventEnd=o,this.firstPaint=h,this.firstContentfulPaint=c,this._id=23}encode(t){return t.uint(23)&&t.uint(this.requestStart)&&t.uint(this.responseStart)&&t.uint(this.responseEnd)&&t.uint(this.domContentLoadedEventStart)&&t.uint(this.domContentLoadedEventEnd)&&t.uint(this.loadEventStart)&&t.uint(this.loadEventEnd)&&t.uint(this.firstPaint)&&t.uint(this.firstContentfulPaint)}});s.set(23,b);const x=t(class{constructor(t,s,i){this.speedIndex=t,this.visuallyComplete=s,this.timeToInteractive=i,this._id=24}encode(t){return t.uint(24)&&t.uint(this.speedIndex)&&t.uint(this.visuallyComplete)&&t.uint(this.timeToInteractive)}});s.set(24,x);const E=t(class{constructor(t,s,i){this.name=t,this.message=s,this.payload=i,this._id=25}encode(t){return t.uint(25)&&t.string(this.name)&&t.string(this.message)&&t.string(this.payload)}});s.set(25,E);const k=t(class{constructor(t,s){this.name=t,this.payload=s,this._id=27}encode(t){return t.uint(27)&&t.string(this.name)&&t.string(this.payload)}});s.set(27,k);const I=t(class{constructor(t){this.id=t,this._id=28}encode(t){return t.uint(28)&&t.string(this.id)}});s.set(28,I);const z=t(class{constructor(t){this.id=t,this._id=29}encode(t){return t.uint(29)&&t.string(this.id)}});s.set(29,z);const w=t(class{constructor(t,s){this.key=t,this.value=s,this._id=30}encode(t){return t.uint(30)&&t.string(this.key)&&t.string(this.value)}});s.set(30,w);const T=t(class{constructor(t,s,i){this.id=t,this.rule=s,this.index=i,this._id=37}encode(t){return t.uint(37)&&t.uint(this.id)&&t.string(this.rule)&&t.uint(this.index)}});s.set(37,T);const L=t(class{constructor(t,s){this.id=t,this.index=s,this._id=38}encode(t){return t.uint(38)&&t.uint(this.id)&&t.uint(this.index)}});s.set(38,L);const A=t(class{constructor(t,s,i,n,e,r,o){this.method=t,this.url=s,this.request=i,this.response=n,this.status=e,this.timestamp=r,this.duration=o,this._id=39}encode(t){return t.uint(39)&&t.string(this.method)&&t.string(this.url)&&t.string(this.request)&&t.string(this.response)&&t.uint(this.status)&&t.uint(this.timestamp)&&t.uint(this.duration)}});s.set(39,A);const C=t(class{constructor(t,s,i,n){this.name=t,this.duration=s,this.args=i,this.result=n,this._id=40}encode(t){return t.uint(40)&&t.string(this.name)&&t.uint(this.duration)&&t.string(this.args)&&t.string(this.result)}});s.set(40,C);const M=t(class{constructor(t,s){this.key=t,this.value=s,this._id=41}encode(t){return t.uint(41)&&t.string(this.key)&&t.string(this.value)}});s.set(41,M);const R=t(class{constructor(t){this.type=t,this._id=42}encode(t){return t.uint(42)&&t.string(this.type)}});s.set(42,R);const N=t(class{constructor(t,s,i){this.action=t,this.state=s,this.duration=i,this._id=44}encode(t){return t.uint(44)&&t.string(this.action)&&t.string(this.state)&&t.uint(this.duration)}});s.set(44,N);const D=t(class{constructor(t,s){this.mutation=t,this.state=s,this._id=45}encode(t){return t.uint(45)&&t.string(this.mutation)&&t.string(this.state)}});s.set(45,D);const U=t(class{constructor(t,s){this.type=t,this.payload=s,this._id=46}encode(t){return t.uint(46)&&t.string(this.type)&&t.string(this.payload)}});s.set(46,U);const O=t(class{constructor(t,s,i){this.action=t,this.state=s,this.duration=i,this._id=47}encode(t){return t.uint(47)&&t.string(this.action)&&t.string(this.state)&&t.uint(this.duration)}});s.set(47,O);const q=t(class{constructor(t,s,i,n){this.operationKind=t,this.operationName=s,this.variables=i,this.response=n,this._id=48}encode(t){return t.uint(48)&&t.string(this.operationKind)&&t.string(this.operationName)&&t.string(this.variables)&&t.string(this.response)}});s.set(48,q);const H=t(class{constructor(t,s,i,n){this.frames=t,this.ticks=s,this.totalJSHeapSize=i,this.usedJSHeapSize=n,this._id=49}encode(t){return t.uint(49)&&t.int(this.frames)&&t.int(this.ticks)&&t.uint(this.totalJSHeapSize)&&t.uint(this.usedJSHeapSize)}});s.set(49,H);const P=t(class{constructor(t,s,i,n,e,r,o,h){this.timestamp=t,this.duration=s,this.ttfb=i,this.headerSize=n,this.encodedBodySize=e,this.decodedBodySize=r,this.url=o,this.initiator=h,this._id=53}encode(t){return t.uint(53)&&t.uint(this.timestamp)&&t.uint(this.duration)&&t.uint(this.ttfb)&&t.uint(this.headerSize)&&t.uint(this.encodedBodySize)&&t.uint(this.decodedBodySize)&&t.string(this.url)&&t.string(this.initiator)}});s.set(53,P);const B=t(class{constructor(t,s){this.downlink=t,this.type=s,this._id=54}encode(t){return t.uint(54)&&t.uint(this.downlink)&&t.string(this.type)}});s.set(54,B);const J=t(class{constructor(t){this.hidden=t,this._id=55}encode(t){return t.uint(55)&&t.boolean(this.hidden)}});s.set(55,J);const j=t(class{constructor(t,s,i,n,e,r,o){this.timestamp=t,this.duration=s,this.context=i,this.containerType=n,this.containerSrc=e,this.containerId=r,this.containerName=o,this._id=59}encode(t){return t.uint(59)&&t.uint(this.timestamp)&&t.uint(this.duration)&&t.uint(this.context)&&t.uint(this.containerType)&&t.string(this.containerSrc)&&t.string(this.containerId)&&t.string(this.containerName)}});s.set(59,j);const G=t(class{constructor(t,s,i,n){this.id=t,this.name=s,this.value=i,this.baseURL=n,this._id=60}encode(t){return t.uint(60)&&t.uint(this.id)&&t.string(this.name)&&t.string(this.value)&&t.string(this.baseURL)}});s.set(60,G);const K=t(class{constructor(t,s,i){this.id=t,this.data=s,this.baseURL=i,this._id=61}encode(t){return t.uint(61)&&t.uint(this.id)&&t.string(this.data)&&t.string(this.baseURL)}});s.set(61,K);const X=t(class{constructor(t,s){this.type=t,this.value=s,this._id=63}encode(t){return t.uint(63)&&t.string(this.type)&&t.string(this.value)}});s.set(63,X);const F=t(class{constructor(t,s){this.name=t,this.payload=s,this._id=64}encode(t){return t.uint(64)&&t.string(this.name)&&t.string(this.payload)}});s.set(64,F);const Q=t(class{constructor(){this._id=65}encode(t){return t.uint(65)}});s.set(65,Q);const V=t(class{constructor(t,s,i,n){this.id=t,this.rule=s,this.index=i,this.baseURL=n,this._id=67}encode(t){return t.uint(67)&&t.uint(this.id)&&t.string(this.rule)&&t.uint(this.index)&&t.string(this.baseURL)}});s.set(67,V);const W=t(class{constructor(t,s,i,n){this.id=t,this.hesitationTime=s,this.label=i,this.selector=n,this._id=69}encode(t){return t.uint(69)&&t.uint(this.id)&&t.uint(this.hesitationTime)&&t.string(this.label)&&t.string(this.selector)}});s.set(69,W);const Y=t(class{constructor(t,s){this.frameID=t,this.id=s,this._id=70}encode(t){return t.uint(70)&&t.uint(this.frameID)&&t.uint(this.id)}});s.set(70,Y);const Z="function"==typeof TextEncoder?new TextEncoder:{encode(t){const s=t.length,i=new Uint8Array(3*s);let n=-1;for(var e=0,r=0,o=0;o!==s;){if(e=t.charCodeAt(o),o+=1,e>=55296&&e<=56319){if(o===s){i[n+=1]=239,i[n+=1]=191,i[n+=1]=189;break}if(!((r=t.charCodeAt(o))>=56320&&r<=57343)){i[n+=1]=239,i[n+=1]=191,i[n+=1]=189;continue}if(o+=1,(e=1024*(e-55296)+r-56320+65536)>65535){i[n+=1]=240|e>>>18,i[n+=1]=128|e>>>12&63,i[n+=1]=128|e>>>6&63,i[n+=1]=128|63&e;continue}}e<=127?i[n+=1]=0|e:e<=2047?(i[n+=1]=192|e>>>6,i[n+=1]=128|63&e):(i[n+=1]=224|e>>>12,i[n+=1]=128|e>>>6&63,i[n+=1]=128|63&e)}return i.subarray(0,n+1)}};class tt{constructor(t){this.size=t,this.offset=0,this.checkpointOffset=0,this.data=new Uint8Array(t)}checkpoint(){this.checkpointOffset=this.offset}isEmpty(){return 0===this.offset}boolean(t){return this.data[this.offset++]=+t,this.offset<=this.size}uint(t){for((t<0||t>Number.MAX_SAFE_INTEGER)&&(t=0);t>=128;)this.data[this.offset++]=t%256|128,t=Math.floor(t/128);return this.data[this.offset++]=t,this.offset<=this.size}int(t){return t=Math.round(t),this.uint(t>=0?2*t:-2*t-1)}string(t){const s=Z.encode(t),i=s.byteLength;return!(!this.uint(i)||this.offset+i>this.size)&&(this.data.set(s,this.offset),this.offset+=i,!0)}reset(){this.offset=0,this.checkpointOffset=0}flush(){const t=this.data.slice(0,this.checkpointOffset);return this.reset(),t}}let st=1e6,it=2e5,nt=new tt(it),et="",rt="",ot=0,ht=0,ct=0,ut=0,at=!0;function dt(){return new i(ot,ut,ht).encode(nt)}let lt=null;const gt=[];let ft,pt=!1,mt=0,_t=8e3,yt=10;function vt(){if(at||""===rt||""===et)return;const t=nt.flush();pt?gt.push(t):(pt=!0,function t(s){const i=new XMLHttpRequest;i.open("POST",et+"/v1/web/i",!1),i.setRequestHeader("Authorization","Bearer "+rt),i.onreadystatechange=function(){if(4===this.readyState){if(0==this.status)return;if(this.status>=400)return pt=!1,St(),gt.length=0,401===this.status?void self.postMessage("restart"):void self.postMessage(null);const s=gt.shift();s?t(s):pt=!1}},i.onerror=function(i){if(mt>=yt)return St(),void self.postMessage(null);mt++,setTimeout(()=>t(s),_t)},i.send(s.buffer)}(t)),at=!0,dt()}function St(){et="",rt="",null!==lt&&(clearInterval(lt),lt=null),nt.reset()}self.onmessage=({data:t})=>{if(null!==t)return"stop"===t?(vt(),void St()):Array.isArray(t)?void t.forEach(t=>{const i=new(s.get(t._id));if(Object.assign(i,t),i instanceof n?ht=i.timestamp:i instanceof J&&(i.hidden?ft=setTimeout(()=>self.postMessage("restart"),18e5):clearTimeout(ft)),nt.checkpoint(),!i.encode(nt)&&(vt(),!i.encode(nt)))for(;!i.encode(nt);){if(it===st)return console.warn("OpenReplay: beacon size overflow."),nt.reset(),void dt();it=Math.min(2*it,st),nt=new tt(it),dt()}ut++,at=!1}):(et=t.ingestPoint||et,rt=t.token||rt,ot=t.pageNo||ot,ht=t.startTimestamp||ht,ct=t.timeAdjustment||ct,yt=t.connAttemptCount||yt,_t=t.connAttemptGap||_t,st=t.beaconSizeLimit||st,it=Math.min(st,t.beaconSize||it),nt.isEmpty()&&dt(),void(null===lt&&(lt=setInterval(vt,1e4))));vt()};
|
|
47
62
|
`], { type: 'text/javascript' })));
|
|
48
63
|
this.worker.onerror = e => {
|
|
49
64
|
this._debug("webworker_error", e);
|
|
@@ -56,7 +71,11 @@ class App {
|
|
|
56
71
|
}
|
|
57
72
|
else if (data === "restart") {
|
|
58
73
|
this.stop();
|
|
59
|
-
this.start(
|
|
74
|
+
this.start({
|
|
75
|
+
forceNew: true,
|
|
76
|
+
userID: this._userID || undefined,
|
|
77
|
+
metadata: this._metadata || undefined,
|
|
78
|
+
});
|
|
60
79
|
}
|
|
61
80
|
};
|
|
62
81
|
const alertWorker = () => {
|
|
@@ -84,12 +103,10 @@ class App {
|
|
|
84
103
|
})
|
|
85
104
|
});
|
|
86
105
|
}
|
|
87
|
-
|
|
88
|
-
(0, utils_js_1.warn)("OpenReplay error: ", context, e);
|
|
89
|
-
}
|
|
106
|
+
this.debug.error("OpenReplay error: ", context, e);
|
|
90
107
|
}
|
|
91
108
|
send(message, urgent = false) {
|
|
92
|
-
if (
|
|
109
|
+
if (this.activityState !== ActivityState.Active) {
|
|
93
110
|
return;
|
|
94
111
|
}
|
|
95
112
|
this.messages.push(message);
|
|
@@ -108,10 +125,6 @@ class App {
|
|
|
108
125
|
attachCommitCallback(cb) {
|
|
109
126
|
this.commitCallbacks.push(cb);
|
|
110
127
|
}
|
|
111
|
-
// @Depricated (TODO: remove in 3.5.*)
|
|
112
|
-
addCommitCallback(cb) {
|
|
113
|
-
this.attachCommitCallback(cb);
|
|
114
|
-
}
|
|
115
128
|
safe(fn) {
|
|
116
129
|
const app = this;
|
|
117
130
|
return function (...args) {
|
|
@@ -140,6 +153,30 @@ class App {
|
|
|
140
153
|
this.attachStartCallback(() => target.addEventListener(type, listener, useCapture));
|
|
141
154
|
this.attachStopCallback(() => target.removeEventListener(type, listener, useCapture));
|
|
142
155
|
}
|
|
156
|
+
checkRequiredVersion(version) {
|
|
157
|
+
const reqVer = version.split('.');
|
|
158
|
+
const ver = this.version.split('.');
|
|
159
|
+
for (let i = 0; i < ver.length; i++) {
|
|
160
|
+
if (Number(ver[i]) < Number(reqVer[i]) || isNaN(Number(ver[i])) || isNaN(Number(reqVer[i]))) {
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return true;
|
|
165
|
+
}
|
|
166
|
+
getStartInfo() {
|
|
167
|
+
return {
|
|
168
|
+
userUUID: localStorage.getItem(this.options.local_uuid_key),
|
|
169
|
+
projectKey: this.projectKey,
|
|
170
|
+
revID: this.revID,
|
|
171
|
+
timestamp: (0, utils_js_1.timestamp)(),
|
|
172
|
+
trackerVersion: this.version,
|
|
173
|
+
userID: this._userID,
|
|
174
|
+
isSnippet: this.options.__is_snippet,
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
getSessionInfo() {
|
|
178
|
+
return Object.assign({ sessionID: this._sessionID, metadata: this._metadata }, this.getStartInfo());
|
|
179
|
+
}
|
|
143
180
|
getSessionToken() {
|
|
144
181
|
const token = sessionStorage.getItem(this.options.session_token_key);
|
|
145
182
|
if (token !== null) {
|
|
@@ -179,116 +216,112 @@ class App {
|
|
|
179
216
|
return url.startsWith(this.options.ingestPoint);
|
|
180
217
|
}
|
|
181
218
|
active() {
|
|
182
|
-
return this.
|
|
219
|
+
return this.activityState === ActivityState.Active;
|
|
183
220
|
}
|
|
184
|
-
|
|
185
|
-
if (
|
|
221
|
+
resetNextPageSession(flag) {
|
|
222
|
+
if (flag) {
|
|
223
|
+
sessionStorage.setItem(this.options.session_reset_key, 't');
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
sessionStorage.removeItem(this.options.session_reset_key);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
_start(startOpts) {
|
|
230
|
+
if (!this.worker) {
|
|
231
|
+
return Promise.reject("No worker found: perhaps, CSP is not set.");
|
|
232
|
+
}
|
|
233
|
+
if (this.activityState !== ActivityState.NotActive) {
|
|
234
|
+
return Promise.reject("OpenReplay: trying to call `start()` on the instance that has been started already.");
|
|
235
|
+
}
|
|
236
|
+
this.activityState = ActivityState.Starting;
|
|
237
|
+
let pageNo = 0;
|
|
238
|
+
const pageNoStr = sessionStorage.getItem(this.options.session_pageno_key);
|
|
239
|
+
if (pageNoStr != null) {
|
|
240
|
+
pageNo = parseInt(pageNoStr);
|
|
241
|
+
pageNo++;
|
|
242
|
+
}
|
|
243
|
+
sessionStorage.setItem(this.options.session_pageno_key, pageNo.toString());
|
|
244
|
+
this._userID = startOpts.userID || null;
|
|
245
|
+
this._metadata = startOpts.metadata || {}; // TODO: update both dynamically on corresponding messages
|
|
246
|
+
const startInfo = this.getStartInfo();
|
|
247
|
+
const messageData = {
|
|
248
|
+
ingestPoint: this.options.ingestPoint,
|
|
249
|
+
pageNo,
|
|
250
|
+
startTimestamp: startInfo.timestamp,
|
|
251
|
+
connAttemptCount: this.options.connAttemptCount,
|
|
252
|
+
connAttemptGap: this.options.connAttemptGap,
|
|
253
|
+
};
|
|
254
|
+
this.worker.postMessage(messageData); // brings delay of 10th ms?
|
|
255
|
+
const sReset = sessionStorage.getItem(this.options.session_reset_key);
|
|
256
|
+
sessionStorage.removeItem(this.options.session_reset_key);
|
|
257
|
+
return window.fetch(this.options.ingestPoint + '/v1/web/start', {
|
|
258
|
+
method: 'POST',
|
|
259
|
+
headers: {
|
|
260
|
+
'Content-Type': 'application/json',
|
|
261
|
+
},
|
|
262
|
+
body: JSON.stringify(Object.assign(Object.assign({}, startInfo), { token: sessionStorage.getItem(this.options.session_token_key), deviceMemory: performance_js_1.deviceMemory,
|
|
263
|
+
jsHeapSizeLimit: performance_js_1.jsHeapSizeLimit, reset: startOpts.forceNew || sReset !== null })),
|
|
264
|
+
})
|
|
265
|
+
.then(r => {
|
|
266
|
+
if (r.status === 200) {
|
|
267
|
+
return r.json();
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
return r.text().then(text => text === exports.CANCELED
|
|
271
|
+
? Promise.reject(exports.CANCELED)
|
|
272
|
+
: Promise.reject(`Server error: ${r.status}. ${text}`));
|
|
273
|
+
}
|
|
274
|
+
})
|
|
275
|
+
.then(r => {
|
|
186
276
|
if (!this.worker) {
|
|
187
|
-
return Promise.reject("
|
|
277
|
+
return Promise.reject("no worker found after start request (this might not happen)");
|
|
188
278
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
pageNo++;
|
|
279
|
+
const { token, userUUID, sessionID, beaconSizeLimit } = r;
|
|
280
|
+
if (typeof token !== 'string' ||
|
|
281
|
+
typeof userUUID !== 'string' ||
|
|
282
|
+
(typeof beaconSizeLimit !== 'number' && typeof beaconSizeLimit !== 'undefined')) {
|
|
283
|
+
return Promise.reject(`Incorrect server response: ${JSON.stringify(r)}`);
|
|
195
284
|
}
|
|
196
|
-
sessionStorage.setItem(this.options.
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
this.
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
//
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
jsHeapSizeLimit: performance_js_1.jsHeapSizeLimit,
|
|
226
|
-
reset,
|
|
227
|
-
}),
|
|
228
|
-
})
|
|
229
|
-
.then(r => {
|
|
230
|
-
if (r.status === 200) {
|
|
231
|
-
return r.json();
|
|
232
|
-
}
|
|
233
|
-
else { // TODO: handle canceling && 403
|
|
234
|
-
return r.text().then(text => {
|
|
235
|
-
throw new Error(`Server error: ${r.status}. ${text}`);
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
})
|
|
239
|
-
.then(r => {
|
|
240
|
-
const { token, userUUID, sessionID, beaconSizeLimit } = r;
|
|
241
|
-
if (typeof token !== 'string' ||
|
|
242
|
-
typeof userUUID !== 'string' ||
|
|
243
|
-
(typeof beaconSizeLimit !== 'number' && typeof beaconSizeLimit !== 'undefined')) {
|
|
244
|
-
throw new Error(`Incorrect server response: ${JSON.stringify(r)}`);
|
|
245
|
-
}
|
|
246
|
-
sessionStorage.setItem(this.options.session_token_key, token);
|
|
247
|
-
localStorage.setItem(this.options.local_uuid_key, userUUID);
|
|
248
|
-
// localStorage.setItem("__or_at_" + token, "true")
|
|
249
|
-
// this.attachEventListener(window, 'beforeunload', ()=>{
|
|
250
|
-
// localStorage.removeItem("__or_at_" + token)
|
|
251
|
-
// }, false);
|
|
252
|
-
// this.attachEventListener(window, 'pagehide', ()=>{
|
|
253
|
-
// localStorage.removeItem("__or_at_" + token)
|
|
254
|
-
// }, false);
|
|
255
|
-
if (typeof sessionID === 'string') {
|
|
256
|
-
this._sessionID = sessionID;
|
|
257
|
-
}
|
|
258
|
-
if (!this.worker) {
|
|
259
|
-
throw new Error("no worker found after start request (this might not happen)");
|
|
260
|
-
}
|
|
261
|
-
this.worker.postMessage({ token, beaconSizeLimit });
|
|
262
|
-
this.startCallbacks.forEach((cb) => cb());
|
|
263
|
-
this.observer.observe();
|
|
264
|
-
this.ticker.start();
|
|
265
|
-
(0, utils_js_1.log)("OpenReplay tracking started.");
|
|
266
|
-
const onStartInfo = { sessionToken: token, userUUID, sessionID };
|
|
267
|
-
if (typeof this.options.onStart === 'function') {
|
|
268
|
-
this.options.onStart(onStartInfo);
|
|
269
|
-
}
|
|
270
|
-
return onStartInfo;
|
|
271
|
-
})
|
|
272
|
-
.catch(e => {
|
|
273
|
-
sessionStorage.removeItem(this.options.session_token_key);
|
|
274
|
-
this.stop();
|
|
275
|
-
(0, utils_js_1.warn)("OpenReplay was unable to start. ", e);
|
|
276
|
-
this._debug("session_start", e);
|
|
277
|
-
throw e;
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
return Promise.reject("Player is already active");
|
|
285
|
+
sessionStorage.setItem(this.options.session_token_key, token);
|
|
286
|
+
localStorage.setItem(this.options.local_uuid_key, userUUID);
|
|
287
|
+
if (typeof sessionID === 'string') {
|
|
288
|
+
this._sessionID = sessionID;
|
|
289
|
+
}
|
|
290
|
+
this.activityState = ActivityState.Active;
|
|
291
|
+
this.worker.postMessage({ token, beaconSizeLimit });
|
|
292
|
+
this.startCallbacks.forEach((cb) => cb());
|
|
293
|
+
this.observer.observe();
|
|
294
|
+
this.ticker.start();
|
|
295
|
+
Object.entries(this._metadata).forEach(([key, value]) => this.send(new index_js_1.Metadata(key, value)));
|
|
296
|
+
this.notify.log("OpenReplay tracking started.");
|
|
297
|
+
// TODO: get rid of onStart
|
|
298
|
+
const onStartInfo = { sessionToken: token, userUUID, sessionID };
|
|
299
|
+
if (typeof this.options.onStart === 'function') {
|
|
300
|
+
this.options.onStart(onStartInfo);
|
|
301
|
+
}
|
|
302
|
+
return onStartInfo;
|
|
303
|
+
})
|
|
304
|
+
.catch(reason => {
|
|
305
|
+
sessionStorage.removeItem(this.options.session_token_key);
|
|
306
|
+
this.stop();
|
|
307
|
+
//if (reason === CANCELED) { return Promise.resolve(CANCELED) } // TODO: what to return ????? Throwing is baad
|
|
308
|
+
if (reason !== exports.CANCELED) {
|
|
309
|
+
this.notify.log("OpenReplay was unable to start. ", reason);
|
|
310
|
+
this._debug("session_start", reason);
|
|
311
|
+
}
|
|
312
|
+
return Promise.reject(reason);
|
|
313
|
+
});
|
|
281
314
|
}
|
|
282
|
-
start(
|
|
315
|
+
start(options = { forceNew: false }) {
|
|
283
316
|
if (!document.hidden) {
|
|
284
|
-
return this._start(
|
|
317
|
+
return this._start(options);
|
|
285
318
|
}
|
|
286
319
|
else {
|
|
287
320
|
return new Promise((resolve) => {
|
|
288
321
|
const onVisibilityChange = () => {
|
|
289
322
|
if (!document.hidden) {
|
|
290
323
|
document.removeEventListener("visibilitychange", onVisibilityChange);
|
|
291
|
-
resolve(this._start(
|
|
324
|
+
resolve(this._start(options));
|
|
292
325
|
}
|
|
293
326
|
};
|
|
294
327
|
document.addEventListener("visibilitychange", onVisibilityChange);
|
|
@@ -296,19 +329,20 @@ class App {
|
|
|
296
329
|
}
|
|
297
330
|
}
|
|
298
331
|
stop() {
|
|
299
|
-
if (this.
|
|
332
|
+
if (this.activityState !== ActivityState.NotActive) {
|
|
300
333
|
try {
|
|
301
334
|
if (this.worker) {
|
|
302
335
|
this.worker.postMessage("stop");
|
|
303
336
|
}
|
|
337
|
+
this.sanitizer.clear();
|
|
304
338
|
this.observer.disconnect();
|
|
305
339
|
this.nodes.clear();
|
|
306
340
|
this.ticker.stop();
|
|
307
341
|
this.stopCallbacks.forEach((cb) => cb());
|
|
308
|
-
|
|
342
|
+
this.notify.log("OpenReplay tracking stopped.");
|
|
309
343
|
}
|
|
310
344
|
finally {
|
|
311
|
-
this.
|
|
345
|
+
this.activityState = ActivityState.NotActive;
|
|
312
346
|
}
|
|
313
347
|
}
|
|
314
348
|
}
|
package/cjs/app/logger.d.ts
CHANGED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export declare const LogLevel: {
|
|
2
|
+
readonly Verbose: 4;
|
|
3
|
+
readonly Errors: 4;
|
|
4
|
+
readonly Warnings: 3;
|
|
5
|
+
readonly Log: 2;
|
|
6
|
+
readonly Silent: 0;
|
|
7
|
+
};
|
|
8
|
+
declare type LogLevel = typeof LogLevel[keyof typeof LogLevel];
|
|
9
|
+
declare type CustomLevel = {
|
|
10
|
+
error: boolean;
|
|
11
|
+
warn: boolean;
|
|
12
|
+
log: boolean;
|
|
13
|
+
};
|
|
14
|
+
interface _Options {
|
|
15
|
+
level: LogLevel | CustomLevel;
|
|
16
|
+
messages?: number[];
|
|
17
|
+
}
|
|
18
|
+
export declare type Options = true | _Options | LogLevel;
|
|
19
|
+
export default class Logger {
|
|
20
|
+
private readonly options;
|
|
21
|
+
private readonly opts;
|
|
22
|
+
constructor(options?: Options);
|
|
23
|
+
log(...args: any): void;
|
|
24
|
+
warn(...args: any): void;
|
|
25
|
+
error(...args: any): void;
|
|
26
|
+
}
|
|
27
|
+
export {};
|