@openreplay/tracker 3.5.16 → 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 +14 -14
- package/cjs/app/index.js +51 -44
- package/cjs/app/logger.js +6 -3
- 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 +1 -1
- package/cjs/app/observer/observer.js +12 -15
- 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 +27 -27
- 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 +15 -15
- 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 +14 -14
- package/lib/app/index.js +60 -53
- package/lib/app/logger.js +6 -3
- 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 +1 -1
- package/lib/app/observer/observer.js +14 -17
- 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 +42 -42
- 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 +18 -18
- 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 from
|
|
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,8 +44,8 @@ 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;
|
|
47
|
+
localStorage: Storage | null;
|
|
48
|
+
sessionStorage: Storage | null;
|
|
49
49
|
onStart?: StartCallback;
|
|
50
50
|
} & WebworkerOptions;
|
|
51
51
|
export declare type Options = AppOptions & ObserverOptions & SanitizerOptions;
|
|
@@ -68,7 +68,7 @@ export default class App {
|
|
|
68
68
|
private readonly options;
|
|
69
69
|
private readonly revID;
|
|
70
70
|
private activityState;
|
|
71
|
-
private version;
|
|
71
|
+
private readonly version;
|
|
72
72
|
private readonly worker?;
|
|
73
73
|
constructor(projectKey: string, sessionToken: string | null | undefined, options: Partial<Options>);
|
|
74
74
|
private _debug;
|
|
@@ -77,7 +77,7 @@ export default class App {
|
|
|
77
77
|
safe<T extends (...args: any[]) => void>(fn: T): T;
|
|
78
78
|
attachCommitCallback(cb: CommitCallback): void;
|
|
79
79
|
attachStartCallback(cb: StartCallback): void;
|
|
80
|
-
attachStopCallback(cb:
|
|
80
|
+
attachStopCallback(cb: () => any): void;
|
|
81
81
|
attachEventListener(target: EventTarget, type: string, listener: EventListener, useSafe?: boolean, useCapture?: boolean): void;
|
|
82
82
|
checkRequiredVersion(version: string): boolean;
|
|
83
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,6 +27,7 @@ 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
|
+
var _a, _b;
|
|
30
31
|
this.messages = [];
|
|
31
32
|
this.startCallbacks = [];
|
|
32
33
|
this.stopCallbacks = [];
|
|
@@ -46,8 +47,8 @@ class App {
|
|
|
46
47
|
verbose: false,
|
|
47
48
|
__is_snippet: false,
|
|
48
49
|
__debug_report_edp: null,
|
|
49
|
-
localStorage:
|
|
50
|
-
sessionStorage:
|
|
50
|
+
localStorage: null,
|
|
51
|
+
sessionStorage: null,
|
|
51
52
|
}, options);
|
|
52
53
|
this.revID = this.options.revID;
|
|
53
54
|
this.sanitizer = new sanitizer_js_1.default(this, options);
|
|
@@ -59,30 +60,31 @@ class App {
|
|
|
59
60
|
this.notify = new logger_js_1.default(this.options.verbose ? logger_js_1.LogLevel.Warnings : logger_js_1.LogLevel.Silent);
|
|
60
61
|
this.session = new session_js_1.default();
|
|
61
62
|
this.session.attachUpdateCallback(({ userID, metadata }) => {
|
|
62
|
-
if (userID != null) {
|
|
63
|
+
if (userID != null) {
|
|
64
|
+
// TODO: nullable userID
|
|
63
65
|
this.send(new messages_js_1.UserID(userID));
|
|
64
66
|
}
|
|
65
67
|
if (metadata != null) {
|
|
66
68
|
Object.entries(metadata).forEach(([key, value]) => this.send(new messages_js_1.Metadata(key, value)));
|
|
67
69
|
}
|
|
68
70
|
});
|
|
69
|
-
|
|
70
|
-
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;
|
|
71
74
|
if (sessionToken != null) {
|
|
72
75
|
this.sessionStorage.setItem(this.options.session_token_key, sessionToken);
|
|
73
76
|
}
|
|
74
77
|
try {
|
|
75
|
-
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()};
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
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);
|
|
79
81
|
};
|
|
80
82
|
this.worker.onmessage = ({ data }) => {
|
|
81
|
-
if (data ===
|
|
83
|
+
if (data === 'failed') {
|
|
82
84
|
this.stop();
|
|
83
|
-
this._debug(
|
|
85
|
+
this._debug('worker_failed', {}); // add context (from worker)
|
|
84
86
|
}
|
|
85
|
-
else if (data ===
|
|
87
|
+
else if (data === 'restart') {
|
|
86
88
|
this.stop();
|
|
87
89
|
this.start({ forceNew: true });
|
|
88
90
|
}
|
|
@@ -99,7 +101,7 @@ class App {
|
|
|
99
101
|
this.attachEventListener(document, 'visibilitychange', alertWorker, false);
|
|
100
102
|
}
|
|
101
103
|
catch (e) {
|
|
102
|
-
this._debug(
|
|
104
|
+
this._debug('worker_start', e);
|
|
103
105
|
}
|
|
104
106
|
}
|
|
105
107
|
_debug(context, e) {
|
|
@@ -109,20 +111,20 @@ class App {
|
|
|
109
111
|
headers: { 'Content-Type': 'application/json' },
|
|
110
112
|
body: JSON.stringify({
|
|
111
113
|
context,
|
|
112
|
-
error: `${e}
|
|
113
|
-
})
|
|
114
|
+
error: `${e}`,
|
|
115
|
+
}),
|
|
114
116
|
});
|
|
115
117
|
}
|
|
116
|
-
this.debug.error(
|
|
118
|
+
this.debug.error('OpenReplay error: ', context, e);
|
|
117
119
|
}
|
|
118
120
|
send(message, urgent = false) {
|
|
119
121
|
if (this.activityState === ActivityState.NotActive) {
|
|
120
122
|
return;
|
|
121
123
|
}
|
|
122
124
|
this.messages.push(message);
|
|
123
|
-
// TODO: commit on start if there were `urgent` sends;
|
|
125
|
+
// TODO: commit on start if there were `urgent` sends;
|
|
124
126
|
// Clearify where urgent can be used for;
|
|
125
|
-
// 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
|
|
126
128
|
// (like Fetch before start; maybe add an option "preCapture: boolean" or sth alike)
|
|
127
129
|
if (this.activityState === ActivityState.Active && urgent) {
|
|
128
130
|
this.commit();
|
|
@@ -132,7 +134,7 @@ class App {
|
|
|
132
134
|
if (this.worker && this.messages.length) {
|
|
133
135
|
this.messages.unshift(new messages_js_1.Timestamp((0, utils_js_1.timestamp)()));
|
|
134
136
|
this.worker.postMessage(this.messages);
|
|
135
|
-
this.commitCallbacks.forEach(cb => cb(this.messages));
|
|
137
|
+
this.commitCallbacks.forEach((cb) => cb(this.messages));
|
|
136
138
|
this.messages.length = 0;
|
|
137
139
|
}
|
|
138
140
|
}
|
|
@@ -143,7 +145,7 @@ class App {
|
|
|
143
145
|
fn.apply(this, args);
|
|
144
146
|
}
|
|
145
147
|
catch (e) {
|
|
146
|
-
app._debug(
|
|
148
|
+
app._debug('safe_fn_call', e);
|
|
147
149
|
// time: timestamp(),
|
|
148
150
|
// name: e.name,
|
|
149
151
|
// message: e.message,
|
|
@@ -218,12 +220,13 @@ class App {
|
|
|
218
220
|
return document.baseURI;
|
|
219
221
|
}
|
|
220
222
|
// IE only
|
|
221
|
-
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);
|
|
222
225
|
}
|
|
223
226
|
resolveResourceURL(resourceURL) {
|
|
224
227
|
const base = new URL(this.getBaseHref());
|
|
225
|
-
base.pathname +=
|
|
226
|
-
base.pathname.replace(/\/+/g,
|
|
228
|
+
base.pathname += '/' + new URL(resourceURL).pathname;
|
|
229
|
+
base.pathname.replace(/\/+/g, '/');
|
|
227
230
|
return base.toString();
|
|
228
231
|
}
|
|
229
232
|
isServiceURL(url) {
|
|
@@ -242,10 +245,10 @@ class App {
|
|
|
242
245
|
}
|
|
243
246
|
_start(startOpts) {
|
|
244
247
|
if (!this.worker) {
|
|
245
|
-
return Promise.resolve(UnsuccessfulStart(
|
|
248
|
+
return Promise.resolve(UnsuccessfulStart('No worker found: perhaps, CSP is not set.'));
|
|
246
249
|
}
|
|
247
250
|
if (this.activityState !== ActivityState.NotActive) {
|
|
248
|
-
return Promise.resolve(UnsuccessfulStart(
|
|
251
|
+
return Promise.resolve(UnsuccessfulStart('OpenReplay: trying to call `start()` on the instance that has been started already.'));
|
|
249
252
|
}
|
|
250
253
|
this.activityState = ActivityState.Starting;
|
|
251
254
|
let pageNo = 0;
|
|
@@ -257,7 +260,7 @@ class App {
|
|
|
257
260
|
this.sessionStorage.setItem(this.options.session_pageno_key, pageNo.toString());
|
|
258
261
|
const startInfo = this.getStartInfo();
|
|
259
262
|
const startWorkerMsg = {
|
|
260
|
-
type:
|
|
263
|
+
type: 'start',
|
|
261
264
|
pageNo,
|
|
262
265
|
ingestPoint: this.options.ingestPoint,
|
|
263
266
|
timestamp: startInfo.timestamp,
|
|
@@ -266,14 +269,16 @@ class App {
|
|
|
266
269
|
};
|
|
267
270
|
this.worker.postMessage(startWorkerMsg);
|
|
268
271
|
this.session.update({
|
|
269
|
-
// "
|
|
272
|
+
// TODO: transparent "session" module logic AND explicit internal api for plugins.
|
|
273
|
+
// "updating" with old metadata in order to trigger session's UpdateCallbacks.
|
|
270
274
|
// (for the case of internal .start() calls, like on "restart" webworker signal or assistent connection in tracker-assist )
|
|
271
275
|
metadata: startOpts.metadata || this.session.getInfo().metadata,
|
|
272
276
|
userID: startOpts.userID,
|
|
273
277
|
});
|
|
274
278
|
const sReset = this.sessionStorage.getItem(this.options.session_reset_key);
|
|
275
279
|
this.sessionStorage.removeItem(this.options.session_reset_key);
|
|
276
|
-
return window
|
|
280
|
+
return window
|
|
281
|
+
.fetch(this.options.ingestPoint + '/v1/web/start', {
|
|
277
282
|
method: 'POST',
|
|
278
283
|
headers: {
|
|
279
284
|
'Content-Type': 'application/json',
|
|
@@ -281,19 +286,21 @@ class App {
|
|
|
281
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,
|
|
282
287
|
jsHeapSizeLimit: performance_js_1.jsHeapSizeLimit, reset: startOpts.forceNew || sReset !== null })),
|
|
283
288
|
})
|
|
284
|
-
.then(r => {
|
|
289
|
+
.then((r) => {
|
|
285
290
|
if (r.status === 200) {
|
|
286
291
|
return r.json();
|
|
287
292
|
}
|
|
288
293
|
else {
|
|
289
|
-
return r
|
|
294
|
+
return r
|
|
295
|
+
.text()
|
|
296
|
+
.then((text) => text === CANCELED
|
|
290
297
|
? Promise.reject(CANCELED)
|
|
291
298
|
: Promise.reject(`Server error: ${r.status}. ${text}`));
|
|
292
299
|
}
|
|
293
300
|
})
|
|
294
|
-
.then(r => {
|
|
301
|
+
.then((r) => {
|
|
295
302
|
if (!this.worker) {
|
|
296
|
-
return Promise.reject(
|
|
303
|
+
return Promise.reject('no worker found after start request (this might not happen)');
|
|
297
304
|
}
|
|
298
305
|
const { token, userUUID, sessionID, beaconSizeLimit } = r;
|
|
299
306
|
if (typeof token !== 'string' ||
|
|
@@ -305,9 +312,9 @@ class App {
|
|
|
305
312
|
this.localStorage.setItem(this.options.local_uuid_key, userUUID);
|
|
306
313
|
this.session.update({ sessionID }); // TODO: no no-explicit 'any'
|
|
307
314
|
const startWorkerMsg = {
|
|
308
|
-
type:
|
|
315
|
+
type: 'auth',
|
|
309
316
|
token,
|
|
310
|
-
beaconSizeLimit
|
|
317
|
+
beaconSizeLimit,
|
|
311
318
|
};
|
|
312
319
|
this.worker.postMessage(startWorkerMsg);
|
|
313
320
|
this.activityState = ActivityState.Active;
|
|
@@ -315,21 +322,21 @@ class App {
|
|
|
315
322
|
this.startCallbacks.forEach((cb) => cb(onStartInfo)); // TODO: start as early as possible (before receiving the token)
|
|
316
323
|
this.observer.observe();
|
|
317
324
|
this.ticker.start();
|
|
318
|
-
this.notify.log(
|
|
325
|
+
this.notify.log('OpenReplay tracking started.');
|
|
319
326
|
// get rid of onStart ?
|
|
320
327
|
if (typeof this.options.onStart === 'function') {
|
|
321
328
|
this.options.onStart(onStartInfo);
|
|
322
329
|
}
|
|
323
330
|
return SuccessfulStart(onStartInfo);
|
|
324
331
|
})
|
|
325
|
-
.catch(reason => {
|
|
332
|
+
.catch((reason) => {
|
|
326
333
|
this.sessionStorage.removeItem(this.options.session_token_key);
|
|
327
334
|
this.stop();
|
|
328
335
|
if (reason === CANCELED) {
|
|
329
336
|
return UnsuccessfulStart(CANCELED);
|
|
330
337
|
}
|
|
331
|
-
this.notify.log(
|
|
332
|
-
this._debug(
|
|
338
|
+
this.notify.log('OpenReplay was unable to start. ', reason);
|
|
339
|
+
this._debug('session_start', reason);
|
|
333
340
|
return UnsuccessfulStart(START_ERROR);
|
|
334
341
|
});
|
|
335
342
|
}
|
|
@@ -341,11 +348,11 @@ class App {
|
|
|
341
348
|
return new Promise((resolve) => {
|
|
342
349
|
const onVisibilityChange = () => {
|
|
343
350
|
if (!document.hidden) {
|
|
344
|
-
document.removeEventListener(
|
|
351
|
+
document.removeEventListener('visibilitychange', onVisibilityChange);
|
|
345
352
|
resolve(this._start(options));
|
|
346
353
|
}
|
|
347
354
|
};
|
|
348
|
-
document.addEventListener(
|
|
355
|
+
document.addEventListener('visibilitychange', onVisibilityChange);
|
|
349
356
|
});
|
|
350
357
|
}
|
|
351
358
|
}
|
|
@@ -360,9 +367,9 @@ class App {
|
|
|
360
367
|
if (calledFromAPI) {
|
|
361
368
|
this.session.reset();
|
|
362
369
|
}
|
|
363
|
-
this.notify.log(
|
|
370
|
+
this.notify.log('OpenReplay tracking stopped.');
|
|
364
371
|
if (this.worker && !restarting) {
|
|
365
|
-
this.worker.postMessage(
|
|
372
|
+
this.worker.postMessage('stop');
|
|
366
373
|
}
|
|
367
374
|
}
|
|
368
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)
|
|
@@ -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));
|
|
@@ -13,13 +13,9 @@ function isIgnored(node) {
|
|
|
13
13
|
if (tag === 'LINK') {
|
|
14
14
|
const rel = node.getAttribute('rel');
|
|
15
15
|
const as = node.getAttribute('as');
|
|
16
|
-
return !((rel === null || rel === void 0 ? void 0 : rel.includes('stylesheet')) || as ===
|
|
16
|
+
return !((rel === null || rel === void 0 ? void 0 : rel.includes('stylesheet')) || as === 'style' || as === 'font');
|
|
17
17
|
}
|
|
18
|
-
return (tag === 'SCRIPT' ||
|
|
19
|
-
tag === 'NOSCRIPT' ||
|
|
20
|
-
tag === 'META' ||
|
|
21
|
-
tag === 'TITLE' ||
|
|
22
|
-
tag === 'BASE');
|
|
18
|
+
return (tag === 'SCRIPT' || tag === 'NOSCRIPT' || tag === 'META' || tag === 'TITLE' || tag === 'BASE');
|
|
23
19
|
}
|
|
24
20
|
function isObservable(node) {
|
|
25
21
|
if ((0, guards_js_1.isRootNode)(node)) {
|
|
@@ -54,7 +50,8 @@ class Observer {
|
|
|
54
50
|
this.attributesMap = new Map();
|
|
55
51
|
this.textSet = new Set();
|
|
56
52
|
this.observer = new MutationObserver(this.app.safe((mutations) => {
|
|
57
|
-
for (const mutation of mutations) {
|
|
53
|
+
for (const mutation of mutations) {
|
|
54
|
+
// mutations order is sequential
|
|
58
55
|
const target = mutation.target;
|
|
59
56
|
const type = mutation.type;
|
|
60
57
|
if (!isObservable(target)) {
|
|
@@ -83,7 +80,7 @@ class Observer {
|
|
|
83
80
|
}
|
|
84
81
|
let attr = this.attributesMap.get(id);
|
|
85
82
|
if (attr === undefined) {
|
|
86
|
-
this.attributesMap.set(id, attr = new Set());
|
|
83
|
+
this.attributesMap.set(id, (attr = new Set()));
|
|
87
84
|
}
|
|
88
85
|
attr.add(name);
|
|
89
86
|
continue;
|
|
@@ -131,7 +128,7 @@ class Observer {
|
|
|
131
128
|
return;
|
|
132
129
|
}
|
|
133
130
|
if (name === 'value' &&
|
|
134
|
-
(0, guards_js_1.hasTag)(node,
|
|
131
|
+
(0, guards_js_1.hasTag)(node, 'INPUT') &&
|
|
135
132
|
node.type !== 'button' &&
|
|
136
133
|
node.type !== 'reset' &&
|
|
137
134
|
node.type !== 'submit') {
|
|
@@ -141,7 +138,7 @@ class Observer {
|
|
|
141
138
|
this.app.send(new messages_js_1.RemoveNodeAttribute(id, name));
|
|
142
139
|
return;
|
|
143
140
|
}
|
|
144
|
-
if (name === 'style' || name === 'href' && (0, guards_js_1.hasTag)(node,
|
|
141
|
+
if (name === 'style' || (name === 'href' && (0, guards_js_1.hasTag)(node, 'LINK'))) {
|
|
145
142
|
this.app.send(new messages_js_1.SetNodeAttributeURLBased(id, name, value, this.app.getBaseHref()));
|
|
146
143
|
return;
|
|
147
144
|
}
|
|
@@ -151,7 +148,7 @@ class Observer {
|
|
|
151
148
|
this.app.send(new messages_js_1.SetNodeAttribute(id, name, value));
|
|
152
149
|
}
|
|
153
150
|
sendNodeData(id, parentElement, data) {
|
|
154
|
-
if ((0, guards_js_1.hasTag)(parentElement,
|
|
151
|
+
if ((0, guards_js_1.hasTag)(parentElement, 'STYLE') || (0, guards_js_1.hasTag)(parentElement, 'style')) {
|
|
155
152
|
this.app.send(new messages_js_1.SetCSSDataURLBased(id, data, this.app.getBaseHref()));
|
|
156
153
|
return;
|
|
157
154
|
}
|
|
@@ -163,7 +160,8 @@ class Observer {
|
|
|
163
160
|
if (isNew) {
|
|
164
161
|
this.recents.set(id, RecentsType.New);
|
|
165
162
|
}
|
|
166
|
-
else if (this.recents.get(id) !== RecentsType.New) {
|
|
163
|
+
else if (this.recents.get(id) !== RecentsType.New) {
|
|
164
|
+
// can we do just `else` here?
|
|
167
165
|
this.recents.set(id, RecentsType.Removed);
|
|
168
166
|
}
|
|
169
167
|
}
|
|
@@ -177,8 +175,7 @@ class Observer {
|
|
|
177
175
|
}
|
|
178
176
|
this.bindNode(node);
|
|
179
177
|
const walker = document.createTreeWalker(node, NodeFilter.SHOW_ELEMENT + NodeFilter.SHOW_TEXT, {
|
|
180
|
-
acceptNode: (node) => isIgnored(node)
|
|
181
|
-
|| (this.app.nodes.getID(node) !== undefined && !isChildUnbinding)
|
|
178
|
+
acceptNode: (node) => isIgnored(node) || (this.app.nodes.getID(node) !== undefined && !isChildUnbinding)
|
|
182
179
|
? NodeFilter.FILTER_REJECT
|
|
183
180
|
: NodeFilter.FILTER_ACCEPT,
|
|
184
181
|
},
|
|
@@ -209,7 +206,7 @@ class Observer {
|
|
|
209
206
|
// Disable parent check for the upper context HTMLHtmlElement, because it is root there... (before)
|
|
210
207
|
// TODO: get rid of "special" cases (there is an issue with CreateDocument altered behaviour though)
|
|
211
208
|
// TODO: Clean the logic (though now it workd fine)
|
|
212
|
-
if (!(0, guards_js_1.hasTag)(node,
|
|
209
|
+
if (!(0, guards_js_1.hasTag)(node, 'HTML') || !this.isTopContext) {
|
|
213
210
|
if (parent === null) {
|
|
214
211
|
// Sometimes one observation contains attribute mutations for the removimg node, which gets ignored here.
|
|
215
212
|
// That shouldn't affect the visual rendering ( should it? )
|
|
@@ -11,7 +11,7 @@ class ShadowRootObserver extends observer_js_1.default {
|
|
|
11
11
|
} // log
|
|
12
12
|
this.observeRoot(shRoot, (rootID) => {
|
|
13
13
|
if (rootID === undefined) {
|
|
14
|
-
console.log(
|
|
14
|
+
console.log('OpenReplay: Shadow Root was not bound');
|
|
15
15
|
return;
|
|
16
16
|
}
|
|
17
17
|
this.app.send((0, messages_js_1.CreateIFrameDocument)(hostID, rootID));
|
|
@@ -13,18 +13,18 @@ class TopObserver extends observer_js_1.default {
|
|
|
13
13
|
this.iframeObservers = [];
|
|
14
14
|
this.shadowRootObservers = [];
|
|
15
15
|
this.options = Object.assign({
|
|
16
|
-
captureIFrames: true
|
|
16
|
+
captureIFrames: true,
|
|
17
17
|
}, options);
|
|
18
18
|
// IFrames
|
|
19
|
-
this.app.nodes.attachNodeCallback(node => {
|
|
20
|
-
if ((0, guards_js_1.hasTag)(node,
|
|
21
|
-
((this.options.captureIFrames && !(0, utils_js_1.hasOpenreplayAttribute)(node,
|
|
22
|
-
|
|
19
|
+
this.app.nodes.attachNodeCallback((node) => {
|
|
20
|
+
if ((0, guards_js_1.hasTag)(node, 'IFRAME') &&
|
|
21
|
+
((this.options.captureIFrames && !(0, utils_js_1.hasOpenreplayAttribute)(node, 'obscured')) ||
|
|
22
|
+
(0, utils_js_1.hasOpenreplayAttribute)(node, 'capture'))) {
|
|
23
23
|
this.handleIframe(node);
|
|
24
24
|
}
|
|
25
25
|
});
|
|
26
26
|
// ShadowDOM
|
|
27
|
-
this.app.nodes.attachNodeCallback(node => {
|
|
27
|
+
this.app.nodes.attachNodeCallback((node) => {
|
|
28
28
|
if ((0, guards_js_1.isElementNode)(node) && node.shadowRoot !== null) {
|
|
29
29
|
this.handleShadowRoot(node.shadowRoot);
|
|
30
30
|
}
|
|
@@ -48,7 +48,7 @@ class TopObserver extends observer_js_1.default {
|
|
|
48
48
|
this.iframeObservers.push(observer);
|
|
49
49
|
observer.observe(iframe);
|
|
50
50
|
});
|
|
51
|
-
iframe.addEventListener(
|
|
51
|
+
iframe.addEventListener('load', handle); // why app.attachEventListener not working?
|
|
52
52
|
handle();
|
|
53
53
|
}
|
|
54
54
|
handleShadowRoot(shRoot) {
|
|
@@ -60,14 +60,15 @@ class TopObserver extends observer_js_1.default {
|
|
|
60
60
|
// Protection from several subsequent calls?
|
|
61
61
|
const observer = this;
|
|
62
62
|
Element.prototype.attachShadow = function () {
|
|
63
|
+
// eslint-disable-next-line
|
|
63
64
|
const shadow = attachShadowNativeFn.apply(this, arguments);
|
|
64
65
|
observer.handleShadowRoot(shadow);
|
|
65
66
|
return shadow;
|
|
66
67
|
};
|
|
67
68
|
// Can observe documentElement (<html>) here, because it is not supposed to be changing.
|
|
68
69
|
// However, it is possible in some exotic cases and may cause an ignorance of the newly created <html>
|
|
69
|
-
// In this case context.document have to be observed, but this will cause
|
|
70
|
-
// the change in the re-player behaviour caused by CreateDocument message:
|
|
70
|
+
// In this case context.document have to be observed, but this will cause
|
|
71
|
+
// the change in the re-player behaviour caused by CreateDocument message:
|
|
71
72
|
// the 0-node ("fRoot") will become #document rather than documentElement as it is now.
|
|
72
73
|
// Alternatively - observe(#document) then bindNode(documentElement)
|
|
73
74
|
this.observeRoot(window.document, () => {
|
|
@@ -76,9 +77,9 @@ class TopObserver extends observer_js_1.default {
|
|
|
76
77
|
}
|
|
77
78
|
disconnect() {
|
|
78
79
|
Element.prototype.attachShadow = attachShadowNativeFn;
|
|
79
|
-
this.iframeObservers.forEach(o => o.disconnect());
|
|
80
|
+
this.iframeObservers.forEach((o) => o.disconnect());
|
|
80
81
|
this.iframeObservers = [];
|
|
81
|
-
this.shadowRootObservers.forEach(o => o.disconnect());
|
|
82
|
+
this.shadowRootObservers.forEach((o) => o.disconnect());
|
|
82
83
|
this.shadowRootObservers = [];
|
|
83
84
|
super.disconnect();
|
|
84
85
|
}
|
package/cjs/app/sanitizer.d.ts
CHANGED