Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@openreplay/tracker

Package Overview
Dependencies
Maintainers
3
Versions
220
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@openreplay/tracker - npm Package Compare versions

Comparing version 3.4.17 to 3.5.0

26

cjs/app/index.d.ts

@@ -5,4 +5,6 @@ import Message from "../messages/message.js";

import Ticker from "./ticker.js";
import Logger from "./logger.js";
import type { Options as ObserverOptions } from "./observer/top_observer.js";
import type { Options as SanitizerOptions } from "./sanitizer.js";
import type { Options as LoggerOptions } from "./logger.js";
import type { Options as WebworkerOptions } from "../messages/webworker.js";

@@ -16,2 +18,3 @@ export interface OnStartInfo {

userID?: string;
metadata?: Record<string, string>;
forceNew: boolean;

@@ -28,5 +31,6 @@ }

resourceBaseHref: string | null;
verbose: boolean;
__is_snippet: boolean;
__debug_report_edp: string | null;
__debug_log: boolean;
__debug__?: LoggerOptions;
onStart?: (info: OnStartInfo) => void;

@@ -37,2 +41,3 @@ } & WebworkerOptions;

declare type CommitCallback = (messages: Array<Message>) => void;
export declare const CANCELED = "canceled";
export declare const DEFAULT_INGEST_POINT = "https://api.openreplay.com/ingest";

