@openreplay/tracker 3.5.16-beta.2 → 3.5.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/.eslintignore +8 -0
- package/cjs/app/guards.js +1 -2
- package/cjs/app/index.d.ts +15 -17
- package/cjs/app/index.js +53 -61
- package/cjs/app/logger.js +6 -3
- package/cjs/app/nodes.d.ts +2 -8
- package/cjs/app/nodes.js +3 -18
- package/cjs/app/observer/iframe_observer.d.ts +1 -1
- package/cjs/app/observer/iframe_observer.js +1 -1
- package/cjs/app/observer/observer.d.ts +2 -1
- package/cjs/app/observer/observer.js +30 -18
- package/cjs/app/observer/shadow_root_observer.d.ts +1 -1
- package/cjs/app/observer/shadow_root_observer.js +1 -1
- package/cjs/app/observer/top_observer.d.ts +2 -2
- package/cjs/app/observer/top_observer.js +12 -11
- package/cjs/app/sanitizer.d.ts +1 -1
- package/cjs/app/sanitizer.js +5 -5
- package/cjs/app/session.d.ts +1 -1
- package/cjs/app/session.js +4 -3
- package/cjs/app/ticker.d.ts +1 -1
- package/cjs/common/webworker.d.ts +3 -3
- package/cjs/index.d.ts +8 -8
- package/cjs/index.js +28 -28
- package/cjs/modules/connection.d.ts +1 -1
- package/cjs/modules/console.d.ts +1 -1
- package/cjs/modules/console.js +5 -5
- package/cjs/modules/cssrules.d.ts +1 -1
- package/cjs/modules/cssrules.js +3 -3
- package/cjs/modules/exception.d.ts +2 -2
- package/cjs/modules/exception.js +7 -6
- package/cjs/modules/img.d.ts +1 -1
- package/cjs/modules/img.js +15 -12
- package/cjs/modules/input.d.ts +1 -1
- package/cjs/modules/input.js +25 -21
- package/cjs/modules/longtasks.d.ts +1 -1
- package/cjs/modules/longtasks.js +13 -5
- package/cjs/modules/mouse.d.ts +1 -1
- package/cjs/modules/mouse.js +10 -12
- package/cjs/modules/performance.d.ts +1 -1
- package/cjs/modules/scroll.d.ts +1 -1
- package/cjs/modules/timing.d.ts +1 -1
- package/cjs/modules/timing.js +12 -24
- package/cjs/modules/viewport.d.ts +1 -1
- package/cjs/utils.js +7 -7
- package/cjs/vendors/finder/finder.js +53 -48
- package/lib/app/guards.js +1 -2
- package/lib/app/index.d.ts +15 -17
- package/lib/app/index.js +62 -70
- package/lib/app/logger.js +6 -3
- package/lib/app/nodes.d.ts +2 -8
- package/lib/app/nodes.js +3 -18
- package/lib/app/observer/iframe_observer.d.ts +1 -1
- package/lib/app/observer/iframe_observer.js +3 -3
- package/lib/app/observer/observer.d.ts +2 -1
- package/lib/app/observer/observer.js +32 -20
- package/lib/app/observer/shadow_root_observer.d.ts +1 -1
- package/lib/app/observer/shadow_root_observer.js +3 -3
- package/lib/app/observer/top_observer.d.ts +2 -2
- package/lib/app/observer/top_observer.js +17 -16
- package/lib/app/sanitizer.d.ts +1 -1
- package/lib/app/sanitizer.js +7 -7
- package/lib/app/session.d.ts +1 -1
- package/lib/app/session.js +4 -3
- package/lib/app/ticker.d.ts +1 -1
- package/lib/common/tsconfig.tsbuildinfo +1 -1
- package/lib/common/webworker.d.ts +3 -3
- package/lib/index.d.ts +8 -8
- package/lib/index.js +43 -43
- package/lib/modules/connection.d.ts +1 -1
- package/lib/modules/connection.js +1 -1
- package/lib/modules/console.d.ts +1 -1
- package/lib/modules/console.js +8 -8
- package/lib/modules/cssrules.d.ts +1 -1
- package/lib/modules/cssrules.js +5 -5
- package/lib/modules/exception.d.ts +2 -2
- package/lib/modules/exception.js +8 -7
- package/lib/modules/img.d.ts +1 -1
- package/lib/modules/img.js +18 -15
- package/lib/modules/input.d.ts +1 -1
- package/lib/modules/input.js +28 -24
- package/lib/modules/longtasks.d.ts +1 -1
- package/lib/modules/longtasks.js +14 -6
- package/lib/modules/mouse.d.ts +1 -1
- package/lib/modules/mouse.js +14 -16
- package/lib/modules/performance.d.ts +1 -1
- package/lib/modules/performance.js +2 -2
- package/lib/modules/scroll.d.ts +1 -1
- package/lib/modules/scroll.js +2 -2
- package/lib/modules/timing.d.ts +1 -1
- package/lib/modules/timing.js +15 -27
- package/lib/modules/viewport.d.ts +1 -1
- package/lib/modules/viewport.js +1 -1
- package/lib/utils.js +7 -7
- package/lib/vendors/finder/finder.js +53 -48
- package/package.json +27 -10
package/.eslintignore
ADDED
package/cjs/app/guards.js
CHANGED
|
@@ -14,8 +14,7 @@ function isTextNode(node) {
|
|
|
14
14
|
}
|
|
15
15
|
exports.isTextNode = isTextNode;
|
|
16
16
|
function isRootNode(node) {
|
|
17
|
-
return node.nodeType === Node.DOCUMENT_NODE ||
|
|
18
|
-
node.nodeType === Node.DOCUMENT_FRAGMENT_NODE;
|
|
17
|
+
return node.nodeType === Node.DOCUMENT_NODE || node.nodeType === Node.DOCUMENT_FRAGMENT_NODE;
|
|
19
18
|
}
|
|
20
19
|
exports.isRootNode = isRootNode;
|
|
21
20
|
function hasTag(el, tagName) {
|
package/cjs/app/index.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import type Message from
|
|
2
|
-
import Nodes
|
|
3
|
-
import Sanitizer from
|
|
4
|
-
import Ticker from
|
|
5
|
-
import Logger from
|
|
6
|
-
import Session from
|
|
7
|
-
import type { Options as ObserverOptions } from
|
|
8
|
-
import type { Options as SanitizerOptions } from
|
|
9
|
-
import type { Options as LoggerOptions } from
|
|
10
|
-
import type { Options as WebworkerOptions } from
|
|
1
|
+
import type Message from '../common/messages.js';
|
|
2
|
+
import Nodes from './nodes.js';
|
|
3
|
+
import Sanitizer from './sanitizer.js';
|
|
4
|
+
import Ticker from './ticker.js';
|
|
5
|
+
import Logger from './logger.js';
|
|
6
|
+
import Session from './session.js';
|
|
7
|
+
import type { Options as ObserverOptions } from './observer/top_observer.js';
|
|
8
|
+
import type { Options as SanitizerOptions } from './sanitizer.js';
|
|
9
|
+
import type { Options as LoggerOptions } from './logger.js';
|
|
10
|
+
import type { Options as WebworkerOptions } from '../common/webworker.js';
|
|
11
11
|
export interface StartOptions {
|
|
12
12
|
userID?: string;
|
|
13
13
|
metadata?: Record<string, string>;
|
|
@@ -44,12 +44,10 @@ declare type AppOptions = {
|
|
|
44
44
|
__is_snippet: boolean;
|
|
45
45
|
__debug_report_edp: string | null;
|
|
46
46
|
__debug__?: LoggerOptions;
|
|
47
|
-
localStorage: Storage;
|
|
48
|
-
sessionStorage: Storage;
|
|
49
|
-
maxMemorySize: number;
|
|
50
|
-
memoryCheckInterval: number;
|
|
47
|
+
localStorage: Storage | null;
|
|
48
|
+
sessionStorage: Storage | null;
|
|
51
49
|
onStart?: StartCallback;
|
|
52
|
-
} & WebworkerOptions
|
|
50
|
+
} & WebworkerOptions;
|
|
53
51
|
export declare type Options = AppOptions & ObserverOptions & SanitizerOptions;
|
|
54
52
|
export declare const DEFAULT_INGEST_POINT = "https://api.openreplay.com/ingest";
|
|
55
53
|
export default class App {
|
|
@@ -70,7 +68,7 @@ export default class App {
|
|
|
70
68
|
private readonly options;
|
|
71
69
|
private readonly revID;
|
|
72
70
|
private activityState;
|
|
73
|
-
private version;
|
|
71
|
+
private readonly version;
|
|
74
72
|
private readonly worker?;
|
|
75
73
|
constructor(projectKey: string, sessionToken: string | null | undefined, options: Partial<Options>);
|
|
76
74
|
private _debug;
|
|
@@ -79,7 +77,7 @@ export default class App {
|
|
|
79
77
|
safe<T extends (...args: any[]) => void>(fn: T): T;
|
|
80
78
|
attachCommitCallback(cb: CommitCallback): void;
|
|
81
79
|
attachStartCallback(cb: StartCallback): void;
|
|
82
|
-
attachStopCallback(cb:
|
|
80
|
+
attachStopCallback(cb: () => any): void;
|
|
83
81
|
attachEventListener(target: EventTarget, type: string, listener: EventListener, useSafe?: boolean, useCapture?: boolean): void;
|
|
84
82
|
checkRequiredVersion(version: string): boolean;
|
|
85
83
|
private getStartInfo;
|
package/cjs/app/index.js
CHANGED
|
@@ -10,8 +10,8 @@ const ticker_js_1 = require("./ticker.js");
|
|
|
10
10
|
const logger_js_1 = require("./logger.js");
|
|
11
11
|
const session_js_1 = require("./session.js");
|
|
12
12
|
const performance_js_1 = require("../modules/performance.js");
|
|
13
|
-
const CANCELED =
|
|
14
|
-
const START_ERROR =
|
|
13
|
+
const CANCELED = 'canceled';
|
|
14
|
+
const START_ERROR = ':(';
|
|
15
15
|
const UnsuccessfulStart = (reason) => ({ reason, success: false });
|
|
16
16
|
const SuccessfulStart = (body) => (Object.assign(Object.assign({}, body), { success: true }));
|
|
17
17
|
var ActivityState;
|
|
@@ -27,13 +27,13 @@ class App {
|
|
|
27
27
|
// if (options.onStart !== undefined) {
|
|
28
28
|
// deprecationWarn("'onStart' option", "tracker.start().then(/* handle session info */)")
|
|
29
29
|
// } ?? maybe onStart is good
|
|
30
|
-
|
|
30
|
+
var _a, _b;
|
|
31
31
|
this.messages = [];
|
|
32
32
|
this.startCallbacks = [];
|
|
33
33
|
this.stopCallbacks = [];
|
|
34
34
|
this.commitCallbacks = [];
|
|
35
35
|
this.activityState = ActivityState.NotActive;
|
|
36
|
-
this.version = '3.5.16
|
|
36
|
+
this.version = '3.5.16'; // TODO: version compatability check inside each plugin.
|
|
37
37
|
this.projectKey = projectKey;
|
|
38
38
|
this.options = Object.assign({
|
|
39
39
|
revID: '',
|
|
@@ -47,14 +47,12 @@ class App {
|
|
|
47
47
|
verbose: false,
|
|
48
48
|
__is_snippet: false,
|
|
49
49
|
__debug_report_edp: null,
|
|
50
|
-
localStorage:
|
|
51
|
-
sessionStorage:
|
|
52
|
-
maxMemorySize: 550 * 1e6,
|
|
53
|
-
memoryCheckInterval: 2 * 60 * 1000,
|
|
50
|
+
localStorage: null,
|
|
51
|
+
sessionStorage: null,
|
|
54
52
|
}, options);
|
|
55
53
|
this.revID = this.options.revID;
|
|
56
54
|
this.sanitizer = new sanitizer_js_1.default(this, options);
|
|
57
|
-
this.nodes = new nodes_js_1.default(this.options.node_id
|
|
55
|
+
this.nodes = new nodes_js_1.default(this.options.node_id);
|
|
58
56
|
this.observer = new top_observer_js_1.default(this, options);
|
|
59
57
|
this.ticker = new ticker_js_1.default(this);
|
|
60
58
|
this.ticker.attach(() => this.commit());
|
|
@@ -62,30 +60,31 @@ class App {
|
|
|
62
60
|
this.notify = new logger_js_1.default(this.options.verbose ? logger_js_1.LogLevel.Warnings : logger_js_1.LogLevel.Silent);
|
|
63
61
|
this.session = new session_js_1.default();
|
|
64
62
|
this.session.attachUpdateCallback(({ userID, metadata }) => {
|
|
65
|
-
if (userID != null) {
|
|
63
|
+
if (userID != null) {
|
|
64
|
+
// TODO: nullable userID
|
|
66
65
|
this.send(new messages_js_1.UserID(userID));
|
|
67
66
|
}
|
|
68
67
|
if (metadata != null) {
|
|
69
68
|
Object.entries(metadata).forEach(([key, value]) => this.send(new messages_js_1.Metadata(key, value)));
|
|
70
69
|
}
|
|
71
70
|
});
|
|
72
|
-
|
|
73
|
-
this.
|
|
71
|
+
// window.localStorage and window.sessionStorage should only be accessed if required, see #490, #637
|
|
72
|
+
this.localStorage = (_a = this.options.localStorage) !== null && _a !== void 0 ? _a : window.localStorage;
|
|
73
|
+
this.sessionStorage = (_b = this.options.sessionStorage) !== null && _b !== void 0 ? _b : window.sessionStorage;
|
|
74
74
|
if (sessionToken != null) {
|
|
75
75
|
this.sessionStorage.setItem(this.options.session_token_key, sessionToken);
|
|
76
76
|
}
|
|
77
77
|
try {
|
|
78
|
-
this.worker = new Worker(URL.createObjectURL(new Blob([`"use strict";function t(t){function i(...i){return new t(...i)}return i.prototype=t.prototype,i}const i=new Map;const s=t(class{constructor(t,i,s){this.pageNo=t,this.firstIndex=i,this.timestamp=s,this._id=80}encode(t){return t.uint(80)&&t.uint(this.pageNo)&&t.uint(this.firstIndex)&&t.int(this.timestamp)}});i.set(80,s);const e=t(class{constructor(t){this.timestamp=t,this._id=0}encode(t){return t.uint(0)&&t.uint(this.timestamp)}});i.set(0,e);const n=t(class{constructor(t,i,s){this.url=t,this.referrer=i,this.navigationStart=s,this._id=4}encode(t){return t.uint(4)&&t.string(this.url)&&t.string(this.referrer)&&t.uint(this.navigationStart)}});i.set(4,n);const r=t(class{constructor(t,i){this.width=t,this.height=i,this._id=5}encode(t){return t.uint(5)&&t.uint(this.width)&&t.uint(this.height)}});i.set(5,r);const h=t(class{constructor(t,i){this.x=t,this.y=i,this._id=6}encode(t){return t.uint(6)&&t.int(this.x)&&t.int(this.y)}});i.set(6,h);const o=t(class{constructor(){this._id=7}encode(t){return t.uint(7)}});i.set(7,o);const c=t(class{constructor(t,i,s,e,n){this.id=t,this.parentID=i,this.index=s,this.tag=e,this.svg=n,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)}});i.set(8,c);const a=t(class{constructor(t,i,s){this.id=t,this.parentID=i,this.index=s,this._id=9}encode(t){return t.uint(9)&&t.uint(this.id)&&t.uint(this.parentID)&&t.uint(this.index)}});i.set(9,a);const u=t(class{constructor(t,i,s){this.id=t,this.parentID=i,this.index=s,this._id=10}encode(t){return t.uint(10)&&t.uint(this.id)&&t.uint(this.parentID)&&t.uint(this.index)}});i.set(10,u);const d=t(class{constructor(t){this.id=t,this._id=11}encode(t){return t.uint(11)&&t.uint(this.id)}});i.set(11,d);const l=t(class{constructor(t,i,s){this.id=t,this.name=i,this.value=s,this._id=12}encode(t){return t.uint(12)&&t.uint(this.id)&&t.string(this.name)&&t.string(this.value)}});i.set(12,l);const p=t(class{constructor(t,i){this.id=t,this.name=i,this._id=13}encode(t){return t.uint(13)&&t.uint(this.id)&&t.string(this.name)}});i.set(13,p);const g=t(class{constructor(t,i){this.id=t,this.data=i,this._id=14}encode(t){return t.uint(14)&&t.uint(this.id)&&t.string(this.data)}});i.set(14,g);const m=t(class{constructor(t,i,s){this.id=t,this.x=i,this.y=s,this._id=16}encode(t){return t.uint(16)&&t.uint(this.id)&&t.int(this.x)&&t.int(this.y)}});i.set(16,m);const f=t(class{constructor(t,i){this.id=t,this.label=i,this._id=17}encode(t){return t.uint(17)&&t.uint(this.id)&&t.string(this.label)}});i.set(17,f);const y=t(class{constructor(t,i,s){this.id=t,this.value=i,this.mask=s,this._id=18}encode(t){return t.uint(18)&&t.uint(this.id)&&t.string(this.value)&&t.int(this.mask)}});i.set(18,y);const _=t(class{constructor(t,i){this.id=t,this.checked=i,this._id=19}encode(t){return t.uint(19)&&t.uint(this.id)&&t.boolean(this.checked)}});i.set(19,_);const v=t(class{constructor(t,i){this.x=t,this.y=i,this._id=20}encode(t){return t.uint(20)&&t.uint(this.x)&&t.uint(this.y)}});i.set(20,v);const S=t(class{constructor(t,i){this.level=t,this.value=i,this._id=22}encode(t){return t.uint(22)&&t.string(this.level)&&t.string(this.value)}});i.set(22,S);const b=t(class{constructor(t,i,s,e,n,r,h,o,c){this.requestStart=t,this.responseStart=i,this.responseEnd=s,this.domContentLoadedEventStart=e,this.domContentLoadedEventEnd=n,this.loadEventStart=r,this.loadEventEnd=h,this.firstPaint=o,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)}});i.set(23,b);const w=t(class{constructor(t,i,s){this.speedIndex=t,this.visuallyComplete=i,this.timeToInteractive=s,this._id=24}encode(t){return t.uint(24)&&t.uint(this.speedIndex)&&t.uint(this.visuallyComplete)&&t.uint(this.timeToInteractive)}});i.set(24,w);const E=t(class{constructor(t,i,s){this.name=t,this.message=i,this.payload=s,this._id=25}encode(t){return t.uint(25)&&t.string(this.name)&&t.string(this.message)&&t.string(this.payload)}});i.set(25,E);const x=t(class{constructor(t,i){this.name=t,this.payload=i,this._id=27}encode(t){return t.uint(27)&&t.string(this.name)&&t.string(this.payload)}});i.set(27,x);const T=t(class{constructor(t){this.id=t,this._id=28}encode(t){return t.uint(28)&&t.string(this.id)}});i.set(28,T);const z=t(class{constructor(t){this.id=t,this._id=29}encode(t){return t.uint(29)&&t.string(this.id)}});i.set(29,z);const k=t(class{constructor(t,i){this.key=t,this.value=i,this._id=30}encode(t){return t.uint(30)&&t.string(this.key)&&t.string(this.value)}});i.set(30,k);const A=t(class{constructor(t,i,s){this.id=t,this.rule=i,this.index=s,this._id=37}encode(t){return t.uint(37)&&t.uint(this.id)&&t.string(this.rule)&&t.uint(this.index)}});i.set(37,A);const I=t(class{constructor(t,i){this.id=t,this.index=i,this._id=38}encode(t){return t.uint(38)&&t.uint(this.id)&&t.uint(this.index)}});i.set(38,I);const L=t(class{constructor(t,i,s,e,n,r,h){this.method=t,this.url=i,this.request=s,this.response=e,this.status=n,this.timestamp=r,this.duration=h,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)}});i.set(39,L);const C=t(class{constructor(t,i,s,e){this.name=t,this.duration=i,this.args=s,this.result=e,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)}});i.set(40,C);const M=t(class{constructor(t,i){this.key=t,this.value=i,this._id=41}encode(t){return t.uint(41)&&t.string(this.key)&&t.string(this.value)}});i.set(41,M);const N=t(class{constructor(t){this.type=t,this._id=42}encode(t){return t.uint(42)&&t.string(this.type)}});i.set(42,N);const B=t(class{constructor(t,i,s){this.action=t,this.state=i,this.duration=s,this._id=44}encode(t){return t.uint(44)&&t.string(this.action)&&t.string(this.state)&&t.uint(this.duration)}});i.set(44,B);const U=t(class{constructor(t,i){this.mutation=t,this.state=i,this._id=45}encode(t){return t.uint(45)&&t.string(this.mutation)&&t.string(this.state)}});i.set(45,U);const R=t(class{constructor(t,i){this.type=t,this.payload=i,this._id=46}encode(t){return t.uint(46)&&t.string(this.type)&&t.string(this.payload)}});i.set(46,R);const O=t(class{constructor(t,i,s){this.action=t,this.state=i,this.duration=s,this._id=47}encode(t){return t.uint(47)&&t.string(this.action)&&t.string(this.state)&&t.uint(this.duration)}});i.set(47,O);const P=t(class{constructor(t,i,s,e){this.operationKind=t,this.operationName=i,this.variables=s,this.response=e,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)}});i.set(48,P);const q=t(class{constructor(t,i,s,e){this.frames=t,this.ticks=i,this.totalJSHeapSize=s,this.usedJSHeapSize=e,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)}});i.set(49,q);const D=t(class{constructor(t,i,s,e,n,r,h,o){this.timestamp=t,this.duration=i,this.ttfb=s,this.headerSize=e,this.encodedBodySize=n,this.decodedBodySize=r,this.url=h,this.initiator=o,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)}});i.set(53,D);const W=t(class{constructor(t,i){this.downlink=t,this.type=i,this._id=54}encode(t){return t.uint(54)&&t.uint(this.downlink)&&t.string(this.type)}});i.set(54,W);const H=t(class{constructor(t){this.hidden=t,this._id=55}encode(t){return t.uint(55)&&t.boolean(this.hidden)}});i.set(55,H);const J=t(class{constructor(t,i,s,e,n,r,h){this.timestamp=t,this.duration=i,this.context=s,this.containerType=e,this.containerSrc=n,this.containerId=r,this.containerName=h,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)}});i.set(59,J);const F=t(class{constructor(t,i,s,e){this.id=t,this.name=i,this.value=s,this.baseURL=e,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)}});i.set(60,F);const X=t(class{constructor(t,i,s){this.id=t,this.data=i,this.baseURL=s,this._id=61}encode(t){return t.uint(61)&&t.uint(this.id)&&t.string(this.data)&&t.string(this.baseURL)}});i.set(61,X);const G=t(class{constructor(t,i){this.type=t,this.value=i,this._id=63}encode(t){return t.uint(63)&&t.string(this.type)&&t.string(this.value)}});i.set(63,G);const K=t(class{constructor(t,i){this.name=t,this.payload=i,this._id=64}encode(t){return t.uint(64)&&t.string(this.name)&&t.string(this.payload)}});i.set(64,K);const j=t(class{constructor(){this._id=65}encode(t){return t.uint(65)}});i.set(65,j);const Q=t(class{constructor(t,i,s,e){this.id=t,this.rule=i,this.index=s,this.baseURL=e,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)}});i.set(67,Q);const V=t(class{constructor(t,i,s,e){this.id=t,this.hesitationTime=i,this.label=s,this.selector=e,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)}});i.set(69,V);const Y=t(class{constructor(t,i){this.frameID=t,this.id=i,this._id=70}encode(t){return t.uint(70)&&t.uint(this.frameID)&&t.uint(this.id)}});i.set(70,Y);class Z{constructor(t,i,s,e=10,n=1e3){this.onUnauthorised=i,this.onFailure=s,this.MAX_ATTEMPTS_COUNT=e,this.ATTEMPT_TIMEOUT=n,this.attemptsCount=0,this.busy=!1,this.queue=[],this.token=null,this.ingestURL=t+"/v1/web/i"}authorise(t){this.token=t}push(t){this.busy||!this.token?this.queue.push(t):this.sendBatch(t)}retry(t){this.attemptsCount>=this.MAX_ATTEMPTS_COUNT?this.onFailure():(this.attemptsCount++,setTimeout(()=>this.sendBatch(t),this.ATTEMPT_TIMEOUT*this.attemptsCount))}sendBatch(t){this.busy=!0,fetch(this.ingestURL,{body:t,method:"POST",headers:{Authorization:"Bearer "+this.token},keepalive:t.length<65536}).then(i=>{if(401===i.status)return this.busy=!1,void this.onUnauthorised();if(i.status>=400)return void this.retry(t);this.attemptsCount=0;const s=this.queue.shift();s?this.sendBatch(s):this.busy=!1}).catch(i=>{console.warn("OpenReplay:",i),this.retry(t)})}clean(){this.queue.length=0}}const tt="function"==typeof TextEncoder?new TextEncoder:{encode(t){const i=t.length,s=new Uint8Array(3*i);let e=-1;for(var n=0,r=0,h=0;h!==i;){if(n=t.charCodeAt(h),h+=1,n>=55296&&n<=56319){if(h===i){s[e+=1]=239,s[e+=1]=191,s[e+=1]=189;break}if(!((r=t.charCodeAt(h))>=56320&&r<=57343)){s[e+=1]=239,s[e+=1]=191,s[e+=1]=189;continue}if(h+=1,(n=1024*(n-55296)+r-56320+65536)>65535){s[e+=1]=240|n>>>18,s[e+=1]=128|n>>>12&63,s[e+=1]=128|n>>>6&63,s[e+=1]=128|63&n;continue}}n<=127?s[e+=1]=0|n:n<=2047?(s[e+=1]=192|n>>>6,s[e+=1]=128|63&n):(s[e+=1]=224|n>>>12,s[e+=1]=128|n>>>6&63,s[e+=1]=128|63&n)}return s.subarray(0,e+1)}};class it{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 i=tt.encode(t),s=i.byteLength;return!(!this.uint(s)||this.offset+s>this.size)&&(this.data.set(i,this.offset),this.offset+=s,!0)}reset(){this.offset=0,this.checkpointOffset=0}flush(){const t=this.data.slice(0,this.checkpointOffset);return this.reset(),t}}class st{constructor(t,i,s){this.pageNo=t,this.timestamp=i,this.onBatch=s,this.nextIndex=0,this.beaconSize=2e5,this.writer=new it(this.beaconSize),this.isEmpty=!0,this.beaconSizeLimit=1e6,this.prepare()}prepare(){this.writer.isEmpty()&&new s(this.pageNo,this.nextIndex,this.timestamp).encode(this.writer)}write(t){const i=t.encode(this.writer);return i&&(this.isEmpty=!1,this.writer.checkpoint(),this.nextIndex++),i}setBeaconSizeLimit(t){this.beaconSizeLimit=t}writeMessage(t){for(t instanceof e&&(this.timestamp=t.timestamp);!this.write(t);){if(this.finaliseBatch(),this.beaconSize===this.beaconSizeLimit)return console.warn("OpenReplay: beacon size overflow. Skipping large message."),this.writer.reset(),this.prepare(),void(this.isEmpty=!0);this.beaconSize=Math.min(2*this.beaconSize,this.beaconSizeLimit),this.writer=new it(this.beaconSize),this.prepare(),this.isEmpty=!0}}finaliseBatch(){this.isEmpty||(this.onBatch(this.writer.flush()),this.prepare(),this.isEmpty=!0)}clean(){this.writer.reset()}}var et;!function(t){t[t.NotActive=0]="NotActive",t[t.Starting=1]="Starting",t[t.Stopping=2]="Stopping",t[t.Active=3]="Active"}(et||(et={}));let nt=null,rt=null;function ht(){rt&&rt.finaliseBatch()}function ot(){et.Stopping,null!==at&&(clearInterval(at),at=null),rt&&(rt.clean(),rt=null),et.NotActive}et.NotActive;let ct,at=null;self.onmessage=({data:t})=>{if(null!=t){if("stop"===t)return ht(),void ot();if(Array.isArray(t)){if(!rt)throw new Error("WebWorker: writer not initialised. Service Should be Started.");const s=rt;t.forEach(t=>{const e=new(i.get(t._id));Object.assign(e,t),e instanceof H&&(e.hidden?ct=setTimeout(()=>self.postMessage("restart"),18e5):clearTimeout(ct)),s.writeMessage(e)})}else{if("start"===t.type)return et.Starting,nt=new Z(t.ingestPoint,()=>{self.postMessage("restart")},()=>{nt&&(nt.clean(),nt=null),ot(),self.postMessage("failed")},t.connAttemptCount,t.connAttemptGap),rt=new st(t.pageNo,t.timestamp,t=>nt&&nt.push(t)),null===at&&(at=setInterval(ht,1e4)),et.Active;if("auth"===t.type){if(!nt)throw new Error("WebWorker: sender not initialised. Received auth.");if(!rt)throw new Error("WebWorker: writer not initialised. Received auth.");return nt.authorise(t.token),void(t.beaconSizeLimit&&rt.setBeaconSizeLimit(t.beaconSizeLimit))}}}else ht()};
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
this._debug("webworker_error", e);
|
|
78
|
+
this.worker = new Worker(URL.createObjectURL(new Blob(['"use strict";function t(t){function i(...i){return new t(...i)}return i.prototype=t.prototype,i}const i=new Map;const s=t(class{constructor(t,i,s){this.pageNo=t,this.firstIndex=i,this.timestamp=s,this._id=80}encode(t){return t.uint(80)&&t.uint(this.pageNo)&&t.uint(this.firstIndex)&&t.int(this.timestamp)}});i.set(80,s);const e=t(class{constructor(t){this.timestamp=t,this._id=0}encode(t){return t.uint(0)&&t.uint(this.timestamp)}});i.set(0,e);const n=t(class{constructor(t,i,s){this.url=t,this.referrer=i,this.navigationStart=s,this._id=4}encode(t){return t.uint(4)&&t.string(this.url)&&t.string(this.referrer)&&t.uint(this.navigationStart)}});i.set(4,n);const r=t(class{constructor(t,i){this.width=t,this.height=i,this._id=5}encode(t){return t.uint(5)&&t.uint(this.width)&&t.uint(this.height)}});i.set(5,r);const h=t(class{constructor(t,i){this.x=t,this.y=i,this._id=6}encode(t){return t.uint(6)&&t.int(this.x)&&t.int(this.y)}});i.set(6,h);const o=t(class{constructor(){this._id=7}encode(t){return t.uint(7)}});i.set(7,o);const c=t(class{constructor(t,i,s,e,n){this.id=t,this.parentID=i,this.index=s,this.tag=e,this.svg=n,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)}});i.set(8,c);const a=t(class{constructor(t,i,s){this.id=t,this.parentID=i,this.index=s,this._id=9}encode(t){return t.uint(9)&&t.uint(this.id)&&t.uint(this.parentID)&&t.uint(this.index)}});i.set(9,a);const u=t(class{constructor(t,i,s){this.id=t,this.parentID=i,this.index=s,this._id=10}encode(t){return t.uint(10)&&t.uint(this.id)&&t.uint(this.parentID)&&t.uint(this.index)}});i.set(10,u);const d=t(class{constructor(t){this.id=t,this._id=11}encode(t){return t.uint(11)&&t.uint(this.id)}});i.set(11,d);const l=t(class{constructor(t,i,s){this.id=t,this.name=i,this.value=s,this._id=12}encode(t){return t.uint(12)&&t.uint(this.id)&&t.string(this.name)&&t.string(this.value)}});i.set(12,l);const p=t(class{constructor(t,i){this.id=t,this.name=i,this._id=13}encode(t){return t.uint(13)&&t.uint(this.id)&&t.string(this.name)}});i.set(13,p);const g=t(class{constructor(t,i){this.id=t,this.data=i,this._id=14}encode(t){return t.uint(14)&&t.uint(this.id)&&t.string(this.data)}});i.set(14,g);const m=t(class{constructor(t,i,s){this.id=t,this.x=i,this.y=s,this._id=16}encode(t){return t.uint(16)&&t.uint(this.id)&&t.int(this.x)&&t.int(this.y)}});i.set(16,m);const f=t(class{constructor(t,i){this.id=t,this.label=i,this._id=17}encode(t){return t.uint(17)&&t.uint(this.id)&&t.string(this.label)}});i.set(17,f);const y=t(class{constructor(t,i,s){this.id=t,this.value=i,this.mask=s,this._id=18}encode(t){return t.uint(18)&&t.uint(this.id)&&t.string(this.value)&&t.int(this.mask)}});i.set(18,y);const _=t(class{constructor(t,i){this.id=t,this.checked=i,this._id=19}encode(t){return t.uint(19)&&t.uint(this.id)&&t.boolean(this.checked)}});i.set(19,_);const v=t(class{constructor(t,i){this.x=t,this.y=i,this._id=20}encode(t){return t.uint(20)&&t.uint(this.x)&&t.uint(this.y)}});i.set(20,v);const S=t(class{constructor(t,i){this.level=t,this.value=i,this._id=22}encode(t){return t.uint(22)&&t.string(this.level)&&t.string(this.value)}});i.set(22,S);const b=t(class{constructor(t,i,s,e,n,r,h,o,c){this.requestStart=t,this.responseStart=i,this.responseEnd=s,this.domContentLoadedEventStart=e,this.domContentLoadedEventEnd=n,this.loadEventStart=r,this.loadEventEnd=h,this.firstPaint=o,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)}});i.set(23,b);const w=t(class{constructor(t,i,s){this.speedIndex=t,this.visuallyComplete=i,this.timeToInteractive=s,this._id=24}encode(t){return t.uint(24)&&t.uint(this.speedIndex)&&t.uint(this.visuallyComplete)&&t.uint(this.timeToInteractive)}});i.set(24,w);const E=t(class{constructor(t,i,s){this.name=t,this.message=i,this.payload=s,this._id=25}encode(t){return t.uint(25)&&t.string(this.name)&&t.string(this.message)&&t.string(this.payload)}});i.set(25,E);const x=t(class{constructor(t,i){this.name=t,this.payload=i,this._id=27}encode(t){return t.uint(27)&&t.string(this.name)&&t.string(this.payload)}});i.set(27,x);const T=t(class{constructor(t){this.id=t,this._id=28}encode(t){return t.uint(28)&&t.string(this.id)}});i.set(28,T);const z=t(class{constructor(t){this.id=t,this._id=29}encode(t){return t.uint(29)&&t.string(this.id)}});i.set(29,z);const k=t(class{constructor(t,i){this.key=t,this.value=i,this._id=30}encode(t){return t.uint(30)&&t.string(this.key)&&t.string(this.value)}});i.set(30,k);const A=t(class{constructor(t,i,s){this.id=t,this.rule=i,this.index=s,this._id=37}encode(t){return t.uint(37)&&t.uint(this.id)&&t.string(this.rule)&&t.uint(this.index)}});i.set(37,A);const I=t(class{constructor(t,i){this.id=t,this.index=i,this._id=38}encode(t){return t.uint(38)&&t.uint(this.id)&&t.uint(this.index)}});i.set(38,I);const L=t(class{constructor(t,i,s,e,n,r,h){this.method=t,this.url=i,this.request=s,this.response=e,this.status=n,this.timestamp=r,this.duration=h,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)}});i.set(39,L);const C=t(class{constructor(t,i,s,e){this.name=t,this.duration=i,this.args=s,this.result=e,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)}});i.set(40,C);const M=t(class{constructor(t,i){this.key=t,this.value=i,this._id=41}encode(t){return t.uint(41)&&t.string(this.key)&&t.string(this.value)}});i.set(41,M);const N=t(class{constructor(t){this.type=t,this._id=42}encode(t){return t.uint(42)&&t.string(this.type)}});i.set(42,N);const B=t(class{constructor(t,i,s){this.action=t,this.state=i,this.duration=s,this._id=44}encode(t){return t.uint(44)&&t.string(this.action)&&t.string(this.state)&&t.uint(this.duration)}});i.set(44,B);const U=t(class{constructor(t,i){this.mutation=t,this.state=i,this._id=45}encode(t){return t.uint(45)&&t.string(this.mutation)&&t.string(this.state)}});i.set(45,U);const R=t(class{constructor(t,i){this.type=t,this.payload=i,this._id=46}encode(t){return t.uint(46)&&t.string(this.type)&&t.string(this.payload)}});i.set(46,R);const O=t(class{constructor(t,i,s){this.action=t,this.state=i,this.duration=s,this._id=47}encode(t){return t.uint(47)&&t.string(this.action)&&t.string(this.state)&&t.uint(this.duration)}});i.set(47,O);const P=t(class{constructor(t,i,s,e){this.operationKind=t,this.operationName=i,this.variables=s,this.response=e,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)}});i.set(48,P);const q=t(class{constructor(t,i,s,e){this.frames=t,this.ticks=i,this.totalJSHeapSize=s,this.usedJSHeapSize=e,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)}});i.set(49,q);const D=t(class{constructor(t,i,s,e,n,r,h,o){this.timestamp=t,this.duration=i,this.ttfb=s,this.headerSize=e,this.encodedBodySize=n,this.decodedBodySize=r,this.url=h,this.initiator=o,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)}});i.set(53,D);const W=t(class{constructor(t,i){this.downlink=t,this.type=i,this._id=54}encode(t){return t.uint(54)&&t.uint(this.downlink)&&t.string(this.type)}});i.set(54,W);const H=t(class{constructor(t){this.hidden=t,this._id=55}encode(t){return t.uint(55)&&t.boolean(this.hidden)}});i.set(55,H);const J=t(class{constructor(t,i,s,e,n,r,h){this.timestamp=t,this.duration=i,this.context=s,this.containerType=e,this.containerSrc=n,this.containerId=r,this.containerName=h,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)}});i.set(59,J);const F=t(class{constructor(t,i,s,e){this.id=t,this.name=i,this.value=s,this.baseURL=e,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)}});i.set(60,F);const X=t(class{constructor(t,i,s){this.id=t,this.data=i,this.baseURL=s,this._id=61}encode(t){return t.uint(61)&&t.uint(this.id)&&t.string(this.data)&&t.string(this.baseURL)}});i.set(61,X);const G=t(class{constructor(t,i){this.type=t,this.value=i,this._id=63}encode(t){return t.uint(63)&&t.string(this.type)&&t.string(this.value)}});i.set(63,G);const K=t(class{constructor(t,i){this.name=t,this.payload=i,this._id=64}encode(t){return t.uint(64)&&t.string(this.name)&&t.string(this.payload)}});i.set(64,K);const j=t(class{constructor(){this._id=65}encode(t){return t.uint(65)}});i.set(65,j);const Q=t(class{constructor(t,i,s,e){this.id=t,this.rule=i,this.index=s,this.baseURL=e,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)}});i.set(67,Q);const V=t(class{constructor(t,i,s,e){this.id=t,this.hesitationTime=i,this.label=s,this.selector=e,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)}});i.set(69,V);const Y=t(class{constructor(t,i){this.frameID=t,this.id=i,this._id=70}encode(t){return t.uint(70)&&t.uint(this.frameID)&&t.uint(this.id)}});i.set(70,Y);class Z{constructor(t,i,s,e=10,n=1e3){this.onUnauthorised=i,this.onFailure=s,this.MAX_ATTEMPTS_COUNT=e,this.ATTEMPT_TIMEOUT=n,this.attemptsCount=0,this.busy=!1,this.queue=[],this.token=null,this.ingestURL=t+"/v1/web/i"}authorise(t){this.token=t}push(t){this.busy||!this.token?this.queue.push(t):this.sendBatch(t)}retry(t){this.attemptsCount>=this.MAX_ATTEMPTS_COUNT?this.onFailure():(this.attemptsCount++,setTimeout(()=>this.sendBatch(t),this.ATTEMPT_TIMEOUT*this.attemptsCount))}sendBatch(t){this.busy=!0,fetch(this.ingestURL,{body:t,method:"POST",headers:{Authorization:"Bearer "+this.token},keepalive:t.length<65536}).then(i=>{if(401===i.status)return this.busy=!1,void this.onUnauthorised();if(i.status>=400)return void this.retry(t);this.attemptsCount=0;const s=this.queue.shift();s?this.sendBatch(s):this.busy=!1}).catch(i=>{console.warn("OpenReplay:",i),this.retry(t)})}clean(){this.queue.length=0}}const tt="function"==typeof TextEncoder?new TextEncoder:{encode(t){const i=t.length,s=new Uint8Array(3*i);let e=-1;for(let n=0,r=0,h=0;h!==i;){if(n=t.charCodeAt(h),h+=1,n>=55296&&n<=56319){if(h===i){s[e+=1]=239,s[e+=1]=191,s[e+=1]=189;break}if(r=t.charCodeAt(h),!(r>=56320&&r<=57343)){s[e+=1]=239,s[e+=1]=191,s[e+=1]=189;continue}if(n=1024*(n-55296)+r-56320+65536,h+=1,n>65535){s[e+=1]=240|n>>>18,s[e+=1]=128|n>>>12&63,s[e+=1]=128|n>>>6&63,s[e+=1]=128|63&n;continue}}n<=127?s[e+=1]=0|n:n<=2047?(s[e+=1]=192|n>>>6,s[e+=1]=128|63&n):(s[e+=1]=224|n>>>12,s[e+=1]=128|n>>>6&63,s[e+=1]=128|63&n)}return s.subarray(0,e+1)}};class it{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 i=tt.encode(t),s=i.byteLength;return!(!this.uint(s)||this.offset+s>this.size)&&(this.data.set(i,this.offset),this.offset+=s,!0)}reset(){this.offset=0,this.checkpointOffset=0}flush(){const t=this.data.slice(0,this.checkpointOffset);return this.reset(),t}}class st{constructor(t,i,s){this.pageNo=t,this.timestamp=i,this.onBatch=s,this.nextIndex=0,this.beaconSize=2e5,this.writer=new it(this.beaconSize),this.isEmpty=!0,this.beaconSizeLimit=1e6,this.prepare()}prepare(){this.writer.isEmpty()&&new s(this.pageNo,this.nextIndex,this.timestamp).encode(this.writer)}write(t){const i=t.encode(this.writer);return i&&(this.isEmpty=!1,this.writer.checkpoint(),this.nextIndex++),i}setBeaconSizeLimit(t){this.beaconSizeLimit=t}writeMessage(t){if(t instanceof e&&(this.timestamp=t.timestamp),!this.write(t))for(this.finaliseBatch();!this.write(t);){if(this.beaconSize===this.beaconSizeLimit)return console.warn("OpenReplay: beacon size overflow. Skipping large message."),this.writer.reset(),this.prepare(),void(this.isEmpty=!0);this.beaconSize=Math.min(2*this.beaconSize,this.beaconSizeLimit),this.writer=new it(this.beaconSize),this.prepare(),this.isEmpty=!0}}finaliseBatch(){this.isEmpty||(this.onBatch(this.writer.flush()),this.prepare(),this.isEmpty=!0)}clean(){this.writer.reset()}}var et;!function(t){t[t.NotActive=0]="NotActive",t[t.Starting=1]="Starting",t[t.Stopping=2]="Stopping",t[t.Active=3]="Active"}(et||(et={}));let nt=null,rt=null;function ht(){rt&&rt.finaliseBatch()}function ot(){et.Stopping,null!==at&&(clearInterval(at),at=null),rt&&(rt.clean(),rt=null),et.NotActive}et.NotActive;let ct,at=null;self.onmessage=({data:t})=>{if(null!=t){if("stop"===t)return ht(),void ot();if(Array.isArray(t)){if(!rt)throw new Error("WebWorker: writer not initialised. Service Should be Started.");const s=rt;t.forEach(t=>{const e=new(i.get(t._id));Object.assign(e,t),e instanceof H&&(e.hidden?ct=setTimeout(()=>self.postMessage("restart"),18e5):clearTimeout(ct)),s.writeMessage(e)})}else{if("start"===t.type)return et.Starting,nt=new Z(t.ingestPoint,()=>{self.postMessage("restart")},()=>{nt&&(nt.clean(),nt=null),ot(),self.postMessage("failed")},t.connAttemptCount,t.connAttemptGap),rt=new st(t.pageNo,t.timestamp,t=>nt&&nt.push(t)),null===at&&(at=setInterval(ht,1e4)),et.Active;if("auth"===t.type){if(!nt)throw new Error("WebWorker: sender not initialised. Received auth.");if(!rt)throw new Error("WebWorker: writer not initialised. Received auth.");return nt.authorise(t.token),void(t.beaconSizeLimit&&rt.setBeaconSizeLimit(t.beaconSizeLimit))}}}else ht()};'], { type: 'text/javascript' })));
|
|
79
|
+
this.worker.onerror = (e) => {
|
|
80
|
+
this._debug('webworker_error', e);
|
|
82
81
|
};
|
|
83
82
|
this.worker.onmessage = ({ data }) => {
|
|
84
|
-
if (data ===
|
|
83
|
+
if (data === 'failed') {
|
|
85
84
|
this.stop();
|
|
86
|
-
this._debug(
|
|
85
|
+
this._debug('worker_failed', {}); // add context (from worker)
|
|
87
86
|
}
|
|
88
|
-
else if (data ===
|
|
87
|
+
else if (data === 'restart') {
|
|
89
88
|
this.stop();
|
|
90
89
|
this.start({ forceNew: true });
|
|
91
90
|
}
|
|
@@ -102,7 +101,7 @@ class App {
|
|
|
102
101
|
this.attachEventListener(document, 'visibilitychange', alertWorker, false);
|
|
103
102
|
}
|
|
104
103
|
catch (e) {
|
|
105
|
-
this._debug(
|
|
104
|
+
this._debug('worker_start', e);
|
|
106
105
|
}
|
|
107
106
|
}
|
|
108
107
|
_debug(context, e) {
|
|
@@ -112,20 +111,20 @@ class App {
|
|
|
112
111
|
headers: { 'Content-Type': 'application/json' },
|
|
113
112
|
body: JSON.stringify({
|
|
114
113
|
context,
|
|
115
|
-
error: `${e}
|
|
116
|
-
})
|
|
114
|
+
error: `${e}`,
|
|
115
|
+
}),
|
|
117
116
|
});
|
|
118
117
|
}
|
|
119
|
-
this.debug.error(
|
|
118
|
+
this.debug.error('OpenReplay error: ', context, e);
|
|
120
119
|
}
|
|
121
120
|
send(message, urgent = false) {
|
|
122
121
|
if (this.activityState === ActivityState.NotActive) {
|
|
123
122
|
return;
|
|
124
123
|
}
|
|
125
124
|
this.messages.push(message);
|
|
126
|
-
// TODO: commit on start if there were `urgent` sends;
|
|
125
|
+
// TODO: commit on start if there were `urgent` sends;
|
|
127
126
|
// Clearify where urgent can be used for;
|
|
128
|
-
// Clearify workflow for each type of message in case it was sent before start
|
|
127
|
+
// Clearify workflow for each type of message in case it was sent before start
|
|
129
128
|
// (like Fetch before start; maybe add an option "preCapture: boolean" or sth alike)
|
|
130
129
|
if (this.activityState === ActivityState.Active && urgent) {
|
|
131
130
|
this.commit();
|
|
@@ -135,7 +134,7 @@ class App {
|
|
|
135
134
|
if (this.worker && this.messages.length) {
|
|
136
135
|
this.messages.unshift(new messages_js_1.Timestamp((0, utils_js_1.timestamp)()));
|
|
137
136
|
this.worker.postMessage(this.messages);
|
|
138
|
-
this.commitCallbacks.forEach(cb => cb(this.messages));
|
|
137
|
+
this.commitCallbacks.forEach((cb) => cb(this.messages));
|
|
139
138
|
this.messages.length = 0;
|
|
140
139
|
}
|
|
141
140
|
}
|
|
@@ -146,8 +145,7 @@ class App {
|
|
|
146
145
|
fn.apply(this, args);
|
|
147
146
|
}
|
|
148
147
|
catch (e) {
|
|
149
|
-
|
|
150
|
-
app._debug("safe_fn_call", e);
|
|
148
|
+
app._debug('safe_fn_call', e);
|
|
151
149
|
// time: timestamp(),
|
|
152
150
|
// name: e.name,
|
|
153
151
|
// message: e.message,
|
|
@@ -222,12 +220,13 @@ class App {
|
|
|
222
220
|
return document.baseURI;
|
|
223
221
|
}
|
|
224
222
|
// IE only
|
|
225
|
-
return ((_b = (_a = document.head) === null || _a === void 0 ? void 0 : _a.getElementsByTagName(
|
|
223
|
+
return (((_b = (_a = document.head) === null || _a === void 0 ? void 0 : _a.getElementsByTagName('base')[0]) === null || _b === void 0 ? void 0 : _b.getAttribute('href')) ||
|
|
224
|
+
location.origin + location.pathname);
|
|
226
225
|
}
|
|
227
226
|
resolveResourceURL(resourceURL) {
|
|
228
227
|
const base = new URL(this.getBaseHref());
|
|
229
|
-
base.pathname +=
|
|
230
|
-
base.pathname.replace(/\/+/g,
|
|
228
|
+
base.pathname += '/' + new URL(resourceURL).pathname;
|
|
229
|
+
base.pathname.replace(/\/+/g, '/');
|
|
231
230
|
return base.toString();
|
|
232
231
|
}
|
|
233
232
|
isServiceURL(url) {
|
|
@@ -246,10 +245,10 @@ class App {
|
|
|
246
245
|
}
|
|
247
246
|
_start(startOpts) {
|
|
248
247
|
if (!this.worker) {
|
|
249
|
-
return Promise.resolve(UnsuccessfulStart(
|
|
248
|
+
return Promise.resolve(UnsuccessfulStart('No worker found: perhaps, CSP is not set.'));
|
|
250
249
|
}
|
|
251
250
|
if (this.activityState !== ActivityState.NotActive) {
|
|
252
|
-
return Promise.resolve(UnsuccessfulStart(
|
|
251
|
+
return Promise.resolve(UnsuccessfulStart('OpenReplay: trying to call `start()` on the instance that has been started already.'));
|
|
253
252
|
}
|
|
254
253
|
this.activityState = ActivityState.Starting;
|
|
255
254
|
let pageNo = 0;
|
|
@@ -261,7 +260,7 @@ class App {
|
|
|
261
260
|
this.sessionStorage.setItem(this.options.session_pageno_key, pageNo.toString());
|
|
262
261
|
const startInfo = this.getStartInfo();
|
|
263
262
|
const startWorkerMsg = {
|
|
264
|
-
type:
|
|
263
|
+
type: 'start',
|
|
265
264
|
pageNo,
|
|
266
265
|
ingestPoint: this.options.ingestPoint,
|
|
267
266
|
timestamp: startInfo.timestamp,
|
|
@@ -270,14 +269,16 @@ class App {
|
|
|
270
269
|
};
|
|
271
270
|
this.worker.postMessage(startWorkerMsg);
|
|
272
271
|
this.session.update({
|
|
273
|
-
// "
|
|
272
|
+
// TODO: transparent "session" module logic AND explicit internal api for plugins.
|
|
273
|
+
// "updating" with old metadata in order to trigger session's UpdateCallbacks.
|
|
274
274
|
// (for the case of internal .start() calls, like on "restart" webworker signal or assistent connection in tracker-assist )
|
|
275
275
|
metadata: startOpts.metadata || this.session.getInfo().metadata,
|
|
276
276
|
userID: startOpts.userID,
|
|
277
277
|
});
|
|
278
278
|
const sReset = this.sessionStorage.getItem(this.options.session_reset_key);
|
|
279
279
|
this.sessionStorage.removeItem(this.options.session_reset_key);
|
|
280
|
-
return window
|
|
280
|
+
return window
|
|
281
|
+
.fetch(this.options.ingestPoint + '/v1/web/start', {
|
|
281
282
|
method: 'POST',
|
|
282
283
|
headers: {
|
|
283
284
|
'Content-Type': 'application/json',
|
|
@@ -285,19 +286,21 @@ class App {
|
|
|
285
286
|
body: JSON.stringify(Object.assign(Object.assign({}, startInfo), { userID: this.session.getInfo().userID, token: this.sessionStorage.getItem(this.options.session_token_key), deviceMemory: performance_js_1.deviceMemory,
|
|
286
287
|
jsHeapSizeLimit: performance_js_1.jsHeapSizeLimit, reset: startOpts.forceNew || sReset !== null })),
|
|
287
288
|
})
|
|
288
|
-
.then(r => {
|
|
289
|
+
.then((r) => {
|
|
289
290
|
if (r.status === 200) {
|
|
290
291
|
return r.json();
|
|
291
292
|
}
|
|
292
293
|
else {
|
|
293
|
-
return r
|
|
294
|
+
return r
|
|
295
|
+
.text()
|
|
296
|
+
.then((text) => text === CANCELED
|
|
294
297
|
? Promise.reject(CANCELED)
|
|
295
298
|
: Promise.reject(`Server error: ${r.status}. ${text}`));
|
|
296
299
|
}
|
|
297
300
|
})
|
|
298
|
-
.then(r => {
|
|
301
|
+
.then((r) => {
|
|
299
302
|
if (!this.worker) {
|
|
300
|
-
return Promise.reject(
|
|
303
|
+
return Promise.reject('no worker found after start request (this might not happen)');
|
|
301
304
|
}
|
|
302
305
|
const { token, userUUID, sessionID, beaconSizeLimit } = r;
|
|
303
306
|
if (typeof token !== 'string' ||
|
|
@@ -309,9 +312,9 @@ class App {
|
|
|
309
312
|
this.localStorage.setItem(this.options.local_uuid_key, userUUID);
|
|
310
313
|
this.session.update({ sessionID }); // TODO: no no-explicit 'any'
|
|
311
314
|
const startWorkerMsg = {
|
|
312
|
-
type:
|
|
315
|
+
type: 'auth',
|
|
313
316
|
token,
|
|
314
|
-
beaconSizeLimit
|
|
317
|
+
beaconSizeLimit,
|
|
315
318
|
};
|
|
316
319
|
this.worker.postMessage(startWorkerMsg);
|
|
317
320
|
this.activityState = ActivityState.Active;
|
|
@@ -319,31 +322,21 @@ class App {
|
|
|
319
322
|
this.startCallbacks.forEach((cb) => cb(onStartInfo)); // TODO: start as early as possible (before receiving the token)
|
|
320
323
|
this.observer.observe();
|
|
321
324
|
this.ticker.start();
|
|
322
|
-
this.notify.log(
|
|
323
|
-
// // GC
|
|
324
|
-
// if (!this.gc) {
|
|
325
|
-
// this.gc = setInterval(() => {
|
|
326
|
-
// console.log('checking')
|
|
327
|
-
// // @ts-ignore
|
|
328
|
-
// if (window.performance.memory.usedJSHeapSize > this.options.maxMemorySize) {
|
|
329
|
-
// this.restart();
|
|
330
|
-
// }
|
|
331
|
-
// }, this.options.memoryCheckInterval)
|
|
332
|
-
// }
|
|
325
|
+
this.notify.log('OpenReplay tracking started.');
|
|
333
326
|
// get rid of onStart ?
|
|
334
327
|
if (typeof this.options.onStart === 'function') {
|
|
335
328
|
this.options.onStart(onStartInfo);
|
|
336
329
|
}
|
|
337
330
|
return SuccessfulStart(onStartInfo);
|
|
338
331
|
})
|
|
339
|
-
.catch(reason => {
|
|
332
|
+
.catch((reason) => {
|
|
340
333
|
this.sessionStorage.removeItem(this.options.session_token_key);
|
|
341
334
|
this.stop();
|
|
342
335
|
if (reason === CANCELED) {
|
|
343
336
|
return UnsuccessfulStart(CANCELED);
|
|
344
337
|
}
|
|
345
|
-
this.notify.log(
|
|
346
|
-
this._debug(
|
|
338
|
+
this.notify.log('OpenReplay was unable to start. ', reason);
|
|
339
|
+
this._debug('session_start', reason);
|
|
347
340
|
return UnsuccessfulStart(START_ERROR);
|
|
348
341
|
});
|
|
349
342
|
}
|
|
@@ -355,18 +348,17 @@ class App {
|
|
|
355
348
|
return new Promise((resolve) => {
|
|
356
349
|
const onVisibilityChange = () => {
|
|
357
350
|
if (!document.hidden) {
|
|
358
|
-
document.removeEventListener(
|
|
351
|
+
document.removeEventListener('visibilitychange', onVisibilityChange);
|
|
359
352
|
resolve(this._start(options));
|
|
360
353
|
}
|
|
361
354
|
};
|
|
362
|
-
document.addEventListener(
|
|
355
|
+
document.addEventListener('visibilitychange', onVisibilityChange);
|
|
363
356
|
});
|
|
364
357
|
}
|
|
365
358
|
}
|
|
366
359
|
stop(calledFromAPI = false, restarting = false) {
|
|
367
360
|
if (this.activityState !== ActivityState.NotActive) {
|
|
368
361
|
try {
|
|
369
|
-
// this.gc && clearInterval(this.gc)
|
|
370
362
|
this.sanitizer.clear();
|
|
371
363
|
this.observer.disconnect();
|
|
372
364
|
this.nodes.clear();
|
|
@@ -375,9 +367,9 @@ class App {
|
|
|
375
367
|
if (calledFromAPI) {
|
|
376
368
|
this.session.reset();
|
|
377
369
|
}
|
|
378
|
-
this.notify.log(
|
|
370
|
+
this.notify.log('OpenReplay tracking stopped.');
|
|
379
371
|
if (this.worker && !restarting) {
|
|
380
|
-
this.worker.postMessage(
|
|
372
|
+
this.worker.postMessage('stop');
|
|
381
373
|
}
|
|
382
374
|
}
|
|
383
375
|
finally {
|
package/cjs/app/logger.js
CHANGED
|
@@ -13,9 +13,12 @@ function IsCustomLevel(l) {
|
|
|
13
13
|
}
|
|
14
14
|
class Logger {
|
|
15
15
|
constructor(options = exports.LogLevel.Silent) {
|
|
16
|
-
this.options =
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
this.options =
|
|
17
|
+
options === true
|
|
18
|
+
? { level: exports.LogLevel.Verbose }
|
|
19
|
+
: typeof options === 'number'
|
|
20
|
+
? { level: options }
|
|
21
|
+
: options;
|
|
19
22
|
}
|
|
20
23
|
log(...args) {
|
|
21
24
|
if (IsCustomLevel(this.options.level)
|
package/cjs/app/nodes.d.ts
CHANGED
|
@@ -1,16 +1,10 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
1
|
declare type NodeCallback = (node: Node, isStart: boolean) => void;
|
|
3
|
-
export interface CheckOptions {
|
|
4
|
-
maxMemorySize: number;
|
|
5
|
-
memoryCheckInterval: number;
|
|
6
|
-
}
|
|
7
2
|
export default class Nodes {
|
|
8
3
|
private readonly node_id;
|
|
9
4
|
private nodes;
|
|
10
5
|
private readonly nodeCallbacks;
|
|
11
6
|
private readonly elementListeners;
|
|
12
|
-
|
|
13
|
-
constructor(node_id: string, maxMemorySize: CheckOptions["maxMemorySize"], memoryCheckInterval: CheckOptions["memoryCheckInterval"]);
|
|
7
|
+
constructor(node_id: string);
|
|
14
8
|
attachNodeCallback(nodeCallback: NodeCallback): void;
|
|
15
9
|
attachElementListener(type: string, node: Element, elementListener: EventListener): void;
|
|
16
10
|
registerNode(node: Node): [id: number, isNew: boolean];
|
|
@@ -18,7 +12,7 @@ export default class Nodes {
|
|
|
18
12
|
cleanTree(): void;
|
|
19
13
|
callNodeCallbacks(node: Node, isStart: boolean): void;
|
|
20
14
|
getID(node: Node): number | undefined;
|
|
21
|
-
getNode(id: number):
|
|
15
|
+
getNode(id: number): void | Node;
|
|
22
16
|
clear(): void;
|
|
23
17
|
}
|
|
24
18
|
export {};
|
package/cjs/app/nodes.js
CHANGED
|
@@ -1,17 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
class Nodes {
|
|
4
|
-
constructor(node_id
|
|
4
|
+
constructor(node_id) {
|
|
5
5
|
this.node_id = node_id;
|
|
6
6
|
this.nodes = [];
|
|
7
7
|
this.nodeCallbacks = [];
|
|
8
8
|
this.elementListeners = new Map();
|
|
9
|
-
this.gc = setInterval(() => {
|
|
10
|
-
// @ts-ignore should use settings object here
|
|
11
|
-
if (window.performance.memory.usedJSHeapSize > maxMemorySize) {
|
|
12
|
-
this.cleanTree();
|
|
13
|
-
}
|
|
14
|
-
}, memoryCheckInterval);
|
|
15
9
|
}
|
|
16
10
|
attachNodeCallback(nodeCallback) {
|
|
17
11
|
this.nodeCallbacks.push(nodeCallback);
|
|
@@ -44,7 +38,7 @@ class Nodes {
|
|
|
44
38
|
const id = node[this.node_id];
|
|
45
39
|
if (id !== undefined) {
|
|
46
40
|
delete node[this.node_id];
|
|
47
|
-
this.nodes[id]
|
|
41
|
+
delete this.nodes[id];
|
|
48
42
|
const listeners = this.elementListeners.get(id);
|
|
49
43
|
if (listeners !== undefined) {
|
|
50
44
|
this.elementListeners.delete(id);
|
|
@@ -60,13 +54,8 @@ class Nodes {
|
|
|
60
54
|
// performance test: 3ms for 30k nodes with 17k dead ones
|
|
61
55
|
for (let i = 0; i < this.nodes.length; i++) {
|
|
62
56
|
const node = this.nodes[i];
|
|
63
|
-
if (node
|
|
64
|
-
delete this.nodes[i];
|
|
65
|
-
continue;
|
|
66
|
-
}
|
|
67
|
-
if (!document.contains(node)) {
|
|
57
|
+
if (node && !document.contains(node)) {
|
|
68
58
|
this.unregisterNode(node);
|
|
69
|
-
delete this.nodes[i];
|
|
70
59
|
}
|
|
71
60
|
}
|
|
72
61
|
}
|
|
@@ -88,10 +77,6 @@ class Nodes {
|
|
|
88
77
|
this.unregisterNode(node);
|
|
89
78
|
}
|
|
90
79
|
this.nodes.length = 0;
|
|
91
|
-
if (this.gc) {
|
|
92
|
-
clearInterval(this.gc);
|
|
93
|
-
this.gc = undefined;
|
|
94
|
-
}
|
|
95
80
|
}
|
|
96
81
|
}
|
|
97
82
|
exports.default = Nodes;
|
|
@@ -12,7 +12,7 @@ class IFrameObserver extends observer_js_1.default {
|
|
|
12
12
|
// Have to observe document, because the inner <html> might be changed
|
|
13
13
|
this.observeRoot(doc, (docID) => {
|
|
14
14
|
if (docID === undefined) {
|
|
15
|
-
console.log(
|
|
15
|
+
console.log('OpenReplay: Iframe document not bound');
|
|
16
16
|
return;
|
|
17
17
|
}
|
|
18
18
|
this.app.send((0, messages_js_1.CreateIFrameDocument)(hostID, docID));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import App from
|
|
1
|
+
import App from '../index.js';
|
|
2
2
|
export default abstract class Observer {
|
|
3
3
|
protected readonly app: App;
|
|
4
4
|
protected readonly isTopContext: boolean;
|
|
@@ -13,6 +13,7 @@ export default abstract class Observer {
|
|
|
13
13
|
private sendNodeAttribute;
|
|
14
14
|
private sendNodeData;
|
|
15
15
|
private bindNode;
|
|
16
|
+
private unbindChildNode;
|
|
16
17
|
private bindTree;
|
|
17
18
|
private unbindNode;
|
|
18
19
|
private _commitNode;
|