@openreplay/tracker 15.1.3 → 15.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/entry.js CHANGED
@@ -4633,7 +4633,7 @@ class Session {
4633
4633
  }
4634
4634
  }
4635
4635
 
4636
- function wrap(callback, n) {
4636
+ function wrap$1(callback, n) {
4637
4637
  let t = 0;
4638
4638
  return () => {
4639
4639
  if (t++ >= n) {
@@ -4661,7 +4661,7 @@ class Ticker {
4661
4661
  if (useSafe) {
4662
4662
  callback = this.app.safe(callback);
4663
4663
  }
4664
- this.callbacks.unshift(n ? wrap(callback, n) : callback) - 1;
4664
+ this.callbacks.unshift(n ? wrap$1(callback, n) : callback) - 1;
4665
4665
  }
4666
4666
  start() {
4667
4667
  if (this.timer === null) {
@@ -4683,7 +4683,7 @@ class Ticker {
4683
4683
  * this value is injected during build time via rollup
4684
4684
  * */
4685
4685
  // @ts-ignore
4686
- const workerBodyFn = "!function(){\"use strict\";class t{constructor(t,s,i,e=10,n=250,h,r){this.onUnauthorised=s,this.onFailure=i,this.MAX_ATTEMPTS_COUNT=e,this.ATTEMPT_TIMEOUT=n,this.onCompress=h,this.pageNo=r,this.attemptsCount=0,this.busy=!1,this.queue=[],this.token=null,this.lastBatchNum=0,this.ingestURL=t+\"/v1/web/i\",this.isCompressing=void 0!==h}getQueueStatus(){return 0===this.queue.length&&!this.busy}authorise(t){this.token=t,this.busy||this.sendNext()}push(t){if(this.busy||!this.token)this.queue.push(t);else if(this.busy=!0,this.isCompressing&&this.onCompress)this.onCompress(t);else{const s=++this.lastBatchNum;this.sendBatch(t,!1,s)}}sendNext(){const t=this.queue.shift();if(t)if(this.busy=!0,this.isCompressing&&this.onCompress)this.onCompress(t);else{const s=++this.lastBatchNum;this.sendBatch(t,!1,s)}else this.busy=!1}retry(t,s,i){this.attemptsCount>=this.MAX_ATTEMPTS_COUNT?this.onFailure(`Failed to send batch after ${this.attemptsCount} attempts.`):(this.attemptsCount++,setTimeout((()=>this.sendBatch(t,s,i)),this.ATTEMPT_TIMEOUT*this.attemptsCount))}sendBatch(t,s,i){var e;const n=null==i?void 0:i.toString().replace(/^([^_]+)_([^_]+).*/,\"$1_$2_$3\");this.busy=!0;const h={Authorization:`Bearer ${this.token}`};s&&(h[\"Content-Encoding\"]=\"gzip\"),null!==this.token?fetch(`${this.ingestURL}?batch=${null!==(e=this.pageNo)&&void 0!==e?e:\"noPageNum\"}_${null!=n?n:\"noBatchNum\"}`,{body:t,method:\"POST\",headers:h,keepalive:t.length<65536}).then((e=>{if(401===e.status)return this.busy=!1,void this.onUnauthorised();e.status>=400?this.retry(t,s,`${null!=i?i:\"noBatchNum\"}_network:${e.status}`):(this.attemptsCount=0,this.sendNext())})).catch((e=>{console.warn(\"OpenReplay:\",e),this.retry(t,s,`${null!=i?i:\"noBatchNum\"}_reject:${e.message}`)})):setTimeout((()=>{this.sendBatch(t,s,`${null!=i?i:\"noBatchNum\"}_newToken`)}),500)}sendCompressed(t){const s=++this.lastBatchNum;this.sendBatch(t,!0,s)}sendUncompressed(t){const s=++this.lastBatchNum;this.sendBatch(t,!1,s)}clean(){this.sendNext(),setTimeout((()=>{this.token=null,this.queue.length=0}),10)}}const s=\"function\"==typeof TextEncoder?new TextEncoder:{encode(t){const s=t.length,i=new Uint8Array(3*s);let e=-1;for(let n=0,h=0,r=0;r!==s;){if(n=t.charCodeAt(r),r+=1,n>=55296&&n<=56319){if(r===s){i[e+=1]=239,i[e+=1]=191,i[e+=1]=189;break}if(h=t.charCodeAt(r),!(h>=56320&&h<=57343)){i[e+=1]=239,i[e+=1]=191,i[e+=1]=189;continue}if(n=1024*(n-55296)+h-56320+65536,r+=1,n>65535){i[e+=1]=240|n>>>18,i[e+=1]=128|n>>>12&63,i[e+=1]=128|n>>>6&63,i[e+=1]=128|63&n;continue}}n<=127?i[e+=1]=0|n:n<=2047?(i[e+=1]=192|n>>>6,i[e+=1]=128|63&n):(i[e+=1]=224|n>>>12,i[e+=1]=128|n>>>6&63,i[e+=1]=128|63&n)}return i.subarray(0,e+1)}};class i{constructor(t){this.size=t,this.offset=0,this.checkpointOffset=0,this.data=new Uint8Array(t)}getCurrentOffset(){return this.offset}checkpoint(){this.checkpointOffset=this.offset}get isEmpty(){return 0===this.offset}skip(t){return this.offset+=t,this.offset<=this.size}set(t,s){this.data.set(t,s)}boolean(t){return this.data[this.offset++]=+t,this.offset<=this.size}uint(t){for((t<0||t>Number.MAX_SAFE_INTEGER)&&(t=0);t>=128;)this.data[this.offset++]=t%256|128,t=Math.floor(t/128);return this.data[this.offset++]=t,this.offset<=this.size}int(t){return t=Math.round(t),this.uint(t>=0?2*t:-2*t-1)}string(t){const i=s.encode(t),e=i.byteLength;return!(!this.uint(e)||this.offset+e>this.size)&&(this.data.set(i,this.offset),this.offset+=e,!0)}reset(){this.offset=0,this.checkpointOffset=0}flush(){const t=this.data.slice(0,this.checkpointOffset);return this.reset(),t}}class e extends i{encode(t){switch(t[0]){case 0:case 11:case 114:case 115:return this.uint(t[1]);case 4:case 44:case 47:return this.string(t[1])&&this.string(t[2])&&this.uint(t[3]);case 5:case 20:case 38:case 70:case 75:case 76:case 77:case 82:return this.uint(t[1])&&this.uint(t[2]);case 6:return this.int(t[1])&&this.int(t[2]);case 7:return!0;case 8:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3])&&this.string(t[4])&&this.boolean(t[5]);case 9:case 10:case 24:case 51:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3]);case 12:case 52:case 61:case 71:return this.uint(t[1])&&this.string(t[2])&&this.string(t[3]);case 13:case 14:case 17:case 50:case 54:return this.uint(t[1])&&this.string(t[2]);case 16:return this.uint(t[1])&&this.int(t[2])&&this.int(t[3]);case 18:return this.uint(t[1])&&this.string(t[2])&&this.int(t[3]);case 19:return this.uint(t[1])&&this.boolean(t[2]);case 21:return this.string(t[1])&&this.string(t[2])&&this.string(t[3])&&this.string(t[4])&&this.string(t[5])&&this.uint(t[6])&&this.uint(t[7])&&this.uint(t[8]);case 22:case 27:case 30:case 41:case 45:case 46:case 43:case 63:case 64:case 79:case 124:return this.string(t[1])&&this.string(t[2]);case 23:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3])&&this.uint(t[4])&&this.uint(t[5])&&this.uint(t[6])&&this.uint(t[7])&&this.uint(t[8])&&this.uint(t[9]);case 28:case 29:case 42:case 117:case 118:return this.string(t[1]);case 37:return this.uint(t[1])&&this.string(t[2])&&this.uint(t[3]);case 39:return this.string(t[1])&&this.string(t[2])&&this.string(t[3])&&this.string(t[4])&&this.uint(t[5])&&this.uint(t[6])&&this.uint(t[7]);case 40:return this.string(t[1])&&this.uint(t[2])&&this.string(t[3])&&this.string(t[4]);case 48:return this.string(t[1])&&this.string(t[2])&&this.string(t[3])&&this.string(t[4])&&this.int(t[5]);case 49:return this.int(t[1])&&this.int(t[2])&&this.uint(t[3])&&this.uint(t[4]);case 53:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3])&&this.uint(t[4])&&this.uint(t[5])&&this.uint(t[6])&&this.string(t[7])&&this.string(t[8]);case 55:return this.boolean(t[1]);case 57:case 60:return this.uint(t[1])&&this.string(t[2])&&this.string(t[3])&&this.string(t[4]);case 58:case 120:return this.int(t[1]);case 59:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3])&&this.uint(t[4])&&this.string(t[5])&&this.string(t[6])&&this.string(t[7]);case 67:case 73:return this.uint(t[1])&&this.string(t[2])&&this.uint(t[3])&&this.string(t[4]);case 68:return this.uint(t[1])&&this.uint(t[2])&&this.string(t[3])&&this.string(t[4])&&this.uint(t[5])&&this.uint(t[6]);case 69:return this.uint(t[1])&&this.uint(t[2])&&this.string(t[3])&&this.string(t[4]);case 78:return this.string(t[1])&&this.string(t[2])&&this.string(t[3])&&this.string(t[4]);case 81:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3])&&this.int(t[4])&&this.string(t[5]);case 83:return this.string(t[1])&&this.string(t[2])&&this.string(t[3])&&this.string(t[4])&&this.string(t[5])&&this.uint(t[6])&&this.uint(t[7])&&this.uint(t[8])&&this.uint(t[9]);case 84:return this.string(t[1])&&this.string(t[2])&&this.string(t[3])&&this.uint(t[4])&&this.string(t[5])&&this.string(t[6]);case 112:return this.uint(t[1])&&this.string(t[2])&&this.boolean(t[3])&&this.string(t[4])&&this.int(t[5])&&this.int(t[6]);case 113:return this.uint(t[1])&&this.uint(t[2])&&this.string(t[3]);case 116:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3])&&this.uint(t[4])&&this.uint(t[5])&&this.uint(t[6])&&this.string(t[7])&&this.string(t[8])&&this.uint(t[9])&&this.boolean(t[10]);case 119:return this.string(t[1])&&this.uint(t[2]);case 121:return this.string(t[1])&&this.string(t[2])&&this.uint(t[3])&&this.uint(t[4]);case 122:return this.string(t[1])&&this.string(t[2])&&this.uint(t[3])&&this.string(t[4]);case 123:return this.string(t[1])&&this.string(t[2])&&this.string(t[3])&&this.string(t[4])&&this.uint(t[5])}}}class n{constructor(t,s,i,n,h,r){this.pageNo=t,this.timestamp=s,this.url=i,this.onBatch=n,this.tabId=h,this.onOfflineEnd=r,this.nextIndex=0,this.beaconSize=2e5,this.encoder=new e(this.beaconSize),this.sizeBuffer=new Uint8Array(3),this.isEmpty=!0,this.beaconSizeLimit=1e6,this.prepare()}writeType(t){return this.encoder.uint(t[0])}writeFields(t){return this.encoder.encode(t)}writeSizeAt(t,s){for(let s=0;s<3;s++)this.sizeBuffer[s]=t>>8*s;this.encoder.set(this.sizeBuffer,s)}prepare(){if(!this.encoder.isEmpty)return;const t=[81,1,this.pageNo,this.nextIndex,this.timestamp,this.url],s=[0,this.timestamp],i=[118,this.tabId];this.writeType(t),this.writeFields(t),this.writeWithSize(s),this.writeWithSize(i),this.isEmpty=!0}writeWithSize(t){const s=this.encoder;if(!this.writeType(t)||!s.skip(3))return!1;const i=s.getCurrentOffset(),e=this.writeFields(t);if(e){const e=s.getCurrentOffset()-i;if(e>16777215)return console.warn(\"OpenReplay: max message size overflow.\"),!1;this.writeSizeAt(e,i-3),s.checkpoint(),this.isEmpty=this.isEmpty&&0===t[0],this.nextIndex++}return e}setBeaconSizeLimit(t){this.beaconSizeLimit=t}writeMessage(t){if(\"q_end\"===t[0])return this.finaliseBatch(),this.onOfflineEnd();0===t[0]&&(this.timestamp=t[1]),122===t[0]&&(this.url=t[1]),this.writeWithSize(t)||(this.finaliseBatch(),this.writeWithSize(t)||(this.encoder=new e(this.beaconSizeLimit),this.prepare(),this.writeWithSize(t)?this.finaliseBatch():console.warn(\"OpenReplay: beacon size overflow. Skipping large message.\",t,this),this.encoder=new e(this.beaconSize),this.prepare()))}finaliseBatch(){if(this.isEmpty)return;const t=this.encoder.flush();this.onBatch(t),this.prepare()}clean(){this.encoder.reset()}}var h;!function(t){t[t.NotActive=0]=\"NotActive\",t[t.Starting=1]=\"Starting\",t[t.Stopping=2]=\"Stopping\",t[t.Active=3]=\"Active\",t[t.Stopped=4]=\"Stopped\"}(h||(h={}));let r=null,u=null,a=h.NotActive;function o(){u&&u.finaliseBatch()}function c(){return new Promise((t=>{a=h.Stopping,null!==p&&(clearInterval(p),p=null),u&&(u.clean(),u=null),r&&(r.clean(),setTimeout((()=>{r=null}),20)),setTimeout((()=>{a=h.NotActive,t(null)}),100)}))}function g(){[h.Stopped,h.Stopping].includes(a)||(postMessage(\"a_stop\"),c().then((()=>{postMessage(\"a_start\")})))}let l,p=null;self.onmessage=({data:s})=>{if(null!=s){if(\"stop\"===s)return o(),void c().then((()=>{a=h.Stopped}));if(\"forceFlushBatch\"!==s){if(!Array.isArray(s)){if(\"compressed\"===s.type){if(!r)return console.debug(\"OR WebWorker: sender not initialised. Compressed batch.\"),void g();s.batch&&r.sendCompressed(s.batch)}if(\"uncompressed\"===s.type){if(!r)return console.debug(\"OR WebWorker: sender not initialised. Uncompressed batch.\"),void g();s.batch&&r.sendUncompressed(s.batch)}return\"start\"===s.type?(a=h.Starting,r=new t(s.ingestPoint,(()=>{g()}),(t=>{!function(t){postMessage({type:\"failure\",reason:t}),c()}(t)}),s.connAttemptCount,s.connAttemptGap,(t=>{postMessage({type:\"compress\",batch:t},[t.buffer])}),s.pageNo),u=new n(s.pageNo,s.timestamp,s.url,(t=>{r&&r.push(t)}),s.tabId,(()=>postMessage({type:\"queue_empty\"}))),null===p&&(p=setInterval(o,1e4)),a=h.Active):\"auth\"===s.type?r?u?(r.authorise(s.token),void(s.beaconSizeLimit&&u.setBeaconSizeLimit(s.beaconSizeLimit))):(console.debug(\"OR WebWorker: writer not initialised. Received auth.\"),void g()):(console.debug(\"OR WebWorker: sender not initialised. Received auth.\"),void g()):void 0}if(u){const t=u;s.forEach((s=>{55===s[0]&&(s[1]?l=setTimeout((()=>g()),18e5):clearTimeout(l)),t.writeMessage(s)}))}else postMessage(\"not_init\"),g()}else o()}else o()}}();\n";
4686
+ const workerBodyFn = "!function(){\"use strict\";class t{constructor(t,s,i,e=10,n=250,h,r){this.onUnauthorised=s,this.onFailure=i,this.MAX_ATTEMPTS_COUNT=e,this.ATTEMPT_TIMEOUT=n,this.onCompress=h,this.pageNo=r,this.attemptsCount=0,this.busy=!1,this.queue=[],this.token=null,this.lastBatchNum=0,this.ingestURL=t+\"/v1/web/i\",this.isCompressing=void 0!==h}getQueueStatus(){return 0===this.queue.length&&!this.busy}authorise(t){this.token=t,this.busy||this.sendNext()}push(t){if(this.busy||!this.token)this.queue.push(t);else if(this.busy=!0,this.isCompressing&&this.onCompress)this.onCompress(t);else{const s=++this.lastBatchNum;this.sendBatch(t,!1,s)}}sendNext(){const t=this.queue.shift();if(t)if(this.busy=!0,this.isCompressing&&this.onCompress)this.onCompress(t);else{const s=++this.lastBatchNum;this.sendBatch(t,!1,s)}else this.busy=!1}retry(t,s,i){this.attemptsCount>=this.MAX_ATTEMPTS_COUNT?this.onFailure(`Failed to send batch after ${this.attemptsCount} attempts.`):(this.attemptsCount++,setTimeout(()=>this.sendBatch(t,s,i),this.ATTEMPT_TIMEOUT*this.attemptsCount))}sendBatch(t,s,i){var e;const n=null==i?void 0:i.toString().replace(/^([^_]+)_([^_]+).*/,\"$1_$2_$3\");this.busy=!0;const h={Authorization:`Bearer ${this.token}`};s&&(h[\"Content-Encoding\"]=\"gzip\"),null!==this.token?fetch(`${this.ingestURL}?batch=${null!==(e=this.pageNo)&&void 0!==e?e:\"noPageNum\"}_${null!=n?n:\"noBatchNum\"}`,{body:t,method:\"POST\",headers:h,keepalive:t.length<65536}).then(e=>{if(401===e.status)return this.busy=!1,void this.onUnauthorised();e.status>=400?this.retry(t,s,`${null!=i?i:\"noBatchNum\"}_network:${e.status}`):(this.attemptsCount=0,this.sendNext())}).catch(e=>{console.warn(\"OpenReplay:\",e),this.retry(t,s,`${null!=i?i:\"noBatchNum\"}_reject:${e.message}`)}):setTimeout(()=>{this.sendBatch(t,s,`${null!=i?i:\"noBatchNum\"}_newToken`)},500)}sendCompressed(t){const s=++this.lastBatchNum;this.sendBatch(t,!0,s)}sendUncompressed(t){const s=++this.lastBatchNum;this.sendBatch(t,!1,s)}clean(){this.sendNext(),setTimeout(()=>{this.token=null,this.queue.length=0},10)}}const s=\"function\"==typeof TextEncoder?new TextEncoder:{encode(t){const s=t.length,i=new Uint8Array(3*s);let e=-1;for(let n=0,h=0,r=0;r!==s;){if(n=t.charCodeAt(r),r+=1,n>=55296&&n<=56319){if(r===s){i[e+=1]=239,i[e+=1]=191,i[e+=1]=189;break}if(h=t.charCodeAt(r),!(h>=56320&&h<=57343)){i[e+=1]=239,i[e+=1]=191,i[e+=1]=189;continue}if(n=1024*(n-55296)+h-56320+65536,r+=1,n>65535){i[e+=1]=240|n>>>18,i[e+=1]=128|n>>>12&63,i[e+=1]=128|n>>>6&63,i[e+=1]=128|63&n;continue}}n<=127?i[e+=1]=0|n:n<=2047?(i[e+=1]=192|n>>>6,i[e+=1]=128|63&n):(i[e+=1]=224|n>>>12,i[e+=1]=128|n>>>6&63,i[e+=1]=128|63&n)}return i.subarray(0,e+1)}};class i{constructor(t){this.size=t,this.offset=0,this.checkpointOffset=0,this.data=new Uint8Array(t)}getCurrentOffset(){return this.offset}checkpoint(){this.checkpointOffset=this.offset}get isEmpty(){return 0===this.offset}skip(t){return this.offset+=t,this.offset<=this.size}set(t,s){this.data.set(t,s)}boolean(t){return this.data[this.offset++]=+t,this.offset<=this.size}uint(t){for((t<0||t>Number.MAX_SAFE_INTEGER)&&(t=0);t>=128;)this.data[this.offset++]=t%256|128,t=Math.floor(t/128);return this.data[this.offset++]=t,this.offset<=this.size}int(t){return t=Math.round(t),this.uint(t>=0?2*t:-2*t-1)}string(t){const i=s.encode(t),e=i.byteLength;return!(!this.uint(e)||this.offset+e>this.size)&&(this.data.set(i,this.offset),this.offset+=e,!0)}reset(){this.offset=0,this.checkpointOffset=0}flush(){const t=this.data.slice(0,this.checkpointOffset);return this.reset(),t}}class e extends i{encode(t){switch(t[0]){case 0:case 11:case 114:case 115:return this.uint(t[1]);case 4:case 44:case 47:return this.string(t[1])&&this.string(t[2])&&this.uint(t[3]);case 5:case 20:case 38:case 70:case 75:case 76:case 77:case 82:return this.uint(t[1])&&this.uint(t[2]);case 6:return this.int(t[1])&&this.int(t[2]);case 7:return!0;case 8:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3])&&this.string(t[4])&&this.boolean(t[5]);case 9:case 10:case 24:case 51:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3]);case 12:case 52:case 61:case 71:return this.uint(t[1])&&this.string(t[2])&&this.string(t[3]);case 13:case 14:case 17:case 50:case 54:return this.uint(t[1])&&this.string(t[2]);case 16:return this.uint(t[1])&&this.int(t[2])&&this.int(t[3]);case 18:return this.uint(t[1])&&this.string(t[2])&&this.int(t[3]);case 19:return this.uint(t[1])&&this.boolean(t[2]);case 21:return this.string(t[1])&&this.string(t[2])&&this.string(t[3])&&this.string(t[4])&&this.string(t[5])&&this.uint(t[6])&&this.uint(t[7])&&this.uint(t[8]);case 22:case 27:case 30:case 41:case 45:case 46:case 43:case 63:case 64:case 79:case 124:return this.string(t[1])&&this.string(t[2]);case 23:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3])&&this.uint(t[4])&&this.uint(t[5])&&this.uint(t[6])&&this.uint(t[7])&&this.uint(t[8])&&this.uint(t[9]);case 28:case 29:case 42:case 117:case 118:return this.string(t[1]);case 37:return this.uint(t[1])&&this.string(t[2])&&this.uint(t[3]);case 39:return this.string(t[1])&&this.string(t[2])&&this.string(t[3])&&this.string(t[4])&&this.uint(t[5])&&this.uint(t[6])&&this.uint(t[7]);case 40:return this.string(t[1])&&this.uint(t[2])&&this.string(t[3])&&this.string(t[4]);case 48:return this.string(t[1])&&this.string(t[2])&&this.string(t[3])&&this.string(t[4])&&this.int(t[5]);case 49:return this.int(t[1])&&this.int(t[2])&&this.uint(t[3])&&this.uint(t[4]);case 53:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3])&&this.uint(t[4])&&this.uint(t[5])&&this.uint(t[6])&&this.string(t[7])&&this.string(t[8]);case 55:return this.boolean(t[1]);case 57:case 60:return this.uint(t[1])&&this.string(t[2])&&this.string(t[3])&&this.string(t[4]);case 58:case 120:return this.int(t[1]);case 59:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3])&&this.uint(t[4])&&this.string(t[5])&&this.string(t[6])&&this.string(t[7]);case 67:case 73:return this.uint(t[1])&&this.string(t[2])&&this.uint(t[3])&&this.string(t[4]);case 68:return this.uint(t[1])&&this.uint(t[2])&&this.string(t[3])&&this.string(t[4])&&this.uint(t[5])&&this.uint(t[6]);case 69:return this.uint(t[1])&&this.uint(t[2])&&this.string(t[3])&&this.string(t[4]);case 78:return this.string(t[1])&&this.string(t[2])&&this.string(t[3])&&this.string(t[4]);case 81:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3])&&this.int(t[4])&&this.string(t[5]);case 83:return this.string(t[1])&&this.string(t[2])&&this.string(t[3])&&this.string(t[4])&&this.string(t[5])&&this.uint(t[6])&&this.uint(t[7])&&this.uint(t[8])&&this.uint(t[9]);case 84:return this.string(t[1])&&this.string(t[2])&&this.string(t[3])&&this.uint(t[4])&&this.string(t[5])&&this.string(t[6]);case 112:return this.uint(t[1])&&this.string(t[2])&&this.boolean(t[3])&&this.string(t[4])&&this.int(t[5])&&this.int(t[6]);case 113:return this.uint(t[1])&&this.uint(t[2])&&this.string(t[3]);case 116:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3])&&this.uint(t[4])&&this.uint(t[5])&&this.uint(t[6])&&this.string(t[7])&&this.string(t[8])&&this.uint(t[9])&&this.boolean(t[10]);case 119:return this.string(t[1])&&this.uint(t[2]);case 121:return this.string(t[1])&&this.string(t[2])&&this.uint(t[3])&&this.uint(t[4]);case 122:return this.string(t[1])&&this.string(t[2])&&this.uint(t[3])&&this.string(t[4]);case 123:return this.string(t[1])&&this.string(t[2])&&this.string(t[3])&&this.string(t[4])&&this.uint(t[5])}}}class n{constructor(t,s,i,n,h,r){this.pageNo=t,this.timestamp=s,this.url=i,this.onBatch=n,this.tabId=h,this.onOfflineEnd=r,this.nextIndex=0,this.beaconSize=2e5,this.encoder=new e(this.beaconSize),this.sizeBuffer=new Uint8Array(3),this.isEmpty=!0,this.beaconSizeLimit=1e6,this.prepare()}writeType(t){return this.encoder.uint(t[0])}writeFields(t){return this.encoder.encode(t)}writeSizeAt(t,s){for(let s=0;s<3;s++)this.sizeBuffer[s]=t>>8*s;this.encoder.set(this.sizeBuffer,s)}prepare(){if(!this.encoder.isEmpty)return;const t=[81,1,this.pageNo,this.nextIndex,this.timestamp,this.url],s=[0,this.timestamp],i=[118,this.tabId];this.writeType(t),this.writeFields(t),this.writeWithSize(s),this.writeWithSize(i),this.isEmpty=!0}writeWithSize(t){const s=this.encoder;if(!this.writeType(t)||!s.skip(3))return!1;const i=s.getCurrentOffset(),e=this.writeFields(t);if(e){const e=s.getCurrentOffset()-i;if(e>16777215)return console.warn(\"OpenReplay: max message size overflow.\"),!1;this.writeSizeAt(e,i-3),s.checkpoint(),this.isEmpty=this.isEmpty&&0===t[0],this.nextIndex++}return e}setBeaconSizeLimit(t){this.beaconSizeLimit=t}writeMessage(t){if(\"q_end\"===t[0])return this.finaliseBatch(),this.onOfflineEnd();0===t[0]&&(this.timestamp=t[1]),122===t[0]&&(this.url=t[1]),this.writeWithSize(t)||(this.finaliseBatch(),this.writeWithSize(t)||(this.encoder=new e(this.beaconSizeLimit),this.prepare(),this.writeWithSize(t)?this.finaliseBatch():console.warn(\"OpenReplay: beacon size overflow. Skipping large message.\",t,this),this.encoder=new e(this.beaconSize),this.prepare()))}finaliseBatch(){if(this.isEmpty)return;const t=this.encoder.flush();this.onBatch(t),this.prepare()}clean(){this.encoder.reset()}}var h;!function(t){t[t.NotActive=0]=\"NotActive\",t[t.Starting=1]=\"Starting\",t[t.Stopping=2]=\"Stopping\",t[t.Active=3]=\"Active\",t[t.Stopped=4]=\"Stopped\"}(h||(h={}));let r=null,u=null,a=h.NotActive;function o(){u&&u.finaliseBatch()}function c(){return new Promise(t=>{a=h.Stopping,null!==p&&(clearInterval(p),p=null),u&&(u.clean(),u=null),r&&(r.clean(),setTimeout(()=>{r=null},20)),setTimeout(()=>{a=h.NotActive,t(null)},100)})}function g(){[h.Stopped,h.Stopping].includes(a)||(postMessage(\"a_stop\"),c().then(()=>{postMessage(\"a_start\")}))}let l,p=null;self.onmessage=({data:s})=>{if(null!=s){if(\"stop\"===s)return o(),void c().then(()=>{a=h.Stopped});if(\"forceFlushBatch\"!==s){if(!Array.isArray(s)){if(\"compressed\"===s.type){if(!r)return console.debug(\"OR WebWorker: sender not initialised. Compressed batch.\"),void g();s.batch&&r.sendCompressed(s.batch)}if(\"uncompressed\"===s.type){if(!r)return console.debug(\"OR WebWorker: sender not initialised. Uncompressed batch.\"),void g();s.batch&&r.sendUncompressed(s.batch)}return\"start\"===s.type?(a=h.Starting,r=new t(s.ingestPoint,()=>{g()},t=>{!function(t){postMessage({type:\"failure\",reason:t}),c()}(t)},s.connAttemptCount,s.connAttemptGap,t=>{postMessage({type:\"compress\",batch:t},[t.buffer])},s.pageNo),u=new n(s.pageNo,s.timestamp,s.url,t=>{r&&r.push(t)},s.tabId,()=>postMessage({type:\"queue_empty\"})),null===p&&(p=setInterval(o,1e4)),a=h.Active):\"auth\"===s.type?r?u?(r.authorise(s.token),void(s.beaconSizeLimit&&u.setBeaconSizeLimit(s.beaconSizeLimit))):(console.debug(\"OR WebWorker: writer not initialised. Received auth.\"),void g()):(console.debug(\"OR WebWorker: sender not initialised. Received auth.\"),void g()):void 0}if(u){const t=u;s.forEach(s=>{55===s[0]&&(s[1]?l=setTimeout(()=>g(),18e5):clearTimeout(l)),t.writeMessage(s)})}else postMessage(\"not_init\"),g()}else o()}else o()}}();\n";
4687
4687
  const CANCELED = 'canceled';
4688
4688
  const uxtStorageKey = 'or_uxt_active';
4689
4689
  const bufferStorageKey = 'or_buffer_1';
@@ -4737,7 +4737,7 @@ class App {
4737
4737
  this.stopCallbacks = [];
4738
4738
  this.commitCallbacks = [];
4739
4739
  this.activityState = ActivityState.NotActive;
4740
- this.version = '15.1.3'; // TODO: version compatability check inside each plugin.
4740
+ this.version = '15.2.0'; // TODO: version compatability check inside each plugin.
4741
4741
  this.socketMode = false;
4742
4742
  this.compressionThreshold = 24 * 1000;
4743
4743
  this.bc = null;
@@ -5375,6 +5375,7 @@ class App {
5375
5375
  }
5376
5376
  }
5377
5377
  this.emptyBatchCounter = 0;
5378
+ console.log('messages', this.messages.join(', '));
5378
5379
  try {
5379
5380
  requestIdleCb(() => {
5380
5381
  this.messages.unshift(Timestamp(this.timestamp()), TabData(this.session.getTabId()));
@@ -7532,15 +7533,18 @@ function Scroll (app, insideIframe) {
7532
7533
  }, 5, false);
7533
7534
  }
7534
7535
 
7535
- function Viewport (app) {
7536
+ function Viewport (app, options) {
7536
7537
  let url, width, height;
7537
7538
  let navigationStart;
7538
7539
  let referrer = document.referrer;
7540
+ const urlSanitizer = options?.urlSanitizer || ((u) => u);
7541
+ const titleSanitizer = options?.titleSanitizer || ((t) => t);
7539
7542
  const sendSetPageLocation = app.safe(() => {
7540
7543
  const { URL } = document;
7541
7544
  if (URL !== url) {
7542
- url = URL;
7543
- app.send(SetPageLocation(url, referrer, navigationStart, document.title));
7545
+ url = urlSanitizer(URL);
7546
+ const title = titleSanitizer(document.title);
7547
+ app.send(SetPageLocation(url, referrer, navigationStart, title));
7544
7548
  navigationStart = 0;
7545
7549
  referrer = url;
7546
7550
  }
@@ -8009,6 +8013,152 @@ function isObject(thing) {
8009
8013
  return thing !== null && typeof thing === 'object';
8010
8014
  }
8011
8015
 
8016
+ const sensitiveParams = new Set([
8017
+ "password",
8018
+ "pass",
8019
+ "pwd",
8020
+ "mdp",
8021
+ "token",
8022
+ "bearer",
8023
+ "jwt",
8024
+ "api_key",
8025
+ "api-key",
8026
+ "apiKey",
8027
+ "secret",
8028
+ "ssn",
8029
+ "zip",
8030
+ "zipcode",
8031
+ "x-api-key",
8032
+ "www-authenticate",
8033
+ "x-csrf-token",
8034
+ "x-requested-with",
8035
+ "x-forwarded-for",
8036
+ "x-real-ip",
8037
+ "cookie",
8038
+ "authorization",
8039
+ "auth",
8040
+ "proxy-authorization",
8041
+ "set-cookie",
8042
+ "account_key",
8043
+ ]);
8044
+ function numDigits(x) {
8045
+ return (Math.log10((x ^ (x >> 31)) - (x >> 31)) | 0) + 1;
8046
+ }
8047
+ function obscure(value) {
8048
+ if (typeof value === "number") {
8049
+ const digits = numDigits(value);
8050
+ return "9".repeat(digits);
8051
+ }
8052
+ if (typeof value === "string") {
8053
+ return value.replace(/[^\f\n\r\t\v\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff\s]/g, '*');
8054
+ }
8055
+ return value;
8056
+ }
8057
+ function filterHeaders(headers) {
8058
+ const filteredHeaders = {};
8059
+ if (Array.isArray(headers)) {
8060
+ headers.forEach(({ name, value }) => {
8061
+ if (sensitiveParams.has(name.toLowerCase())) {
8062
+ filteredHeaders[name] = obscure(value);
8063
+ }
8064
+ else {
8065
+ filteredHeaders[name] = value;
8066
+ }
8067
+ });
8068
+ }
8069
+ else {
8070
+ for (const [key, value] of Object.entries(headers)) {
8071
+ if (sensitiveParams.has(key.toLowerCase())) {
8072
+ filteredHeaders[key] = obscure(value);
8073
+ }
8074
+ else {
8075
+ filteredHeaders[key] = value;
8076
+ }
8077
+ }
8078
+ }
8079
+ return filteredHeaders;
8080
+ }
8081
+ function filterBody(body) {
8082
+ if (!body) {
8083
+ return body;
8084
+ }
8085
+ let parsedBody;
8086
+ let isJSON = false;
8087
+ try {
8088
+ parsedBody = JSON.parse(body);
8089
+ isJSON = true;
8090
+ }
8091
+ catch (e) {
8092
+ // not json
8093
+ }
8094
+ if (isJSON) {
8095
+ obscureSensitiveData(parsedBody);
8096
+ return JSON.stringify(parsedBody);
8097
+ }
8098
+ else {
8099
+ const isUrlSearch = typeof body === "string" && body.includes("?") && body.includes("=");
8100
+ if (isUrlSearch) {
8101
+ try {
8102
+ const params = new URLSearchParams(body);
8103
+ for (const key of params.keys()) {
8104
+ if (sensitiveParams.has(key.toLowerCase())) {
8105
+ const value = obscure(params.get(key));
8106
+ params.set(key, value);
8107
+ }
8108
+ }
8109
+ return params.toString();
8110
+ }
8111
+ catch (e) {
8112
+ // not url query ?
8113
+ return body;
8114
+ }
8115
+ }
8116
+ else {
8117
+ // not json or url query
8118
+ return body;
8119
+ }
8120
+ }
8121
+ }
8122
+ function sanitizeObject(obj) {
8123
+ obscureSensitiveData(obj);
8124
+ return obj;
8125
+ }
8126
+ function obscureSensitiveData(obj) {
8127
+ if (Array.isArray(obj)) {
8128
+ obj.forEach(obscureSensitiveData);
8129
+ }
8130
+ else if (obj && typeof obj === "object") {
8131
+ for (const key in obj) {
8132
+ if (Object.hasOwn(obj, key)) {
8133
+ if (sensitiveParams.has(key.toLowerCase())) {
8134
+ obj[key] = obscure(obj[key]);
8135
+ }
8136
+ else if (obj[key] !== null && typeof obj[key] === "object") {
8137
+ obscureSensitiveData(obj[key]);
8138
+ }
8139
+ }
8140
+ }
8141
+ }
8142
+ }
8143
+ function tryFilterUrl(url) {
8144
+ if (!url)
8145
+ return "";
8146
+ try {
8147
+ const urlObj = new URL(url);
8148
+ if (urlObj.searchParams) {
8149
+ for (const key of urlObj.searchParams.keys()) {
8150
+ if (sensitiveParams.has(key.toLowerCase())) {
8151
+ urlObj.searchParams.set(key, "******");
8152
+ }
8153
+ }
8154
+ }
8155
+ return urlObj.toString();
8156
+ }
8157
+ catch (e) {
8158
+ return url;
8159
+ }
8160
+ }
8161
+
8012
8162
  /**
8013
8163
  * I know we're not using most of the information from this class
8014
8164
  * but it can be useful in the future if we will decide to display more stuff in our ui
@@ -8040,13 +8190,18 @@ class NetworkMessage {
8040
8190
  }
8041
8191
  getMessage() {
8042
8192
  const { reqHs, resHs } = this.writeHeaders();
8193
+ const reqBody = this.method === 'GET'
8194
+ ? JSON.stringify(sanitizeObject(this.getData)) : filterBody(this.requestData);
8043
8195
  const request = {
8044
- headers: reqHs,
8045
- body: this.method === 'GET' ? JSON.stringify(this.getData) : this.requestData,
8196
+ headers: filterHeaders(reqHs),
8197
+ body: reqBody,
8198
+ };
8199
+ const response = {
8200
+ headers: filterHeaders(resHs),
8201
+ body: filterBody(this.response)
8046
8202
  };
8047
- const response = { headers: resHs, body: this.response };
8048
8203
  const messageInfo = this.sanitize({
8049
- url: this.url,
8204
+ url: tryFilterUrl(this.url),
8050
8205
  method: this.method,
8051
8206
  status: this.status,
8052
8207
  request,
@@ -8132,42 +8287,47 @@ const genStringBody = (body) => {
8132
8287
  return null;
8133
8288
  }
8134
8289
  let result;
8135
- if (typeof body === 'string') {
8136
- if (body[0] === '{' || body[0] === '[') {
8137
- result = body;
8290
+ try {
8291
+ if (typeof body === 'string') {
8292
+ if (body[0] === '{' || body[0] === '[') {
8293
+ result = body;
8294
+ }
8295
+ // 'a=1&b=2' => try to parse as query
8296
+ const arr = body.split('&');
8297
+ if (arr.length === 1) {
8298
+ // not a query, parse as original string
8299
+ result = body;
8300
+ }
8301
+ else {
8302
+ // 'a=1&b=2&c' => parse as query
8303
+ result = arr.join(',');
8304
+ }
8138
8305
  }
8139
- // 'a=1&b=2' => try to parse as query
8140
- const arr = body.split('&');
8141
- if (arr.length === 1) {
8142
- // not a query, parse as original string
8306
+ else if (isIterable(body)) {
8307
+ // FormData or URLSearchParams or Array
8308
+ const arr = [];
8309
+ for (const [key, value] of body) {
8310
+ arr.push(`${key}=${typeof value === 'string' ? value : '[object Object]'}`);
8311
+ }
8312
+ result = arr.join(',');
8313
+ }
8314
+ else if (body instanceof Blob ||
8315
+ body instanceof ReadableStream ||
8316
+ body instanceof ArrayBuffer) {
8317
+ result = 'byte data';
8318
+ }
8319
+ else if (isPureObject(body)) {
8320
+ // overriding ArrayBufferView which is not convertable to string
8143
8321
  result = body;
8144
8322
  }
8145
8323
  else {
8146
- // 'a=1&b=2&c' => parse as query
8147
- result = arr.join(',');
8148
- }
8149
- }
8150
- else if (isIterable(body)) {
8151
- // FormData or URLSearchParams or Array
8152
- const arr = [];
8153
- for (const [key, value] of body) {
8154
- arr.push(`${key}=${typeof value === 'string' ? value : '[object Object]'}`);
8324
+ result = `can't parse body ${typeof body}`;
8155
8325
  }
8156
- result = arr.join(',');
8157
- }
8158
- else if (body instanceof Blob ||
8159
- body instanceof ReadableStream ||
8160
- body instanceof ArrayBuffer) {
8161
- result = 'byte data';
8326
+ return result;
8162
8327
  }
8163
- else if (isPureObject(body)) {
8164
- // overriding ArrayBufferView which is not convertable to string
8165
- result = body;
8328
+ catch (_) {
8329
+ return "can't parse body";
8166
8330
  }
8167
- else {
8168
- result = `can't parse body ${typeof body}`;
8169
- }
8170
- return result;
8171
8331
  };
8172
8332
  const genGetDataByUrl = (url, getData = {}) => {
8173
8333
  if (!isPureObject(getData)) {
@@ -8362,9 +8522,10 @@ class ResponseProxyHandler {
8362
8522
  if (typeof this.resp.body.getReader !== 'function') {
8363
8523
  return;
8364
8524
  }
8365
- const _getReader = this.resp.body.getReader;
8525
+ const clonedResp = this.resp.clone();
8526
+ const _getReader = clonedResp.body.getReader;
8366
8527
  // @ts-ignore
8367
- this.resp.body.getReader = () => {
8528
+ clonedResp.body.getReader = () => {
8368
8529
  const reader = _getReader.apply(this.resp.body);
8369
8530
  // when readyState is already 4,
8370
8531
  // it's not a chunked stream, or it had already been read.
@@ -8809,10 +8970,17 @@ class XHRProxy {
8809
8970
  }
8810
8971
  }
8811
8972
 
8812
- const getWarning = (api) => {
8973
+ const warn = (api) => {
8813
8974
  const str = `Openreplay: Can't find ${api} in global context.`;
8814
8975
  console.warn(str);
8815
8976
  };
8977
+ const OR_FLAG = Symbol('OpenReplayProxyOriginal');
8978
+ const isProxied = (fn) => !!fn && fn[OR_FLAG] !== undefined;
8979
+ const unwrap = (fn) => isProxied(fn) ? fn[OR_FLAG] : fn;
8980
+ const wrap = (proxy, orig) => {
8981
+ proxy[OR_FLAG] = orig;
8982
+ return proxy;
8983
+ };
8816
8984
  /**
8817
8985
  * Creates network proxies for XMLHttpRequest, fetch, and sendBeacon to intercept and monitor network requests and
8818
8986
  * responses.
@@ -8846,26 +9014,24 @@ function createNetworkProxy(context, ignoredHeaders, setSessionTokenHeader, sani
8846
9014
  if (!context)
8847
9015
  return;
8848
9016
  if (modules.xhr) {
8849
- if (context.XMLHttpRequest) {
8850
- context.XMLHttpRequest = XHRProxy.create(ignoredHeaders, setSessionTokenHeader, sanitize, sendMessage, isServiceUrl, tokenUrlMatcher);
8851
- }
9017
+ const original = unwrap(context.XMLHttpRequest);
9018
+ if (!original)
9019
+ warn('XMLHttpRequest');
8852
9020
  else {
8853
- getWarning("XMLHttpRequest");
9021
+ context.XMLHttpRequest = wrap(XHRProxy.create(ignoredHeaders, setSessionTokenHeader, sanitize, sendMessage, isServiceUrl, tokenUrlMatcher), original);
8854
9022
  }
8855
9023
  }
8856
9024
  if (modules.fetch) {
8857
- if (context.fetch) {
8858
- context.fetch = FetchProxy.create(ignoredHeaders, setSessionTokenHeader, sanitize, sendMessage, isServiceUrl, tokenUrlMatcher);
8859
- }
9025
+ const original = unwrap(context.fetch);
9026
+ if (!original)
9027
+ warn('fetch');
8860
9028
  else {
8861
- getWarning("fetch");
9029
+ context.fetch = wrap(FetchProxy.create(ignoredHeaders, setSessionTokenHeader, sanitize, sendMessage, isServiceUrl, tokenUrlMatcher), original);
8862
9030
  }
8863
9031
  }
8864
- if (modules.beacon) {
8865
- if ((_a = context.navigator) === null || _a === void 0 ? void 0 : _a.sendBeacon) {
8866
- const origBeacon = context.navigator.sendBeacon;
8867
- context.navigator.sendBeacon = BeaconProxy.create(origBeacon, ignoredHeaders, setSessionTokenHeader, sanitize, sendMessage, isServiceUrl);
8868
- }
9032
+ if (modules.beacon && ((_a = context.navigator) === null || _a === void 0 ? void 0 : _a.sendBeacon)) {
9033
+ const original = unwrap(context.navigator.sendBeacon);
9034
+ context.navigator.sendBeacon = wrap(BeaconProxy.create(original, ignoredHeaders, setSessionTokenHeader, sanitize, sendMessage, isServiceUrl), original);
8869
9035
  }
8870
9036
  }
8871
9037
 
@@ -9205,7 +9371,7 @@ class API {
9205
9371
  this.signalStartIssue = (reason, missingApi) => {
9206
9372
  const doNotTrack = this.checkDoNotTrack();
9207
9373
  console.log("Tracker couldn't start due to:", JSON.stringify({
9208
- trackerVersion: '15.1.3',
9374
+ trackerVersion: '15.2.0',
9209
9375
  projectKey: this.options.projectKey,
9210
9376
  doNotTrack,
9211
9377
  reason: missingApi.length ? `missing api: ${missingApi.join(',')}` : reason,
@@ -9293,7 +9459,7 @@ class API {
9293
9459
  this.app = app;
9294
9460
  if (!this.crossdomainMode) {
9295
9461
  // no need to send iframe viewport data since its a node for us
9296
- Viewport(app);
9462
+ Viewport(app, options.urls);
9297
9463
  // calculated in main window
9298
9464
  Connection(app);
9299
9465
  // while we can calculate it here, trying to compute it for all parts is hard