@@ -44,2 +49,4 @@ export default class App {

readonly sanitizer: Sanitizer;
readonly debug: Logger;
readonly notify: Logger;
private readonly messages;

@@ -54,3 +61,4 @@ private readonly observer;

private _userID;
private isActive;
private _metadata;
private activityState;
private version;

@@ -63,3 +71,2 @@ private readonly worker?;

attachCommitCallback(cb: CommitCallback): void;
addCommitCallback(cb: CommitCallback): void;
safe<T extends (...args: any[]) => void>(fn: T): T;

@@ -69,2 +76,15 @@ attachStartCallback(cb: Callback): void;

attachEventListener(target: EventTarget, type: string, listener: EventListener, useSafe?: boolean, useCapture?: boolean): void;
checkRequiredVersion(version: string): boolean;
private getStartInfo;
getSessionInfo(): {
userUUID: string | null;
projectKey: string;
revID: string;
timestamp: number;
trackerVersion: string;
userID: string | null;
isSnippet: boolean;
sessionID: string | null;
metadata: Record<string, string>;
};
getSessionToken(): string | undefined;

@@ -71,0 +91,0 @@ getSessionID(): string | undefined;

138

cjs/app/index.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DEFAULT_INGEST_POINT = void 0;
exports.DEFAULT_INGEST_POINT = exports.CANCELED = void 0;
const utils_js_1 = require("../utils.js");

@@ -10,3 +10,11 @@ const index_js_1 = require("../messages/index.js");

const ticker_js_1 = require("./ticker.js");
const logger_js_1 = require("./logger.js");
const performance_js_1 = require("../modules/performance.js");
var ActivityState;
(function (ActivityState) {
ActivityState[ActivityState["NotActive"] = 0] = "NotActive";
ActivityState[ActivityState["Starting"] = 1] = "Starting";
ActivityState[ActivityState["Active"] = 2] = "Active";
})(ActivityState || (ActivityState = {}));
exports.CANCELED = "canceled";
// TODO: use backendHost only

@@ -16,2 +24,5 @@ exports.DEFAULT_INGEST_POINT = 'https://api.openreplay.com/ingest';

constructor(projectKey, sessionToken, options) {
// if (options.onStart !== undefined) {
// deprecationWarn("'onStart' option", "tracker.start().then(/* handle session info */)")
// } ?? maybe onStart is good
this.messages = [];

@@ -22,4 +33,6 @@ this.startCallbacks = [];

this._sessionID = null;
this.isActive = false;
this.version = '3.4.17';
this._userID = null;
this._metadata = {};
this.activityState = ActivityState.NotActive;
this.version = '3.5.0'; // TODO: version compatability check inside each plugin.
this.projectKey = projectKey;

@@ -35,5 +48,5 @@ this.options = Object.assign({

resourceBaseHref: null,
verbose: false,
__is_snippet: false,
__debug_report_edp: null,
__debug_log: false,
}, options);

@@ -49,2 +62,4 @@ if (sessionToken != null) {

this.ticker.attach(() => this.commit());
this.debug = new logger_js_1.default(this.options.__debug__);
this.notify = new logger_js_1.default(this.options.verbose ? logger_js_1.LogLevel.Warnings : logger_js_1.LogLevel.Silent);
try {

@@ -66,3 +81,4 @@ 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()};

forceNew: true,
userID: this._userID,
userID: this._userID || undefined,
metadata: this._metadata || undefined,
});

@@ -96,8 +112,6 @@ }

}
if (this.options.__debug_log) {
(0, utils_js_1.warn)("OpenReplay error: ", context, e);
}
this.debug.error("OpenReplay error: ", context, e);
}
send(message, urgent = false) {
if (!this.isActive) {
if (this.activityState !== ActivityState.Active) {
return;

@@ -121,6 +135,2 @@ }

}
// @Depricated (TODO: remove in 3.5.*)
addCommitCallback(cb) {
this.attachCommitCallback(cb);
}
safe(fn) {

@@ -154,2 +164,26 @@ const app = this;

}
checkRequiredVersion(version) {
const reqVer = version.split('.');
const ver = this.version.split('.');
for (let i = 0; i < ver.length; i++) {
if (Number(ver[i]) < Number(reqVer[i]) || isNaN(Number(ver[i])) || isNaN(Number(reqVer[i]))) {
return false;
}
}
return true;
}
getStartInfo() {
return {
userUUID: localStorage.getItem(this.options.local_uuid_key),
projectKey: this.projectKey,
revID: this.revID,
timestamp: (0, utils_js_1.timestamp)(),
trackerVersion: this.version,
userID: this._userID,
isSnippet: this.options.__is_snippet,
};
}
getSessionInfo() {
return Object.assign({ sessionID: this._sessionID, metadata: this._metadata }, this.getStartInfo());
}
getSessionToken() {

@@ -194,3 +228,3 @@ const token = sessionStorage.getItem(this.options.session_token_key);

active() {
return this.isActive;
return this.activityState === ActivityState.Active;
}

@@ -209,6 +243,6 @@ resetNextPageSession(flag) {

}
if (this.isActive) {
if (this.activityState !== ActivityState.NotActive) {
return Promise.reject("OpenReplay: trying to call `start()` on the instance that has been started already.");
}
this.isActive = true;
this.activityState = ActivityState.Starting;
let pageNo = 0;

@@ -221,7 +255,9 @@ const pageNoStr = sessionStorage.getItem(this.options.session_pageno_key);

sessionStorage.setItem(this.options.session_pageno_key, pageNo.toString());
const startTimestamp = (0, utils_js_1.timestamp)();
this._userID = startOpts.userID || null;
this._metadata = startOpts.metadata || {}; // TODO: update both dynamically on corresponding messages
const startInfo = this.getStartInfo();
const messageData = {
ingestPoint: this.options.ingestPoint,
pageNo,
startTimestamp,
startTimestamp: startInfo.timestamp,
connAttemptCount: this.options.connAttemptCount,

@@ -231,10 +267,4 @@ connAttemptGap: this.options.connAttemptGap,

this.worker.postMessage(messageData); // brings delay of 10th ms?
// let token = sessionStorage.getItem(this.options.session_token_key)
// const tokenIsActive = localStorage.getItem("__or_at_" + token)
// if (tokenIsActive) {
// token = null
// }
const sReset = sessionStorage.getItem(this.options.session_reset_key);
sessionStorage.removeItem(this.options.session_reset_key);
this._userID = startOpts.userID || undefined;
return window.fetch(this.options.ingestPoint + '/v1/web/start', {

@@ -245,15 +275,4 @@ method: 'POST',

},
body: JSON.stringify({
token: sessionStorage.getItem(this.options.session_token_key),
userUUID: localStorage.getItem(this.options.local_uuid_key),
projectKey: this.projectKey,
revID: this.revID,
timestamp: startTimestamp,
trackerVersion: this.version,
isSnippet: this.options.__is_snippet,
deviceMemory: performance_js_1.deviceMemory,
jsHeapSizeLimit: performance_js_1.jsHeapSizeLimit,
reset: startOpts.forceNew || sReset !== null,
userID: this._userID,
}),
body: JSON.stringify(Object.assign(Object.assign({}, startInfo), { token: sessionStorage.getItem(this.options.session_token_key), deviceMemory: performance_js_1.deviceMemory,
jsHeapSizeLimit: performance_js_1.jsHeapSizeLimit, reset: startOpts.forceNew || sReset !== null })),
})

@@ -264,9 +283,12 @@ .then(r => {

}
else { // TODO: handle canceling && 403
return r.text().then(text => {
throw new Error(`Server error: ${r.status}. ${text}`);
});
else {
return r.text().then(text => text === exports.CANCELED
? Promise.reject(exports.CANCELED)
: Promise.reject(`Server error: ${r.status}. ${text}`));
}
})
.then(r => {
if (!this.worker) {
return Promise.reject("no worker found after start request (this might not happen)");
}
const { token, userUUID, sessionID, beaconSizeLimit } = r;

@@ -276,19 +298,10 @@ if (typeof token !== 'string' ||

(typeof beaconSizeLimit !== 'number' && typeof beaconSizeLimit !== 'undefined')) {
throw new Error(`Incorrect server response: ${JSON.stringify(r)}`);
return Promise.reject(`Incorrect server response: ${JSON.stringify(r)}`);
}
sessionStorage.setItem(this.options.session_token_key, token);
localStorage.setItem(this.options.local_uuid_key, userUUID);
// localStorage.setItem("__or_at_" + token, "true")
// this.attachEventListener(window, 'beforeunload', ()=>{
// localStorage.removeItem("__or_at_" + token)
// }, false);
// this.attachEventListener(window, 'pagehide', ()=>{
// localStorage.removeItem("__or_at_" + token)
// }, false);
if (typeof sessionID === 'string') {
this._sessionID = sessionID;
}
if (!this.worker) {
throw new Error("no worker found after start request (this might not happen)");
}
this.activityState = ActivityState.Active;
this.worker.postMessage({ token, beaconSizeLimit });

@@ -298,3 +311,5 @@ this.startCallbacks.forEach((cb) => cb());

this.ticker.start();
(0, utils_js_1.log)("OpenReplay tracking started.");
Object.entries(this._metadata).forEach(([key, value]) => this.send(new index_js_1.Metadata(key, value)));
this.notify.log("OpenReplay tracking started.");
// TODO: get rid of onStart
const onStartInfo = { sessionToken: token, userUUID, sessionID };

@@ -306,8 +321,11 @@ if (typeof this.options.onStart === 'function') {

})
.catch(e => {
.catch(reason => {
sessionStorage.removeItem(this.options.session_token_key);
this.stop();
(0, utils_js_1.warn)("OpenReplay was unable to start. ", e);
this._debug("session_start", e);
throw e;
//if (reason === CANCELED) { return Promise.resolve(CANCELED) } // TODO: what to return ????? Throwing is baad
if (reason !== exports.CANCELED) {
this.notify.log("OpenReplay was unable to start. ", reason);
this._debug("session_start", reason);
}
return Promise.reject(reason);
});

@@ -332,3 +350,3 @@ }

stop() {
if (this.isActive) {
if (this.activityState !== ActivityState.NotActive) {
try {

@@ -343,6 +361,6 @@ if (this.worker) {

this.stopCallbacks.forEach((cb) => cb());
(0, utils_js_1.log)("OpenReplay tracking stopped.");
this.notify.log("OpenReplay tracking stopped.");
}
finally {
this.isActive = false;
this.activityState = ActivityState.NotActive;
}

@@ -349,0 +367,0 @@ }

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LogLevel = void 0;
exports.LogLevel = {
Verbose: 4,
Errors: 4,
Warnings: 3,
Log: 2,
Silent: 0,
};
function IsCustomLevel(l) {
return typeof l === 'object';
}
class Logger {
constructor(options = exports.LogLevel.Silent) {
this.options = options;
this.opts = options === true
? { level: exports.LogLevel.Verbose }
: typeof options === "number" ? { level: options } : options;
}
log(...args) {
if (IsCustomLevel(this.opts.level)
? this.opts.level.log
: this.opts.level >= exports.LogLevel.Log) {
console.log(...args);
}
}
warn(...args) {
if (IsCustomLevel(this.opts.level)
? this.opts.level.warn
: this.opts.level >= exports.LogLevel.Warnings) {
console.warn(...args);
}
}
error(...args) {
if (IsCustomLevel(this.opts.level)
? this.opts.level.error
: this.opts.level >= exports.LogLevel.Errors) {
console.error(...args);
}
}
}
exports.default = Logger;

@@ -27,3 +27,2 @@ import App from "./app/index.js";

isActive(): boolean;
active(): boolean;
start(startOpts?: StartOptions): Promise<OnStartInfo>;

@@ -30,0 +29,0 @@ stop(): void;

@@ -132,3 +132,3 @@ "use strict";

req.send(JSON.stringify({
trackerVersion: '3.4.17',
trackerVersion: '3.5.0',
projectKey: options.projectKey,

@@ -149,6 +149,2 @@ doNotTrack,

}
active() {
(0, utils_js_1.deprecationWarn)("'active' method", "'isActive' method", "/");
return this.isActive();
}
start(startOpts) {

@@ -162,2 +158,3 @@ if (!utils_js_1.IN_BROWSER) {

}
// TODO: check argument typing
return this.app.start(startOpts);

@@ -164,0 +161,0 @@ }

@@ -21,3 +21,3 @@ "use strict";

}
return arg.toString();
return String(arg);
}

@@ -24,0 +24,0 @@ function printFloat(arg) {

@@ -60,2 +60,3 @@ "use strict";

tag === 'LI' ||
tag === 'SELECT' ||
element.onclick != null ||

@@ -87,2 +88,3 @@ element.getAttribute('role') === 'button' ||

tag === 'LI' ||
tag === 'SELECT' ||
target.onclick != null ||

@@ -89,0 +91,0 @@ target.getAttribute('role') === 'button') {

@@ -6,10 +6,2 @@ export declare function timestamp(): number;

export declare const IN_BROWSER: boolean;
export declare const log: {
(...data: any[]): void;
(message?: any, ...optionalParams: any[]): void;
};
export declare const warn: {
(...data: any[]): void;
(message?: any, ...optionalParams: any[]): void;
};
export declare const DOCS_HOST = "https://docs.openreplay.com";

@@ -16,0 +8,0 @@ export declare function deprecationWarn(nameOfFeature: string, useInstead: string, docsPath?: string): void;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.hasOpenreplayAttribute = exports.getLabelAttribute = exports.deprecationWarn = exports.DOCS_HOST = exports.warn = exports.log = exports.IN_BROWSER = exports.isURL = exports.normSpaces = exports.stars = exports.timestamp = void 0;
exports.hasOpenreplayAttribute = exports.getLabelAttribute = exports.deprecationWarn = exports.DOCS_HOST = exports.IN_BROWSER = exports.isURL = exports.normSpaces = exports.stars = exports.timestamp = void 0;
function timestamp() {

@@ -21,4 +21,3 @@ return Math.round(performance.now()) + performance.timing.navigationStart;

exports.IN_BROWSER = !(typeof window === "undefined");
exports.log = console.log;
exports.warn = console.warn;
// TODO: JOIN IT WITH LOGGER somehow (use logging decorators?); Don't forget about index.js loggin when there is no logger instance.
exports.DOCS_HOST = 'https://docs.openreplay.com';

@@ -30,3 +29,3 @@ const warnedFeatures = {};

}
(0, exports.warn)(`OpenReplay: ${nameOfFeature} is deprecated. ${useInstead ? `Please, use ${useInstead} instead.` : ""} Visit ${exports.DOCS_HOST}${docsPath} for more information.`);
console.warn(`OpenReplay: ${nameOfFeature} is deprecated. ${useInstead ? `Please, use ${useInstead} instead.` : ""} Visit ${exports.DOCS_HOST}${docsPath} for more information.`);
warnedFeatures[nameOfFeature] = true;

@@ -33,0 +32,0 @@ }

@@ -5,4 +5,6 @@ import Message from "../messages/message.js";

import Ticker from "./ticker.js";
import Logger from "./logger.js";
import type { Options as ObserverOptions } from "./observer/top_observer.js";
import type { Options as SanitizerOptions } from "./sanitizer.js";
import type { Options as LoggerOptions } from "./logger.js";
import type { Options as WebworkerOptions } from "../messages/webworker.js";

@@ -16,2 +18,3 @@ export interface OnStartInfo {

userID?: string;
metadata?: Record<string, string>;
forceNew: boolean;

@@ -28,5 +31,6 @@ }

resourceBaseHref: string | null;
verbose: boolean;
__is_snippet: boolean;
__debug_report_edp: string | null;
__debug_log: boolean;
__debug__?: LoggerOptions;
onStart?: (info: OnStartInfo) => void;

@@ -37,2 +41,3 @@ } & WebworkerOptions;

declare type CommitCallback = (messages: Array<Message>) => void;
export declare const CANCELED = "canceled";
export declare const DEFAULT_INGEST_POINT = "https://api.openreplay.com/ingest";

@@ -44,2 +49,4 @@ export default class App {

readonly sanitizer: Sanitizer;
readonly debug: Logger;
readonly notify: Logger;
private readonly messages;

@@ -54,3 +61,4 @@ private readonly observer;

private _userID;
private isActive;
private _metadata;
private activityState;
private version;

@@ -63,3 +71,2 @@ private readonly worker?;

attachCommitCallback(cb: CommitCallback): void;
addCommitCallback(cb: CommitCallback): void;
safe<T extends (...args: any[]) => void>(fn: T): T;

@@ -69,2 +76,15 @@ attachStartCallback(cb: Callback): void;

attachEventListener(target: EventTarget, type: string, listener: EventListener, useSafe?: boolean, useCapture?: boolean): void;
checkRequiredVersion(version: string): boolean;
private getStartInfo;
getSessionInfo(): {
userUUID: string | null;
projectKey: string;
revID: string;
timestamp: number;
trackerVersion: string;
userID: string | null;
isSnippet: boolean;
sessionID: string | null;
metadata: Record<string, string>;
};
getSessionToken(): string | undefined;

@@ -71,0 +91,0 @@ getSessionID(): string | undefined;

@@ -1,3 +0,3 @@

import { timestamp, log, warn } from "../utils.js";
import { Timestamp } from "../messages/index.js";
import { timestamp } from "../utils.js";
import { Timestamp, Metadata } from "../messages/index.js";
import Nodes from "./nodes.js";

@@ -7,3 +7,11 @@ import Observer from "./observer/top_observer.js";

import Ticker from "./ticker.js";
import Logger, { LogLevel } from "./logger.js";
import { deviceMemory, jsHeapSizeLimit } from "../modules/performance.js";
var ActivityState;
(function (ActivityState) {
ActivityState[ActivityState["NotActive"] = 0] = "NotActive";
ActivityState[ActivityState["Starting"] = 1] = "Starting";
ActivityState[ActivityState["Active"] = 2] = "Active";
})(ActivityState || (ActivityState = {}));
export const CANCELED = "canceled";
// TODO: use backendHost only

@@ -13,2 +21,5 @@ export const DEFAULT_INGEST_POINT = 'https://api.openreplay.com/ingest';

constructor(projectKey, sessionToken, options) {
// if (options.onStart !== undefined) {
// deprecationWarn("'onStart' option", "tracker.start().then(/* handle session info */)")
// } ?? maybe onStart is good
this.messages = [];

@@ -19,4 +30,6 @@ this.startCallbacks = [];

this._sessionID = null;
this.isActive = false;
this.version = '3.4.17';
this._userID = null;
this._metadata = {};
this.activityState = ActivityState.NotActive;
this.version = '3.5.0'; // TODO: version compatability check inside each plugin.
this.projectKey = projectKey;

@@ -32,5 +45,5 @@ this.options = Object.assign({

resourceBaseHref: null,
verbose: false,
__is_snippet: false,
__debug_report_edp: null,
__debug_log: false,
}, options);

@@ -46,2 +59,4 @@ if (sessionToken != null) {

this.ticker.attach(() => this.commit());
this.debug = new Logger(this.options.__debug__);
this.notify = new Logger(this.options.verbose ? LogLevel.Warnings : LogLevel.Silent);
try {

@@ -63,3 +78,4 @@ 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()};

forceNew: true,
userID: this._userID,
userID: this._userID || undefined,
metadata: this._metadata || undefined,
});

@@ -93,8 +109,6 @@ }

}
if (this.options.__debug_log) {
warn("OpenReplay error: ", context, e);
}
this.debug.error("OpenReplay error: ", context, e);
}
send(message, urgent = false) {
if (!this.isActive) {
if (this.activityState !== ActivityState.Active) {
return;

@@ -118,6 +132,2 @@ }

}
// @Depricated (TODO: remove in 3.5.*)
addCommitCallback(cb) {
this.attachCommitCallback(cb);
}
safe(fn) {

@@ -151,2 +161,26 @@ const app = this;

}
checkRequiredVersion(version) {
const reqVer = version.split('.');
const ver = this.version.split('.');
for (let i = 0; i < ver.length; i++) {
if (Number(ver[i]) < Number(reqVer[i]) || isNaN(Number(ver[i])) || isNaN(Number(reqVer[i]))) {
return false;
}
}
return true;
}
getStartInfo() {
return {
userUUID: localStorage.getItem(this.options.local_uuid_key),
projectKey: this.projectKey,
revID: this.revID,
timestamp: timestamp(),
trackerVersion: this.version,
userID: this._userID,
isSnippet: this.options.__is_snippet,
};
}
getSessionInfo() {
return Object.assign({ sessionID: this._sessionID, metadata: this._metadata }, this.getStartInfo());
}
getSessionToken() {

@@ -191,3 +225,3 @@ const token = sessionStorage.getItem(this.options.session_token_key);

active() {
return this.isActive;
return this.activityState === ActivityState.Active;
}

@@ -206,6 +240,6 @@ resetNextPageSession(flag) {

}
if (this.isActive) {
if (this.activityState !== ActivityState.NotActive) {
return Promise.reject("OpenReplay: trying to call `start()` on the instance that has been started already.");
}
this.isActive = true;
this.activityState = ActivityState.Starting;
let pageNo = 0;

@@ -218,7 +252,9 @@ const pageNoStr = sessionStorage.getItem(this.options.session_pageno_key);

sessionStorage.setItem(this.options.session_pageno_key, pageNo.toString());
const startTimestamp = timestamp();
this._userID = startOpts.userID || null;
this._metadata = startOpts.metadata || {}; // TODO: update both dynamically on corresponding messages
const startInfo = this.getStartInfo();
const messageData = {
ingestPoint: this.options.ingestPoint,
pageNo,
startTimestamp,
startTimestamp: startInfo.timestamp,
connAttemptCount: this.options.connAttemptCount,

@@ -228,10 +264,4 @@ connAttemptGap: this.options.connAttemptGap,

this.worker.postMessage(messageData); // brings delay of 10th ms?
// let token = sessionStorage.getItem(this.options.session_token_key)
// const tokenIsActive = localStorage.getItem("__or_at_" + token)
// if (tokenIsActive) {
// token = null
// }
const sReset = sessionStorage.getItem(this.options.session_reset_key);
sessionStorage.removeItem(this.options.session_reset_key);
this._userID = startOpts.userID || undefined;
return window.fetch(this.options.ingestPoint + '/v1/web/start', {

@@ -242,15 +272,4 @@ method: 'POST',

},
body: JSON.stringify({
token: sessionStorage.getItem(this.options.session_token_key),
userUUID: localStorage.getItem(this.options.local_uuid_key),
projectKey: this.projectKey,
revID: this.revID,
timestamp: startTimestamp,
trackerVersion: this.version,
isSnippet: this.options.__is_snippet,
deviceMemory,
jsHeapSizeLimit,
reset: startOpts.forceNew || sReset !== null,
userID: this._userID,
}),
body: JSON.stringify(Object.assign(Object.assign({}, startInfo), { token: sessionStorage.getItem(this.options.session_token_key), deviceMemory,
jsHeapSizeLimit, reset: startOpts.forceNew || sReset !== null })),
})

@@ -261,9 +280,12 @@ .then(r => {

}
else { // TODO: handle canceling && 403
return r.text().then(text => {
throw new Error(`Server error: ${r.status}. ${text}`);
});
else {
return r.text().then(text => text === CANCELED
? Promise.reject(CANCELED)
: Promise.reject(`Server error: ${r.status}. ${text}`));
}
})
.then(r => {
if (!this.worker) {
return Promise.reject("no worker found after start request (this might not happen)");
}
const { token, userUUID, sessionID, beaconSizeLimit } = r;

@@ -273,19 +295,10 @@ if (typeof token !== 'string' ||

(typeof beaconSizeLimit !== 'number' && typeof beaconSizeLimit !== 'undefined')) {
throw new Error(`Incorrect server response: ${JSON.stringify(r)}`);
return Promise.reject(`Incorrect server response: ${JSON.stringify(r)}`);
}
sessionStorage.setItem(this.options.session_token_key, token);
localStorage.setItem(this.options.local_uuid_key, userUUID);
// localStorage.setItem("__or_at_" + token, "true")
// this.attachEventListener(window, 'beforeunload', ()=>{
// localStorage.removeItem("__or_at_" + token)
// }, false);
// this.attachEventListener(window, 'pagehide', ()=>{
// localStorage.removeItem("__or_at_" + token)
// }, false);
if (typeof sessionID === 'string') {
this._sessionID = sessionID;
}
if (!this.worker) {
throw new Error("no worker found after start request (this might not happen)");
}
this.activityState = ActivityState.Active;
this.worker.postMessage({ token, beaconSizeLimit });

@@ -295,3 +308,5 @@ this.startCallbacks.forEach((cb) => cb());

this.ticker.start();
log("OpenReplay tracking started.");
Object.entries(this._metadata).forEach(([key, value]) => this.send(new Metadata(key, value)));
this.notify.log("OpenReplay tracking started.");
// TODO: get rid of onStart
const onStartInfo = { sessionToken: token, userUUID, sessionID };

@@ -303,8 +318,11 @@ if (typeof this.options.onStart === 'function') {

})
.catch(e => {
.catch(reason => {
sessionStorage.removeItem(this.options.session_token_key);
this.stop();
warn("OpenReplay was unable to start. ", e);
this._debug("session_start", e);
throw e;
//if (reason === CANCELED) { return Promise.resolve(CANCELED) } // TODO: what to return ????? Throwing is baad
if (reason !== CANCELED) {
this.notify.log("OpenReplay was unable to start. ", reason);
this._debug("session_start", reason);
}
return Promise.reject(reason);
});

@@ -329,3 +347,3 @@ }

stop() {
if (this.isActive) {
if (this.activityState !== ActivityState.NotActive) {
try {

@@ -340,6 +358,6 @@ if (this.worker) {

this.stopCallbacks.forEach((cb) => cb());
log("OpenReplay tracking stopped.");
this.notify.log("OpenReplay tracking stopped.");
}
finally {
this.isActive = false;
this.activityState = ActivityState.NotActive;
}

@@ -346,0 +364,0 @@ }

@@ -1,1 +0,39 @@

"use strict";
export const LogLevel = {
Verbose: 4,
Errors: 4,
Warnings: 3,
Log: 2,
Silent: 0,
};
function IsCustomLevel(l) {
return typeof l === 'object';
}
export default class Logger {
constructor(options = LogLevel.Silent) {
this.options = options;
this.opts = options === true
? { level: LogLevel.Verbose }
: typeof options === "number" ? { level: options } : options;
}
log(...args) {
if (IsCustomLevel(this.opts.level)
? this.opts.level.log
: this.opts.level >= LogLevel.Log) {
console.log(...args);
}
}
warn(...args) {
if (IsCustomLevel(this.opts.level)
? this.opts.level.warn
: this.opts.level >= LogLevel.Warnings) {
console.warn(...args);
}
}
error(...args) {
if (IsCustomLevel(this.opts.level)
? this.opts.level.error
: this.opts.level >= LogLevel.Errors) {
console.error(...args);
}
}
}

@@ -27,3 +27,2 @@ import App from "./app/index.js";

isActive(): boolean;
active(): boolean;
start(startOpts?: StartOptions): Promise<OnStartInfo>;

@@ -30,0 +29,0 @@ stop(): void;

@@ -128,3 +128,3 @@ import App, { DEFAULT_INGEST_POINT } from "./app/index.js";

req.send(JSON.stringify({
trackerVersion: '3.4.17',
trackerVersion: '3.5.0',
projectKey: options.projectKey,

@@ -145,6 +145,2 @@ doNotTrack,

}
active() {
deprecationWarn("'active' method", "'isActive' method", "/");
return this.isActive();
}
start(startOpts) {

@@ -158,2 +154,3 @@ if (!IN_BROWSER) {

}
// TODO: check argument typing
return this.app.start(startOpts);

@@ -160,0 +157,0 @@ }

@@ -19,3 +19,3 @@ import { IN_BROWSER } from "../utils.js";

}
return arg.toString();
return String(arg);
}

@@ -22,0 +22,0 @@ function printFloat(arg) {

@@ -58,2 +58,3 @@ import { normSpaces, hasOpenreplayAttribute, getLabelAttribute } from "../utils.js";

tag === 'LI' ||
tag === 'SELECT' ||
element.onclick != null ||

@@ -85,2 +86,3 @@ element.getAttribute('role') === 'button' ||

tag === 'LI' ||
tag === 'SELECT' ||
target.onclick != null ||

@@ -87,0 +89,0 @@ target.getAttribute('role') === 'button') {

@@ -6,10 +6,2 @@ export declare function timestamp(): number;

export declare const IN_BROWSER: boolean;
export declare const log: {
(...data: any[]): void;
(message?: any, ...optionalParams: any[]): void;
};
export declare const warn: {
(...data: any[]): void;
(message?: any, ...optionalParams: any[]): void;
};
export declare const DOCS_HOST = "https://docs.openreplay.com";

@@ -16,0 +8,0 @@ export declare function deprecationWarn(nameOfFeature: string, useInstead: string, docsPath?: string): void;

@@ -15,4 +15,3 @@ export function timestamp() {

export const IN_BROWSER = !(typeof window === "undefined");
export const log = console.log;
export const warn = console.warn;
// TODO: JOIN IT WITH LOGGER somehow (use logging decorators?); Don't forget about index.js loggin when there is no logger instance.
export const DOCS_HOST = 'https://docs.openreplay.com';

@@ -24,3 +23,3 @@ const warnedFeatures = {};

}
warn(`OpenReplay: ${nameOfFeature} is deprecated. ${useInstead ? `Please, use ${useInstead} instead.` : ""} Visit ${DOCS_HOST}${docsPath} for more information.`);
console.warn(`OpenReplay: ${nameOfFeature} is deprecated. ${useInstead ? `Please, use ${useInstead} instead.` : ""} Visit ${DOCS_HOST}${docsPath} for more information.`);
warnedFeatures[nameOfFeature] = true;

@@ -27,0 +26,0 @@ }

{
"name": "@openreplay/tracker",
"description": "The OpenReplay tracker main package",
"version": "3.4.17",
"version": "3.5.0",
"keywords": [

@@ -6,0 +6,0 @@ "logging",

@@ -21,3 +21,10 @@ # OpenReplay Tracker

});
tracker.start();
tracker.start({
userID: "Mr.Smith",
metadata: {
version: "3.5.0",
balance: "10M",
role: "admin",
}
});
```

@@ -24,0 +31,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc