@openreplay/tracker 3.4.17-beta.1 → 3.4.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/app/index.d.ts +6 -1
- package/cjs/app/index.js +107 -102
- package/cjs/index.d.ts +10 -9
- package/cjs/index.js +31 -23
- package/lib/app/index.d.ts +6 -1
- package/lib/app/index.js +107 -102
- package/lib/index.d.ts +10 -9
- package/lib/index.js +31 -23
- package/package.json +1 -1
package/cjs/app/index.d.ts
CHANGED
|
@@ -10,6 +10,10 @@ export interface OnStartInfo {
|
|
|
10
10
|
sessionToken: string;
|
|
11
11
|
userUUID: string;
|
|
12
12
|
}
|
|
13
|
+
export interface StartOptions {
|
|
14
|
+
userID?: string;
|
|
15
|
+
forceNew: boolean;
|
|
16
|
+
}
|
|
13
17
|
declare type AppOptions = {
|
|
14
18
|
revID: string;
|
|
15
19
|
node_id: string;
|
|
@@ -41,6 +45,7 @@ export default class App {
|
|
|
41
45
|
private readonly options;
|
|
42
46
|
private readonly revID;
|
|
43
47
|
private _sessionID;
|
|
48
|
+
private _userID;
|
|
44
49
|
private isActive;
|
|
45
50
|
private version;
|
|
46
51
|
private readonly worker?;
|
|
@@ -64,7 +69,7 @@ export default class App {
|
|
|
64
69
|
active(): boolean;
|
|
65
70
|
resetNextPageSession(flag: boolean): void;
|
|
66
71
|
private _start;
|
|
67
|
-
start(
|
|
72
|
+
start(options?: StartOptions): Promise<OnStartInfo>;
|
|
68
73
|
stop(): void;
|
|
69
74
|
}
|
|
70
75
|
export {};
|
package/cjs/app/index.js
CHANGED
|
@@ -18,7 +18,7 @@ class App {
|
|
|
18
18
|
this.commitCallbacks = [];
|
|
19
19
|
this._sessionID = null;
|
|
20
20
|
this.isActive = false;
|
|
21
|
-
this.version = '3.4.17
|
|
21
|
+
this.version = '3.4.17';
|
|
22
22
|
this.projectKey = projectKey;
|
|
23
23
|
this.options = Object.assign({
|
|
24
24
|
revID: '',
|
|
@@ -43,7 +43,7 @@ class App {
|
|
|
43
43
|
this.ticker = new ticker_js_1.default(this);
|
|
44
44
|
this.ticker.attach(() => this.commit());
|
|
45
45
|
try {
|
|
46
|
-
this.worker = new Worker(URL.createObjectURL(new Blob([`"use strict";function t(t){function s(...s){return new t(...s)}return s.prototype=t.prototype,s}const s=new Map;const i=t(class{constructor(t,s,i){this.pageNo=t,this.firstIndex=s,this.timestamp=i,this._id=80}encode(t){return t.uint(80)&&t.uint(this.pageNo)&&t.uint(this.firstIndex)&&t.int(this.timestamp)}});s.set(80,i);const n=t(class{constructor(t){this.timestamp=t,this._id=0}encode(t){return t.uint(0)&&t.uint(this.timestamp)}});s.set(0,n);const e=t(class{constructor(t,s,i){this.url=t,this.referrer=s,this.navigationStart=i,this._id=4}encode(t){return t.uint(4)&&t.string(this.url)&&t.string(this.referrer)&&t.uint(this.navigationStart)}});s.set(4,e);const r=t(class{constructor(t,s){this.width=t,this.height=s,this._id=5}encode(t){return t.uint(5)&&t.uint(this.width)&&t.uint(this.height)}});s.set(5,r);const o=t(class{constructor(t,s){this.x=t,this.y=s,this._id=6}encode(t){return t.uint(6)&&t.int(this.x)&&t.int(this.y)}});s.set(6,o);const h=t(class{constructor(){this._id=7}encode(t){return t.uint(7)}});s.set(7,h);const c=t(class{constructor(t,s,i,n,e){this.id=t,this.parentID=s,this.index=i,this.tag=n,this.svg=e,this._id=8}encode(t){return t.uint(8)&&t.uint(this.id)&&t.uint(this.parentID)&&t.uint(this.index)&&t.string(this.tag)&&t.boolean(this.svg)}});s.set(8,c);const u=t(class{constructor(t,s,i){this.id=t,this.parentID=s,this.index=i,this._id=9}encode(t){return t.uint(9)&&t.uint(this.id)&&t.uint(this.parentID)&&t.uint(this.index)}});s.set(9,u);const a=t(class{constructor(t,s,i){this.id=t,this.parentID=s,this.index=i,this._id=10}encode(t){return t.uint(10)&&t.uint(this.id)&&t.uint(this.parentID)&&t.uint(this.index)}});s.set(10,a);const d=t(class{constructor(t){this.id=t,this._id=11}encode(t){return t.uint(11)&&t.uint(this.id)}});s.set(11,d);const l=t(class{constructor(t,s,i){this.id=t,this.name=s,this.value=i,this._id=12}encode(t){return t.uint(12)&&t.uint(this.id)&&t.string(this.name)&&t.string(this.value)}});s.set(12,l);const g=t(class{constructor(t,s){this.id=t,this.name=s,this._id=13}encode(t){return t.uint(13)&&t.uint(this.id)&&t.string(this.name)}});s.set(13,g);const f=t(class{constructor(t,s){this.id=t,this.data=s,this._id=14}encode(t){return t.uint(14)&&t.uint(this.id)&&t.string(this.data)}});s.set(14,f);const p=t(class{constructor(t,s,i){this.id=t,this.x=s,this.y=i,this._id=16}encode(t){return t.uint(16)&&t.uint(this.id)&&t.int(this.x)&&t.int(this.y)}});s.set(16,p);const m=t(class{constructor(t,s){this.id=t,this.label=s,this._id=17}encode(t){return t.uint(17)&&t.uint(this.id)&&t.string(this.label)}});s.set(17,m);const _=t(class{constructor(t,s,i){this.id=t,this.value=s,this.mask=i,this._id=18}encode(t){return t.uint(18)&&t.uint(this.id)&&t.string(this.value)&&t.int(this.mask)}});s.set(18,_);const y=t(class{constructor(t,s){this.id=t,this.checked=s,this._id=19}encode(t){return t.uint(19)&&t.uint(this.id)&&t.boolean(this.checked)}});s.set(19,y);const v=t(class{constructor(t,s){this.x=t,this.y=s,this._id=20}encode(t){return t.uint(20)&&t.uint(this.x)&&t.uint(this.y)}});s.set(20,v);const S=t(class{constructor(t,s){this.level=t,this.value=s,this._id=22}encode(t){return t.uint(22)&&t.string(this.level)&&t.string(this.value)}});s.set(22,S);const b=t(class{constructor(t,s,i,n,e,r,o,h,c){this.requestStart=t,this.responseStart=s,this.responseEnd=i,this.domContentLoadedEventStart=n,this.domContentLoadedEventEnd=e,this.loadEventStart=r,this.loadEventEnd=o,this.firstPaint=h,this.firstContentfulPaint=c,this._id=23}encode(t){return t.uint(23)&&t.uint(this.requestStart)&&t.uint(this.responseStart)&&t.uint(this.responseEnd)&&t.uint(this.domContentLoadedEventStart)&&t.uint(this.domContentLoadedEventEnd)&&t.uint(this.loadEventStart)&&t.uint(this.loadEventEnd)&&t.uint(this.firstPaint)&&t.uint(this.firstContentfulPaint)}});s.set(23,b);const x=t(class{constructor(t,s,i){this.speedIndex=t,this.visuallyComplete=s,this.timeToInteractive=i,this._id=24}encode(t){return t.uint(24)&&t.uint(this.speedIndex)&&t.uint(this.visuallyComplete)&&t.uint(this.timeToInteractive)}});s.set(24,x);const E=t(class{constructor(t,s,i){this.name=t,this.message=s,this.payload=i,this._id=25}encode(t){return t.uint(25)&&t.string(this.name)&&t.string(this.message)&&t.string(this.payload)}});s.set(25,E);const k=t(class{constructor(t,s){this.name=t,this.payload=s,this._id=27}encode(t){return t.uint(27)&&t.string(this.name)&&t.string(this.payload)}});s.set(27,k);const I=t(class{constructor(t){this.id=t,this._id=28}encode(t){return t.uint(28)&&t.string(this.id)}});s.set(28,I);const z=t(class{constructor(t){this.id=t,this._id=29}encode(t){return t.uint(29)&&t.string(this.id)}});s.set(29,z);const w=t(class{constructor(t,s){this.key=t,this.value=s,this._id=30}encode(t){return t.uint(30)&&t.string(this.key)&&t.string(this.value)}});s.set(30,w);const T=t(class{constructor(t,s,i){this.id=t,this.rule=s,this.index=i,this._id=37}encode(t){return t.uint(37)&&t.uint(this.id)&&t.string(this.rule)&&t.uint(this.index)}});s.set(37,T);const L=t(class{constructor(t,s){this.id=t,this.index=s,this._id=38}encode(t){return t.uint(38)&&t.uint(this.id)&&t.uint(this.index)}});s.set(38,L);const A=t(class{constructor(t,s,i,n,e,r,o){this.method=t,this.url=s,this.request=i,this.response=n,this.status=e,this.timestamp=r,this.duration=o,this._id=39}encode(t){return t.uint(39)&&t.string(this.method)&&t.string(this.url)&&t.string(this.request)&&t.string(this.response)&&t.uint(this.status)&&t.uint(this.timestamp)&&t.uint(this.duration)}});s.set(39,A);const C=t(class{constructor(t,s,i,n){this.name=t,this.duration=s,this.args=i,this.result=n,this._id=40}encode(t){return t.uint(40)&&t.string(this.name)&&t.uint(this.duration)&&t.string(this.args)&&t.string(this.result)}});s.set(40,C);const M=t(class{constructor(t,s){this.key=t,this.value=s,this._id=41}encode(t){return t.uint(41)&&t.string(this.key)&&t.string(this.value)}});s.set(41,M);const R=t(class{constructor(t){this.type=t,this._id=42}encode(t){return t.uint(42)&&t.string(this.type)}});s.set(42,R);const N=t(class{constructor(t,s,i){this.action=t,this.state=s,this.duration=i,this._id=44}encode(t){return t.uint(44)&&t.string(this.action)&&t.string(this.state)&&t.uint(this.duration)}});s.set(44,N);const D=t(class{constructor(t,s){this.mutation=t,this.state=s,this._id=45}encode(t){return t.uint(45)&&t.string(this.mutation)&&t.string(this.state)}});s.set(45,D);const U=t(class{constructor(t,s){this.type=t,this.payload=s,this._id=46}encode(t){return t.uint(46)&&t.string(this.type)&&t.string(this.payload)}});s.set(46,U);const O=t(class{constructor(t,s,i){this.action=t,this.state=s,this.duration=i,this._id=47}encode(t){return t.uint(47)&&t.string(this.action)&&t.string(this.state)&&t.uint(this.duration)}});s.set(47,O);const q=t(class{constructor(t,s,i,n){this.operationKind=t,this.operationName=s,this.variables=i,this.response=n,this._id=48}encode(t){return t.uint(48)&&t.string(this.operationKind)&&t.string(this.operationName)&&t.string(this.variables)&&t.string(this.response)}});s.set(48,q);const H=t(class{constructor(t,s,i,n){this.frames=t,this.ticks=s,this.totalJSHeapSize=i,this.usedJSHeapSize=n,this._id=49}encode(t){return t.uint(49)&&t.int(this.frames)&&t.int(this.ticks)&&t.uint(this.totalJSHeapSize)&&t.uint(this.usedJSHeapSize)}});s.set(49,H);const P=t(class{constructor(t,s,i,n,e,r,o,h){this.timestamp=t,this.duration=s,this.ttfb=i,this.headerSize=n,this.encodedBodySize=e,this.decodedBodySize=r,this.url=o,this.initiator=h,this._id=53}encode(t){return t.uint(53)&&t.uint(this.timestamp)&&t.uint(this.duration)&&t.uint(this.ttfb)&&t.uint(this.headerSize)&&t.uint(this.encodedBodySize)&&t.uint(this.decodedBodySize)&&t.string(this.url)&&t.string(this.initiator)}});s.set(53,P);const B=t(class{constructor(t,s){this.downlink=t,this.type=s,this._id=54}encode(t){return t.uint(54)&&t.uint(this.downlink)&&t.string(this.type)}});s.set(54,B);const J=t(class{constructor(t){this.hidden=t,this._id=55}encode(t){return t.uint(55)&&t.boolean(this.hidden)}});s.set(55,J);const j=t(class{constructor(t,s,i,n,e,r,o){this.timestamp=t,this.duration=s,this.context=i,this.containerType=n,this.containerSrc=e,this.containerId=r,this.containerName=o,this._id=59}encode(t){return t.uint(59)&&t.uint(this.timestamp)&&t.uint(this.duration)&&t.uint(this.context)&&t.uint(this.containerType)&&t.string(this.containerSrc)&&t.string(this.containerId)&&t.string(this.containerName)}});s.set(59,j);const G=t(class{constructor(t,s,i,n){this.id=t,this.name=s,this.value=i,this.baseURL=n,this._id=60}encode(t){return t.uint(60)&&t.uint(this.id)&&t.string(this.name)&&t.string(this.value)&&t.string(this.baseURL)}});s.set(60,G);const K=t(class{constructor(t,s,i){this.id=t,this.data=s,this.baseURL=i,this._id=61}encode(t){return t.uint(61)&&t.uint(this.id)&&t.string(this.data)&&t.string(this.baseURL)}});s.set(61,K);const X=t(class{constructor(t,s){this.type=t,this.value=s,this._id=63}encode(t){return t.uint(63)&&t.string(this.type)&&t.string(this.value)}});s.set(63,X);const F=t(class{constructor(t,s){this.name=t,this.payload=s,this._id=64}encode(t){return t.uint(64)&&t.string(this.name)&&t.string(this.payload)}});s.set(64,F);const Q=t(class{constructor(){this._id=65}encode(t){return t.uint(65)}});s.set(65,Q);const V=t(class{constructor(t,s,i,n){this.id=t,this.rule=s,this.index=i,this.baseURL=n,this._id=67}encode(t){return t.uint(67)&&t.uint(this.id)&&t.string(this.rule)&&t.uint(this.index)&&t.string(this.baseURL)}});s.set(67,V);const W=t(class{constructor(t,s,i,n){this.id=t,this.hesitationTime=s,this.label=i,this.selector=n,this._id=69}encode(t){return t.uint(69)&&t.uint(this.id)&&t.uint(this.hesitationTime)&&t.string(this.label)&&t.string(this.selector)}});s.set(69,W);const Y=t(class{constructor(t,s){this.frameID=t,this.id=s,this._id=70}encode(t){return t.uint(70)&&t.uint(this.frameID)&&t.uint(this.id)}});s.set(70,Y);const Z="function"==typeof TextEncoder?new TextEncoder:{encode(t){const s=t.length,i=new Uint8Array(3*s);let n=-1;for(var e=0,r=0,o=0;o!==s;){if(e=t.charCodeAt(o),o+=1,e>=55296&&e<=56319){if(o===s){i[n+=1]=239,i[n+=1]=191,i[n+=1]=189;break}if(!((r=t.charCodeAt(o))>=56320&&r<=57343)){i[n+=1]=239,i[n+=1]=191,i[n+=1]=189;continue}if(o+=1,(e=1024*(e-55296)+r-56320+65536)>65535){i[n+=1]=240|e>>>18,i[n+=1]=128|e>>>12&63,i[n+=1]=128|e>>>6&63,i[n+=1]=128|63&e;continue}}e<=127?i[n+=1]=0|e:e<=2047?(i[n+=1]=192|e>>>6,i[n+=1]=128|63&e):(i[n+=1]=224|e>>>12,i[n+=1]=128|e>>>6&63,i[n+=1]=128|63&e)}return i.subarray(0,n+1)}};class tt{constructor(t){this.size=t,this.offset=0,this.checkpointOffset=0,this.data=new Uint8Array(t)}checkpoint(){this.checkpointOffset=this.offset}isEmpty(){return 0===this.offset}boolean(t){return this.data[this.offset++]=+t,this.offset<=this.size}uint(t){for((t<0||t>Number.MAX_SAFE_INTEGER)&&(t=0);t>=128;)this.data[this.offset++]=t%256|128,t=Math.floor(t/128);return this.data[this.offset++]=t,this.offset<=this.size}int(t){return t=Math.round(t),this.uint(t>=0?2*t:-2*t-1)}string(t){const s=Z.encode(t),i=s.byteLength;return!(!this.uint(i)||this.offset+i>this.size)&&(this.data.set(s,this.offset),this.offset+=i,!0)}reset(){this.offset=0,this.checkpointOffset=0}flush(){const t=this.data.slice(0,this.checkpointOffset);return this.reset(),t}}let st=1e6,it=2e5,nt=new tt(it),et="",rt="",ot=0,ht=0,ct=0,ut=0,at=!0;function dt(){return new i(ot,ut,ht).encode(nt)}let lt=null;const gt=[];let ft,pt=!1,mt=0,_t=8e3,yt=10;function vt(){if(at||""===rt||""===et)return;const t=nt.flush();pt?gt.push(t):(pt=!0,function t(s){const i=new XMLHttpRequest;i.open("POST",et+"/v1/web/i",!1),i.setRequestHeader("Authorization","Bearer "+rt),i.onreadystatechange=function(){if(4===this.readyState){if(0==this.status)return;if(this.status>=400)return St(),gt.length=0,401===this.status?void self.postMessage("restart"):void self.postMessage(null);const s=gt.shift();s?t(s):pt=!1}},i.onerror=function(i){if(mt>=yt)return St(),void self.postMessage(null);mt++,setTimeout(()=>t(s),_t)},i.send(s.buffer)}(t)),at=!0,dt()}function St(){et="",rt="",null!==lt&&(clearInterval(lt),lt=null),nt.reset()}self.onmessage=({data:t})=>{if(null!==t)return"stop"===t?(vt(),void St()):Array.isArray(t)?void t.forEach(t=>{const i=new(s.get(t._id));if(Object.assign(i,t),i instanceof n?ht=i.timestamp:i instanceof J&&(i.hidden?ft=setTimeout(()=>self.postMessage("restart"),18e5):clearTimeout(ft)),nt.checkpoint(),!i.encode(nt)&&(vt(),!i.encode(nt)))for(;!i.encode(nt);){if(it===st)return console.warn("OpenReplay: beacon size overflow."),nt.reset(),void dt();it=Math.min(2*it,st),nt=new tt(it),dt()}ut++,at=!1}):(et=t.ingestPoint||et,rt=t.token||rt,ot=t.pageNo||ot,ht=t.startTimestamp||ht,ct=t.timeAdjustment||ct,yt=t.connAttemptCount||yt,_t=t.connAttemptGap||_t,st=t.beaconSizeLimit||st,it=Math.min(st,t.beaconSize||it),nt.isEmpty()&&dt(),void(null===lt&&(lt=setInterval(vt,1e4))));vt()};
|
|
46
|
+
this.worker = new Worker(URL.createObjectURL(new Blob([`"use strict";function t(t){function s(...s){return new t(...s)}return s.prototype=t.prototype,s}const s=new Map;const i=t(class{constructor(t,s,i){this.pageNo=t,this.firstIndex=s,this.timestamp=i,this._id=80}encode(t){return t.uint(80)&&t.uint(this.pageNo)&&t.uint(this.firstIndex)&&t.int(this.timestamp)}});s.set(80,i);const n=t(class{constructor(t){this.timestamp=t,this._id=0}encode(t){return t.uint(0)&&t.uint(this.timestamp)}});s.set(0,n);const e=t(class{constructor(t,s,i){this.url=t,this.referrer=s,this.navigationStart=i,this._id=4}encode(t){return t.uint(4)&&t.string(this.url)&&t.string(this.referrer)&&t.uint(this.navigationStart)}});s.set(4,e);const r=t(class{constructor(t,s){this.width=t,this.height=s,this._id=5}encode(t){return t.uint(5)&&t.uint(this.width)&&t.uint(this.height)}});s.set(5,r);const o=t(class{constructor(t,s){this.x=t,this.y=s,this._id=6}encode(t){return t.uint(6)&&t.int(this.x)&&t.int(this.y)}});s.set(6,o);const h=t(class{constructor(){this._id=7}encode(t){return t.uint(7)}});s.set(7,h);const c=t(class{constructor(t,s,i,n,e){this.id=t,this.parentID=s,this.index=i,this.tag=n,this.svg=e,this._id=8}encode(t){return t.uint(8)&&t.uint(this.id)&&t.uint(this.parentID)&&t.uint(this.index)&&t.string(this.tag)&&t.boolean(this.svg)}});s.set(8,c);const u=t(class{constructor(t,s,i){this.id=t,this.parentID=s,this.index=i,this._id=9}encode(t){return t.uint(9)&&t.uint(this.id)&&t.uint(this.parentID)&&t.uint(this.index)}});s.set(9,u);const a=t(class{constructor(t,s,i){this.id=t,this.parentID=s,this.index=i,this._id=10}encode(t){return t.uint(10)&&t.uint(this.id)&&t.uint(this.parentID)&&t.uint(this.index)}});s.set(10,a);const d=t(class{constructor(t){this.id=t,this._id=11}encode(t){return t.uint(11)&&t.uint(this.id)}});s.set(11,d);const l=t(class{constructor(t,s,i){this.id=t,this.name=s,this.value=i,this._id=12}encode(t){return t.uint(12)&&t.uint(this.id)&&t.string(this.name)&&t.string(this.value)}});s.set(12,l);const g=t(class{constructor(t,s){this.id=t,this.name=s,this._id=13}encode(t){return t.uint(13)&&t.uint(this.id)&&t.string(this.name)}});s.set(13,g);const f=t(class{constructor(t,s){this.id=t,this.data=s,this._id=14}encode(t){return t.uint(14)&&t.uint(this.id)&&t.string(this.data)}});s.set(14,f);const p=t(class{constructor(t,s,i){this.id=t,this.x=s,this.y=i,this._id=16}encode(t){return t.uint(16)&&t.uint(this.id)&&t.int(this.x)&&t.int(this.y)}});s.set(16,p);const m=t(class{constructor(t,s){this.id=t,this.label=s,this._id=17}encode(t){return t.uint(17)&&t.uint(this.id)&&t.string(this.label)}});s.set(17,m);const _=t(class{constructor(t,s,i){this.id=t,this.value=s,this.mask=i,this._id=18}encode(t){return t.uint(18)&&t.uint(this.id)&&t.string(this.value)&&t.int(this.mask)}});s.set(18,_);const y=t(class{constructor(t,s){this.id=t,this.checked=s,this._id=19}encode(t){return t.uint(19)&&t.uint(this.id)&&t.boolean(this.checked)}});s.set(19,y);const v=t(class{constructor(t,s){this.x=t,this.y=s,this._id=20}encode(t){return t.uint(20)&&t.uint(this.x)&&t.uint(this.y)}});s.set(20,v);const S=t(class{constructor(t,s){this.level=t,this.value=s,this._id=22}encode(t){return t.uint(22)&&t.string(this.level)&&t.string(this.value)}});s.set(22,S);const b=t(class{constructor(t,s,i,n,e,r,o,h,c){this.requestStart=t,this.responseStart=s,this.responseEnd=i,this.domContentLoadedEventStart=n,this.domContentLoadedEventEnd=e,this.loadEventStart=r,this.loadEventEnd=o,this.firstPaint=h,this.firstContentfulPaint=c,this._id=23}encode(t){return t.uint(23)&&t.uint(this.requestStart)&&t.uint(this.responseStart)&&t.uint(this.responseEnd)&&t.uint(this.domContentLoadedEventStart)&&t.uint(this.domContentLoadedEventEnd)&&t.uint(this.loadEventStart)&&t.uint(this.loadEventEnd)&&t.uint(this.firstPaint)&&t.uint(this.firstContentfulPaint)}});s.set(23,b);const x=t(class{constructor(t,s,i){this.speedIndex=t,this.visuallyComplete=s,this.timeToInteractive=i,this._id=24}encode(t){return t.uint(24)&&t.uint(this.speedIndex)&&t.uint(this.visuallyComplete)&&t.uint(this.timeToInteractive)}});s.set(24,x);const E=t(class{constructor(t,s,i){this.name=t,this.message=s,this.payload=i,this._id=25}encode(t){return t.uint(25)&&t.string(this.name)&&t.string(this.message)&&t.string(this.payload)}});s.set(25,E);const k=t(class{constructor(t,s){this.name=t,this.payload=s,this._id=27}encode(t){return t.uint(27)&&t.string(this.name)&&t.string(this.payload)}});s.set(27,k);const I=t(class{constructor(t){this.id=t,this._id=28}encode(t){return t.uint(28)&&t.string(this.id)}});s.set(28,I);const z=t(class{constructor(t){this.id=t,this._id=29}encode(t){return t.uint(29)&&t.string(this.id)}});s.set(29,z);const w=t(class{constructor(t,s){this.key=t,this.value=s,this._id=30}encode(t){return t.uint(30)&&t.string(this.key)&&t.string(this.value)}});s.set(30,w);const T=t(class{constructor(t,s,i){this.id=t,this.rule=s,this.index=i,this._id=37}encode(t){return t.uint(37)&&t.uint(this.id)&&t.string(this.rule)&&t.uint(this.index)}});s.set(37,T);const L=t(class{constructor(t,s){this.id=t,this.index=s,this._id=38}encode(t){return t.uint(38)&&t.uint(this.id)&&t.uint(this.index)}});s.set(38,L);const A=t(class{constructor(t,s,i,n,e,r,o){this.method=t,this.url=s,this.request=i,this.response=n,this.status=e,this.timestamp=r,this.duration=o,this._id=39}encode(t){return t.uint(39)&&t.string(this.method)&&t.string(this.url)&&t.string(this.request)&&t.string(this.response)&&t.uint(this.status)&&t.uint(this.timestamp)&&t.uint(this.duration)}});s.set(39,A);const C=t(class{constructor(t,s,i,n){this.name=t,this.duration=s,this.args=i,this.result=n,this._id=40}encode(t){return t.uint(40)&&t.string(this.name)&&t.uint(this.duration)&&t.string(this.args)&&t.string(this.result)}});s.set(40,C);const M=t(class{constructor(t,s){this.key=t,this.value=s,this._id=41}encode(t){return t.uint(41)&&t.string(this.key)&&t.string(this.value)}});s.set(41,M);const R=t(class{constructor(t){this.type=t,this._id=42}encode(t){return t.uint(42)&&t.string(this.type)}});s.set(42,R);const N=t(class{constructor(t,s,i){this.action=t,this.state=s,this.duration=i,this._id=44}encode(t){return t.uint(44)&&t.string(this.action)&&t.string(this.state)&&t.uint(this.duration)}});s.set(44,N);const D=t(class{constructor(t,s){this.mutation=t,this.state=s,this._id=45}encode(t){return t.uint(45)&&t.string(this.mutation)&&t.string(this.state)}});s.set(45,D);const U=t(class{constructor(t,s){this.type=t,this.payload=s,this._id=46}encode(t){return t.uint(46)&&t.string(this.type)&&t.string(this.payload)}});s.set(46,U);const O=t(class{constructor(t,s,i){this.action=t,this.state=s,this.duration=i,this._id=47}encode(t){return t.uint(47)&&t.string(this.action)&&t.string(this.state)&&t.uint(this.duration)}});s.set(47,O);const q=t(class{constructor(t,s,i,n){this.operationKind=t,this.operationName=s,this.variables=i,this.response=n,this._id=48}encode(t){return t.uint(48)&&t.string(this.operationKind)&&t.string(this.operationName)&&t.string(this.variables)&&t.string(this.response)}});s.set(48,q);const H=t(class{constructor(t,s,i,n){this.frames=t,this.ticks=s,this.totalJSHeapSize=i,this.usedJSHeapSize=n,this._id=49}encode(t){return t.uint(49)&&t.int(this.frames)&&t.int(this.ticks)&&t.uint(this.totalJSHeapSize)&&t.uint(this.usedJSHeapSize)}});s.set(49,H);const P=t(class{constructor(t,s,i,n,e,r,o,h){this.timestamp=t,this.duration=s,this.ttfb=i,this.headerSize=n,this.encodedBodySize=e,this.decodedBodySize=r,this.url=o,this.initiator=h,this._id=53}encode(t){return t.uint(53)&&t.uint(this.timestamp)&&t.uint(this.duration)&&t.uint(this.ttfb)&&t.uint(this.headerSize)&&t.uint(this.encodedBodySize)&&t.uint(this.decodedBodySize)&&t.string(this.url)&&t.string(this.initiator)}});s.set(53,P);const B=t(class{constructor(t,s){this.downlink=t,this.type=s,this._id=54}encode(t){return t.uint(54)&&t.uint(this.downlink)&&t.string(this.type)}});s.set(54,B);const J=t(class{constructor(t){this.hidden=t,this._id=55}encode(t){return t.uint(55)&&t.boolean(this.hidden)}});s.set(55,J);const j=t(class{constructor(t,s,i,n,e,r,o){this.timestamp=t,this.duration=s,this.context=i,this.containerType=n,this.containerSrc=e,this.containerId=r,this.containerName=o,this._id=59}encode(t){return t.uint(59)&&t.uint(this.timestamp)&&t.uint(this.duration)&&t.uint(this.context)&&t.uint(this.containerType)&&t.string(this.containerSrc)&&t.string(this.containerId)&&t.string(this.containerName)}});s.set(59,j);const G=t(class{constructor(t,s,i,n){this.id=t,this.name=s,this.value=i,this.baseURL=n,this._id=60}encode(t){return t.uint(60)&&t.uint(this.id)&&t.string(this.name)&&t.string(this.value)&&t.string(this.baseURL)}});s.set(60,G);const K=t(class{constructor(t,s,i){this.id=t,this.data=s,this.baseURL=i,this._id=61}encode(t){return t.uint(61)&&t.uint(this.id)&&t.string(this.data)&&t.string(this.baseURL)}});s.set(61,K);const X=t(class{constructor(t,s){this.type=t,this.value=s,this._id=63}encode(t){return t.uint(63)&&t.string(this.type)&&t.string(this.value)}});s.set(63,X);const F=t(class{constructor(t,s){this.name=t,this.payload=s,this._id=64}encode(t){return t.uint(64)&&t.string(this.name)&&t.string(this.payload)}});s.set(64,F);const Q=t(class{constructor(){this._id=65}encode(t){return t.uint(65)}});s.set(65,Q);const V=t(class{constructor(t,s,i,n){this.id=t,this.rule=s,this.index=i,this.baseURL=n,this._id=67}encode(t){return t.uint(67)&&t.uint(this.id)&&t.string(this.rule)&&t.uint(this.index)&&t.string(this.baseURL)}});s.set(67,V);const W=t(class{constructor(t,s,i,n){this.id=t,this.hesitationTime=s,this.label=i,this.selector=n,this._id=69}encode(t){return t.uint(69)&&t.uint(this.id)&&t.uint(this.hesitationTime)&&t.string(this.label)&&t.string(this.selector)}});s.set(69,W);const Y=t(class{constructor(t,s){this.frameID=t,this.id=s,this._id=70}encode(t){return t.uint(70)&&t.uint(this.frameID)&&t.uint(this.id)}});s.set(70,Y);const Z="function"==typeof TextEncoder?new TextEncoder:{encode(t){const s=t.length,i=new Uint8Array(3*s);let n=-1;for(var e=0,r=0,o=0;o!==s;){if(e=t.charCodeAt(o),o+=1,e>=55296&&e<=56319){if(o===s){i[n+=1]=239,i[n+=1]=191,i[n+=1]=189;break}if(!((r=t.charCodeAt(o))>=56320&&r<=57343)){i[n+=1]=239,i[n+=1]=191,i[n+=1]=189;continue}if(o+=1,(e=1024*(e-55296)+r-56320+65536)>65535){i[n+=1]=240|e>>>18,i[n+=1]=128|e>>>12&63,i[n+=1]=128|e>>>6&63,i[n+=1]=128|63&e;continue}}e<=127?i[n+=1]=0|e:e<=2047?(i[n+=1]=192|e>>>6,i[n+=1]=128|63&e):(i[n+=1]=224|e>>>12,i[n+=1]=128|e>>>6&63,i[n+=1]=128|63&e)}return i.subarray(0,n+1)}};class tt{constructor(t){this.size=t,this.offset=0,this.checkpointOffset=0,this.data=new Uint8Array(t)}checkpoint(){this.checkpointOffset=this.offset}isEmpty(){return 0===this.offset}boolean(t){return this.data[this.offset++]=+t,this.offset<=this.size}uint(t){for((t<0||t>Number.MAX_SAFE_INTEGER)&&(t=0);t>=128;)this.data[this.offset++]=t%256|128,t=Math.floor(t/128);return this.data[this.offset++]=t,this.offset<=this.size}int(t){return t=Math.round(t),this.uint(t>=0?2*t:-2*t-1)}string(t){const s=Z.encode(t),i=s.byteLength;return!(!this.uint(i)||this.offset+i>this.size)&&(this.data.set(s,this.offset),this.offset+=i,!0)}reset(){this.offset=0,this.checkpointOffset=0}flush(){const t=this.data.slice(0,this.checkpointOffset);return this.reset(),t}}let st=1e6,it=2e5,nt=new tt(it),et="",rt="",ot=0,ht=0,ct=0,ut=0,at=!0;function dt(){return new i(ot,ut,ht).encode(nt)}let lt=null;const gt=[];let ft,pt=!1,mt=0,_t=8e3,yt=10;function vt(){if(at||""===rt||""===et)return;const t=nt.flush();pt?gt.push(t):(pt=!0,function t(s){const i=new XMLHttpRequest;i.open("POST",et+"/v1/web/i",!1),i.setRequestHeader("Authorization","Bearer "+rt),i.onreadystatechange=function(){if(4===this.readyState){if(0==this.status)return;if(this.status>=400)return pt=!1,St(),gt.length=0,401===this.status?void self.postMessage("restart"):void self.postMessage(null);const s=gt.shift();s?t(s):pt=!1}},i.onerror=function(i){if(mt>=yt)return St(),void self.postMessage(null);mt++,setTimeout(()=>t(s),_t)},i.send(s.buffer)}(t)),at=!0,dt()}function St(){et="",rt="",null!==lt&&(clearInterval(lt),lt=null),nt.reset()}self.onmessage=({data:t})=>{if(null!==t)return"stop"===t?(vt(),void St()):Array.isArray(t)?void t.forEach(t=>{const i=new(s.get(t._id));if(Object.assign(i,t),i instanceof n?ht=i.timestamp:i instanceof J&&(i.hidden?ft=setTimeout(()=>self.postMessage("restart"),18e5):clearTimeout(ft)),nt.checkpoint(),!i.encode(nt)&&(vt(),!i.encode(nt)))for(;!i.encode(nt);){if(it===st)return console.warn("OpenReplay: beacon size overflow."),nt.reset(),void dt();it=Math.min(2*it,st),nt=new tt(it),dt()}ut++,at=!1}):(et=t.ingestPoint||et,rt=t.token||rt,ot=t.pageNo||ot,ht=t.startTimestamp||ht,ct=t.timeAdjustment||ct,yt=t.connAttemptCount||yt,_t=t.connAttemptGap||_t,st=t.beaconSizeLimit||st,it=Math.min(st,t.beaconSize||it),nt.isEmpty()&&dt(),void(null===lt&&(lt=setInterval(vt,1e4))));vt()};
|
|
47
47
|
`], { type: 'text/javascript' })));
|
|
48
48
|
this.worker.onerror = e => {
|
|
49
49
|
this._debug("webworker_error", e);
|
|
@@ -56,7 +56,10 @@ class App {
|
|
|
56
56
|
}
|
|
57
57
|
else if (data === "restart") {
|
|
58
58
|
this.stop();
|
|
59
|
-
this.start(
|
|
59
|
+
this.start({
|
|
60
|
+
forceNew: true,
|
|
61
|
+
userID: this._userID,
|
|
62
|
+
});
|
|
60
63
|
}
|
|
61
64
|
};
|
|
62
65
|
const alertWorker = () => {
|
|
@@ -189,116 +192,118 @@ class App {
|
|
|
189
192
|
sessionStorage.removeItem(this.options.session_reset_key);
|
|
190
193
|
}
|
|
191
194
|
}
|
|
192
|
-
_start(
|
|
193
|
-
if (!this.
|
|
195
|
+
_start(startOpts) {
|
|
196
|
+
if (!this.worker) {
|
|
197
|
+
return Promise.reject("No worker found: perhaps, CSP is not set.");
|
|
198
|
+
}
|
|
199
|
+
if (this.isActive) {
|
|
200
|
+
return Promise.reject("OpenReplay: trying to call `start()` on the instance that has been started already.");
|
|
201
|
+
}
|
|
202
|
+
this.isActive = true;
|
|
203
|
+
let pageNo = 0;
|
|
204
|
+
const pageNoStr = sessionStorage.getItem(this.options.session_pageno_key);
|
|
205
|
+
if (pageNoStr != null) {
|
|
206
|
+
pageNo = parseInt(pageNoStr);
|
|
207
|
+
pageNo++;
|
|
208
|
+
}
|
|
209
|
+
sessionStorage.setItem(this.options.session_pageno_key, pageNo.toString());
|
|
210
|
+
const startTimestamp = (0, utils_js_1.timestamp)();
|
|
211
|
+
const messageData = {
|
|
212
|
+
ingestPoint: this.options.ingestPoint,
|
|
213
|
+
pageNo,
|
|
214
|
+
startTimestamp,
|
|
215
|
+
connAttemptCount: this.options.connAttemptCount,
|
|
216
|
+
connAttemptGap: this.options.connAttemptGap,
|
|
217
|
+
};
|
|
218
|
+
this.worker.postMessage(messageData); // brings delay of 10th ms?
|
|
219
|
+
// let token = sessionStorage.getItem(this.options.session_token_key)
|
|
220
|
+
// const tokenIsActive = localStorage.getItem("__or_at_" + token)
|
|
221
|
+
// if (tokenIsActive) {
|
|
222
|
+
// token = null
|
|
223
|
+
// }
|
|
224
|
+
const sReset = sessionStorage.getItem(this.options.session_reset_key);
|
|
225
|
+
sessionStorage.removeItem(this.options.session_reset_key);
|
|
226
|
+
this._userID = startOpts.userID || undefined;
|
|
227
|
+
return window.fetch(this.options.ingestPoint + '/v1/web/start', {
|
|
228
|
+
method: 'POST',
|
|
229
|
+
headers: {
|
|
230
|
+
'Content-Type': 'application/json',
|
|
231
|
+
},
|
|
232
|
+
body: JSON.stringify({
|
|
233
|
+
token: sessionStorage.getItem(this.options.session_token_key),
|
|
234
|
+
userUUID: localStorage.getItem(this.options.local_uuid_key),
|
|
235
|
+
projectKey: this.projectKey,
|
|
236
|
+
revID: this.revID,
|
|
237
|
+
timestamp: startTimestamp,
|
|
238
|
+
trackerVersion: this.version,
|
|
239
|
+
isSnippet: this.options.__is_snippet,
|
|
240
|
+
deviceMemory: performance_js_1.deviceMemory,
|
|
241
|
+
jsHeapSizeLimit: performance_js_1.jsHeapSizeLimit,
|
|
242
|
+
reset: startOpts.forceNew || sReset !== null,
|
|
243
|
+
userID: this._userID,
|
|
244
|
+
}),
|
|
245
|
+
})
|
|
246
|
+
.then(r => {
|
|
247
|
+
if (r.status === 200) {
|
|
248
|
+
return r.json();
|
|
249
|
+
}
|
|
250
|
+
else { // TODO: handle canceling && 403
|
|
251
|
+
return r.text().then(text => {
|
|
252
|
+
throw new Error(`Server error: ${r.status}. ${text}`);
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
})
|
|
256
|
+
.then(r => {
|
|
257
|
+
const { token, userUUID, sessionID, beaconSizeLimit } = r;
|
|
258
|
+
if (typeof token !== 'string' ||
|
|
259
|
+
typeof userUUID !== 'string' ||
|
|
260
|
+
(typeof beaconSizeLimit !== 'number' && typeof beaconSizeLimit !== 'undefined')) {
|
|
261
|
+
throw new Error(`Incorrect server response: ${JSON.stringify(r)}`);
|
|
262
|
+
}
|
|
263
|
+
sessionStorage.setItem(this.options.session_token_key, token);
|
|
264
|
+
localStorage.setItem(this.options.local_uuid_key, userUUID);
|
|
265
|
+
// localStorage.setItem("__or_at_" + token, "true")
|
|
266
|
+
// this.attachEventListener(window, 'beforeunload', ()=>{
|
|
267
|
+
// localStorage.removeItem("__or_at_" + token)
|
|
268
|
+
// }, false);
|
|
269
|
+
// this.attachEventListener(window, 'pagehide', ()=>{
|
|
270
|
+
// localStorage.removeItem("__or_at_" + token)
|
|
271
|
+
// }, false);
|
|
272
|
+
if (typeof sessionID === 'string') {
|
|
273
|
+
this._sessionID = sessionID;
|
|
274
|
+
}
|
|
194
275
|
if (!this.worker) {
|
|
195
|
-
|
|
276
|
+
throw new Error("no worker found after start request (this might not happen)");
|
|
196
277
|
}
|
|
197
|
-
this.
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
278
|
+
this.worker.postMessage({ token, beaconSizeLimit });
|
|
279
|
+
this.startCallbacks.forEach((cb) => cb());
|
|
280
|
+
this.observer.observe();
|
|
281
|
+
this.ticker.start();
|
|
282
|
+
(0, utils_js_1.log)("OpenReplay tracking started.");
|
|
283
|
+
const onStartInfo = { sessionToken: token, userUUID, sessionID };
|
|
284
|
+
if (typeof this.options.onStart === 'function') {
|
|
285
|
+
this.options.onStart(onStartInfo);
|
|
203
286
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
this.worker.postMessage(messageData); // brings delay of 10th ms?
|
|
214
|
-
// let token = sessionStorage.getItem(this.options.session_token_key)
|
|
215
|
-
// const tokenIsActive = localStorage.getItem("__or_at_" + token)
|
|
216
|
-
// if (tokenIsActive) {
|
|
217
|
-
// token = null
|
|
218
|
-
// }
|
|
219
|
-
const sReset = sessionStorage.getItem(this.options.session_reset_key);
|
|
220
|
-
sessionStorage.removeItem(this.options.session_reset_key);
|
|
221
|
-
return window.fetch(this.options.ingestPoint + '/v1/web/start', {
|
|
222
|
-
method: 'POST',
|
|
223
|
-
headers: {
|
|
224
|
-
'Content-Type': 'application/json',
|
|
225
|
-
},
|
|
226
|
-
body: JSON.stringify({
|
|
227
|
-
token: sessionStorage.getItem(this.options.session_token_key),
|
|
228
|
-
userUUID: localStorage.getItem(this.options.local_uuid_key),
|
|
229
|
-
projectKey: this.projectKey,
|
|
230
|
-
revID: this.revID,
|
|
231
|
-
timestamp: startTimestamp,
|
|
232
|
-
trackerVersion: this.version,
|
|
233
|
-
isSnippet: this.options.__is_snippet,
|
|
234
|
-
deviceMemory: performance_js_1.deviceMemory,
|
|
235
|
-
jsHeapSizeLimit: performance_js_1.jsHeapSizeLimit,
|
|
236
|
-
reset: reset || sReset !== null,
|
|
237
|
-
}),
|
|
238
|
-
})
|
|
239
|
-
.then(r => {
|
|
240
|
-
if (r.status === 200) {
|
|
241
|
-
return r.json();
|
|
242
|
-
}
|
|
243
|
-
else { // TODO: handle canceling && 403
|
|
244
|
-
return r.text().then(text => {
|
|
245
|
-
throw new Error(`Server error: ${r.status}. ${text}`);
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
})
|
|
249
|
-
.then(r => {
|
|
250
|
-
const { token, userUUID, sessionID, beaconSizeLimit } = r;
|
|
251
|
-
if (typeof token !== 'string' ||
|
|
252
|
-
typeof userUUID !== 'string' ||
|
|
253
|
-
(typeof beaconSizeLimit !== 'number' && typeof beaconSizeLimit !== 'undefined')) {
|
|
254
|
-
throw new Error(`Incorrect server response: ${JSON.stringify(r)}`);
|
|
255
|
-
}
|
|
256
|
-
sessionStorage.setItem(this.options.session_token_key, token);
|
|
257
|
-
localStorage.setItem(this.options.local_uuid_key, userUUID);
|
|
258
|
-
// localStorage.setItem("__or_at_" + token, "true")
|
|
259
|
-
// this.attachEventListener(window, 'beforeunload', ()=>{
|
|
260
|
-
// localStorage.removeItem("__or_at_" + token)
|
|
261
|
-
// }, false);
|
|
262
|
-
// this.attachEventListener(window, 'pagehide', ()=>{
|
|
263
|
-
// localStorage.removeItem("__or_at_" + token)
|
|
264
|
-
// }, false);
|
|
265
|
-
if (typeof sessionID === 'string') {
|
|
266
|
-
this._sessionID = sessionID;
|
|
267
|
-
}
|
|
268
|
-
if (!this.worker) {
|
|
269
|
-
throw new Error("no worker found after start request (this might not happen)");
|
|
270
|
-
}
|
|
271
|
-
this.worker.postMessage({ token, beaconSizeLimit });
|
|
272
|
-
this.startCallbacks.forEach((cb) => cb());
|
|
273
|
-
this.observer.observe();
|
|
274
|
-
this.ticker.start();
|
|
275
|
-
(0, utils_js_1.log)("OpenReplay tracking started.");
|
|
276
|
-
const onStartInfo = { sessionToken: token, userUUID, sessionID };
|
|
277
|
-
if (typeof this.options.onStart === 'function') {
|
|
278
|
-
this.options.onStart(onStartInfo);
|
|
279
|
-
}
|
|
280
|
-
return onStartInfo;
|
|
281
|
-
})
|
|
282
|
-
.catch(e => {
|
|
283
|
-
sessionStorage.removeItem(this.options.session_token_key);
|
|
284
|
-
this.stop();
|
|
285
|
-
(0, utils_js_1.warn)("OpenReplay was unable to start. ", e);
|
|
286
|
-
this._debug("session_start", e);
|
|
287
|
-
throw e;
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
return Promise.reject("Player is already active");
|
|
287
|
+
return onStartInfo;
|
|
288
|
+
})
|
|
289
|
+
.catch(e => {
|
|
290
|
+
sessionStorage.removeItem(this.options.session_token_key);
|
|
291
|
+
this.stop();
|
|
292
|
+
(0, utils_js_1.warn)("OpenReplay was unable to start. ", e);
|
|
293
|
+
this._debug("session_start", e);
|
|
294
|
+
throw e;
|
|
295
|
+
});
|
|
291
296
|
}
|
|
292
|
-
start(
|
|
297
|
+
start(options = { forceNew: false }) {
|
|
293
298
|
if (!document.hidden) {
|
|
294
|
-
return this._start(
|
|
299
|
+
return this._start(options);
|
|
295
300
|
}
|
|
296
301
|
else {
|
|
297
302
|
return new Promise((resolve) => {
|
|
298
303
|
const onVisibilityChange = () => {
|
|
299
304
|
if (!document.hidden) {
|
|
300
305
|
document.removeEventListener("visibilitychange", onVisibilityChange);
|
|
301
|
-
resolve(this._start(
|
|
306
|
+
resolve(this._start(options));
|
|
302
307
|
}
|
|
303
308
|
};
|
|
304
309
|
document.addEventListener("visibilitychange", onVisibilityChange);
|
package/cjs/index.d.ts
CHANGED
|
@@ -2,18 +2,20 @@ import App from "./app/index.js";
|
|
|
2
2
|
export { default as App } from './app/index.js';
|
|
3
3
|
import * as _Messages from "./messages/index.js";
|
|
4
4
|
export declare const Messages: typeof _Messages;
|
|
5
|
-
import { Options as AppOptions } from "./app/index.js";
|
|
6
|
-
import { Options as ConsoleOptions } from "./modules/console.js";
|
|
7
|
-
import { Options as ExceptionOptions } from "./modules/exception.js";
|
|
8
|
-
import { Options as InputOptions } from "./modules/input.js";
|
|
9
|
-
import { Options as PerformanceOptions } from "./modules/performance.js";
|
|
10
|
-
import { Options as TimingOptions } from "./modules/timing.js";
|
|
11
|
-
|
|
5
|
+
import type { Options as AppOptions } from "./app/index.js";
|
|
6
|
+
import type { Options as ConsoleOptions } from "./modules/console.js";
|
|
7
|
+
import type { Options as ExceptionOptions } from "./modules/exception.js";
|
|
8
|
+
import type { Options as InputOptions } from "./modules/input.js";
|
|
9
|
+
import type { Options as PerformanceOptions } from "./modules/performance.js";
|
|
10
|
+
import type { Options as TimingOptions } from "./modules/timing.js";
|
|
11
|
+
import type { StartOptions } from './app/index.js';
|
|
12
|
+
import type { OnStartInfo } from './app/index.js';
|
|
12
13
|
export declare type Options = Partial<AppOptions & ConsoleOptions & ExceptionOptions & InputOptions & PerformanceOptions & TimingOptions> & {
|
|
13
14
|
projectID?: number;
|
|
14
15
|
projectKey: string;
|
|
15
16
|
sessionToken?: string;
|
|
16
17
|
respectDoNotTrack?: boolean;
|
|
18
|
+
autoResetOnWindowOpen?: boolean;
|
|
17
19
|
__DISABLE_SECURE_MODE?: boolean;
|
|
18
20
|
};
|
|
19
21
|
export default class API {
|
|
@@ -23,7 +25,7 @@ export default class API {
|
|
|
23
25
|
use<T>(fn: (app: App | null, options?: Options) => T): T;
|
|
24
26
|
isActive(): boolean;
|
|
25
27
|
active(): boolean;
|
|
26
|
-
start(): Promise<
|
|
28
|
+
start(startOpts?: StartOptions): Promise<OnStartInfo>;
|
|
27
29
|
stop(): void;
|
|
28
30
|
getSessionToken(): string | null | undefined;
|
|
29
31
|
getSessionID(): string | null | undefined;
|
|
@@ -37,5 +39,4 @@ export default class API {
|
|
|
37
39
|
event(key: string, payload: any, issue?: boolean): void;
|
|
38
40
|
issue(key: string, payload: any): void;
|
|
39
41
|
handleError: (e: Error | ErrorEvent | PromiseRejectionEvent) => void;
|
|
40
|
-
resetNextPageSession(flag: boolean): void;
|
|
41
42
|
}
|
package/cjs/index.js
CHANGED
|
@@ -81,7 +81,7 @@ class API {
|
|
|
81
81
|
(navigator.doNotTrack == '1'
|
|
82
82
|
// @ts-ignore
|
|
83
83
|
|| window.doNotTrack == '1');
|
|
84
|
-
this.app = doNotTrack ||
|
|
84
|
+
const app = this.app = doNotTrack ||
|
|
85
85
|
!('Map' in window) ||
|
|
86
86
|
!('Set' in window) ||
|
|
87
87
|
!('MutationObserver' in window) ||
|
|
@@ -92,20 +92,34 @@ class API {
|
|
|
92
92
|
!('Worker' in window)
|
|
93
93
|
? null
|
|
94
94
|
: new index_js_1.default(options.projectKey, options.sessionToken, options);
|
|
95
|
-
if (
|
|
96
|
-
(0, viewport_js_1.default)(
|
|
97
|
-
(0, cssrules_js_1.default)(
|
|
98
|
-
(0, connection_js_1.default)(
|
|
99
|
-
(0, console_js_1.default)(
|
|
100
|
-
(0, exception_js_1.default)(
|
|
101
|
-
(0, img_js_1.default)(
|
|
102
|
-
(0, input_js_1.default)(
|
|
103
|
-
(0, mouse_js_1.default)(
|
|
104
|
-
(0, timing_js_1.default)(
|
|
105
|
-
(0, performance_js_1.default)(
|
|
106
|
-
(0, scroll_js_1.default)(
|
|
107
|
-
(0, longtasks_js_1.default)(
|
|
95
|
+
if (app !== null) {
|
|
96
|
+
(0, viewport_js_1.default)(app);
|
|
97
|
+
(0, cssrules_js_1.default)(app);
|
|
98
|
+
(0, connection_js_1.default)(app);
|
|
99
|
+
(0, console_js_1.default)(app, options);
|
|
100
|
+
(0, exception_js_1.default)(app, options);
|
|
101
|
+
(0, img_js_1.default)(app);
|
|
102
|
+
(0, input_js_1.default)(app, options);
|
|
103
|
+
(0, mouse_js_1.default)(app);
|
|
104
|
+
(0, timing_js_1.default)(app, options);
|
|
105
|
+
(0, performance_js_1.default)(app, options);
|
|
106
|
+
(0, scroll_js_1.default)(app);
|
|
107
|
+
(0, longtasks_js_1.default)(app);
|
|
108
108
|
window.__OPENREPLAY__ = this;
|
|
109
|
+
if (options.autoResetOnWindowOpen) {
|
|
110
|
+
const wOpen = window.open;
|
|
111
|
+
app.attachStartCallback(() => {
|
|
112
|
+
// @ts-ignore ?
|
|
113
|
+
window.open = function (...args) {
|
|
114
|
+
app.resetNextPageSession(true);
|
|
115
|
+
wOpen.call(window, ...args);
|
|
116
|
+
app.resetNextPageSession(false);
|
|
117
|
+
};
|
|
118
|
+
});
|
|
119
|
+
app.attachStopCallback(() => {
|
|
120
|
+
window.open = wOpen;
|
|
121
|
+
});
|
|
122
|
+
}
|
|
109
123
|
}
|
|
110
124
|
else {
|
|
111
125
|
console.log("OpenReplay: browser doesn't support API required for tracking or doNotTrack is set to 1.");
|
|
@@ -115,7 +129,7 @@ class API {
|
|
|
115
129
|
// no-cors issue only with text/plain or not-set Content-Type
|
|
116
130
|
// req.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
|
|
117
131
|
req.send(JSON.stringify({
|
|
118
|
-
trackerVersion: '3.4.17
|
|
132
|
+
trackerVersion: '3.4.17',
|
|
119
133
|
projectKey: options.projectKey,
|
|
120
134
|
doNotTrack,
|
|
121
135
|
// TODO: add precise reason (an exact API missing)
|
|
@@ -135,7 +149,7 @@ class API {
|
|
|
135
149
|
(0, utils_js_1.deprecationWarn)("'active' method", "'isActive' method", "/");
|
|
136
150
|
return this.isActive();
|
|
137
151
|
}
|
|
138
|
-
start() {
|
|
152
|
+
start(startOpts) {
|
|
139
153
|
if (!utils_js_1.IN_BROWSER) {
|
|
140
154
|
console.error(`OpenReplay: you are trying to start Tracker on a node.js environment. If you want to use OpenReplay with SSR, please, use componentDidMount or useEffect API for placing the \`tracker.start()\` line. Check documentation on ${utils_js_1.DOCS_HOST}${DOCS_SETUP}`);
|
|
141
155
|
return Promise.reject("Trying to start not in browser.");
|
|
@@ -143,7 +157,7 @@ class API {
|
|
|
143
157
|
if (this.app === null) {
|
|
144
158
|
return Promise.reject("Browser doesn't support required api, or doNotTrack is active.");
|
|
145
159
|
}
|
|
146
|
-
return this.app.start();
|
|
160
|
+
return this.app.start(startOpts);
|
|
147
161
|
}
|
|
148
162
|
stop() {
|
|
149
163
|
if (this.app === null) {
|
|
@@ -223,11 +237,5 @@ class API {
|
|
|
223
237
|
this.app.send(new index_js_3.CustomIssue(key, payload));
|
|
224
238
|
}
|
|
225
239
|
}
|
|
226
|
-
resetNextPageSession(flag) {
|
|
227
|
-
if (typeof flag !== 'boolean' || !this.app) {
|
|
228
|
-
return;
|
|
229
|
-
}
|
|
230
|
-
this.app.resetNextPageSession(flag);
|
|
231
|
-
}
|
|
232
240
|
}
|
|
233
241
|
exports.default = API;
|
package/lib/app/index.d.ts
CHANGED
|
@@ -10,6 +10,10 @@ export interface OnStartInfo {
|
|
|
10
10
|
sessionToken: string;
|
|
11
11
|
userUUID: string;
|
|
12
12
|
}
|
|
13
|
+
export interface StartOptions {
|
|
14
|
+
userID?: string;
|
|
15
|
+
forceNew: boolean;
|
|
16
|
+
}
|
|
13
17
|
declare type AppOptions = {
|
|
14
18
|
revID: string;
|
|
15
19
|
node_id: string;
|
|
@@ -41,6 +45,7 @@ export default class App {
|
|
|
41
45
|
private readonly options;
|
|
42
46
|
private readonly revID;
|
|
43
47
|
private _sessionID;
|
|
48
|
+
private _userID;
|
|
44
49
|
private isActive;
|
|
45
50
|
private version;
|
|
46
51
|
private readonly worker?;
|
|
@@ -64,7 +69,7 @@ export default class App {
|
|
|
64
69
|
active(): boolean;
|
|
65
70
|
resetNextPageSession(flag: boolean): void;
|
|
66
71
|
private _start;
|
|
67
|
-
start(
|
|
72
|
+
start(options?: StartOptions): Promise<OnStartInfo>;
|
|
68
73
|
stop(): void;
|
|
69
74
|
}
|
|
70
75
|
export {};
|
package/lib/app/index.js
CHANGED
|
@@ -15,7 +15,7 @@ export default class App {
|
|
|
15
15
|
this.commitCallbacks = [];
|
|
16
16
|
this._sessionID = null;
|
|
17
17
|
this.isActive = false;
|
|
18
|
-
this.version = '3.4.17
|
|
18
|
+
this.version = '3.4.17';
|
|
19
19
|
this.projectKey = projectKey;
|
|
20
20
|
this.options = Object.assign({
|
|
21
21
|
revID: '',
|
|
@@ -40,7 +40,7 @@ export default class App {
|
|
|
40
40
|
this.ticker = new Ticker(this);
|
|
41
41
|
this.ticker.attach(() => this.commit());
|
|
42
42
|
try {
|
|
43
|
-
this.worker = new Worker(URL.createObjectURL(new Blob([`"use strict";function t(t){function s(...s){return new t(...s)}return s.prototype=t.prototype,s}const s=new Map;const i=t(class{constructor(t,s,i){this.pageNo=t,this.firstIndex=s,this.timestamp=i,this._id=80}encode(t){return t.uint(80)&&t.uint(this.pageNo)&&t.uint(this.firstIndex)&&t.int(this.timestamp)}});s.set(80,i);const n=t(class{constructor(t){this.timestamp=t,this._id=0}encode(t){return t.uint(0)&&t.uint(this.timestamp)}});s.set(0,n);const e=t(class{constructor(t,s,i){this.url=t,this.referrer=s,this.navigationStart=i,this._id=4}encode(t){return t.uint(4)&&t.string(this.url)&&t.string(this.referrer)&&t.uint(this.navigationStart)}});s.set(4,e);const r=t(class{constructor(t,s){this.width=t,this.height=s,this._id=5}encode(t){return t.uint(5)&&t.uint(this.width)&&t.uint(this.height)}});s.set(5,r);const o=t(class{constructor(t,s){this.x=t,this.y=s,this._id=6}encode(t){return t.uint(6)&&t.int(this.x)&&t.int(this.y)}});s.set(6,o);const h=t(class{constructor(){this._id=7}encode(t){return t.uint(7)}});s.set(7,h);const c=t(class{constructor(t,s,i,n,e){this.id=t,this.parentID=s,this.index=i,this.tag=n,this.svg=e,this._id=8}encode(t){return t.uint(8)&&t.uint(this.id)&&t.uint(this.parentID)&&t.uint(this.index)&&t.string(this.tag)&&t.boolean(this.svg)}});s.set(8,c);const u=t(class{constructor(t,s,i){this.id=t,this.parentID=s,this.index=i,this._id=9}encode(t){return t.uint(9)&&t.uint(this.id)&&t.uint(this.parentID)&&t.uint(this.index)}});s.set(9,u);const a=t(class{constructor(t,s,i){this.id=t,this.parentID=s,this.index=i,this._id=10}encode(t){return t.uint(10)&&t.uint(this.id)&&t.uint(this.parentID)&&t.uint(this.index)}});s.set(10,a);const d=t(class{constructor(t){this.id=t,this._id=11}encode(t){return t.uint(11)&&t.uint(this.id)}});s.set(11,d);const l=t(class{constructor(t,s,i){this.id=t,this.name=s,this.value=i,this._id=12}encode(t){return t.uint(12)&&t.uint(this.id)&&t.string(this.name)&&t.string(this.value)}});s.set(12,l);const g=t(class{constructor(t,s){this.id=t,this.name=s,this._id=13}encode(t){return t.uint(13)&&t.uint(this.id)&&t.string(this.name)}});s.set(13,g);const f=t(class{constructor(t,s){this.id=t,this.data=s,this._id=14}encode(t){return t.uint(14)&&t.uint(this.id)&&t.string(this.data)}});s.set(14,f);const p=t(class{constructor(t,s,i){this.id=t,this.x=s,this.y=i,this._id=16}encode(t){return t.uint(16)&&t.uint(this.id)&&t.int(this.x)&&t.int(this.y)}});s.set(16,p);const m=t(class{constructor(t,s){this.id=t,this.label=s,this._id=17}encode(t){return t.uint(17)&&t.uint(this.id)&&t.string(this.label)}});s.set(17,m);const _=t(class{constructor(t,s,i){this.id=t,this.value=s,this.mask=i,this._id=18}encode(t){return t.uint(18)&&t.uint(this.id)&&t.string(this.value)&&t.int(this.mask)}});s.set(18,_);const y=t(class{constructor(t,s){this.id=t,this.checked=s,this._id=19}encode(t){return t.uint(19)&&t.uint(this.id)&&t.boolean(this.checked)}});s.set(19,y);const v=t(class{constructor(t,s){this.x=t,this.y=s,this._id=20}encode(t){return t.uint(20)&&t.uint(this.x)&&t.uint(this.y)}});s.set(20,v);const S=t(class{constructor(t,s){this.level=t,this.value=s,this._id=22}encode(t){return t.uint(22)&&t.string(this.level)&&t.string(this.value)}});s.set(22,S);const b=t(class{constructor(t,s,i,n,e,r,o,h,c){this.requestStart=t,this.responseStart=s,this.responseEnd=i,this.domContentLoadedEventStart=n,this.domContentLoadedEventEnd=e,this.loadEventStart=r,this.loadEventEnd=o,this.firstPaint=h,this.firstContentfulPaint=c,this._id=23}encode(t){return t.uint(23)&&t.uint(this.requestStart)&&t.uint(this.responseStart)&&t.uint(this.responseEnd)&&t.uint(this.domContentLoadedEventStart)&&t.uint(this.domContentLoadedEventEnd)&&t.uint(this.loadEventStart)&&t.uint(this.loadEventEnd)&&t.uint(this.firstPaint)&&t.uint(this.firstContentfulPaint)}});s.set(23,b);const x=t(class{constructor(t,s,i){this.speedIndex=t,this.visuallyComplete=s,this.timeToInteractive=i,this._id=24}encode(t){return t.uint(24)&&t.uint(this.speedIndex)&&t.uint(this.visuallyComplete)&&t.uint(this.timeToInteractive)}});s.set(24,x);const E=t(class{constructor(t,s,i){this.name=t,this.message=s,this.payload=i,this._id=25}encode(t){return t.uint(25)&&t.string(this.name)&&t.string(this.message)&&t.string(this.payload)}});s.set(25,E);const k=t(class{constructor(t,s){this.name=t,this.payload=s,this._id=27}encode(t){return t.uint(27)&&t.string(this.name)&&t.string(this.payload)}});s.set(27,k);const I=t(class{constructor(t){this.id=t,this._id=28}encode(t){return t.uint(28)&&t.string(this.id)}});s.set(28,I);const z=t(class{constructor(t){this.id=t,this._id=29}encode(t){return t.uint(29)&&t.string(this.id)}});s.set(29,z);const w=t(class{constructor(t,s){this.key=t,this.value=s,this._id=30}encode(t){return t.uint(30)&&t.string(this.key)&&t.string(this.value)}});s.set(30,w);const T=t(class{constructor(t,s,i){this.id=t,this.rule=s,this.index=i,this._id=37}encode(t){return t.uint(37)&&t.uint(this.id)&&t.string(this.rule)&&t.uint(this.index)}});s.set(37,T);const L=t(class{constructor(t,s){this.id=t,this.index=s,this._id=38}encode(t){return t.uint(38)&&t.uint(this.id)&&t.uint(this.index)}});s.set(38,L);const A=t(class{constructor(t,s,i,n,e,r,o){this.method=t,this.url=s,this.request=i,this.response=n,this.status=e,this.timestamp=r,this.duration=o,this._id=39}encode(t){return t.uint(39)&&t.string(this.method)&&t.string(this.url)&&t.string(this.request)&&t.string(this.response)&&t.uint(this.status)&&t.uint(this.timestamp)&&t.uint(this.duration)}});s.set(39,A);const C=t(class{constructor(t,s,i,n){this.name=t,this.duration=s,this.args=i,this.result=n,this._id=40}encode(t){return t.uint(40)&&t.string(this.name)&&t.uint(this.duration)&&t.string(this.args)&&t.string(this.result)}});s.set(40,C);const M=t(class{constructor(t,s){this.key=t,this.value=s,this._id=41}encode(t){return t.uint(41)&&t.string(this.key)&&t.string(this.value)}});s.set(41,M);const R=t(class{constructor(t){this.type=t,this._id=42}encode(t){return t.uint(42)&&t.string(this.type)}});s.set(42,R);const N=t(class{constructor(t,s,i){this.action=t,this.state=s,this.duration=i,this._id=44}encode(t){return t.uint(44)&&t.string(this.action)&&t.string(this.state)&&t.uint(this.duration)}});s.set(44,N);const D=t(class{constructor(t,s){this.mutation=t,this.state=s,this._id=45}encode(t){return t.uint(45)&&t.string(this.mutation)&&t.string(this.state)}});s.set(45,D);const U=t(class{constructor(t,s){this.type=t,this.payload=s,this._id=46}encode(t){return t.uint(46)&&t.string(this.type)&&t.string(this.payload)}});s.set(46,U);const O=t(class{constructor(t,s,i){this.action=t,this.state=s,this.duration=i,this._id=47}encode(t){return t.uint(47)&&t.string(this.action)&&t.string(this.state)&&t.uint(this.duration)}});s.set(47,O);const q=t(class{constructor(t,s,i,n){this.operationKind=t,this.operationName=s,this.variables=i,this.response=n,this._id=48}encode(t){return t.uint(48)&&t.string(this.operationKind)&&t.string(this.operationName)&&t.string(this.variables)&&t.string(this.response)}});s.set(48,q);const H=t(class{constructor(t,s,i,n){this.frames=t,this.ticks=s,this.totalJSHeapSize=i,this.usedJSHeapSize=n,this._id=49}encode(t){return t.uint(49)&&t.int(this.frames)&&t.int(this.ticks)&&t.uint(this.totalJSHeapSize)&&t.uint(this.usedJSHeapSize)}});s.set(49,H);const P=t(class{constructor(t,s,i,n,e,r,o,h){this.timestamp=t,this.duration=s,this.ttfb=i,this.headerSize=n,this.encodedBodySize=e,this.decodedBodySize=r,this.url=o,this.initiator=h,this._id=53}encode(t){return t.uint(53)&&t.uint(this.timestamp)&&t.uint(this.duration)&&t.uint(this.ttfb)&&t.uint(this.headerSize)&&t.uint(this.encodedBodySize)&&t.uint(this.decodedBodySize)&&t.string(this.url)&&t.string(this.initiator)}});s.set(53,P);const B=t(class{constructor(t,s){this.downlink=t,this.type=s,this._id=54}encode(t){return t.uint(54)&&t.uint(this.downlink)&&t.string(this.type)}});s.set(54,B);const J=t(class{constructor(t){this.hidden=t,this._id=55}encode(t){return t.uint(55)&&t.boolean(this.hidden)}});s.set(55,J);const j=t(class{constructor(t,s,i,n,e,r,o){this.timestamp=t,this.duration=s,this.context=i,this.containerType=n,this.containerSrc=e,this.containerId=r,this.containerName=o,this._id=59}encode(t){return t.uint(59)&&t.uint(this.timestamp)&&t.uint(this.duration)&&t.uint(this.context)&&t.uint(this.containerType)&&t.string(this.containerSrc)&&t.string(this.containerId)&&t.string(this.containerName)}});s.set(59,j);const G=t(class{constructor(t,s,i,n){this.id=t,this.name=s,this.value=i,this.baseURL=n,this._id=60}encode(t){return t.uint(60)&&t.uint(this.id)&&t.string(this.name)&&t.string(this.value)&&t.string(this.baseURL)}});s.set(60,G);const K=t(class{constructor(t,s,i){this.id=t,this.data=s,this.baseURL=i,this._id=61}encode(t){return t.uint(61)&&t.uint(this.id)&&t.string(this.data)&&t.string(this.baseURL)}});s.set(61,K);const X=t(class{constructor(t,s){this.type=t,this.value=s,this._id=63}encode(t){return t.uint(63)&&t.string(this.type)&&t.string(this.value)}});s.set(63,X);const F=t(class{constructor(t,s){this.name=t,this.payload=s,this._id=64}encode(t){return t.uint(64)&&t.string(this.name)&&t.string(this.payload)}});s.set(64,F);const Q=t(class{constructor(){this._id=65}encode(t){return t.uint(65)}});s.set(65,Q);const V=t(class{constructor(t,s,i,n){this.id=t,this.rule=s,this.index=i,this.baseURL=n,this._id=67}encode(t){return t.uint(67)&&t.uint(this.id)&&t.string(this.rule)&&t.uint(this.index)&&t.string(this.baseURL)}});s.set(67,V);const W=t(class{constructor(t,s,i,n){this.id=t,this.hesitationTime=s,this.label=i,this.selector=n,this._id=69}encode(t){return t.uint(69)&&t.uint(this.id)&&t.uint(this.hesitationTime)&&t.string(this.label)&&t.string(this.selector)}});s.set(69,W);const Y=t(class{constructor(t,s){this.frameID=t,this.id=s,this._id=70}encode(t){return t.uint(70)&&t.uint(this.frameID)&&t.uint(this.id)}});s.set(70,Y);const Z="function"==typeof TextEncoder?new TextEncoder:{encode(t){const s=t.length,i=new Uint8Array(3*s);let n=-1;for(var e=0,r=0,o=0;o!==s;){if(e=t.charCodeAt(o),o+=1,e>=55296&&e<=56319){if(o===s){i[n+=1]=239,i[n+=1]=191,i[n+=1]=189;break}if(!((r=t.charCodeAt(o))>=56320&&r<=57343)){i[n+=1]=239,i[n+=1]=191,i[n+=1]=189;continue}if(o+=1,(e=1024*(e-55296)+r-56320+65536)>65535){i[n+=1]=240|e>>>18,i[n+=1]=128|e>>>12&63,i[n+=1]=128|e>>>6&63,i[n+=1]=128|63&e;continue}}e<=127?i[n+=1]=0|e:e<=2047?(i[n+=1]=192|e>>>6,i[n+=1]=128|63&e):(i[n+=1]=224|e>>>12,i[n+=1]=128|e>>>6&63,i[n+=1]=128|63&e)}return i.subarray(0,n+1)}};class tt{constructor(t){this.size=t,this.offset=0,this.checkpointOffset=0,this.data=new Uint8Array(t)}checkpoint(){this.checkpointOffset=this.offset}isEmpty(){return 0===this.offset}boolean(t){return this.data[this.offset++]=+t,this.offset<=this.size}uint(t){for((t<0||t>Number.MAX_SAFE_INTEGER)&&(t=0);t>=128;)this.data[this.offset++]=t%256|128,t=Math.floor(t/128);return this.data[this.offset++]=t,this.offset<=this.size}int(t){return t=Math.round(t),this.uint(t>=0?2*t:-2*t-1)}string(t){const s=Z.encode(t),i=s.byteLength;return!(!this.uint(i)||this.offset+i>this.size)&&(this.data.set(s,this.offset),this.offset+=i,!0)}reset(){this.offset=0,this.checkpointOffset=0}flush(){const t=this.data.slice(0,this.checkpointOffset);return this.reset(),t}}let st=1e6,it=2e5,nt=new tt(it),et="",rt="",ot=0,ht=0,ct=0,ut=0,at=!0;function dt(){return new i(ot,ut,ht).encode(nt)}let lt=null;const gt=[];let ft,pt=!1,mt=0,_t=8e3,yt=10;function vt(){if(at||""===rt||""===et)return;const t=nt.flush();pt?gt.push(t):(pt=!0,function t(s){const i=new XMLHttpRequest;i.open("POST",et+"/v1/web/i",!1),i.setRequestHeader("Authorization","Bearer "+rt),i.onreadystatechange=function(){if(4===this.readyState){if(0==this.status)return;if(this.status>=400)return St(),gt.length=0,401===this.status?void self.postMessage("restart"):void self.postMessage(null);const s=gt.shift();s?t(s):pt=!1}},i.onerror=function(i){if(mt>=yt)return St(),void self.postMessage(null);mt++,setTimeout(()=>t(s),_t)},i.send(s.buffer)}(t)),at=!0,dt()}function St(){et="",rt="",null!==lt&&(clearInterval(lt),lt=null),nt.reset()}self.onmessage=({data:t})=>{if(null!==t)return"stop"===t?(vt(),void St()):Array.isArray(t)?void t.forEach(t=>{const i=new(s.get(t._id));if(Object.assign(i,t),i instanceof n?ht=i.timestamp:i instanceof J&&(i.hidden?ft=setTimeout(()=>self.postMessage("restart"),18e5):clearTimeout(ft)),nt.checkpoint(),!i.encode(nt)&&(vt(),!i.encode(nt)))for(;!i.encode(nt);){if(it===st)return console.warn("OpenReplay: beacon size overflow."),nt.reset(),void dt();it=Math.min(2*it,st),nt=new tt(it),dt()}ut++,at=!1}):(et=t.ingestPoint||et,rt=t.token||rt,ot=t.pageNo||ot,ht=t.startTimestamp||ht,ct=t.timeAdjustment||ct,yt=t.connAttemptCount||yt,_t=t.connAttemptGap||_t,st=t.beaconSizeLimit||st,it=Math.min(st,t.beaconSize||it),nt.isEmpty()&&dt(),void(null===lt&&(lt=setInterval(vt,1e4))));vt()};
|
|
43
|
+
this.worker = new Worker(URL.createObjectURL(new Blob([`"use strict";function t(t){function s(...s){return new t(...s)}return s.prototype=t.prototype,s}const s=new Map;const i=t(class{constructor(t,s,i){this.pageNo=t,this.firstIndex=s,this.timestamp=i,this._id=80}encode(t){return t.uint(80)&&t.uint(this.pageNo)&&t.uint(this.firstIndex)&&t.int(this.timestamp)}});s.set(80,i);const n=t(class{constructor(t){this.timestamp=t,this._id=0}encode(t){return t.uint(0)&&t.uint(this.timestamp)}});s.set(0,n);const e=t(class{constructor(t,s,i){this.url=t,this.referrer=s,this.navigationStart=i,this._id=4}encode(t){return t.uint(4)&&t.string(this.url)&&t.string(this.referrer)&&t.uint(this.navigationStart)}});s.set(4,e);const r=t(class{constructor(t,s){this.width=t,this.height=s,this._id=5}encode(t){return t.uint(5)&&t.uint(this.width)&&t.uint(this.height)}});s.set(5,r);const o=t(class{constructor(t,s){this.x=t,this.y=s,this._id=6}encode(t){return t.uint(6)&&t.int(this.x)&&t.int(this.y)}});s.set(6,o);const h=t(class{constructor(){this._id=7}encode(t){return t.uint(7)}});s.set(7,h);const c=t(class{constructor(t,s,i,n,e){this.id=t,this.parentID=s,this.index=i,this.tag=n,this.svg=e,this._id=8}encode(t){return t.uint(8)&&t.uint(this.id)&&t.uint(this.parentID)&&t.uint(this.index)&&t.string(this.tag)&&t.boolean(this.svg)}});s.set(8,c);const u=t(class{constructor(t,s,i){this.id=t,this.parentID=s,this.index=i,this._id=9}encode(t){return t.uint(9)&&t.uint(this.id)&&t.uint(this.parentID)&&t.uint(this.index)}});s.set(9,u);const a=t(class{constructor(t,s,i){this.id=t,this.parentID=s,this.index=i,this._id=10}encode(t){return t.uint(10)&&t.uint(this.id)&&t.uint(this.parentID)&&t.uint(this.index)}});s.set(10,a);const d=t(class{constructor(t){this.id=t,this._id=11}encode(t){return t.uint(11)&&t.uint(this.id)}});s.set(11,d);const l=t(class{constructor(t,s,i){this.id=t,this.name=s,this.value=i,this._id=12}encode(t){return t.uint(12)&&t.uint(this.id)&&t.string(this.name)&&t.string(this.value)}});s.set(12,l);const g=t(class{constructor(t,s){this.id=t,this.name=s,this._id=13}encode(t){return t.uint(13)&&t.uint(this.id)&&t.string(this.name)}});s.set(13,g);const f=t(class{constructor(t,s){this.id=t,this.data=s,this._id=14}encode(t){return t.uint(14)&&t.uint(this.id)&&t.string(this.data)}});s.set(14,f);const p=t(class{constructor(t,s,i){this.id=t,this.x=s,this.y=i,this._id=16}encode(t){return t.uint(16)&&t.uint(this.id)&&t.int(this.x)&&t.int(this.y)}});s.set(16,p);const m=t(class{constructor(t,s){this.id=t,this.label=s,this._id=17}encode(t){return t.uint(17)&&t.uint(this.id)&&t.string(this.label)}});s.set(17,m);const _=t(class{constructor(t,s,i){this.id=t,this.value=s,this.mask=i,this._id=18}encode(t){return t.uint(18)&&t.uint(this.id)&&t.string(this.value)&&t.int(this.mask)}});s.set(18,_);const y=t(class{constructor(t,s){this.id=t,this.checked=s,this._id=19}encode(t){return t.uint(19)&&t.uint(this.id)&&t.boolean(this.checked)}});s.set(19,y);const v=t(class{constructor(t,s){this.x=t,this.y=s,this._id=20}encode(t){return t.uint(20)&&t.uint(this.x)&&t.uint(this.y)}});s.set(20,v);const S=t(class{constructor(t,s){this.level=t,this.value=s,this._id=22}encode(t){return t.uint(22)&&t.string(this.level)&&t.string(this.value)}});s.set(22,S);const b=t(class{constructor(t,s,i,n,e,r,o,h,c){this.requestStart=t,this.responseStart=s,this.responseEnd=i,this.domContentLoadedEventStart=n,this.domContentLoadedEventEnd=e,this.loadEventStart=r,this.loadEventEnd=o,this.firstPaint=h,this.firstContentfulPaint=c,this._id=23}encode(t){return t.uint(23)&&t.uint(this.requestStart)&&t.uint(this.responseStart)&&t.uint(this.responseEnd)&&t.uint(this.domContentLoadedEventStart)&&t.uint(this.domContentLoadedEventEnd)&&t.uint(this.loadEventStart)&&t.uint(this.loadEventEnd)&&t.uint(this.firstPaint)&&t.uint(this.firstContentfulPaint)}});s.set(23,b);const x=t(class{constructor(t,s,i){this.speedIndex=t,this.visuallyComplete=s,this.timeToInteractive=i,this._id=24}encode(t){return t.uint(24)&&t.uint(this.speedIndex)&&t.uint(this.visuallyComplete)&&t.uint(this.timeToInteractive)}});s.set(24,x);const E=t(class{constructor(t,s,i){this.name=t,this.message=s,this.payload=i,this._id=25}encode(t){return t.uint(25)&&t.string(this.name)&&t.string(this.message)&&t.string(this.payload)}});s.set(25,E);const k=t(class{constructor(t,s){this.name=t,this.payload=s,this._id=27}encode(t){return t.uint(27)&&t.string(this.name)&&t.string(this.payload)}});s.set(27,k);const I=t(class{constructor(t){this.id=t,this._id=28}encode(t){return t.uint(28)&&t.string(this.id)}});s.set(28,I);const z=t(class{constructor(t){this.id=t,this._id=29}encode(t){return t.uint(29)&&t.string(this.id)}});s.set(29,z);const w=t(class{constructor(t,s){this.key=t,this.value=s,this._id=30}encode(t){return t.uint(30)&&t.string(this.key)&&t.string(this.value)}});s.set(30,w);const T=t(class{constructor(t,s,i){this.id=t,this.rule=s,this.index=i,this._id=37}encode(t){return t.uint(37)&&t.uint(this.id)&&t.string(this.rule)&&t.uint(this.index)}});s.set(37,T);const L=t(class{constructor(t,s){this.id=t,this.index=s,this._id=38}encode(t){return t.uint(38)&&t.uint(this.id)&&t.uint(this.index)}});s.set(38,L);const A=t(class{constructor(t,s,i,n,e,r,o){this.method=t,this.url=s,this.request=i,this.response=n,this.status=e,this.timestamp=r,this.duration=o,this._id=39}encode(t){return t.uint(39)&&t.string(this.method)&&t.string(this.url)&&t.string(this.request)&&t.string(this.response)&&t.uint(this.status)&&t.uint(this.timestamp)&&t.uint(this.duration)}});s.set(39,A);const C=t(class{constructor(t,s,i,n){this.name=t,this.duration=s,this.args=i,this.result=n,this._id=40}encode(t){return t.uint(40)&&t.string(this.name)&&t.uint(this.duration)&&t.string(this.args)&&t.string(this.result)}});s.set(40,C);const M=t(class{constructor(t,s){this.key=t,this.value=s,this._id=41}encode(t){return t.uint(41)&&t.string(this.key)&&t.string(this.value)}});s.set(41,M);const R=t(class{constructor(t){this.type=t,this._id=42}encode(t){return t.uint(42)&&t.string(this.type)}});s.set(42,R);const N=t(class{constructor(t,s,i){this.action=t,this.state=s,this.duration=i,this._id=44}encode(t){return t.uint(44)&&t.string(this.action)&&t.string(this.state)&&t.uint(this.duration)}});s.set(44,N);const D=t(class{constructor(t,s){this.mutation=t,this.state=s,this._id=45}encode(t){return t.uint(45)&&t.string(this.mutation)&&t.string(this.state)}});s.set(45,D);const U=t(class{constructor(t,s){this.type=t,this.payload=s,this._id=46}encode(t){return t.uint(46)&&t.string(this.type)&&t.string(this.payload)}});s.set(46,U);const O=t(class{constructor(t,s,i){this.action=t,this.state=s,this.duration=i,this._id=47}encode(t){return t.uint(47)&&t.string(this.action)&&t.string(this.state)&&t.uint(this.duration)}});s.set(47,O);const q=t(class{constructor(t,s,i,n){this.operationKind=t,this.operationName=s,this.variables=i,this.response=n,this._id=48}encode(t){return t.uint(48)&&t.string(this.operationKind)&&t.string(this.operationName)&&t.string(this.variables)&&t.string(this.response)}});s.set(48,q);const H=t(class{constructor(t,s,i,n){this.frames=t,this.ticks=s,this.totalJSHeapSize=i,this.usedJSHeapSize=n,this._id=49}encode(t){return t.uint(49)&&t.int(this.frames)&&t.int(this.ticks)&&t.uint(this.totalJSHeapSize)&&t.uint(this.usedJSHeapSize)}});s.set(49,H);const P=t(class{constructor(t,s,i,n,e,r,o,h){this.timestamp=t,this.duration=s,this.ttfb=i,this.headerSize=n,this.encodedBodySize=e,this.decodedBodySize=r,this.url=o,this.initiator=h,this._id=53}encode(t){return t.uint(53)&&t.uint(this.timestamp)&&t.uint(this.duration)&&t.uint(this.ttfb)&&t.uint(this.headerSize)&&t.uint(this.encodedBodySize)&&t.uint(this.decodedBodySize)&&t.string(this.url)&&t.string(this.initiator)}});s.set(53,P);const B=t(class{constructor(t,s){this.downlink=t,this.type=s,this._id=54}encode(t){return t.uint(54)&&t.uint(this.downlink)&&t.string(this.type)}});s.set(54,B);const J=t(class{constructor(t){this.hidden=t,this._id=55}encode(t){return t.uint(55)&&t.boolean(this.hidden)}});s.set(55,J);const j=t(class{constructor(t,s,i,n,e,r,o){this.timestamp=t,this.duration=s,this.context=i,this.containerType=n,this.containerSrc=e,this.containerId=r,this.containerName=o,this._id=59}encode(t){return t.uint(59)&&t.uint(this.timestamp)&&t.uint(this.duration)&&t.uint(this.context)&&t.uint(this.containerType)&&t.string(this.containerSrc)&&t.string(this.containerId)&&t.string(this.containerName)}});s.set(59,j);const G=t(class{constructor(t,s,i,n){this.id=t,this.name=s,this.value=i,this.baseURL=n,this._id=60}encode(t){return t.uint(60)&&t.uint(this.id)&&t.string(this.name)&&t.string(this.value)&&t.string(this.baseURL)}});s.set(60,G);const K=t(class{constructor(t,s,i){this.id=t,this.data=s,this.baseURL=i,this._id=61}encode(t){return t.uint(61)&&t.uint(this.id)&&t.string(this.data)&&t.string(this.baseURL)}});s.set(61,K);const X=t(class{constructor(t,s){this.type=t,this.value=s,this._id=63}encode(t){return t.uint(63)&&t.string(this.type)&&t.string(this.value)}});s.set(63,X);const F=t(class{constructor(t,s){this.name=t,this.payload=s,this._id=64}encode(t){return t.uint(64)&&t.string(this.name)&&t.string(this.payload)}});s.set(64,F);const Q=t(class{constructor(){this._id=65}encode(t){return t.uint(65)}});s.set(65,Q);const V=t(class{constructor(t,s,i,n){this.id=t,this.rule=s,this.index=i,this.baseURL=n,this._id=67}encode(t){return t.uint(67)&&t.uint(this.id)&&t.string(this.rule)&&t.uint(this.index)&&t.string(this.baseURL)}});s.set(67,V);const W=t(class{constructor(t,s,i,n){this.id=t,this.hesitationTime=s,this.label=i,this.selector=n,this._id=69}encode(t){return t.uint(69)&&t.uint(this.id)&&t.uint(this.hesitationTime)&&t.string(this.label)&&t.string(this.selector)}});s.set(69,W);const Y=t(class{constructor(t,s){this.frameID=t,this.id=s,this._id=70}encode(t){return t.uint(70)&&t.uint(this.frameID)&&t.uint(this.id)}});s.set(70,Y);const Z="function"==typeof TextEncoder?new TextEncoder:{encode(t){const s=t.length,i=new Uint8Array(3*s);let n=-1;for(var e=0,r=0,o=0;o!==s;){if(e=t.charCodeAt(o),o+=1,e>=55296&&e<=56319){if(o===s){i[n+=1]=239,i[n+=1]=191,i[n+=1]=189;break}if(!((r=t.charCodeAt(o))>=56320&&r<=57343)){i[n+=1]=239,i[n+=1]=191,i[n+=1]=189;continue}if(o+=1,(e=1024*(e-55296)+r-56320+65536)>65535){i[n+=1]=240|e>>>18,i[n+=1]=128|e>>>12&63,i[n+=1]=128|e>>>6&63,i[n+=1]=128|63&e;continue}}e<=127?i[n+=1]=0|e:e<=2047?(i[n+=1]=192|e>>>6,i[n+=1]=128|63&e):(i[n+=1]=224|e>>>12,i[n+=1]=128|e>>>6&63,i[n+=1]=128|63&e)}return i.subarray(0,n+1)}};class tt{constructor(t){this.size=t,this.offset=0,this.checkpointOffset=0,this.data=new Uint8Array(t)}checkpoint(){this.checkpointOffset=this.offset}isEmpty(){return 0===this.offset}boolean(t){return this.data[this.offset++]=+t,this.offset<=this.size}uint(t){for((t<0||t>Number.MAX_SAFE_INTEGER)&&(t=0);t>=128;)this.data[this.offset++]=t%256|128,t=Math.floor(t/128);return this.data[this.offset++]=t,this.offset<=this.size}int(t){return t=Math.round(t),this.uint(t>=0?2*t:-2*t-1)}string(t){const s=Z.encode(t),i=s.byteLength;return!(!this.uint(i)||this.offset+i>this.size)&&(this.data.set(s,this.offset),this.offset+=i,!0)}reset(){this.offset=0,this.checkpointOffset=0}flush(){const t=this.data.slice(0,this.checkpointOffset);return this.reset(),t}}let st=1e6,it=2e5,nt=new tt(it),et="",rt="",ot=0,ht=0,ct=0,ut=0,at=!0;function dt(){return new i(ot,ut,ht).encode(nt)}let lt=null;const gt=[];let ft,pt=!1,mt=0,_t=8e3,yt=10;function vt(){if(at||""===rt||""===et)return;const t=nt.flush();pt?gt.push(t):(pt=!0,function t(s){const i=new XMLHttpRequest;i.open("POST",et+"/v1/web/i",!1),i.setRequestHeader("Authorization","Bearer "+rt),i.onreadystatechange=function(){if(4===this.readyState){if(0==this.status)return;if(this.status>=400)return pt=!1,St(),gt.length=0,401===this.status?void self.postMessage("restart"):void self.postMessage(null);const s=gt.shift();s?t(s):pt=!1}},i.onerror=function(i){if(mt>=yt)return St(),void self.postMessage(null);mt++,setTimeout(()=>t(s),_t)},i.send(s.buffer)}(t)),at=!0,dt()}function St(){et="",rt="",null!==lt&&(clearInterval(lt),lt=null),nt.reset()}self.onmessage=({data:t})=>{if(null!==t)return"stop"===t?(vt(),void St()):Array.isArray(t)?void t.forEach(t=>{const i=new(s.get(t._id));if(Object.assign(i,t),i instanceof n?ht=i.timestamp:i instanceof J&&(i.hidden?ft=setTimeout(()=>self.postMessage("restart"),18e5):clearTimeout(ft)),nt.checkpoint(),!i.encode(nt)&&(vt(),!i.encode(nt)))for(;!i.encode(nt);){if(it===st)return console.warn("OpenReplay: beacon size overflow."),nt.reset(),void dt();it=Math.min(2*it,st),nt=new tt(it),dt()}ut++,at=!1}):(et=t.ingestPoint||et,rt=t.token||rt,ot=t.pageNo||ot,ht=t.startTimestamp||ht,ct=t.timeAdjustment||ct,yt=t.connAttemptCount||yt,_t=t.connAttemptGap||_t,st=t.beaconSizeLimit||st,it=Math.min(st,t.beaconSize||it),nt.isEmpty()&&dt(),void(null===lt&&(lt=setInterval(vt,1e4))));vt()};
|
|
44
44
|
`], { type: 'text/javascript' })));
|
|
45
45
|
this.worker.onerror = e => {
|
|
46
46
|
this._debug("webworker_error", e);
|
|
@@ -53,7 +53,10 @@ export default class App {
|
|
|
53
53
|
}
|
|
54
54
|
else if (data === "restart") {
|
|
55
55
|
this.stop();
|
|
56
|
-
this.start(
|
|
56
|
+
this.start({
|
|
57
|
+
forceNew: true,
|
|
58
|
+
userID: this._userID,
|
|
59
|
+
});
|
|
57
60
|
}
|
|
58
61
|
};
|
|
59
62
|
const alertWorker = () => {
|
|
@@ -186,116 +189,118 @@ export default class App {
|
|
|
186
189
|
sessionStorage.removeItem(this.options.session_reset_key);
|
|
187
190
|
}
|
|
188
191
|
}
|
|
189
|
-
_start(
|
|
190
|
-
if (!this.
|
|
192
|
+
_start(startOpts) {
|
|
193
|
+
if (!this.worker) {
|
|
194
|
+
return Promise.reject("No worker found: perhaps, CSP is not set.");
|
|
195
|
+
}
|
|
196
|
+
if (this.isActive) {
|
|
197
|
+
return Promise.reject("OpenReplay: trying to call `start()` on the instance that has been started already.");
|
|
198
|
+
}
|
|
199
|
+
this.isActive = true;
|
|
200
|
+
let pageNo = 0;
|
|
201
|
+
const pageNoStr = sessionStorage.getItem(this.options.session_pageno_key);
|
|
202
|
+
if (pageNoStr != null) {
|
|
203
|
+
pageNo = parseInt(pageNoStr);
|
|
204
|
+
pageNo++;
|
|
205
|
+
}
|
|
206
|
+
sessionStorage.setItem(this.options.session_pageno_key, pageNo.toString());
|
|
207
|
+
const startTimestamp = timestamp();
|
|
208
|
+
const messageData = {
|
|
209
|
+
ingestPoint: this.options.ingestPoint,
|
|
210
|
+
pageNo,
|
|
211
|
+
startTimestamp,
|
|
212
|
+
connAttemptCount: this.options.connAttemptCount,
|
|
213
|
+
connAttemptGap: this.options.connAttemptGap,
|
|
214
|
+
};
|
|
215
|
+
this.worker.postMessage(messageData); // brings delay of 10th ms?
|
|
216
|
+
// let token = sessionStorage.getItem(this.options.session_token_key)
|
|
217
|
+
// const tokenIsActive = localStorage.getItem("__or_at_" + token)
|
|
218
|
+
// if (tokenIsActive) {
|
|
219
|
+
// token = null
|
|
220
|
+
// }
|
|
221
|
+
const sReset = sessionStorage.getItem(this.options.session_reset_key);
|
|
222
|
+
sessionStorage.removeItem(this.options.session_reset_key);
|
|
223
|
+
this._userID = startOpts.userID || undefined;
|
|
224
|
+
return window.fetch(this.options.ingestPoint + '/v1/web/start', {
|
|
225
|
+
method: 'POST',
|
|
226
|
+
headers: {
|
|
227
|
+
'Content-Type': 'application/json',
|
|
228
|
+
},
|
|
229
|
+
body: JSON.stringify({
|
|
230
|
+
token: sessionStorage.getItem(this.options.session_token_key),
|
|
231
|
+
userUUID: localStorage.getItem(this.options.local_uuid_key),
|
|
232
|
+
projectKey: this.projectKey,
|
|
233
|
+
revID: this.revID,
|
|
234
|
+
timestamp: startTimestamp,
|
|
235
|
+
trackerVersion: this.version,
|
|
236
|
+
isSnippet: this.options.__is_snippet,
|
|
237
|
+
deviceMemory,
|
|
238
|
+
jsHeapSizeLimit,
|
|
239
|
+
reset: startOpts.forceNew || sReset !== null,
|
|
240
|
+
userID: this._userID,
|
|
241
|
+
}),
|
|
242
|
+
})
|
|
243
|
+
.then(r => {
|
|
244
|
+
if (r.status === 200) {
|
|
245
|
+
return r.json();
|
|
246
|
+
}
|
|
247
|
+
else { // TODO: handle canceling && 403
|
|
248
|
+
return r.text().then(text => {
|
|
249
|
+
throw new Error(`Server error: ${r.status}. ${text}`);
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
})
|
|
253
|
+
.then(r => {
|
|
254
|
+
const { token, userUUID, sessionID, beaconSizeLimit } = r;
|
|
255
|
+
if (typeof token !== 'string' ||
|
|
256
|
+
typeof userUUID !== 'string' ||
|
|
257
|
+
(typeof beaconSizeLimit !== 'number' && typeof beaconSizeLimit !== 'undefined')) {
|
|
258
|
+
throw new Error(`Incorrect server response: ${JSON.stringify(r)}`);
|
|
259
|
+
}
|
|
260
|
+
sessionStorage.setItem(this.options.session_token_key, token);
|
|
261
|
+
localStorage.setItem(this.options.local_uuid_key, userUUID);
|
|
262
|
+
// localStorage.setItem("__or_at_" + token, "true")
|
|
263
|
+
// this.attachEventListener(window, 'beforeunload', ()=>{
|
|
264
|
+
// localStorage.removeItem("__or_at_" + token)
|
|
265
|
+
// }, false);
|
|
266
|
+
// this.attachEventListener(window, 'pagehide', ()=>{
|
|
267
|
+
// localStorage.removeItem("__or_at_" + token)
|
|
268
|
+
// }, false);
|
|
269
|
+
if (typeof sessionID === 'string') {
|
|
270
|
+
this._sessionID = sessionID;
|
|
271
|
+
}
|
|
191
272
|
if (!this.worker) {
|
|
192
|
-
|
|
273
|
+
throw new Error("no worker found after start request (this might not happen)");
|
|
193
274
|
}
|
|
194
|
-
this.
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
275
|
+
this.worker.postMessage({ token, beaconSizeLimit });
|
|
276
|
+
this.startCallbacks.forEach((cb) => cb());
|
|
277
|
+
this.observer.observe();
|
|
278
|
+
this.ticker.start();
|
|
279
|
+
log("OpenReplay tracking started.");
|
|
280
|
+
const onStartInfo = { sessionToken: token, userUUID, sessionID };
|
|
281
|
+
if (typeof this.options.onStart === 'function') {
|
|
282
|
+
this.options.onStart(onStartInfo);
|
|
200
283
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
this.worker.postMessage(messageData); // brings delay of 10th ms?
|
|
211
|
-
// let token = sessionStorage.getItem(this.options.session_token_key)
|
|
212
|
-
// const tokenIsActive = localStorage.getItem("__or_at_" + token)
|
|
213
|
-
// if (tokenIsActive) {
|
|
214
|
-
// token = null
|
|
215
|
-
// }
|
|
216
|
-
const sReset = sessionStorage.getItem(this.options.session_reset_key);
|
|
217
|
-
sessionStorage.removeItem(this.options.session_reset_key);
|
|
218
|
-
return window.fetch(this.options.ingestPoint + '/v1/web/start', {
|
|
219
|
-
method: 'POST',
|
|
220
|
-
headers: {
|
|
221
|
-
'Content-Type': 'application/json',
|
|
222
|
-
},
|
|
223
|
-
body: JSON.stringify({
|
|
224
|
-
token: sessionStorage.getItem(this.options.session_token_key),
|
|
225
|
-
userUUID: localStorage.getItem(this.options.local_uuid_key),
|
|
226
|
-
projectKey: this.projectKey,
|
|
227
|
-
revID: this.revID,
|
|
228
|
-
timestamp: startTimestamp,
|
|
229
|
-
trackerVersion: this.version,
|
|
230
|
-
isSnippet: this.options.__is_snippet,
|
|
231
|
-
deviceMemory,
|
|
232
|
-
jsHeapSizeLimit,
|
|
233
|
-
reset: reset || sReset !== null,
|
|
234
|
-
}),
|
|
235
|
-
})
|
|
236
|
-
.then(r => {
|
|
237
|
-
if (r.status === 200) {
|
|
238
|
-
return r.json();
|
|
239
|
-
}
|
|
240
|
-
else { // TODO: handle canceling && 403
|
|
241
|
-
return r.text().then(text => {
|
|
242
|
-
throw new Error(`Server error: ${r.status}. ${text}`);
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
})
|
|
246
|
-
.then(r => {
|
|
247
|
-
const { token, userUUID, sessionID, beaconSizeLimit } = r;
|
|
248
|
-
if (typeof token !== 'string' ||
|
|
249
|
-
typeof userUUID !== 'string' ||
|
|
250
|
-
(typeof beaconSizeLimit !== 'number' && typeof beaconSizeLimit !== 'undefined')) {
|
|
251
|
-
throw new Error(`Incorrect server response: ${JSON.stringify(r)}`);
|
|
252
|
-
}
|
|
253
|
-
sessionStorage.setItem(this.options.session_token_key, token);
|
|
254
|
-
localStorage.setItem(this.options.local_uuid_key, userUUID);
|
|
255
|
-
// localStorage.setItem("__or_at_" + token, "true")
|
|
256
|
-
// this.attachEventListener(window, 'beforeunload', ()=>{
|
|
257
|
-
// localStorage.removeItem("__or_at_" + token)
|
|
258
|
-
// }, false);
|
|
259
|
-
// this.attachEventListener(window, 'pagehide', ()=>{
|
|
260
|
-
// localStorage.removeItem("__or_at_" + token)
|
|
261
|
-
// }, false);
|
|
262
|
-
if (typeof sessionID === 'string') {
|
|
263
|
-
this._sessionID = sessionID;
|
|
264
|
-
}
|
|
265
|
-
if (!this.worker) {
|
|
266
|
-
throw new Error("no worker found after start request (this might not happen)");
|
|
267
|
-
}
|
|
268
|
-
this.worker.postMessage({ token, beaconSizeLimit });
|
|
269
|
-
this.startCallbacks.forEach((cb) => cb());
|
|
270
|
-
this.observer.observe();
|
|
271
|
-
this.ticker.start();
|
|
272
|
-
log("OpenReplay tracking started.");
|
|
273
|
-
const onStartInfo = { sessionToken: token, userUUID, sessionID };
|
|
274
|
-
if (typeof this.options.onStart === 'function') {
|
|
275
|
-
this.options.onStart(onStartInfo);
|
|
276
|
-
}
|
|
277
|
-
return onStartInfo;
|
|
278
|
-
})
|
|
279
|
-
.catch(e => {
|
|
280
|
-
sessionStorage.removeItem(this.options.session_token_key);
|
|
281
|
-
this.stop();
|
|
282
|
-
warn("OpenReplay was unable to start. ", e);
|
|
283
|
-
this._debug("session_start", e);
|
|
284
|
-
throw e;
|
|
285
|
-
});
|
|
286
|
-
}
|
|
287
|
-
return Promise.reject("Player is already active");
|
|
284
|
+
return onStartInfo;
|
|
285
|
+
})
|
|
286
|
+
.catch(e => {
|
|
287
|
+
sessionStorage.removeItem(this.options.session_token_key);
|
|
288
|
+
this.stop();
|
|
289
|
+
warn("OpenReplay was unable to start. ", e);
|
|
290
|
+
this._debug("session_start", e);
|
|
291
|
+
throw e;
|
|
292
|
+
});
|
|
288
293
|
}
|
|
289
|
-
start(
|
|
294
|
+
start(options = { forceNew: false }) {
|
|
290
295
|
if (!document.hidden) {
|
|
291
|
-
return this._start(
|
|
296
|
+
return this._start(options);
|
|
292
297
|
}
|
|
293
298
|
else {
|
|
294
299
|
return new Promise((resolve) => {
|
|
295
300
|
const onVisibilityChange = () => {
|
|
296
301
|
if (!document.hidden) {
|
|
297
302
|
document.removeEventListener("visibilitychange", onVisibilityChange);
|
|
298
|
-
resolve(this._start(
|
|
303
|
+
resolve(this._start(options));
|
|
299
304
|
}
|
|
300
305
|
};
|
|
301
306
|
document.addEventListener("visibilitychange", onVisibilityChange);
|
package/lib/index.d.ts
CHANGED
|
@@ -2,18 +2,20 @@ import App from "./app/index.js";
|
|
|
2
2
|
export { default as App } from './app/index.js';
|
|
3
3
|
import * as _Messages from "./messages/index.js";
|
|
4
4
|
export declare const Messages: typeof _Messages;
|
|
5
|
-
import { Options as AppOptions } from "./app/index.js";
|
|
6
|
-
import { Options as ConsoleOptions } from "./modules/console.js";
|
|
7
|
-
import { Options as ExceptionOptions } from "./modules/exception.js";
|
|
8
|
-
import { Options as InputOptions } from "./modules/input.js";
|
|
9
|
-
import { Options as PerformanceOptions } from "./modules/performance.js";
|
|
10
|
-
import { Options as TimingOptions } from "./modules/timing.js";
|
|
11
|
-
|
|
5
|
+
import type { Options as AppOptions } from "./app/index.js";
|
|
6
|
+
import type { Options as ConsoleOptions } from "./modules/console.js";
|
|
7
|
+
import type { Options as ExceptionOptions } from "./modules/exception.js";
|
|
8
|
+
import type { Options as InputOptions } from "./modules/input.js";
|
|
9
|
+
import type { Options as PerformanceOptions } from "./modules/performance.js";
|
|
10
|
+
import type { Options as TimingOptions } from "./modules/timing.js";
|
|
11
|
+
import type { StartOptions } from './app/index.js';
|
|
12
|
+
import type { OnStartInfo } from './app/index.js';
|
|
12
13
|
export declare type Options = Partial<AppOptions & ConsoleOptions & ExceptionOptions & InputOptions & PerformanceOptions & TimingOptions> & {
|
|
13
14
|
projectID?: number;
|
|
14
15
|
projectKey: string;
|
|
15
16
|
sessionToken?: string;
|
|
16
17
|
respectDoNotTrack?: boolean;
|
|
18
|
+
autoResetOnWindowOpen?: boolean;
|
|
17
19
|
__DISABLE_SECURE_MODE?: boolean;
|
|
18
20
|
};
|
|
19
21
|
export default class API {
|
|
@@ -23,7 +25,7 @@ export default class API {
|
|
|
23
25
|
use<T>(fn: (app: App | null, options?: Options) => T): T;
|
|
24
26
|
isActive(): boolean;
|
|
25
27
|
active(): boolean;
|
|
26
|
-
start(): Promise<
|
|
28
|
+
start(startOpts?: StartOptions): Promise<OnStartInfo>;
|
|
27
29
|
stop(): void;
|
|
28
30
|
getSessionToken(): string | null | undefined;
|
|
29
31
|
getSessionID(): string | null | undefined;
|
|
@@ -37,5 +39,4 @@ export default class API {
|
|
|
37
39
|
event(key: string, payload: any, issue?: boolean): void;
|
|
38
40
|
issue(key: string, payload: any): void;
|
|
39
41
|
handleError: (e: Error | ErrorEvent | PromiseRejectionEvent) => void;
|
|
40
|
-
resetNextPageSession(flag: boolean): void;
|
|
41
42
|
}
|
package/lib/index.js
CHANGED
|
@@ -77,7 +77,7 @@ export default class API {
|
|
|
77
77
|
(navigator.doNotTrack == '1'
|
|
78
78
|
// @ts-ignore
|
|
79
79
|
|| window.doNotTrack == '1');
|
|
80
|
-
this.app = doNotTrack ||
|
|
80
|
+
const app = this.app = doNotTrack ||
|
|
81
81
|
!('Map' in window) ||
|
|
82
82
|
!('Set' in window) ||
|
|
83
83
|
!('MutationObserver' in window) ||
|
|
@@ -88,20 +88,34 @@ export default class API {
|
|
|
88
88
|
!('Worker' in window)
|
|
89
89
|
? null
|
|
90
90
|
: new App(options.projectKey, options.sessionToken, options);
|
|
91
|
-
if (
|
|
92
|
-
Viewport(
|
|
93
|
-
CSSRules(
|
|
94
|
-
Connection(
|
|
95
|
-
Console(
|
|
96
|
-
Exception(
|
|
97
|
-
Img(
|
|
98
|
-
Input(
|
|
99
|
-
Mouse(
|
|
100
|
-
Timing(
|
|
101
|
-
Performance(
|
|
102
|
-
Scroll(
|
|
103
|
-
Longtasks(
|
|
91
|
+
if (app !== null) {
|
|
92
|
+
Viewport(app);
|
|
93
|
+
CSSRules(app);
|
|
94
|
+
Connection(app);
|
|
95
|
+
Console(app, options);
|
|
96
|
+
Exception(app, options);
|
|
97
|
+
Img(app);
|
|
98
|
+
Input(app, options);
|
|
99
|
+
Mouse(app);
|
|
100
|
+
Timing(app, options);
|
|
101
|
+
Performance(app, options);
|
|
102
|
+
Scroll(app);
|
|
103
|
+
Longtasks(app);
|
|
104
104
|
window.__OPENREPLAY__ = this;
|
|
105
|
+
if (options.autoResetOnWindowOpen) {
|
|
106
|
+
const wOpen = window.open;
|
|
107
|
+
app.attachStartCallback(() => {
|
|
108
|
+
// @ts-ignore ?
|
|
109
|
+
window.open = function (...args) {
|
|
110
|
+
app.resetNextPageSession(true);
|
|
111
|
+
wOpen.call(window, ...args);
|
|
112
|
+
app.resetNextPageSession(false);
|
|
113
|
+
};
|
|
114
|
+
});
|
|
115
|
+
app.attachStopCallback(() => {
|
|
116
|
+
window.open = wOpen;
|
|
117
|
+
});
|
|
118
|
+
}
|
|
105
119
|
}
|
|
106
120
|
else {
|
|
107
121
|
console.log("OpenReplay: browser doesn't support API required for tracking or doNotTrack is set to 1.");
|
|
@@ -111,7 +125,7 @@ export default class API {
|
|
|
111
125
|
// no-cors issue only with text/plain or not-set Content-Type
|
|
112
126
|
// req.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
|
|
113
127
|
req.send(JSON.stringify({
|
|
114
|
-
trackerVersion: '3.4.17
|
|
128
|
+
trackerVersion: '3.4.17',
|
|
115
129
|
projectKey: options.projectKey,
|
|
116
130
|
doNotTrack,
|
|
117
131
|
// TODO: add precise reason (an exact API missing)
|
|
@@ -131,7 +145,7 @@ export default class API {
|
|
|
131
145
|
deprecationWarn("'active' method", "'isActive' method", "/");
|
|
132
146
|
return this.isActive();
|
|
133
147
|
}
|
|
134
|
-
start() {
|
|
148
|
+
start(startOpts) {
|
|
135
149
|
if (!IN_BROWSER) {
|
|
136
150
|
console.error(`OpenReplay: you are trying to start Tracker on a node.js environment. If you want to use OpenReplay with SSR, please, use componentDidMount or useEffect API for placing the \`tracker.start()\` line. Check documentation on ${DOCS_HOST}${DOCS_SETUP}`);
|
|
137
151
|
return Promise.reject("Trying to start not in browser.");
|
|
@@ -139,7 +153,7 @@ export default class API {
|
|
|
139
153
|
if (this.app === null) {
|
|
140
154
|
return Promise.reject("Browser doesn't support required api, or doNotTrack is active.");
|
|
141
155
|
}
|
|
142
|
-
return this.app.start();
|
|
156
|
+
return this.app.start(startOpts);
|
|
143
157
|
}
|
|
144
158
|
stop() {
|
|
145
159
|
if (this.app === null) {
|
|
@@ -219,10 +233,4 @@ export default class API {
|
|
|
219
233
|
this.app.send(new CustomIssue(key, payload));
|
|
220
234
|
}
|
|
221
235
|
}
|
|
222
|
-
resetNextPageSession(flag) {
|
|
223
|
-
if (typeof flag !== 'boolean' || !this.app) {
|
|
224
|
-
return;
|
|
225
|
-
}
|
|
226
|
-
this.app.resetNextPageSession(flag);
|
|
227
|
-
}
|
|
228
236
|
}
|