@amplitude/plugin-session-replay-browser 1.25.20 → 1.26.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.
@@ -1,2 +1,2 @@
1
- var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};function t(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}var n,r,i=function(){return i=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},i.apply(this,arguments)};function o(e,t,n,r){return new(n||(n=Promise))(function(i,o){function s(e){try{c(r.next(e))}catch(e){o(e)}}function a(e){try{c(r.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}c((r=r.apply(e,t||[])).next())})}function s(e,t){var n,r,i,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(o=0)),o;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,r=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!(i=o.trys,(i=i.length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){o.label=a[1];break}if(6===a[0]&&o.label<i[1]){o.label=i[1],i=a;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(a);break}i[2]&&o.ops.pop(),o.trys.pop();continue}a=t.call(e,o)}catch(e){a=[6,e],r=0}finally{n=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}function a(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function c(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,i,o=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(r=o.next()).done;)s.push(r.value)}catch(e){i={error:e}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(i)throw i.error}}return s}function l(e,t,n){if(n||2===arguments.length)for(var r,i=0,o=t.length;i<o;i++)!r&&i in t||(r||(r=Array.prototype.slice.call(t,0,i)),r[i]=t[i]);return e.concat(r||Array.prototype.slice.call(t))}"function"==typeof SuppressedError&&SuppressedError,function(e){e.SET="$set",e.SET_ONCE="$setOnce",e.ADD="$add",e.APPEND="$append",e.PREPEND="$prepend",e.REMOVE="$remove",e.PREINSERT="$preInsert",e.POSTINSERT="$postInsert",e.UNSET="$unset",e.CLEAR_ALL="$clearAll"}(n||(n={})),function(e){e.IDENTIFY="$identify",e.GROUP_IDENTIFY="$groupidentify",e.REVENUE="revenue_amount"}(r||(r={}));var u,d="$default_instance",f="https://api2.amplitude.com/2/httpapi";!function(e){e.Unknown="unknown",e.Skipped="skipped",e.Success="success",e.RateLimit="rate_limit",e.PayloadTooLarge="payload_too_large",e.Invalid="invalid",e.Failed="failed",e.Timeout="Timeout",e.SystemError="SystemError"}(u||(u={}));var v,h=function(){var e="ampIntegrationContext";return"undefined"!=typeof globalThis&&void 0!==globalThis[e]?globalThis[e]:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof self?self:"undefined"!=typeof global?global:void 0},g=l([],c(Array(256).keys()),!1).map(function(e){return e.toString(16).padStart(2,"0")}),p=function(e){var t,n=h();if(!(null===(t=null==n?void 0:n.crypto)||void 0===t?void 0:t.getRandomValues))return function(e){return e?(e^16*Math.random()>>e/4).toString(16):(String(1e7)+String(-1e3)+String(-4e3)+String(-8e3)+String(-1e11)).replace(/[018]/g,p)}(e);var r=n.crypto.getRandomValues(new Uint8Array(16));return r[6]=15&r[6]|64,r[8]=63&r[8]|128,l([],c(r.entries()),!1).map(function(e){var t=c(e,2),n=t[0],r=t[1];return[4,6,8,10].includes(n)?"-".concat(g[r]):g[r]}).join("")},m=function(e){return{promise:e||Promise.resolve()}};!function(e){e[e.None=0]="None",e[e.Error=1]="Error",e[e.Warn=2]="Warn",e[e.Verbose=3]="Verbose",e[e.Debug=4]="Debug"}(v||(v={}));var y="Amplitude Logger ",b=function(){function e(){this.logLevel=v.None}return e.prototype.disable=function(){this.logLevel=v.None},e.prototype.enable=function(e){void 0===e&&(e=v.Warn),this.logLevel=e},e.prototype.log=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this.logLevel<v.Verbose||console.log("".concat(y,"[Log]: ").concat(e.join(" ")))},e.prototype.warn=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this.logLevel<v.Warn||console.warn("".concat(y,"[Warn]: ").concat(e.join(" ")))},e.prototype.error=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this.logLevel<v.Error||console.error("".concat(y,"[Error]: ").concat(e.join(" ")))},e.prototype.debug=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this.logLevel<v.Debug||console.log("".concat(y,"[Debug]: ").concat(e.join(" ")))},e}(),S=function(){return{flushMaxRetries:12,flushQueueSize:200,flushIntervalMillis:1e4,instanceName:d,logLevel:v.Warn,loggerProvider:new b,offline:!1,optOut:!1,serverUrl:f,serverZone:"US",useBatch:!1}},w=function(){function e(e){var t,n,r,i;this._optOut=!1;var o=S();this.apiKey=e.apiKey,this.flushIntervalMillis=null!==(t=e.flushIntervalMillis)&&void 0!==t?t:o.flushIntervalMillis,this.flushMaxRetries=e.flushMaxRetries||o.flushMaxRetries,this.flushQueueSize=e.flushQueueSize||o.flushQueueSize,this.instanceName=e.instanceName||o.instanceName,this.loggerProvider=e.loggerProvider||o.loggerProvider,this.logLevel=null!==(n=e.logLevel)&&void 0!==n?n:o.logLevel,this.minIdLength=e.minIdLength,this.plan=e.plan,this.ingestionMetadata=e.ingestionMetadata,this.offline=void 0!==e.offline?e.offline:o.offline,this.optOut=null!==(r=e.optOut)&&void 0!==r?r:o.optOut,this.serverUrl=e.serverUrl,this.serverZone=e.serverZone||o.serverZone,this.storageProvider=e.storageProvider,this.transportProvider=e.transportProvider,this.useBatch=null!==(i=e.useBatch)&&void 0!==i?i:o.useBatch,this.loggerProvider.enable(this.logLevel);var s=C(e.serverUrl,e.serverZone,e.useBatch);this.serverZone=s.serverZone,this.serverUrl=s.serverUrl}return Object.defineProperty(e.prototype,"optOut",{get:function(){return this._optOut},set:function(e){this._optOut=e},enumerable:!1,configurable:!0}),e}(),I=function(e,t){return"EU"===e?t?"https://api.eu.amplitude.com/batch":"https://api.eu.amplitude.com/2/httpapi":t?"https://api2.amplitude.com/batch":f},C=function(e,t,n){if(void 0===e&&(e=""),void 0===t&&(t=S().serverZone),void 0===n&&(n=S().useBatch),e)return{serverUrl:e,serverZone:void 0};var r=["US","EU"].includes(t)?t:S().serverZone;return{serverZone:r,serverUrl:I(r,n)}};var E=function(e,t,n,r,i){return void 0===i&&(i=null),function(){for(var o=[],s=0;s<arguments.length;s++)o[s]=arguments[s];var a=n(),c=a.logger,l=a.logLevel;if(l&&l<v.Debug||!l||!c)return e.apply(i,o);var u,d={type:"invoke public method",name:t,args:o,stacktrace:(u=1,void 0===u&&(u=0),((new Error).stack||"").split("\n").slice(2+u).map(function(e){return e.trim()})),time:{start:(new Date).toISOString()},states:{}};r&&d.states&&(d.states.before=r());var f=e.apply(i,o);return f&&f.promise?f.promise.then(function(){r&&d.states&&(d.states.after=r()),d.time&&(d.time.end=(new Date).toISOString()),c.debug(JSON.stringify(d,null,2))}):(r&&d.states&&(d.states.after=r()),d.time&&(d.time.end=(new Date).toISOString()),c.debug(JSON.stringify(d,null,2))),f}},P=function(){function e(){}return e.prototype.getApplicationContext=function(){return{versionName:this.versionName,language:k(),platform:"Web",os:void 0,deviceModel:void 0}},e}(),k=function(){return"undefined"!=typeof navigator&&(navigator.languages&&navigator.languages[0]||navigator.language)||""},R=function(){function e(){this.queue=[]}return e.prototype.logEvent=function(e){this.receiver?this.receiver(e):this.queue.length<512&&this.queue.push(e)},e.prototype.setEventReceiver=function(e){this.receiver=e,this.queue.length>0&&(this.queue.forEach(function(t){e(t)}),this.queue=[])},e}(),_=function(){return _=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},_.apply(this,arguments)};function T(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function O(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,i,o=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(r=o.next()).done;)s.push(r.value)}catch(e){i={error:e}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(i)throw i.error}}return s}"function"==typeof SuppressedError&&SuppressedError;var x=function(e,t){var n,r,i=typeof e;if(i!==typeof t)return!1;try{for(var o=T(["string","number","boolean","undefined"]),s=o.next();!s.done;s=o.next()){if(s.value===i)return e===t}}catch(e){n={error:e}}finally{try{s&&!s.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}if(null==e&&null==t)return!0;if(null==e||null==t)return!1;if(e.length!==t.length)return!1;var a=Array.isArray(e),c=Array.isArray(t);if(a!==c)return!1;if(!a||!c){var l=Object.keys(e).sort(),u=Object.keys(t).sort();if(!x(l,u))return!1;var d=!0;return Object.keys(e).forEach(function(n){x(e[n],t[n])||(d=!1)}),d}for(var f=0;f<e.length;f++)if(!x(e[f],t[f]))return!1;return!0};Object.entries||(Object.entries=function(e){for(var t=Object.keys(e),n=t.length,r=new Array(n);n--;)r[n]=[t[n],e[t[n]]];return r});var M,D=function(){function e(){this.identity={userProperties:{}},this.listeners=new Set}return e.prototype.editIdentity=function(){var e=this,t=_({},this.identity.userProperties),n=_(_({},this.identity),{userProperties:t});return{setUserId:function(e){return n.userId=e,this},setDeviceId:function(e){return n.deviceId=e,this},setUserProperties:function(e){return n.userProperties=e,this},setOptOut:function(e){return n.optOut=e,this},updateUserProperties:function(e){var t,r,i,o,s,a,c=n.userProperties||{};try{for(var l=T(Object.entries(e)),u=l.next();!u.done;u=l.next()){var d=O(u.value,2),f=d[0],v=d[1];switch(f){case"$set":try{for(var h=(i=void 0,T(Object.entries(v))),g=h.next();!g.done;g=h.next()){var p=O(g.value,2),m=p[0],y=p[1];c[m]=y}}catch(e){i={error:e}}finally{try{g&&!g.done&&(o=h.return)&&o.call(h)}finally{if(i)throw i.error}}break;case"$unset":try{for(var b=(s=void 0,T(Object.keys(v))),S=b.next();!S.done;S=b.next()){delete c[m=S.value]}}catch(e){s={error:e}}finally{try{S&&!S.done&&(a=b.return)&&a.call(b)}finally{if(s)throw s.error}}break;case"$clearAll":c={}}}}catch(e){t={error:e}}finally{try{u&&!u.done&&(r=l.return)&&r.call(l)}finally{if(t)throw t.error}}return n.userProperties=c,this},commit:function(){return e.setIdentity(n),this}}},e.prototype.getIdentity=function(){return _({},this.identity)},e.prototype.setIdentity=function(e){var t=_({},this.identity);this.identity=_({},e),x(t,this.identity)||this.listeners.forEach(function(t){t(e)})},e.prototype.addIdentityListener=function(e){this.listeners.add(e)},e.prototype.removeIdentityListener=function(e){this.listeners.delete(e)},e}(),L="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof global?global:self,N=function(){function e(){this.identityStore=new D,this.eventBridge=new R,this.applicationContextProvider=new P}return e.getInstance=function(t){return L.analyticsConnectorInstances||(L.analyticsConnectorInstances={}),L.analyticsConnectorInstances[t]||(L.analyticsConnectorInstances[t]=new e),L.analyticsConnectorInstances[t]},e}(),q=function(e){var t=0;if(0===e.length)return t;for(var n=0;n<e.length;n++){t=(t<<5)-t+e.charCodeAt(n),t|=0}return t},U=function(){function e(){}return e.prototype.send=function(e,t,n){return Promise.resolve(null)},e.prototype.buildResponse=function(e){var t,n,r,i,o,s,a,c,l,d,f,v,h,g,p,m,y,b,S,w,I,C;if("object"!=typeof e)return null;var E=e.code||0,P=this.buildStatus(E);switch(P){case u.Success:return{status:P,statusCode:E,body:{eventsIngested:null!==(t=e.events_ingested)&&void 0!==t?t:0,payloadSizeBytes:null!==(n=e.payload_size_bytes)&&void 0!==n?n:0,serverUploadTime:null!==(r=e.server_upload_time)&&void 0!==r?r:0}};case u.Invalid:return{status:P,statusCode:E,body:{error:null!==(i=e.error)&&void 0!==i?i:"",missingField:null!==(o=e.missing_field)&&void 0!==o?o:"",eventsWithInvalidFields:null!==(s=e.events_with_invalid_fields)&&void 0!==s?s:{},eventsWithMissingFields:null!==(a=e.events_with_missing_fields)&&void 0!==a?a:{},eventsWithInvalidIdLengths:null!==(c=e.events_with_invalid_id_lengths)&&void 0!==c?c:{},epsThreshold:null!==(l=e.eps_threshold)&&void 0!==l?l:0,exceededDailyQuotaDevices:null!==(d=e.exceeded_daily_quota_devices)&&void 0!==d?d:{},silencedDevices:null!==(f=e.silenced_devices)&&void 0!==f?f:[],silencedEvents:null!==(v=e.silenced_events)&&void 0!==v?v:[],throttledDevices:null!==(h=e.throttled_devices)&&void 0!==h?h:{},throttledEvents:null!==(g=e.throttled_events)&&void 0!==g?g:[]}};case u.PayloadTooLarge:return{status:P,statusCode:E,body:{error:null!==(p=e.error)&&void 0!==p?p:""}};case u.RateLimit:return{status:P,statusCode:E,body:{error:null!==(m=e.error)&&void 0!==m?m:"",epsThreshold:null!==(y=e.eps_threshold)&&void 0!==y?y:0,throttledDevices:null!==(b=e.throttled_devices)&&void 0!==b?b:{},throttledUsers:null!==(S=e.throttled_users)&&void 0!==S?S:{},exceededDailyQuotaDevices:null!==(w=e.exceeded_daily_quota_devices)&&void 0!==w?w:{},exceededDailyQuotaUsers:null!==(I=e.exceeded_daily_quota_users)&&void 0!==I?I:{},throttledEvents:null!==(C=e.throttled_events)&&void 0!==C?C:[]}};case u.Timeout:default:return{status:P,statusCode:E}}},e.prototype.buildStatus=function(e){return function(e){return e>=200&&e<300}(e)?u.Success:429===e?u.RateLimit:413===e?u.PayloadTooLarge:408===e?u.Timeout:e>=400&&e<500?u.Invalid:e>=500?u.Failed:u.Unknown},e}(),j=function(e){function n(t){void 0===t&&(t={});var n=e.call(this)||this;return n.customHeaders=t,n}return t(n,e),n.prototype.send=function(e,t){return o(this,void 0,void 0,function(){var n,r,o;return s(this,function(s){switch(s.label){case 0:if("undefined"==typeof fetch)throw new Error("FetchTransport is not supported");return n={headers:i({"Content-Type":"application/json",Accept:"*/*"},this.customHeaders),body:JSON.stringify(t),method:"POST"},[4,fetch(e,n)];case 1:return[4,(r=s.sent()).text()];case 2:o=s.sent();try{return[2,this.buildResponse(JSON.parse(o))]}catch(e){return[2,this.buildResponse({code:r.status})]}return[2]}})})},n}(U),A=function(){function e(e,t){this.key="AMP_remote_config_".concat(e.substring(0,10)),this.logger=t}return e.prototype.fetchConfig=function(){var e=null,t={remoteConfig:null,lastFetch:new Date};try{e=localStorage.getItem(this.key)}catch(e){return this.logger.debug("Remote config localstorage failed to access: ",e),Promise.resolve(t)}if(null===e)return this.logger.debug("Remote config localstorage gets null because the key does not exist"),Promise.resolve(t);try{var n=JSON.parse(e);return this.logger.debug("Remote config localstorage parsed successfully: ".concat(JSON.stringify(n))),Promise.resolve({remoteConfig:n.remoteConfig,lastFetch:new Date(n.lastFetch)})}catch(e){return this.logger.debug("Remote config localstorage failed to parse: ",e),localStorage.removeItem(this.key),Promise.resolve(t)}},e.prototype.setConfig=function(e){try{return localStorage.setItem(this.key,JSON.stringify(e)),this.logger.debug("Remote config localstorage set successfully."),Promise.resolve(!0)}catch(e){this.logger.debug("Remote config localstorage failed to set: ",e)}return Promise.resolve(!1)},e}(),F=function(){function e(e,t,n,r){void 0===n&&(n="US"),this.callbackInfos=[],this.lastSuccessfulFetch=null,this.fetchPromise=null,this.apiKey=e,this.serverUrl=r||("US"===n?"https://sr-client-cfg.amplitude.com/config":"https://sr-client-cfg.eu.amplitude.com/config"),this.logger=t,this.storage=new A(e,t)}return e.prototype.subscribe=function(e,t,n){var r=p(),i={id:r,key:e,deliveryMode:t,callback:n};return this.callbackInfos.push(i),"all"===t?this.subscribeAll(i):this.subscribeWaitForRemote(i,t.timeout),r},e.prototype.unsubscribe=function(e){var t=this.callbackInfos.findIndex(function(t){return t.id===e});return-1===t?(this.logger.debug("Remote config client unsubscribe failed because callback with id ".concat(e," doesn't exist.")),!1):(this.callbackInfos.splice(t,1),this.logger.debug("Remote config client unsubscribe succeeded removing callback with id ".concat(e,".")),!0)},e.prototype.updateConfigs=function(){return o(this,void 0,void 0,function(){var e,t=this;return s(this,function(n){switch(n.label){case 0:return this.lastSuccessfulFetch&&Date.now()-this.lastSuccessfulFetch<3e5?(this.logger.debug("Remote config client skipping updateConfigs: Too recent"),[2]):[4,this.getOrCreateFetchPromise()];case 1:return e=n.sent(),this.storage.setConfig(e),this.callbackInfos.forEach(function(n){t.sendCallback(n,e,"remote")}),[2]}})})},e.prototype.getOrCreateFetchPromise=function(){var e=this;return this.fetchPromise||(this.fetchPromise=this.fetch().then(function(t){return null!==t.remoteConfig&&(e.lastSuccessfulFetch=Date.now()),t}).finally(function(){e.fetchPromise=null})),this.fetchPromise},e.prototype.subscribeAll=function(e){return o(this,void 0,void 0,function(){var t,n,r,i=this;return s(this,function(o){switch(o.label){case 0:return t=this.getOrCreateFetchPromise().then(function(t){i.logger.debug("Remote config client subscription all mode fetched from remote: ".concat(JSON.stringify(t))),i.sendCallback(e,t,"remote"),i.storage.setConfig(t)}),n=this.storage.fetchConfig().then(function(e){return e}),[4,Promise.race([t,n])];case 1:return void 0!==(r=o.sent())&&(this.logger.debug("Remote config client subscription all mode fetched from cache: ".concat(JSON.stringify(r))),null!==r.remoteConfig?this.sendCallback(e,r,"cache"):this.logger.debug("Remote config client skips sending callback because cache is empty (first time user).")),[4,t];case 2:return o.sent(),[2]}})})},e.prototype.subscribeWaitForRemote=function(e,t){return o(this,void 0,void 0,function(){var n,r;return s(this,function(i){switch(i.label){case 0:n=new Promise(function(e,n){setTimeout(function(){n("Timeout exceeded")},t)}),i.label=1;case 1:return i.trys.push([1,3,,5]),[4,Promise.race([this.getOrCreateFetchPromise(),n])];case 2:return r=i.sent(),this.logger.debug("Remote config client subscription wait for remote mode returns from remote."),this.sendCallback(e,r,"remote"),this.storage.setConfig(r),[3,5];case 3:return i.sent(),this.logger.debug("Remote config client subscription wait for remote mode exceeded timeout. Try to fetch from cache."),[4,this.storage.fetchConfig()];case 4:return null!==(r=i.sent()).remoteConfig?(this.logger.debug("Remote config client subscription wait for remote mode returns a cached copy."),this.sendCallback(e,r,"cache")):(this.logger.debug("Remote config client subscription wait for remote mode failed to fetch cache."),this.sendCallback(e,r,"remote")),[3,5];case 5:return[2]}})})},e.prototype.sendCallback=function(e,t,n){var r;e.lastCallback=new Date,r=e.key?e.key.split(".").reduce(function(e,t){return null===e?e:t in e?e[t]:null},t.remoteConfig):t.remoteConfig,e.callback(r,n,t.lastFetch)},e.prototype.fetch=function(e,t){return void 0===e&&(e=3),void 0===t&&(t=1e3),o(this,void 0,void 0,function(){var n,r,i,o,a,c,l=this;return s(this,function(u){switch(u.label){case 0:n=t/e,r={remoteConfig:null,lastFetch:new Date},i=function(r){var i,a,c,u,d;return s(this,function(s){switch(s.label){case 0:i=new AbortController,a=setTimeout(function(){return i.abort()},t),s.label=1;case 1:return s.trys.push([1,7,8,9]),[4,fetch(o.getUrlParams(),{method:"GET",headers:{Accept:"*/*"},signal:i.signal})];case 2:return(c=s.sent()).ok?[3,4]:[4,c.text()];case 3:return u=s.sent(),o.logger.debug("Remote config client fetch with retry time ".concat(e," failed with ").concat(c.status,": ").concat(u)),[3,6];case 4:return[4,c.json()];case 5:return[2,{value:{remoteConfig:s.sent(),lastFetch:new Date}}];case 6:return[3,9];case 7:return(d=s.sent())instanceof Error&&"AbortError"===d.name?o.logger.debug("Remote config client fetch with retry time ".concat(e," timed out after ").concat(t,"ms")):o.logger.debug("Remote config client fetch with retry time ".concat(e," is rejected because: "),d),[3,9];case 8:return clearTimeout(a),[7];case 9:return r<e-1?[4,new Promise(function(e){return setTimeout(e,l.getJitterDelay(n))})]:[3,11];case 10:s.sent(),s.label=11;case 11:return[2]}})},o=this,a=0,u.label=1;case 1:return a<e?[5,i(a)]:[3,4];case 2:if("object"==typeof(c=u.sent()))return[2,c.value];u.label=3;case 3:return a++,[3,1];case 4:return[2,r]}})})},e.prototype.getJitterDelay=function(e){return Math.floor(Math.random()*e)},e.prototype.getUrlParams=function(){var t=encodeURIComponent(this.apiKey),n=new URLSearchParams;return n.append("config_group",e.CONFIG_GROUP),"".concat(this.serverUrl,"/").concat(t,"?").concat(n.toString())},e.CONFIG_GROUP="browser",e}();!function(e){e.US="US",e.EU="EU",e.STAGING="STAGING"}(M||(M={}));var B,W="https://app.amplitude.com",$={US:W,EU:"https://app.eu.amplitude.com",STAGING:"https://apps.stag2.amplitude.com"};var K="__AMPLITUDE_MESSENGER_INSTANCE__",z="__AMPLITUDE_MESSENGER__",H=function(){function e(e){var t=(void 0===e?{}:e).origin,n=void 0===t?W:t;this[B]=!0,this.isSetup=!1,this.messageHandler=null,this.requestCallbacks={},this.actionHandlers=new Map,this.pendingMessages=new Map,this.scriptLoadPromises=new Map,this.endpoint=n}return e.prototype.notify=function(e){var t,n,r,i;null===(n=null===(t=this.logger)||void 0===t?void 0:t.debug)||void 0===n||n.call(t,"Message sent: ",JSON.stringify(e)),null===(i=null===(r=window.opener)||void 0===r?void 0:r.postMessage)||void 0===i||i.call(r,e,this.endpoint)},e.prototype.sendRequest=function(e,t,n){var r=this;void 0===n&&(n={timeout:15e3});var i="".concat(Date.now(),"-").concat(Math.random().toString(36).substr(2,9)),o={id:i,action:e,args:t};return new Promise(function(t,s){r.requestCallbacks[i]={resolve:t,reject:s},r.notify(o),n.timeout>0&&setTimeout(function(){s(new Error("".concat(e," timed out (id: ").concat(i,")"))),delete r.requestCallbacks[i]},n.timeout)})},e.prototype.handleResponse=function(e){var t;this.requestCallbacks[e.id]?(this.requestCallbacks[e.id].resolve(e.responseData),delete this.requestCallbacks[e.id]):null===(t=this.logger)||void 0===t||t.warn("No callback found for request id: ".concat(e.id))},e.prototype.registerActionHandler=function(e,t){var n,r,i,o;this.actionHandlers.has(e)&&(null===(o=null===(i=this.logger)||void 0===i?void 0:i.warn)||void 0===o||o.call(i,"Overwriting existing action handler for: ".concat(e))),this.actionHandlers.set(e,t);var s=this.pendingMessages.get(e);if(s){this.pendingMessages.delete(e);try{for(var c=a(s),l=c.next();!l.done;l=c.next()){t(l.value)}}catch(e){n={error:e}}finally{try{l&&!l.done&&(r=c.return)&&r.call(c)}finally{if(n)throw n.error}}}},e.prototype.loadScriptOnce=function(e){return o(this,void 0,void 0,function(){var t,n,r;return s(this,function(i){switch(i.label){case 0:if(t=this.scriptLoadPromises.get(e))return[2,t];n=function(e){return document.querySelector('script[src="'.concat(CSS.escape(e),'"]'))?Promise.resolve({status:!0}):new Promise(function(t,n){var r;try{var i=document.createElement("script");i.type="text/javascript",i.async=!0,i.src=e,i.addEventListener("load",function(){t({status:!0})},{once:!0}),i.addEventListener("error",function(){n({status:!1,message:"Failed to load the script ".concat(e)})}),null===(r=document.head)||void 0===r||r.appendChild(i)}catch(e){n(e)}})}(e).then(function(){}),this.scriptLoadPromises.set(e,n),i.label=1;case 1:return i.trys.push([1,3,,4]),[4,n];case 2:return i.sent(),[3,4];case 3:throw r=i.sent(),this.scriptLoadPromises.delete(e),r;case 4:return[2]}})})},e.prototype.setup=function(e){var t,n,r=this,i=void 0===e?{}:e,o=i.logger,s=i.endpoint;o&&(this.logger=o),s&&this.endpoint===W&&(this.endpoint=s),this.isSetup||(this.isSetup=!0,null===(n=null===(t=this.logger)||void 0===t?void 0:t.debug)||void 0===n||n.call(t,"Setting up messenger"),this.messageHandler=function(e){var t,n,i,o,s;if(null===(n=null===(t=r.logger)||void 0===t?void 0:t.debug)||void 0===n||n.call(t,"Message received: ",JSON.stringify(e)),r.endpoint===e.origin){var a=e.data,c=null==a?void 0:a.action;if(c)if("id"in a&&a.id)null===(o=null===(i=r.logger)||void 0===i?void 0:i.debug)||void 0===o||o.call(i,"Received Response to previous request: ",JSON.stringify(e)),r.handleResponse(a);else{if("ping"===c)return void r.notify({action:"pong"});var l=r.actionHandlers.get(c);if(l)l(a.data);else{var u=null!==(s=r.pendingMessages.get(c))&&void 0!==s?s:[];u.push(a.data),r.pendingMessages.set(c,u)}}}},window.addEventListener("message",this.messageHandler),this.notify({action:"page-loaded"}))},e.prototype.destroy=function(){this.messageHandler&&(window.removeEventListener("message",this.messageHandler),this.messageHandler=null),this.isSetup=!1,this.actionHandlers.clear(),this.pendingMessages.clear(),this.requestCallbacks={},this.scriptLoadPromises.clear();var e=h();(null==e?void 0:e[z])===this&&delete e[z]},e}();function J(e){var t,n=h(),r=null==n?void 0:n[z];if("object"==typeof(t=r)&&null!==t&&K in t&&!0===t[K])return r;var i=new H(e);return n&&(n[z]=i),i}B=K;var G="__AMPLITUDE_BACKGROUND_CAPTURE__";var V,Q="[Amplitude]",Z="".concat(Q," Session Replay ID"),Y=M.US,X={enabled:!0},ee="".concat(Q," Session Replay Debug"),te="amp-mask";!function(e){e.GET_SR_PROPS="get-sr-props",e.DEBUG_INFO="debug-info",e.FETCH_REQUEST="fetch-request",e.METADATA="metadata",e.TARGETING_DECISION="targeting-decision"}(V||(V={}));var ne=function(){function e(e){this.logger=e,this.log=this.getSafeMethod("log"),this.warn=this.getSafeMethod("warn"),this.error=this.getSafeMethod("error"),this.debug=this.getSafeMethod("debug")}return e.prototype.getSafeMethod=function(e){var t;if(!this.logger)return function(){};var n=this.logger[e];return"function"==typeof n?(null!==(t=n.__rrweb_original__)&&void 0!==t?t:n).bind(this.logger):function(){}},e.prototype.enable=function(e){this.logger.enable(e)},e.prototype.disable=function(){this.logger.disable()},e}(),re="medium";var ie=function(e,t,n){switch(t){case"light":if("input"!==e)return!0;var r=n?function(e){var t=e.type;return e.hasAttribute("data-rr-is-password")?"password":t?t.toLowerCase():null}(n):"";return!!r&&(!!["password","hidden","email","tel"].includes(r)||!!n.autocomplete.startsWith("cc-"));case"medium":case"conservative":return!0;default:return ie(e,re,n)}},oe=function(e,t){return function(n,r){return function(e,t,n){var r,i,o;if(void 0===t&&(t={defaultMaskLevel:re}),n){if(n.closest("."+te))return!0;var s=(null!==(r=t.maskSelector)&&void 0!==r?r:[]).some(function(e){return n.closest(e)});if(s)return!0;if(n.closest(".amp-unmask"))return!1;var a=(null!==(i=t.unmaskSelector)&&void 0!==i?i:[]).some(function(e){return n.closest(e)});if(a)return!1}return ie(e,null!==(o=t.defaultMaskLevel)&&void 0!==o?o:re,n)}(e,t,r)?n.replace(/[^\s]/g,"*"):n}},se=function(e,t){return t||(e===M.STAGING?"https://api-sr.stag2.amplitude.com/sessions/v2/track":e===M.EU?"https://api-sr.eu.amplitude.com/sessions/v2/track":"https://api-sr.amplitude.com/sessions/v2/track")},ae=function(e){var t=e.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*").replace(/\?/g,".");return new RegExp("^".concat(t,"$"))},ce=function(e,t){var n,r;try{for(var i=a(t),o=i.next();!o.done;o=i.next()){var s=o.value,c=ae(s.selector);if(c.test(e))return e.replace(c,s.replacement)}}catch(e){n={error:e}}finally{try{o&&!o.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.error}}return e},le=function(){return o(void 0,void 0,void 0,function(){var e,t,n,r,i,o,a;return s(this,function(s){switch(s.label){case 0:return s.trys.push([0,3,,4]),(e=h())?[4,e.navigator.storage.estimate()]:[3,2];case 1:return t=s.sent(),n=t.usage,r=t.quota,i=t.usageDetails,o=n?Math.round(n/1024):0,a=n&&r?Math.round(1e3*(n/r+Number.EPSILON))/1e3:0,[2,{totalStorageSize:o,percentOfQuota:a,usageDetails:JSON.stringify(i)}];case 2:return[3,4];case 3:return s.sent(),[3,4];case 4:return[2,{totalStorageSize:0,percentOfQuota:0,usageDetails:""}]}})})},ue=function(e){var t=i({},e),n=t.apiKey;return t.apiKey="****".concat(n.substring(n.length-4)),t},de=function(){return{flushMaxRetries:2,logLevel:v.Warn,loggerProvider:new b,transportProvider:new j}},fe=function(e){function n(t,n){var r,o,s,a,c,l,u=this,d=de();if((u=e.call(this,i(i({transportProvider:d.transportProvider,loggerProvider:new ne(n.loggerProvider||d.loggerProvider)},n),{apiKey:t}))||this).flushMaxRetries=void 0!==n.flushMaxRetries&&n.flushMaxRetries<=d.flushMaxRetries?n.flushMaxRetries:d.flushMaxRetries,u.apiKey=t,u.sampleRate=n.sampleRate||0,u.serverZone=n.serverZone||Y,u.configServerUrl=n.configServerUrl,u.trackServerUrl=n.trackServerUrl,u.shouldInlineStylesheet=n.shouldInlineStylesheet,u.version=n.version,u.performanceConfig=n.performanceConfig||X,u.storeType=null!==(r=n.storeType)&&void 0!==r?r:"idb",u.applyBackgroundColorToBlockedElements=null!==(o=n.applyBackgroundColorToBlockedElements)&&void 0!==o&&o,u.enableUrlChangePolling=null!==(s=n.enableUrlChangePolling)&&void 0!==s&&s,u.urlChangePollingInterval=null!==(a=n.urlChangePollingInterval)&&void 0!==a?a:1e3,u.captureDocumentTitle=null!==(c=n.captureDocumentTitle)&&void 0!==c&&c,n.privacyConfig&&(u.privacyConfig=n.privacyConfig),n.interactionConfig&&(u.interactionConfig=n.interactionConfig,u.interactionConfig.ugcFilterRules&&function(e){if(!e.every(function(e){return"string"==typeof e.selector&&"string"==typeof e.replacement}))throw new Error("ugcFilterRules must be an array of objects with selector and replacement properties");if(!e.every(function(e){return"string"==typeof(t=e.selector)&&""!==t.trim()&&!!/^\/|^https?:\/\/[^\s]+$/.test(t);var t}))throw new Error("ugcFilterRules must be an array of objects with valid globs")}(u.interactionConfig.ugcFilterRules)),n.debugMode&&(u.debugMode=n.debugMode),void 0!==n.useWebWorker)u.useWebWorker=n.useWebWorker;else{var f=n;void 0!==(null===(l=f.experimental)||void 0===l?void 0:l.useWebWorker)&&(u.useWebWorker=f.experimental.useWebWorker)}return n.omitElementTags&&(u.omitElementTags=n.omitElementTags),u}return t(n,e),n}(w),ve=(e=>(e[e.DomContentLoaded=0]="DomContentLoaded",e[e.Load=1]="Load",e[e.FullSnapshot=2]="FullSnapshot",e[e.IncrementalSnapshot=3]="IncrementalSnapshot",e[e.Meta=4]="Meta",e[e.Custom=5]="Custom",e[e.Plugin=6]="Plugin",e))(ve||{}),he=(e=>(e[e.MouseUp=0]="MouseUp",e[e.MouseDown=1]="MouseDown",e[e.Click=2]="Click",e[e.ContextMenu=3]="ContextMenu",e[e.DblClick=4]="DblClick",e[e.Focus=5]="Focus",e[e.Blur=6]="Blur",e[e.TouchStart=7]="TouchStart",e[e.TouchMove_Departed=8]="TouchMove_Departed",e[e.TouchEnd=9]="TouchEnd",e[e.TouchCancel=10]="TouchCancel",e))(he||{}),ge=function(){function e(e,t){this.localConfig=t,this.remoteConfigClient=e}return e.prototype.generateJoinedConfig=function(){var e,t,n;return o(this,void 0,void 0,function(){var r,o,l,u,d,f,v,h,g,p,m,y,b,S,w,I,C,E=this;return s(this,function(s){switch(s.label){case 0:(r=i({},this.localConfig)).optOut=this.localConfig.optOut,r.captureEnabled=!0,s.label=1;case 1:return s.trys.push([1,3,,4]),[4,new Promise(function(e,t){E.remoteConfigClient.subscribe("configs.sessionReplay","all",function(n,i){var s;if(E.localConfig.loggerProvider.debug("Session Replay remote configuration received from ".concat(i,":"),JSON.stringify(n,null,2)),n){var a=n,c=a.sr_sampling_config,l=a.sr_privacy_config,u=a.sr_targeting_config,d=null===(s=r.interactionConfig)||void 0===s?void 0:s.ugcFilterRules;r.interactionConfig=a.sr_interaction_config,r.interactionConfig&&d&&(r.interactionConfig.ugcFilterRules=d),r.loggingConfig=a.sr_logging_config,(c||l||u)&&(o={},c&&(o.sr_sampling_config=c),l&&(o.sr_privacy_config=l),u&&(o.sr_targeting_config=u)),e()}else t(new Error("No remote config received"))})})];case 2:return s.sent(),[3,4];case 3:return l=s.sent(),this.localConfig.loggerProvider.error("Failed to generate joined config: ",l),r.captureEnabled=!1,[2,{localConfig:this.localConfig,joinedConfig:r,remoteConfig:void 0}];case 4:if(!o)return[2,{localConfig:this.localConfig,joinedConfig:r,remoteConfig:o}];if(u=o.sr_sampling_config,d=o.sr_privacy_config,f=o.sr_targeting_config,u&&Object.keys(u).length>0?(Object.prototype.hasOwnProperty.call(u,"capture_enabled")?r.captureEnabled=u.capture_enabled:r.captureEnabled=!1,Object.prototype.hasOwnProperty.call(u,"sample_rate")&&(r.sampleRate=u.sample_rate)):(r.captureEnabled=!0,this.localConfig.loggerProvider.debug("Remote config successfully fetched, but no values set for project, Session Replay capture enabled.")),d){v=null!==(e=r.privacyConfig)&&void 0!==e?e:{},h={defaultMaskLevel:null!==(n=null!==(t=d.defaultMaskLevel)&&void 0!==t?t:v.defaultMaskLevel)&&void 0!==n?n:"medium",blockSelector:[],maskSelector:[],unmaskSelector:[]},g=function(e){var t,n,r,i,o,s,c,l,u,d={};"string"==typeof e.blockSelector&&(e.blockSelector=[e.blockSelector]);try{for(var f=a(null!==(c=e.blockSelector)&&void 0!==c?c:[]),v=f.next();!v.done;v=f.next()){d[v.value]="block"}}catch(e){t={error:e}}finally{try{v&&!v.done&&(n=f.return)&&n.call(f)}finally{if(t)throw t.error}}try{for(var h=a(null!==(l=e.maskSelector)&&void 0!==l?l:[]),g=h.next();!g.done;g=h.next()){d[g.value]="mask"}}catch(e){r={error:e}}finally{try{g&&!g.done&&(i=h.return)&&i.call(h)}finally{if(r)throw r.error}}try{for(var p=a(null!==(u=e.unmaskSelector)&&void 0!==u?u:[]),m=p.next();!m.done;m=p.next()){d[m.value]="unmask"}}catch(e){o={error:e}}finally{try{m&&!m.done&&(s=p.return)&&s.call(p)}finally{if(o)throw o.error}}return d},p=i(i({},g(v)),g(d));try{for(m=a(Object.entries(p)),y=m.next();!y.done;y=m.next())b=c(y.value,2),S=b[0],"mask"===(w=b[1])?h.maskSelector.push(S):"block"===w?h.blockSelector.push(S):"unmask"===w&&h.unmaskSelector.push(S)}catch(e){I={error:e}}finally{try{y&&!y.done&&(C=m.return)&&C.call(m)}finally{if(I)throw I.error}}r.privacyConfig=(P=h,k=this.localConfig.loggerProvider,R=document.createDocumentFragment(),_=function(e){if(void 0===e&&(e=[]),"string"==typeof e&&(e=[e]),e=e.filter(function(e){try{R.querySelector(e)}catch(t){return k.warn('[session-replay-browser] omitting selector "'.concat(e,'" because it is invalid')),!1}return!0}),0!==e.length)return e},P.blockSelector=_(P.blockSelector),P.maskSelector=_(P.maskSelector),P.unmaskSelector=_(P.unmaskSelector),P)}return f&&Object.keys(f).length>0&&(r.targetingConfig=f),this.localConfig.loggerProvider.debug(JSON.stringify({name:"session replay joined config",config:ue(r)},null,2)),[2,{localConfig:this.localConfig,joinedConfig:r,remoteConfig:o}]}var P,k,R,_})})},e}(),pe=function(e,t){return o(void 0,void 0,void 0,function(){var n,r;return s(this,function(i){return n=new fe(e,t),r=new F(e,n.loggerProvider,n.serverZone,t.configServerUrl),[2,new ge(r,n)]})})},me=Uint8Array,ye=Uint16Array,be=Uint32Array,Se=new me([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),we=new me([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),Ie=new me([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Ce=function(e,t){for(var n=new ye(31),r=0;r<31;++r)n[r]=t+=1<<e[r-1];var i=new be(n[30]);for(r=1;r<30;++r)for(var o=n[r];o<n[r+1];++o)i[o]=o-n[r]<<5|r;return[n,i]},Ee=Ce(Se,2),Pe=Ee[0],ke=Ee[1];Pe[28]=258,ke[258]=28;for(var Re=Ce(we,0)[1],_e=new ye(32768),Te=0;Te<32768;++Te){var Oe=(43690&Te)>>>1|(21845&Te)<<1;Oe=(61680&(Oe=(52428&Oe)>>>2|(13107&Oe)<<2))>>>4|(3855&Oe)<<4,_e[Te]=((65280&Oe)>>>8|(255&Oe)<<8)>>>1}var xe=function(e,t,n){for(var r=e.length,i=0,o=new ye(t);i<r;++i)++o[e[i]-1];var s,a=new ye(t);for(i=0;i<t;++i)a[i]=a[i-1]+o[i-1]<<1;if(n){s=new ye(1<<t);var c=15-t;for(i=0;i<r;++i)if(e[i])for(var l=i<<4|e[i],u=t-e[i],d=a[e[i]-1]++<<u,f=d|(1<<u)-1;d<=f;++d)s[_e[d]>>>c]=l}else for(s=new ye(r),i=0;i<r;++i)s[i]=_e[a[e[i]-1]++]>>>15-e[i];return s},Me=new me(288);for(Te=0;Te<144;++Te)Me[Te]=8;for(Te=144;Te<256;++Te)Me[Te]=9;for(Te=256;Te<280;++Te)Me[Te]=7;for(Te=280;Te<288;++Te)Me[Te]=8;var De=new me(32);for(Te=0;Te<32;++Te)De[Te]=5;var Le=xe(Me,9,0),Ne=xe(De,5,0),qe=function(e){return(e/8|0)+(7&e&&1)},Ue=function(e,t,n){(null==n||n>e.length)&&(n=e.length);var r=new(e instanceof ye?ye:e instanceof be?be:me)(n-t);return r.set(e.subarray(t,n)),r},je=function(e,t,n){n<<=7&t;var r=t/8|0;e[r]|=n,e[r+1]|=n>>>8},Ae=function(e,t,n){n<<=7&t;var r=t/8|0;e[r]|=n,e[r+1]|=n>>>8,e[r+2]|=n>>>16},Fe=function(e,t){for(var n=[],r=0;r<e.length;++r)e[r]&&n.push({s:r,f:e[r]});var i=n.length,o=n.slice();if(!i)return[new me(0),0];if(1==i){var s=new me(n[0].s+1);return s[n[0].s]=1,[s,1]}n.sort(function(e,t){return e.f-t.f}),n.push({s:-1,f:25001});var a=n[0],c=n[1],l=0,u=1,d=2;for(n[0]={s:-1,f:a.f+c.f,l:a,r:c};u!=i-1;)a=n[n[l].f<n[d].f?l++:d++],c=n[l!=u&&n[l].f<n[d].f?l++:d++],n[u++]={s:-1,f:a.f+c.f,l:a,r:c};var f=o[0].s;for(r=1;r<i;++r)o[r].s>f&&(f=o[r].s);var v=new ye(f+1),h=Be(n[u-1],v,0);if(h>t){r=0;var g=0,p=h-t,m=1<<p;for(o.sort(function(e,t){return v[t.s]-v[e.s]||e.f-t.f});r<i;++r){var y=o[r].s;if(!(v[y]>t))break;g+=m-(1<<h-v[y]),v[y]=t}for(g>>>=p;g>0;){var b=o[r].s;v[b]<t?g-=1<<t-v[b]++-1:++r}for(;r>=0&&g;--r){var S=o[r].s;v[S]==t&&(--v[S],++g)}h=t}return[new me(v),h]},Be=function(e,t,n){return-1==e.s?Math.max(Be(e.l,t,n+1),Be(e.r,t,n+1)):t[e.s]=n},We=function(e){for(var t=e.length;t&&!e[--t];);for(var n=new ye(++t),r=0,i=e[0],o=1,s=function(e){n[r++]=e},a=1;a<=t;++a)if(e[a]==i&&a!=t)++o;else{if(!i&&o>2){for(;o>138;o-=138)s(32754);o>2&&(s(o>10?o-11<<5|28690:o-3<<5|12305),o=0)}else if(o>3){for(s(i),--o;o>6;o-=6)s(8304);o>2&&(s(o-3<<5|8208),o=0)}for(;o--;)s(i);o=1,i=e[a]}return[n.subarray(0,r),t]},$e=function(e,t){for(var n=0,r=0;r<t.length;++r)n+=e[r]*t[r];return n},Ke=function(e,t,n){var r=n.length,i=qe(t+2);e[i]=255&r,e[i+1]=r>>>8,e[i+2]=255^e[i],e[i+3]=255^e[i+1];for(var o=0;o<r;++o)e[i+o+4]=n[o];return 8*(i+4+r)},ze=function(e,t,n,r,i,o,s,a,c,l,u){je(t,u++,n),++i[256];for(var d=Fe(i,15),f=d[0],v=d[1],h=Fe(o,15),g=h[0],p=h[1],m=We(f),y=m[0],b=m[1],S=We(g),w=S[0],I=S[1],C=new ye(19),E=0;E<y.length;++E)C[31&y[E]]++;for(E=0;E<w.length;++E)C[31&w[E]]++;for(var P=Fe(C,7),k=P[0],R=P[1],_=19;_>4&&!k[Ie[_-1]];--_);var T,O,x,M,D=l+5<<3,L=$e(i,Me)+$e(o,De)+s,N=$e(i,f)+$e(o,g)+s+14+3*_+$e(C,k)+(2*C[16]+3*C[17]+7*C[18]);if(D<=L&&D<=N)return Ke(t,u,e.subarray(c,c+l));if(je(t,u,1+(N<L)),u+=2,N<L){T=xe(f,v,0),O=f,x=xe(g,p,0),M=g;var q=xe(k,R,0);je(t,u,b-257),je(t,u+5,I-1),je(t,u+10,_-4),u+=14;for(E=0;E<_;++E)je(t,u+3*E,k[Ie[E]]);u+=3*_;for(var U=[y,w],j=0;j<2;++j){var A=U[j];for(E=0;E<A.length;++E){var F=31&A[E];je(t,u,q[F]),u+=k[F],F>15&&(je(t,u,A[E]>>>5&127),u+=A[E]>>>12)}}}else T=Le,O=Me,x=Ne,M=De;for(E=0;E<a;++E)if(r[E]>255){F=r[E]>>>18&31;Ae(t,u,T[F+257]),u+=O[F+257],F>7&&(je(t,u,r[E]>>>23&31),u+=Se[F]);var B=31&r[E];Ae(t,u,x[B]),u+=M[B],B>3&&(Ae(t,u,r[E]>>>5&8191),u+=we[B])}else Ae(t,u,T[r[E]]),u+=O[r[E]];return Ae(t,u,T[256]),u+O[256]},He=new be([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),Je=function(e,t,n,r,i){return function(e,t,n,r,i,o){var s=e.length,a=new me(r+s+5*(1+Math.floor(s/7e3))+i),c=a.subarray(r,a.length-i),l=0;if(!t||s<8)for(var u=0;u<=s;u+=65535){var d=u+65535;d<s?l=Ke(c,l,e.subarray(u,d)):(c[u]=o,l=Ke(c,l,e.subarray(u,s)))}else{for(var f=He[t-1],v=f>>>13,h=8191&f,g=(1<<n)-1,p=new ye(32768),m=new ye(g+1),y=Math.ceil(n/3),b=2*y,S=function(t){return(e[t]^e[t+1]<<y^e[t+2]<<b)&g},w=new be(25e3),I=new ye(288),C=new ye(32),E=0,P=0,k=(u=0,0),R=0,_=0;u<s;++u){var T=S(u),O=32767&u,x=m[T];if(p[O]=x,m[T]=O,R<=u){var M=s-u;if((E>7e3||k>24576)&&M>423){l=ze(e,c,0,w,I,C,P,k,_,u-_,l),k=E=P=0,_=u;for(var D=0;D<286;++D)I[D]=0;for(D=0;D<30;++D)C[D]=0}var L=2,N=0,q=h,U=O-x&32767;if(M>2&&T==S(u-U))for(var j=Math.min(v,M)-1,A=Math.min(32767,u),F=Math.min(258,M);U<=A&&--q&&O!=x;){if(e[u+L]==e[u+L-U]){for(var B=0;B<F&&e[u+B]==e[u+B-U];++B);if(B>L){if(L=B,N=U,B>j)break;var W=Math.min(U,B-2),$=0;for(D=0;D<W;++D){var K=u-U+D+32768&32767,z=K-p[K]+32768&32767;z>$&&($=z,x=K)}}}U+=(O=x)-(x=p[O])+32768&32767}if(N){w[k++]=268435456|ke[L]<<18|Re[N];var H=31&ke[L],J=31&Re[N];P+=Se[H]+we[J],++I[257+H],++C[J],R=u+L,++E}else w[k++]=e[u],++I[e[u]]}}l=ze(e,c,o,w,I,C,P,k,_,u-_,l)}return Ue(a,0,r+qe(l)+i)}(e,null==t.level?6:t.level,null==t.mem?Math.ceil(1.5*Math.max(8,Math.min(13,Math.log(e.length)))):12+t.mem,n,r,!0)};function Ge(e,t){void 0===t&&(t={});var n=function(){var e=1,t=0;return{p:function(n){for(var r=e,i=t,o=n.length,s=0;s!=o;){for(var a=Math.min(s+5552,o);s<a;++s)i+=r+=n[s];r%=65521,i%=65521}e=r,t=i},d:function(){return(e>>>8<<16|(255&t)<<8|t>>>8)+2*((255&e)<<23)}}}();n.p(e);var r,i,o,s=Je(e,t,2,4);return r=s,i=t.level,o=0==i?0:i<6?1:9==i?3:2,r[0]=120,r[1]=o<<6|(o?32-2*o:1),function(e,t,n){for(;n;++t)e[t]=n,n>>>=8}(s,s.length-4,n.d()),s}const Ve=e=>{const t={...e,v:"v1"};return function(e,t){var n="";if(!t&&"undefined"!=typeof TextDecoder)return(new TextDecoder).decode(e);for(var r=0;r<e.length;){var i=e[r++];i<128||t?n+=String.fromCharCode(i):i<224?n+=String.fromCharCode((31&i)<<6|63&e[r++]):i<240?n+=String.fromCharCode((15&i)<<12|(63&e[r++])<<6|63&e[r++]):(i=((15&i)<<18|(63&e[r++])<<12|(63&e[r++])<<6|63&e[r++])-65536,n+=String.fromCharCode(55296|i>>10,56320|1023&i))}return n}(Ge(function(e,t){var n=e.length;if(!t&&"undefined"!=typeof TextEncoder)return(new TextEncoder).encode(e);for(var r=new me(e.length+(e.length>>>1)),i=0,o=function(e){r[i++]=e},s=0;s<n;++s){if(i+5>r.length){var a=new me(i+8+(n-s<<1));a.set(r),r=a}var c=e.charCodeAt(s);c<128||t?o(c):c<2048?(o(192|c>>>6),o(128|63&c)):c>55295&&c<57344?(o(240|(c=65536+(1047552&c)|1023&e.charCodeAt(++s))>>>18),o(128|c>>>12&63),o(128|c>>>6&63),o(128|63&c)):(o(224|c>>>12),o(128|c>>>6&63),o(128|63&c))}return Ue(r,0,i)}(JSON.stringify(t))),!0)};var Qe=function(){function e(e,t,n,r){var i,o=this;this.taskQueue=[],this.isProcessing=!1,this.compressEvent=function(e){var t=Ve(e);return JSON.stringify(t)},this.addCompressedEventToManager=function(e,t){o.eventsManager&&o.deviceId&&o.eventsManager.addEvent({event:{type:"replay",data:e},sessionId:t,deviceId:o.deviceId})},this.addCompressedEvent=function(e,t){if(o.worker)try{o.worker.postMessage({event:e,sessionId:t})}catch(n){"DataCloneError"===n.name?o.worker.postMessage(JSON.stringify({event:e,sessionId:t})):o.config.loggerProvider.warn("Unexpected error while posting message to worker:",n)}else{var n=o.compressEvent(e);o.addCompressedEventToManager(n,t)}},this.terminate=function(){var e;null===(e=o.worker)||void 0===e||e.terminate()};var s=h();if(this.canUseIdleCallback=s&&"requestIdleCallback"in s,this.eventsManager=e,this.config=t,this.deviceId=n,this.timeout=(null===(i=t.performanceConfig)||void 0===i?void 0:i.timeout)||2e3,r){t.loggerProvider.log("Enabling web worker for compression");try{var a=new Blob([r],{type:"application/javascript"}),c=URL.createObjectURL(a),l=new Worker(c);l.onerror=function(e){t.loggerProvider.error("Worker failed, falling back to non-worker compression:",e),l.terminate(),o.worker=void 0},l.onmessage=function(e){var t=e.data,n=t.compressedEvent,r=t.sessionId;o.addCompressedEventToManager(n,r)},this.worker=l}catch(e){t.loggerProvider.error("Failed to create worker, falling back to non-worker compression:",e)}}}return e.prototype.scheduleIdleProcessing=function(){var e=this;this.isProcessing||(this.isProcessing=!0,requestIdleCallback(function(t){e.processQueue(t)},{timeout:this.timeout}))},e.prototype.enqueueEvent=function(e,t){var n;this.canUseIdleCallback&&(null===(n=this.config.performanceConfig)||void 0===n?void 0:n.enabled)?(this.config.loggerProvider.debug("Enqueuing event for processing during idle time."),this.taskQueue.push({event:e,sessionId:t}),this.scheduleIdleProcessing()):(this.config.loggerProvider.debug("Processing event without idle callback."),this.addCompressedEvent(e,t))},e.prototype.processQueue=function(e){for(var t=this;this.taskQueue.length>0&&(e.timeRemaining()>0||e.didTimeout);){var n=this.taskQueue.shift();if(n){var r=n.event,i=n.sessionId;this.addCompressedEvent(r,i)}}this.taskQueue.length>0?requestIdleCallback(function(e){t.processQueue(e)},{timeout:this.timeout}):this.isProcessing=!1},e}(),Ze="Session replay event batch rejected due to exceeded retry count",Ye="Failed to store session replay events in IndexedDB",Xe="1.31.6",et=function(){function e(e){var t=e.trackServerUrl,n=e.loggerProvider,r=e.payloadBatcher;this.storageKey="",this.retryTimeout=1e3,this.scheduled=null,this.queue=[],this.loggerProvider=n,this.payloadBatcher=r||function(e){return e},this.trackServerUrl=t}return e.prototype.sendEventsList=function(e){this.addToQueue(i(i({},e),{attempts:0,timeout:0}))},e.prototype.addToQueue=function(){for(var e=this,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];t.filter(function(t){return t.attempts<(t.flushMaxRetries||0)?(t.attempts+=1,!0):(e.completeRequest({context:t,err:Ze}),!1)}).forEach(function(t){e.queue=e.queue.concat(t),e.schedule(0)})},e.prototype.schedule=function(e){var t=this;this.scheduled||(this.scheduled=setTimeout(function(){t.flush(!0).then(function(){t.queue.length>0&&t.schedule(e)})},e))},e.prototype.flush=function(e){return void 0===e&&(e=!1),o(this,void 0,void 0,function(){var t,n,r,i,o,c,l;return s(this,function(s){switch(s.label){case 0:t=this.queue,this.queue=[],this.scheduled&&(clearTimeout(this.scheduled),this.scheduled=null),s.label=1;case 1:s.trys.push([1,6,7,8]),n=a(t),r=n.next(),s.label=2;case 2:return r.done?[3,5]:(i=r.value,[4,this.send(i,e)]);case 3:s.sent(),s.label=4;case 4:return r=n.next(),[3,2];case 5:return[3,8];case 6:return o=s.sent(),c={error:o},[3,8];case 7:try{r&&!r.done&&(l=n.return)&&l.call(n)}finally{if(c)throw c.error}return[7];case 8:return[2]}})})},e.prototype.send=function(e,t){var n,r;return void 0===t&&(t=!0),o(this,void 0,void 0,function(){var i,o,a,c,l,u,d,f,v,g,p,m,y;return s(this,function(s){switch(s.label){case 0:if(!(i=e.apiKey))return[2,this.completeRequest({context:e,err:"Session replay event batch not sent due to missing api key"})];if(!(o=e.deviceId))return[2,this.completeRequest({context:e,err:"Session replay event batch not sent due to missing device ID"})];if(b=h(),a=(null==b?void 0:b.location)?b.location.href:"",c=Xe,l=e.sampleRate,u=new URLSearchParams({device_id:o,session_id:"".concat(e.sessionId),type:"".concat(e.type)}),d="".concat((null===(n=e.version)||void 0===n?void 0:n.type)||"standalone","/").concat((null===(r=e.version)||void 0===r?void 0:r.version)||c),0===(f=this.payloadBatcher({version:1,events:e.events})).events.length)return this.completeRequest({context:e}),[2];s.label=1;case 1:return s.trys.push([1,6,,7]),v={headers:{"Content-Type":"application/json",Accept:"*/*",Authorization:"Bearer ".concat(i),"X-Client-Version":c,"X-Client-Library":d,"X-Client-Url":a.substring(0,1e3),"X-Client-Sample-Rate":"".concat(l)},body:JSON.stringify(f),method:"POST"},g="".concat(se(e.serverZone,this.trackServerUrl),"?").concat(u.toString()),[4,fetch(g,v)];case 2:if(null===(p=s.sent()))return this.completeRequest({context:e,err:"Unexpected error occurred"}),[2];if(t)return[3,3];m="";try{m=JSON.stringify(p.body,null,2)}catch(e){}return this.completeRequest({context:e,success:"".concat(p.status,": ").concat(m)}),[3,5];case 3:return[4,this.handleReponse(p.status,e)];case 4:s.sent(),s.label=5;case 5:return[3,7];case 6:return y=s.sent(),this.completeRequest({context:e,err:y}),[3,7];case 7:return[2]}var b})})},e.prototype.handleReponse=function(e,t){return o(this,void 0,void 0,function(){var n;return s(this,function(r){switch(r.label){case 0:switch(n=(new U).buildStatus(e),n){case u.Success:return[3,1];case u.Failed:return[3,2]}return[3,4];case 1:return this.handleSuccessResponse(t),[3,5];case 2:return[4,this.handleOtherResponse(t)];case 3:return r.sent(),[3,5];case 4:this.completeRequest({context:t,err:"Network error occurred, event batch rejected"}),r.label=5;case 5:return[2]}})})},e.prototype.handleSuccessResponse=function(e){var t=Math.round(new Blob(e.events).size/1024);this.completeRequest({context:e,success:"Session replay event batch tracked successfully for session id ".concat(e.sessionId,", size of events: ").concat(t," KB")})},e.prototype.handleOtherResponse=function(e){return o(this,void 0,void 0,function(){var t;return s(this,function(n){switch(n.label){case 0:return t=e.attempts*this.retryTimeout,e.attempts++,e.attempts>(e.flushMaxRetries||0)?(this.completeRequest({context:e,err:Ze}),[2]):[4,new Promise(function(e){return setTimeout(e,t)})];case 1:return n.sent(),[4,this.send(e,!0)];case 2:return n.sent(),[2]}})})},e.prototype.completeRequest=function(e){var t=e.context,n=e.err,r=e.success;t.onComplete(),n?this.loggerProvider.warn(n):r&&this.loggerProvider.log(r)},e}();const tt=(e,t)=>t.some(t=>e instanceof t);let nt,rt;const it=new WeakMap,ot=new WeakMap,st=new WeakMap;let at={get(e,t,n){if(e instanceof IDBTransaction){if("done"===t)return it.get(e);if("store"===t)return n.objectStoreNames[1]?void 0:n.objectStore(n.objectStoreNames[0])}return dt(e[t])},set:(e,t,n)=>(e[t]=n,!0),has:(e,t)=>e instanceof IDBTransaction&&("done"===t||"store"===t)||t in e};function ct(e){at=e(at)}function lt(e){return(rt||(rt=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])).includes(e)?function(...t){return e.apply(ft(this),t),dt(this.request)}:function(...t){return dt(e.apply(ft(this),t))}}function ut(e){return"function"==typeof e?lt(e):(e instanceof IDBTransaction&&function(e){if(it.has(e))return;const t=new Promise((t,n)=>{const r=()=>{e.removeEventListener("complete",i),e.removeEventListener("error",o),e.removeEventListener("abort",o)},i=()=>{t(),r()},o=()=>{n(e.error||new DOMException("AbortError","AbortError")),r()};e.addEventListener("complete",i),e.addEventListener("error",o),e.addEventListener("abort",o)});it.set(e,t)}(e),tt(e,nt||(nt=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction]))?new Proxy(e,at):e)}function dt(e){if(e instanceof IDBRequest)return function(e){const t=new Promise((t,n)=>{const r=()=>{e.removeEventListener("success",i),e.removeEventListener("error",o)},i=()=>{t(dt(e.result)),r()},o=()=>{n(e.error),r()};e.addEventListener("success",i),e.addEventListener("error",o)});return st.set(t,e),t}(e);if(ot.has(e))return ot.get(e);const t=ut(e);return t!==e&&(ot.set(e,t),st.set(t,e)),t}const ft=e=>st.get(e);function vt(e,t,{blocked:n,upgrade:r,blocking:i,terminated:o}={}){const s=indexedDB.open(e,t),a=dt(s);return r&&s.addEventListener("upgradeneeded",e=>{r(dt(s.result),e.oldVersion,e.newVersion,dt(s.transaction),e)}),n&&s.addEventListener("blocked",e=>n(e.oldVersion,e.newVersion,e)),a.then(e=>{o&&e.addEventListener("close",()=>o()),i&&e.addEventListener("versionchange",e=>i(e.oldVersion,e.newVersion,e))}).catch(()=>{}),a}const ht=["get","getKey","getAll","getAllKeys","count"],gt=["put","add","delete","clear"],pt=new Map;function mt(e,t){if(!(e instanceof IDBDatabase)||t in e||"string"!=typeof t)return;if(pt.get(t))return pt.get(t);const n=t.replace(/FromIndex$/,""),r=t!==n,i=gt.includes(n);if(!(n in(r?IDBIndex:IDBObjectStore).prototype)||!i&&!ht.includes(n))return;const o=async function(e,...t){const o=this.transaction(e,i?"readwrite":"readonly");let s=o.store;return r&&(s=s.index(t.shift())),(await Promise.all([s[n](...t),i&&o.done]))[0]};return pt.set(t,o),o}ct(e=>({...e,get:(t,n,r)=>mt(t,n)||e.get(t,n,r),has:(t,n)=>!!mt(t,n)||e.has(t,n)}));const yt=["continue","continuePrimaryKey","advance"],bt={},St=new WeakMap,wt=new WeakMap,It={get(e,t){if(!yt.includes(t))return e[t];let n=bt[t];return n||(n=bt[t]=function(...e){St.set(this,wt.get(this)[t](...e))}),n}};async function*Ct(...e){let t=this;if(t instanceof IDBCursor||(t=await t.openCursor(...e)),!t)return;const n=new Proxy(t,It);for(wt.set(n,t),st.set(n,ft(t));t;)yield n,t=await(St.get(n)||t.continue()),St.delete(n)}function Et(e,t){return t===Symbol.asyncIterator&&tt(e,[IDBIndex,IDBObjectStore,IDBCursor])||"iterate"===t&&tt(e,[IDBIndex,IDBObjectStore])}ct(e=>({...e,get:(t,n,r)=>Et(t,n)?Ct:e.get(t,n,r),has:(t,n)=>Et(t,n)||e.has(t,n)}));var Pt,kt,Rt,_t=function(){function e(e){var t,n,r,i=this;this.minInterval=500,this.maxInterval=1e4,this.maxPersistedEventsSize=1e6,this.interval=this.minInterval,this._timeAtLastSplit=Date.now(),this.shouldSplitEventsList=function(e,t){var n=i.getStringSize(t);return i.getEventsArraySize(e)+n>=i.maxPersistedEventsSize||!!(Date.now()-i.timeAtLastSplit>i.interval&&e.length)&&(i.interval=Math.min(i.maxInterval,i.interval+i.minInterval),i._timeAtLastSplit=Date.now(),!0)},this.loggerProvider=e.loggerProvider,this.minInterval=null!==(t=e.minInterval)&&void 0!==t?t:this.minInterval,this.maxInterval=null!==(n=e.maxInterval)&&void 0!==n?n:this.maxInterval,this.maxPersistedEventsSize=null!==(r=e.maxPersistedEventsSize)&&void 0!==r?r:this.maxPersistedEventsSize}return Object.defineProperty(e.prototype,"timeAtLastSplit",{get:function(){return this._timeAtLastSplit},enumerable:!1,configurable:!0}),e.prototype.getStringSize=function(e){return e.length},e.prototype.getEventsArraySize=function(e){var t,n,r=0;try{for(var i=a(e),o=i.next();!o.done;o=i.next()){var s=o.value;r+=this.getStringSize(s)}}catch(e){t={error:e}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(t)throw t.error}}return r+(2+Math.max(0,e.length-1)+2*e.length)},e}(),Tt=function(e,t,n){var r;"object"==typeof(r=n)&&null!==r&&"AbortError"===r.name?e.debug(t):e.warn(t)},Ot="sessionCurrentSequence",xt="sequencesToSend",Mt=function(e){var t,n;return e.objectStoreNames.contains(Ot)||(n=e.createObjectStore(Ot,{keyPath:"sessionId"})),e.objectStoreNames.contains(xt)||(t=e.createObjectStore(xt,{keyPath:"sequenceId",autoIncrement:!0})).createIndex("sessionId","sessionId"),{sequencesStore:t,currentSequenceStore:n}},Dt=function(e){return o(void 0,void 0,void 0,function(){return s(this,function(t){switch(t.label){case 0:return[4,vt(e,1,{upgrade:Mt})];case 1:return[2,t.sent()]}})})},Lt=function(e){function n(t){var n=e.call(this,t)||this;return n.getSequencesToSend=function(){return o(n,void 0,void 0,function(){var e,t,n,r,i,o;return s(this,function(s){switch(s.label){case 0:return s.trys.push([0,5,,6]),e=[],[4,this.db.transaction("sequencesToSend").store.openCursor()];case 1:t=s.sent(),s.label=2;case 2:return t?(n=t.value,r=n.sessionId,i=n.events,e.push({events:i,sequenceId:t.key,sessionId:r}),[4,t.continue()]):[3,4];case 3:return t=s.sent(),[3,2];case 4:return[2,e];case 5:return o=s.sent(),Tt(this.loggerProvider,"".concat(Ye,": ").concat(o),o),[3,6];case 6:return[2,void 0]}})})},n.storeCurrentSequence=function(e){return o(n,void 0,void 0,function(){var t,n,r;return s(this,function(o){switch(o.label){case 0:return o.trys.push([0,4,,5]),[4,this.db.get(Ot,e)];case 1:return(t=o.sent())?[4,this.db.put(xt,{sessionId:e,events:t.events})]:[2,void 0];case 2:return n=o.sent(),[4,this.db.put(Ot,{sessionId:e,events:[]})];case 3:return o.sent(),[2,i(i({},t),{sessionId:e,sequenceId:n})];case 4:return r=o.sent(),Tt(this.loggerProvider,"".concat(Ye,": ").concat(r),r),[3,5];case 5:return[2,void 0]}})})},n.addEventToCurrentSequence=function(e,t){return o(n,void 0,void 0,function(){var n,r,i,o,a,c;return s(this,function(s){switch(s.label){case 0:return s.trys.push([0,10,,11]),[4,(n=this.db.transaction(Ot,"readwrite")).store.get(e)];case 1:return(r=s.sent())?[3,3]:[4,n.store.put({sessionId:e,events:[t]})];case 2:return s.sent(),[2];case 3:return i=void 0,this.shouldSplitEventsList(r.events,t)?(i=r.events,[4,n.store.put({sessionId:e,events:[t]})]):[3,5];case 4:return s.sent(),[3,7];case 5:return o=r.events.concat(t),[4,n.store.put({sessionId:e,events:o})];case 6:s.sent(),s.label=7;case 7:return[4,n.done];case 8:return s.sent(),i?[4,this.storeSendingEvents(e,i)]:[2,void 0];case 9:return(a=s.sent())?[2,{events:i,sessionId:e,sequenceId:a}]:[2,void 0];case 10:return c=s.sent(),Tt(this.loggerProvider,"".concat(Ye,": ").concat(c),c),[3,11];case 11:return[2,void 0]}})})},n.storeSendingEvents=function(e,t){return o(n,void 0,void 0,function(){var n;return s(this,function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,this.db.put(xt,{sessionId:e,events:t})];case 1:return[2,r.sent()];case 2:return n=r.sent(),Tt(this.loggerProvider,"".concat(Ye,": ").concat(n),n),[3,3];case 3:return[2,void 0]}})})},n.cleanUpSessionEventsStore=function(e,t){return o(n,void 0,void 0,function(){var e;return s(this,function(n){switch(n.label){case 0:if(!t)return[2];n.label=1;case 1:return n.trys.push([1,3,,4]),[4,this.db.delete(xt,t)];case 2:return n.sent(),[3,4];case 3:return e=n.sent(),Tt(this.loggerProvider,"".concat(Ye,": ").concat(e),e),[3,4];case 4:return[2]}})})},n.db=t.db,n}return t(n,e),n.new=function(e,t){return o(this,void 0,void 0,function(){var r,o,a,c;return s(this,function(s){switch(s.label){case 0:return s.trys.push([0,2,,3]),r="replay"===e?"":"_".concat(e),o="".concat(t.apiKey.substring(0,10),"_amp_session_replay_events").concat(r),[4,Dt(o)];case 1:return a=s.sent(),[2,new n(i(i({},t),{db:a}))];case 2:return c=s.sent(),Tt(t.loggerProvider,"".concat(Ye,": ").concat(c),c),[3,3];case 3:return[2]}})})},n.prototype.getCurrentSequenceEvents=function(e){return o(this,void 0,void 0,function(){var t,n,r,i,o,c,l;return s(this,function(s){switch(s.label){case 0:return e?[4,this.db.get("sessionCurrentSequence",e)]:[3,2];case 1:return(i=s.sent())?[2,[i]]:[2,void 0];case 2:t=[],s.label=3;case 3:return s.trys.push([3,8,9,10]),[4,this.db.getAll("sessionCurrentSequence")];case 4:n=a.apply(void 0,[s.sent()]),r=n.next(),s.label=5;case 5:if(r.done)return[3,7];i=r.value,t.push(i),s.label=6;case 6:return r=n.next(),[3,5];case 7:return[3,10];case 8:return o=s.sent(),c={error:o},[3,10];case 9:try{r&&!r.done&&(l=n.return)&&l.call(n)}finally{if(c)throw c.error}return[7];case 10:return[2,t]}})})},n}(_t),Nt=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t.finalizedSequences={},t.sequences={},t.sequenceId=0,t}return t(n,e),n.prototype.resetCurrentSequence=function(e){this.sequences[e]=[]},n.prototype.addSequence=function(e){var t=this.sequenceId++,n=l([],c(this.sequences[e]),!1);return this.finalizedSequences[t]={sessionId:e,events:n},this.resetCurrentSequence(e),{sequenceId:t,events:n,sessionId:e}},n.prototype.getSequencesToSend=function(){return o(this,void 0,void 0,function(){return s(this,function(e){return[2,Object.entries(this.finalizedSequences).map(function(e){var t=c(e,2),n=t[0],r=t[1],i=r.sessionId,o=r.events;return{sequenceId:Number(n),sessionId:i,events:o}})]})})},n.prototype.storeCurrentSequence=function(e){return o(this,void 0,void 0,function(){return s(this,function(t){return this.sequences[e]?[2,this.addSequence(e)]:[2,void 0]})})},n.prototype.addEventToCurrentSequence=function(e,t){return o(this,void 0,void 0,function(){var n;return s(this,function(r){return this.sequences[e]||this.resetCurrentSequence(e),this.shouldSplitEventsList(this.sequences[e],t)&&(n=this.addSequence(e)),this.sequences[e].push(t),[2,n]})})},n.prototype.storeSendingEvents=function(e,t){return o(this,void 0,void 0,function(){return s(this,function(n){return this.finalizedSequences[this.sequenceId]={sessionId:e,events:t},[2,this.sequenceId++]})})},n.prototype.cleanUpSessionEventsStore=function(e,t){return o(this,void 0,void 0,function(){return s(this,function(e){return void 0!==t&&delete this.finalizedSequences[t],[2]})})},n}(_t),qt=function(e){var t=e.config,n=e.minInterval,r=e.maxInterval,a=e.type,c=e.payloadBatcher,l=e.storeType;return o(void 0,void 0,void 0,function(){function e(e){return void 0===e&&(e=!1),o(this,void 0,void 0,function(){return s(this,function(t){return[2,u.flush(e)]})})}var u,d,f,v,h,g,p,m,y;return s(this,function(b){switch(b.label){case 0:return u=new et(i(i({},t),{loggerProvider:t.loggerProvider,payloadBatcher:c})),d=function(){return new Nt({loggerProvider:t.loggerProvider,maxInterval:r,minInterval:n})},f=function(){return o(void 0,void 0,void 0,function(){var e;return s(this,function(i){switch(i.label){case 0:return[4,Lt.new(a,{loggerProvider:t.loggerProvider,minInterval:n,maxInterval:r,apiKey:t.apiKey})];case 1:return(e=i.sent())?[2,e]:(t.loggerProvider.log("Failed to initialize idb store, falling back to memory store."),[2,d()])}})})},"idb"!==l?[3,2]:[4,f()];case 1:return h=b.sent(),[3,3];case 2:h=d(),b.label=3;case 3:return v=h,g=function(e){var n=e.events,r=e.sessionId,i=e.deviceId,c=e.sequenceId;t.debugMode&&le().then(function(e){var n=e.totalStorageSize,r=e.percentOfQuota,i=e.usageDetails;t.loggerProvider.debug("Total storage size: ".concat(n," KB, percentage of quota: ").concat(r,"%, usage details: ").concat(i))}).catch(function(){}),u.sendEventsList({events:n,sessionId:r,flushMaxRetries:t.flushMaxRetries,apiKey:t.apiKey,deviceId:i,sampleRate:t.sampleRate,serverZone:t.serverZone,version:t.version,type:a,onComplete:function(){return o(void 0,void 0,void 0,function(){return s(this,function(e){switch(e.label){case 0:return[4,v.cleanUpSessionEventsStore(r,c)];case 1:return e.sent(),[2]}})})}})},p=function(e){var n=e.sessionId,r=e.deviceId;v.storeCurrentSequence(n).then(function(e){e&&g({sequenceId:e.sequenceId,events:e.events,sessionId:e.sessionId,deviceId:r})}).catch(function(e){t.loggerProvider.warn("Failed to get current sequence of session replay events for session:",e)})},m=function(e){var t=e.deviceId;return o(void 0,void 0,void 0,function(){var e;return s(this,function(n){switch(n.label){case 0:return[4,v.getSequencesToSend()];case 1:return(e=n.sent())&&e.forEach(function(e){g({sequenceId:e.sequenceId,events:e.events,sessionId:e.sessionId,deviceId:t})}),[2]}})})},y=function(e){var n=e.event,r=e.sessionId,i=e.deviceId;v.addEventToCurrentSequence(r,n.data).then(function(e){return e&&g({sequenceId:e.sequenceId,events:e.events,sessionId:e.sessionId,deviceId:i})}).catch(function(e){t.loggerProvider.warn("Failed to add event to session replay capture:",e)})},[2,{sendCurrentSequenceEvents:p,addEvent:y,sendStoredEvents:m,flush:e}]}})})},Ut=function(){function e(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=new Map;e.forEach(function(e){n.set(e.name,e.manager)}),this.managers=n}return e.prototype.sendStoredEvents=function(e){return o(this,void 0,void 0,function(){var t;return s(this,function(n){switch(n.label){case 0:return t=[],this.managers.forEach(function(n){t.push(n.sendStoredEvents(e))}),[4,Promise.all(t)];case 1:return n.sent(),[2]}})})},e.prototype.addEvent=function(e){var t,n=e.sessionId,r=e.event,i=e.deviceId;null===(t=this.managers.get(r.type))||void 0===t||t.addEvent({sessionId:n,event:r,deviceId:i})},e.prototype.sendCurrentSequenceEvents=function(e){var t=e.sessionId,n=e.deviceId;this.managers.forEach(function(e){e.sendCurrentSequenceEvents({sessionId:t,deviceId:n})})},e.prototype.flush=function(e){return o(this,void 0,void 0,function(){var t;return s(this,function(n){switch(n.label){case 0:return t=[],this.managers.forEach(function(n){t.push(n.flush(e))}),[4,Promise.all(t)];case 1:return n.sent(),[2]}})})},e}();function jt(e,t){if(Rt=new Date,e.nodeType!==Node.ELEMENT_NODE)throw new Error("Can't generate CSS selector for non-element node type.");if("html"===e.tagName.toLowerCase())return"html";var n={root:document.body,idName:function(e){return!0},className:function(e){return!0},tagName:function(e){return!0},attr:function(e,t){return!1},seedMinLength:1,optimizedMinLength:2,threshold:1e3,maxNumberOfTries:1e4,timeoutMs:void 0};Pt=i(i({},n),t),kt=function(e,t){if(e.nodeType===Node.DOCUMENT_NODE)return e;if(e===t.root)return e.ownerDocument;return e}(Pt.root,n);var r=At(e,"all",function(){return At(e,"two",function(){return At(e,"one",function(){return At(e,"none")})})});if(r){var o=Vt(Qt(r,e));return o.length>0&&(r=o[0]),Bt(r)}throw new Error("Selector was not found.")}function At(e,t,n){for(var r=null,i=[],o=e,s=0,u=function(){var e,u,d=(new Date).getTime()-Rt.getTime();if(void 0!==Pt.timeoutMs&&d>Pt.timeoutMs)throw new Error("Timeout: Can't find a unique selector after ".concat(d,"ms"));var f=Ht(function(e){var t=e.getAttribute("id");if(t&&Pt.idName(t))return{name:"#"+CSS.escape(t),penalty:0};return null}(o))||Ht.apply(void 0,l([],c(function(e){var t=Array.from(e.attributes).filter(function(e){return Pt.attr(e.name,e.value)});return t.map(function(e){return{name:"[".concat(CSS.escape(e.name),'="').concat(CSS.escape(e.value),'"]'),penalty:.5}})}(o)),!1))||Ht.apply(void 0,l([],c(function(e){var t=Array.from(e.classList).filter(Pt.className);return t.map(function(e){return{name:"."+CSS.escape(e),penalty:1}})}(o)),!1))||Ht(function(e){var t=e.tagName.toLowerCase();if(Pt.tagName(t))return{name:t,penalty:2};return null}(o))||[{name:"*",penalty:3}],v=function(e){var t=e.parentNode;if(!t)return null;var n=t.firstChild;if(!n)return null;var r=0;for(;n&&(n.nodeType===Node.ELEMENT_NODE&&r++,n!==e);)n=n.nextSibling;return r}(o);if("all"==t)v&&(f=f.concat(f.filter(zt).map(function(e){return Kt(e,v)})));else if("two"==t)f=f.slice(0,1),v&&(f=f.concat(f.filter(zt).map(function(e){return Kt(e,v)})));else if("one"==t){var h=c(f=f.slice(0,1),1)[0];v&&zt(h)&&(f=[Kt(h,v)])}else"none"==t&&(f=[{name:"*",penalty:3}],v&&(f=[Kt(f[0],v)]));try{for(var g=(e=void 0,a(f)),p=g.next();!p.done;p=g.next()){(h=p.value).level=s}}catch(t){e={error:t}}finally{try{p&&!p.done&&(u=g.return)&&u.call(g)}finally{if(e)throw e.error}}if(i.push(f),i.length>=Pt.seedMinLength&&(r=Ft(i,n)))return"break";o=o.parentElement,s++};o;){if("break"===u())break}return r||(r=Ft(i,n)),!r&&n?n():r}function Ft(e,t){var n,r,i=Vt(Gt(e));if(i.length>Pt.threshold)return t?t():null;try{for(var o=a(i),s=o.next();!s.done;s=o.next()){var c=s.value;if($t(c))return c}}catch(e){n={error:e}}finally{try{s&&!s.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}return null}function Bt(e){for(var t=e[0],n=t.name,r=1;r<e.length;r++){var i=e[r].level||0;n=t.level===i-1?"".concat(e[r].name," > ").concat(n):"".concat(e[r].name," ").concat(n),t=e[r]}return n}function Wt(e){return e.map(function(e){return e.penalty}).reduce(function(e,t){return e+t},0)}function $t(e){var t=Bt(e);switch(kt.querySelectorAll(t).length){case 0:throw new Error("Can't select any node with this selector: ".concat(t));case 1:return!0;default:return!1}}function Kt(e,t){return{name:e.name+":nth-child(".concat(t,")"),penalty:e.penalty+1}}function zt(e){return"html"!==e.name&&!e.name.startsWith("#")}function Ht(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=e.filter(Jt);return n.length>0?n:null}function Jt(e){return null!=e}function Gt(e,t){var n,r,i,o,c,l;return void 0===t&&(t=[]),s(this,function(s){switch(s.label){case 0:if(!(e.length>0))return[3,9];s.label=1;case 1:s.trys.push([1,6,7,8]),n=a(e[0]),r=n.next(),s.label=2;case 2:return r.done?[3,5]:(i=r.value,[5,a(Gt(e.slice(1,e.length),t.concat(i)))]);case 3:s.sent(),s.label=4;case 4:return r=n.next(),[3,2];case 5:return[3,8];case 6:return o=s.sent(),c={error:o},[3,8];case 7:try{r&&!r.done&&(l=n.return)&&l.call(n)}finally{if(c)throw c.error}return[7];case 8:return[3,11];case 9:return[4,t];case 10:s.sent(),s.label=11;case 11:return[2]}})}function Vt(e){return l([],c(e),!1).sort(function(e,t){return Wt(e)-Wt(t)})}function Qt(e,t,n){var r,i,o;return void 0===n&&(n={counter:0,visited:new Map}),s(this,function(s){switch(s.label){case 0:if(!(e.length>2&&e.length>Pt.optimizedMinLength))return[3,5];r=1,s.label=1;case 1:return r<e.length-1?n.counter>Pt.maxNumberOfTries?[2]:(n.counter+=1,(i=l([],c(e),!1)).splice(r,1),o=Bt(i),n.visited.has(o)?[2]:$t(i)&&function(e,t){return kt.querySelector(Bt(e))===t}(i,t)?[4,i]:[3,4]):[3,5];case 2:return s.sent(),n.visited.set(o,!0),[5,a(Qt(i,t,n))];case 3:s.sent(),s.label=4;case 4:return r++,[3,1];case 5:return[2]}})}var Zt=function(e){var t=e.version,n=e.events,r=[];return n.forEach(function(e){var t=JSON.parse(e);t.count=1,"click"===t.type&&r.push(t)}),{version:t,events:r}},Yt=function(e){var t=e.version,n=e.events,r=[];n.forEach(function(e){var t=JSON.parse(e);"click"===t.type&&r.push(t)});var o=r.reduce(function(e,t){var n=t.x,r=t.y,o=t.selector,s=t.timestamp,a=s-s%36e5,c="".concat(n,":").concat(r,":").concat(null!=o?o:"",":").concat(a);return e[c]?e[c].count+=1:e[c]=i(i({},t),{timestamp:a,count:1}),e},{});return{version:t,events:Object.values(o)}},Xt=function(e,t){var n=this;this.createHook=function(e){var t=e.eventsManager,r=e.sessionId,i=e.deviceIdFn,o=e.mirror,s=e.ugcFilterRules,a=e.performanceOptions;return function(e){if(e.type===he.Click){var c=h();if(c){var l=c.location,u=c.innerHeight,d=c.innerWidth;if(l){var f=e.x,v=e.y;if(void 0!==f&&void 0!==v){var g,p=o.getNode(e.id);if(p)try{g=jt(p,a)}catch(e){n.logger.debug("error resolving selector from finder")}var m=ce(l.href,s),y={x:f+n.scrollWatcher.currentScrollX,y:v+n.scrollWatcher.currentScrollY,selector:g,viewportHeight:u,viewportWidth:d,pageUrl:m,timestamp:Date.now(),type:"click"},b=i();b&&t.addEvent({sessionId:r,event:{type:"interaction",data:JSON.stringify(y)},deviceId:b})}}}}}},this.logger=e,this.scrollWatcher=t};function en(){var e=h();return(null==e?void 0:e.innerHeight)||document.documentElement&&document.documentElement.clientHeight||0}function tn(){var e=h();return(null==e?void 0:e.innerWidth)||document.documentElement&&document.documentElement.clientWidth||0}var nn=function(){function e(e,t){var n=h();n&&n.navigator&&"function"==typeof n.navigator.sendBeacon?this.sendBeacon=function(e,t){try{if(n.navigator.sendBeacon(e,JSON.stringify(t)))return!0}catch(e){}return!1}:this.sendBeacon=function(){return!1},this.sendXhr=function(e,t){var n=new XMLHttpRequest;return n.open("POST",e,!0),n.setRequestHeader("Accept","*/*"),n.send(JSON.stringify(t)),!0},this.basePageUrl=se(t.serverZone,t.trackServerUrl),this.apiKey=t.apiKey,this.context=e}return e.prototype.send=function(e,t){var n=this.context,r=n.sessionId,i=n.type,o=new URLSearchParams({device_id:e,session_id:String(r),type:String(i),api_key:this.apiKey}),s="".concat(this.basePageUrl,"?").concat(o.toString());this.sendBeacon(s,t)||this.sendXhr(s,t)},e}(),rn=function(){function e(e,t){var n=this;this.timestamp=Date.now(),this.hook=function(e){n.update(e)},this.send=function(e){return function(t){var r,i,o=e(),s=h();s&&o&&n.transport.send(o,{version:1,events:[{maxScrollX:n._maxScrollX,maxScrollY:n._maxScrollY,maxScrollWidth:n._maxScrollWidth,maxScrollHeight:n._maxScrollHeight,viewportHeight:en(),viewportWidth:tn(),pageUrl:ce(s.location.href,null!==(i=null===(r=n.config.interactionConfig)||void 0===r?void 0:r.ugcFilterRules)&&void 0!==i?i:[]),timestamp:n.timestamp,type:"scroll"}]})}},this._maxScrollX=0,this._maxScrollY=0,this._currentScrollX=0,this._currentScrollY=0,this._maxScrollWidth=tn(),this._maxScrollHeight=en(),this.config=t,this.transport=e}return e.default=function(t,n){return new e(new nn(t,n),n)},Object.defineProperty(e.prototype,"maxScrollX",{get:function(){return this._maxScrollX},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"maxScrollY",{get:function(){return this._maxScrollY},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"maxScrollWidth",{get:function(){return this._maxScrollWidth},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"maxScrollHeight",{get:function(){return this._maxScrollHeight},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"currentScrollX",{get:function(){return this._currentScrollX},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"currentScrollY",{get:function(){return this._currentScrollY},enumerable:!1,configurable:!0}),e.prototype.update=function(e){var t=Date.now();if(this._currentScrollX=e.x,this._currentScrollY=e.y,e.x>this._maxScrollX){var n=tn();this._maxScrollX=e.x;var r=e.x+n;r>this._maxScrollWidth&&(this._maxScrollWidth=r),this.timestamp=t}if(e.y>this._maxScrollY){var i=en();this._maxScrollY=e.y;var o=e.y+i;o>this._maxScrollHeight&&(this._maxScrollHeight=o),this.timestamp=t}},e}(),on=function(e){var t=e.sessionId,n=e.deviceId;this.deviceId=n,this.sessionId=t,t&&n&&(this.sessionReplayId=function(e,t){return"".concat(t,"/").concat(e)}(t,n))},sn=function(){var e=this;this.dbs={},this.createStore=function(t){return o(e,void 0,void 0,function(){return s(this,function(e){switch(e.label){case 0:return[4,vt(t,1,{upgrade:function(e){e.objectStoreNames.contains("sessionTargetingMatch")||e.createObjectStore("sessionTargetingMatch",{keyPath:"sessionId"})}})];case 1:return[2,e.sent()]}})})},this.openOrCreateDB=function(t){return o(e,void 0,void 0,function(){var e,n;return s(this,function(r){switch(r.label){case 0:return this.dbs&&this.dbs[t]?[2,this.dbs[t]]:(e="".concat(t.substring(0,10),"_amp_session_replay_targeting"),[4,this.createStore(e)]);case 1:return n=r.sent(),this.dbs[t]=n,[2,n]}})})},this.getTargetingMatchForSession=function(t){var n=t.loggerProvider,r=t.apiKey,i=t.sessionId;return o(e,void 0,void 0,function(){var e,t,o,a;return s(this,function(s){switch(s.label){case 0:return s.trys.push([0,3,,4]),[4,this.openOrCreateDB(r)];case 1:return e=s.sent(),t=String(i),[4,e.get("sessionTargetingMatch",t)];case 2:return[2,null==(o=s.sent())?void 0:o.targetingMatch];case 3:return a=s.sent(),Tt(n,"Failed to get targeting match for session id ".concat(i,": ").concat(a),a),[3,4];case 4:return[2,void 0]}})})},this.storeTargetingMatchForSession=function(t){var n=t.loggerProvider,r=t.apiKey,i=t.sessionId,a=t.targetingMatch;return o(e,void 0,void 0,function(){var e,t,o;return s(this,function(s){switch(s.label){case 0:return s.trys.push([0,3,,4]),[4,this.openOrCreateDB(r)];case 1:return e=s.sent(),t=String(i),[4,e.put("sessionTargetingMatch",{targetingMatch:a,sessionId:t,lastUpdated:Date.now()})];case 2:return[2,s.sent()];case 3:return o=s.sent(),Tt(n,"Failed to store targeting match for session id ".concat(i,": ").concat(o),o),[3,4];case 4:return[2,void 0]}})})},this.clearStoreOfOldSessions=function(t){var n=t.loggerProvider,r=t.apiKey,i=t.currentSessionId;return o(e,void 0,void 0,function(){var e,t,o,a,c,l,u,d;return s(this,function(s){switch(s.label){case 0:return s.trys.push([0,8,,9]),[4,this.openOrCreateDB(r)];case 1:return e=s.sent(),t=String(i),[4,(o=e.transaction("sessionTargetingMatch","readwrite")).store.getAll()];case 2:a=s.sent(),c=0,s.label=3;case 3:return c<a.length?(l=a[c],u=Date.now()-l.lastUpdated,l.sessionId!==t&&u>1728e5?[4,o.store.delete(l.sessionId)]:[3,5]):[3,6];case 4:s.sent(),s.label=5;case 5:return c++,[3,3];case 6:return[4,o.done];case 7:return s.sent(),[3,9];case 8:return d=s.sent(),Tt(n,"Failed to clear old targeting matches for sessions: ".concat(d),d),[3,9];case 9:return[2]}})})}},an=new sn,cn=function(e){var t=e.sessionId,n=e.targetingConfig,r=e.loggerProvider,a=e.apiKey,c=e.targetingParams;return o(void 0,void 0,void 0,function(){var e,o,l,u;return s(this,function(s){switch(s.label){case 0:return[4,an.clearStoreOfOldSessions({loggerProvider:r,apiKey:a,currentSessionId:t})];case 1:return s.sent(),[4,an.getTargetingMatchForSession({loggerProvider:r,apiKey:a,sessionId:t})];case 2:if(!0===s.sent())return[2,!0];e=!0,s.label=3;case 3:return s.trys.push([3,6,,7]),[4,import("./index-min3.js")];case 4:return[4,(0,s.sent().evaluateTargeting)(i(i({},c),{flag:n,sessionId:"string"==typeof t?parseInt(t,10):t,apiKey:a,loggerProvider:r}))];case 5:return(o=s.sent())&&o.sr_targeting_config&&(e="on"===o.sr_targeting_config.key),an.storeTargetingMatchForSession({loggerProvider:r,apiKey:a,sessionId:t,targetingMatch:e}),[3,7];case 6:return l=s.sent(),u=l,r.warn(u.message),[3,7];case 7:return[2,e]}})})};function ln(e){return void 0===e&&(e={}),{name:"amplitude/url-tracking@1",observer:function(t,n,r){var o,s,a,c=i(i({},e),r),l=c.ugcFilterRules||[],u=null!==(o=c.enablePolling)&&void 0!==o&&o,d=null!==(s=c.pollingInterval)&&void 0!==s?s:1e3,f=null!==(a=c.captureDocumentTitle)&&void 0!==a&&a;if(!n)return function(){};var v=void 0,h="__amplitude_url_tracking_patched__",g="__amplitude_url_tracking_reset__",p=function(){return n.location&&n.location.href||""},m=function(){var e=p();if(void 0===v||e!==v){v=e;var r=function(){var e=n.innerHeight,t=n.innerWidth,r=n.document,i=p(),o="";return f&&(o=(null==r?void 0:r.title)||""),{href:l.length>0?ce(i,l):i,title:o,viewportHeight:e,viewportWidth:t,type:"url-change-event"}}();t(r)}},y=function(e){var t=function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];var i=e.apply(this,t);return n[g]||m(),i};return t[h]=!0,t},b=function(){m()};if(u){var S=n.setInterval(function(){m()},d);return m(),function(){S&&n.clearInterval(S)}}if(n.history){var w=n.history.pushState.bind(n.history),I=n.history.replaceState.bind(n.history);return n.history.pushState[h]||(n.history.pushState=y(w),n.history.replaceState=y(I)),n.addEventListener("popstate",m),n.addEventListener("hashchange",b),m(),function(){n[g]=!0,n.removeEventListener("popstate",m),n.removeEventListener("hashchange",b)}}return n.addEventListener("hashchange",b),m(),function(){n.removeEventListener("hashchange",b)}},options:e}}ln();var un,dn,fn,vn=function(){function e(){var e=this;this.name="@amplitude/session-replay-browser",this.recordCancelCallback=null,this.eventCount=0,this.sessionTargetingMatch=!1,this.pageLeaveFns=[],this.recordFunction=null,this.teardownEventListeners=function(t){var n=h();n&&(n.removeEventListener("blur",e.blurListener),n.removeEventListener("focus",e.focusListener),!t&&n.addEventListener("blur",e.blurListener),!t&&n.addEventListener("focus",e.focusListener),n.self&&"onpagehide"in n.self?(n.removeEventListener("pagehide",e.pageLeaveListener),!t&&n.addEventListener("pagehide",e.pageLeaveListener)):(n.removeEventListener("beforeunload",e.pageLeaveListener),!t&&n.addEventListener("beforeunload",e.pageLeaveListener)))},this.blurListener=function(){e.sendEvents()},this.focusListener=function(){e.recordEvents(!1)},this.pageLeaveListener=function(t){e.pageLeaveFns.forEach(function(e){e(t)})},this.evaluateTargetingAndCapture=function(t,n,i){return void 0===n&&(n=!1),void 0===i&&(i=!1),o(e,void 0,void 0,function(){var e,o;return s(this,function(s){switch(s.label){case 0:if(!this.identifiers||!this.identifiers.sessionId||!this.config)return this.identifiers&&!this.identifiers.sessionId?this.loggerProvider.log("Session ID has not been set yet, cannot evaluate targeting for Session Replay."):this.loggerProvider.warn("Session replay init has not been called, cannot evaluate targeting."),[2];if(!this.config.targetingConfig){if(!n)return this.loggerProvider.log("No targeting config set, skipping initialization/recording for event."),[2];this.loggerProvider.log("Targeting config has not been set yet, cannot evaluate targeting.")}return this.lastTargetingParams=t,!this.config.targetingConfig||this.sessionTargetingMatch?[3,2]:((e=t.event)&&Object.values(r).includes(e.event_type)&&(e=void 0),o=this,[4,cn({sessionId:this.identifiers.sessionId,targetingConfig:this.config.targetingConfig,loggerProvider:this.loggerProvider,apiKey:this.config.apiKey,targetingParams:{userProperties:t.userProperties,event:e}})]);case 1:o.sessionTargetingMatch=s.sent(),this.loggerProvider.debug(JSON.stringify({name:"targeted replay capture config",sessionTargetingMatch:this.sessionTargetingMatch,event:e,targetingParams:t},null,2)),s.label=2;case 2:return n?(this.initialize(!0),[3,5]):[3,3];case 3:return!i&&this.recordCancelCallback?[3,5]:(this.loggerProvider.log("Recording events for session due to forceRestart or no ongoing recording."),[4,this.recordEvents()]);case 4:s.sent(),s.label=5;case 5:return[2]}})})},this.addCustomRRWebEvent=function(t,n,r){return void 0===n&&(n={}),void 0===r&&(r=!0),o(e,void 0,void 0,function(){var e,o,a,c;return s(this,function(s){switch(s.label){case 0:return s.trys.push([0,3,,4]),e=void 0,(o=this.config)&&t!==V.METADATA?(e={config:ue(o),version:Xe},r?[4,le()]:[3,2]):[3,2];case 1:a=s.sent(),e=i(i({},a),e),s.label=2;case 2:return this.recordCancelCallback&&this.recordFunction?this.recordFunction.addCustomEvent(t,i(i({},n),e)):this.loggerProvider.debug("Not able to add custom replay capture event ".concat(t," due to no ongoing recording.")),[3,4];case 3:return c=s.sent(),this.loggerProvider.debug("Error while adding custom replay capture event: ",c),[3,4];case 4:return[2]}})})},this.stopRecordingEvents=function(){var t;try{e.loggerProvider.log("Session Replay capture stopping."),e.recordCancelCallback&&e.recordCancelCallback(),e.recordCancelCallback=null,null===(t=e.networkObservers)||void 0===t||t.stop()}catch(t){var n=t;e.loggerProvider.warn("Error occurred while stopping replay capture: ".concat(n.toString()))}},this.loggerProvider=new ne(new b)}return e.prototype.init=function(e,t){return m(this._init(e,t))},e.prototype._init=function(e,t){var n,r,a,u,d,f,v;return o(this,void 0,void 0,function(){var o,g,p,m,y,S,w,I,C,E,P,k,R,_,T,O,x,M;return s(this,function(s){switch(s.label){case 0:return this.loggerProvider=new ne(t.loggerProvider||new b),Object.prototype.hasOwnProperty.call(t,"logLevel")&&this.loggerProvider.enable(t.logLevel),this.identifiers=new on({sessionId:t.sessionId,deviceId:t.deviceId}),o=this,[4,pe(e,t)];case 1:return o.joinedConfigGenerator=s.sent(),[4,this.joinedConfigGenerator.generateJoinedConfig()];case 2:g=s.sent(),p=g.joinedConfig,m=g.localConfig,y=g.remoteConfig,this.config=p,this.setMetadata(t.sessionId,p,m,y,null===(n=t.version)||void 0===n?void 0:n.version,Xe,null===(r=t.version)||void 0===r?void 0:r.type),t.sessionId&&(null===(a=this.config.interactionConfig)||void 0===a?void 0:a.enabled)&&(S=rn.default({sessionId:t.sessionId,type:"interaction"},this.config),this.pageLeaveFns=[S.send(this.getDeviceId.bind(this)).bind(S)],this.scrollHook=S.hook.bind(S),this.clickHandler=new Xt(this.loggerProvider,S)),w=[],"idb"!==(I=this.config.storeType)||(null===(u=h())||void 0===u?void 0:u.indexedDB)||(I="memory",this.loggerProvider.warn("Could not use preferred indexedDB storage, reverting to in memory option.")),this.loggerProvider.log("Using ".concat(I," for event storage.")),s.label=3;case 3:return s.trys.push([3,5,,6]),[4,qt({config:this.config,type:"replay",storeType:I})];case 4:return C=s.sent(),w.push({name:"replay",manager:C}),[3,6];case 5:return E=s.sent(),_=E,this.loggerProvider.warn("Error occurred while creating replay events manager: ".concat(_.toString())),[3,6];case 6:if(!(null===(d=this.config.interactionConfig)||void 0===d?void 0:d.enabled))return[3,10];P=this.config.interactionConfig.batch?Yt:Zt,s.label=7;case 7:return s.trys.push([7,9,,10]),[4,qt({config:this.config,type:"interaction",minInterval:null!==(f=this.config.interactionConfig.trackEveryNms)&&void 0!==f?f:3e4,maxInterval:6e4,payloadBatcher:P,storeType:I})];case 8:return k=s.sent(),w.push({name:"interaction",manager:k}),[3,10];case 9:return R=s.sent(),_=R,this.loggerProvider.warn("Error occurred while creating interaction events manager: ".concat(_.toString())),[3,10];case 10:return this.eventsManager=new(Ut.bind.apply(Ut,l([void 0],c(w),!1))),this.eventCompressor&&this.eventCompressor.terminate(),T=void 0,O=h(),this.config.useWebWorker&&O&&O.Worker?[4,import("./index-min2.js")]:[3,12];case 11:x=s.sent().compressionScript,T=x,s.label=12;case 12:return this.eventCompressor=new Qe(this.eventsManager,this.config,this.getDeviceId(),T),[4,this.initializeNetworkObservers()];case 13:return s.sent(),(null===(v=h())||void 0===v?void 0:v.opener)&&(function(e,t){var n,r=e;if(!0!==r[G]){r[G]=!0;var i=null!==(n=null==t?void 0:t.scriptUrl)&&void 0!==n?n:"https://cdn.amplitude.com/libs/background-capture-1.0.0-alpha.2.js.gz",o=null,s=function(t,n){var r,i;"background-capture-complete"===t&&(null===(i=null===(r=e.logger)||void 0===r?void 0:r.debug)||void 0===i||i.call(r,"Background capture complete"),e.notify({action:"background-capture-complete",data:n}))};e.registerActionHandler("initialize-background-capture",function(){var t,n;null===(n=null===(t=e.logger)||void 0===t?void 0:t.debug)||void 0===n||n.call(t,"Initializing background capture (external script)");var r=new URL(i,e.endpoint).toString();e.loadScriptOnce(r).then(function(){var t,n,r;null===(n=null===(t=e.logger)||void 0===t?void 0:t.debug)||void 0===n||n.call(t,"Background capture script loaded (external)"),o=null===(r=null===window||void 0===window?void 0:window.amplitudeBackgroundCapture)||void 0===r?void 0:r.call(window,{messenger:e,onBackgroundCapture:s}),e.notify({action:"background-capture-loaded"})}).catch(function(){var t;null===(t=e.logger)||void 0===t||t.warn("Failed to initialize background capture")})}),e.registerActionHandler("close-background-capture",function(){var e;null===(e=null==o?void 0:o.close)||void 0===e||e.call(o),o=null})}}(M=J()),M.setup(i({logger:this.loggerProvider},this.config.serverZone&&{endpoint:$[this.config.serverZone]}))),this.loggerProvider.log("Installing @amplitude/session-replay-browser."),this.teardownEventListeners(!1),[4,this.evaluateTargetingAndCapture({userProperties:t.userProperties},!0)];case 14:return s.sent(),[2]}})})},e.prototype.setSessionId=function(e,t){return m(this.asyncSetSessionId(e,t))},e.prototype.asyncSetSessionId=function(e,t,n){var r;return o(this,void 0,void 0,function(){var i,o,a;return s(this,function(s){switch(s.label){case 0:return this.sessionTargetingMatch=!1,this.lastShouldRecordDecision=void 0,(i=this.identifiers&&this.identifiers.sessionId)&&this.sendEvents(i),o=t||this.getDeviceId(),this.identifiers=new on({sessionId:e,deviceId:o}),this.joinedConfigGenerator&&i?[4,this.joinedConfigGenerator.generateJoinedConfig()]:[3,2];case 1:a=s.sent().joinedConfig,this.config=a,s.label=2;case 2:return(null===(r=this.config)||void 0===r?void 0:r.targetingConfig)?[4,this.evaluateTargetingAndCapture({userProperties:null==n?void 0:n.userProperties},!1,!0)]:[3,4];case 3:return s.sent(),[3,6];case 4:return[4,this.recordEvents()];case 5:s.sent(),s.label=6;case 6:return[2]}})})},e.prototype.getSessionReplayProperties=function(){var e,t=this.config,n=this.identifiers;if(!t||!n)return this.loggerProvider.warn("Session replay init has not been called, cannot get session replay properties."),{};var r=this.getShouldRecord(),i={};return r&&((e={})[Z]=n.sessionReplayId?n.sessionReplayId:null,i=e,t.debugMode&&(i[ee]=JSON.stringify({appHash:q(t.apiKey).toString()}))),this.addCustomRRWebEvent(V.GET_SR_PROPS,{shouldRecord:r,eventProperties:i},10===this.eventCount),10===this.eventCount&&(this.eventCount=0),this.eventCount++,i},e.prototype.sendEvents=function(e){var t,n=e||(null===(t=this.identifiers)||void 0===t?void 0:t.sessionId),r=this.getDeviceId();this.eventsManager&&n&&r&&this.eventsManager.sendCurrentSequenceEvents({sessionId:n,deviceId:r})},e.prototype.initialize=function(e){var t;return void 0===e&&(e=!1),o(this,void 0,void 0,function(){var n;return s(this,function(r){return(null===(t=this.identifiers)||void 0===t?void 0:t.sessionId)?(n=this.getDeviceId())?(this.eventsManager&&e&&this.eventsManager.sendStoredEvents({deviceId:n}),[2,this.recordEvents()]):(this.loggerProvider.log("Session is not being recorded due to lack of device id."),[2,Promise.resolve()]):(this.loggerProvider.log("Session is not being recorded due to lack of session id."),[2,Promise.resolve()])})})},e.prototype.shouldOptOut=function(){var e,t,n,r;(null===(e=this.config)||void 0===e?void 0:e.instanceName)&&(n=(r=this.config.instanceName,void 0===r&&(r=d),N.getInstance(r)).identityStore.getIdentity().optOut);return void 0!==n?n:null===(t=this.config)||void 0===t?void 0:t.optOut},e.prototype.getShouldRecord=function(){if(!this.identifiers||!this.config||!this.identifiers.sessionId)return this.loggerProvider.warn("Session is not being recorded due to lack of config, please call sessionReplay.init."),!1;if(!this.config.captureEnabled)return this.loggerProvider.log("Session ".concat(this.identifiers.sessionId," not being captured due to capture being disabled for project or because the remote config could not be fetched.")),!1;if(this.shouldOptOut())return this.loggerProvider.log("Opting session ".concat(this.identifiers.sessionId," out of recording due to optOut config.")),!1;var e,t,n,r=!1,i="",o=!1;this.config.targetingConfig?this.sessionTargetingMatch?(i="Capturing replays for session ".concat(this.identifiers.sessionId," due to matching targeting conditions."),this.loggerProvider.log(i),r=!0,o=!0):(i="Not capturing replays for session ".concat(this.identifiers.sessionId," due to not matching targeting conditions."),this.loggerProvider.log(i),r=!1,o=!1):(e=this.identifiers.sessionId,t=this.config.sampleRate,n=q(e.toString()),31*Math.abs(n)%1e6/1e6<t)?(r=!0,o=!0):(i="Opting session ".concat(this.identifiers.sessionId," out of recording due to sample rate."),this.loggerProvider.log(i),r=!1,o=!1);return this.lastShouldRecordDecision!==r&&this.config.targetingConfig&&(this.addCustomRRWebEvent(V.TARGETING_DECISION,{message:i,sessionId:this.identifiers.sessionId,matched:o,targetingParams:this.lastTargetingParams}),this.lastShouldRecordDecision=r),r},e.prototype.getBlockSelectors=function(){var e,t,n,r=null!==(n=null===(t=null===(e=this.config)||void 0===e?void 0:e.privacyConfig)||void 0===t?void 0:t.blockSelector)&&void 0!==n?n:[];if(0!==r.length)return r},e.prototype.getMaskTextSelectors=function(){var e,t,n,r;if("conservative"===(null===(t=null===(e=this.config)||void 0===e?void 0:e.privacyConfig)||void 0===t?void 0:t.defaultMaskLevel))return"*";var i=null===(r=null===(n=this.config)||void 0===n?void 0:n.privacyConfig)||void 0===r?void 0:r.maskSelector;return i||void 0},e.prototype.getRecordingPlugins=function(e){var t,n,r,i,a,c;return o(this,void 0,void 0,function(){var o,l,u,d;return s(this,function(s){switch(s.label){case 0:o=[];try{l=ln({ugcFilterRules:(null===(n=null===(t=this.config)||void 0===t?void 0:t.interactionConfig)||void 0===n?void 0:n.ugcFilterRules)||[],enablePolling:(null===(r=this.config)||void 0===r?void 0:r.enableUrlChangePolling)||!1,pollingInterval:null===(i=this.config)||void 0===i?void 0:i.urlChangePollingInterval,captureDocumentTitle:null===(a=this.config)||void 0===a?void 0:a.captureDocumentTitle}),o.push(l)}catch(e){this.loggerProvider.warn("Failed to create URL tracking plugin:",e)}if(!(null===(c=null==e?void 0:e.console)||void 0===c?void 0:c.enabled))return[3,4];s.label=1;case 1:return s.trys.push([1,3,,4]),[4,import("./console-plugin-min.js")];case 2:return u=s.sent().getRecordConsolePlugin,o.push(u({level:e.console.levels})),[3,4];case 3:return d=s.sent(),this.loggerProvider.warn("Failed to load console plugin:",d),[3,4];case 4:return[2,o.length>0?o:void 0]}})})},e.prototype.getRecordFunction=function(){return o(this,void 0,void 0,function(){var e,t;return s(this,function(n){switch(n.label){case 0:if(this.recordFunction)return[2,this.recordFunction];n.label=1;case 1:return n.trys.push([1,3,,4]),[4,import("./rrweb-record-min.js")];case 2:return e=n.sent().record,this.recordFunction=e,[2,e];case 3:return t=n.sent(),this.loggerProvider.warn("Failed to load rrweb-record module:",t),[2,null];case 4:return[2]}})})},e.prototype.recordEvents=function(e){var t,n,r,i,a,c,l;return void 0===e&&(e=!0),o(this,void 0,void 0,function(){var o,u,d,f,v,h,g,p,m,y,b,S,w,I=this;return s(this,function(s){switch(s.label){case 0:return o=this.config,u=this.getShouldRecord(),d=null===(t=this.identifiers)||void 0===t?void 0:t.sessionId,u&&d&&o?(this.stopRecordingEvents(),[4,this.getRecordFunction()]):[2];case 1:return(f=s.sent())?[4,this.initializeNetworkObservers()]:[2];case 2:s.sent(),null===(n=this.networkObservers)||void 0===n||n.start(function(e){I.addCustomRRWebEvent(V.FETCH_REQUEST,e)}),v=o.privacyConfig,h=o.interactionConfig,g=o.loggingConfig,p=(null==h?void 0:h.enabled)?{mouseInteraction:this.eventsManager&&(null===(r=this.clickHandler)||void 0===r?void 0:r.createHook({eventsManager:this.eventsManager,sessionId:d,deviceIdFn:this.getDeviceId.bind(this),mirror:f.mirror,ugcFilterRules:null!==(i=h.ugcFilterRules)&&void 0!==i?i:[],performanceOptions:null===(a=o.performanceConfig)||void 0===a?void 0:a.interaction})),scroll:this.scrollHook}:{},m=(null==h?void 0:h.enabled)&&h.ugcFilterRules?h.ugcFilterRules:[],this.loggerProvider.log("Session Replay capture beginning for ".concat(d,".")),s.label=3;case 3:return s.trys.push([3,5,,6]),y=this,b=f,w={emit:function(e){if(I.shouldOptOut())return I.loggerProvider.log("Opting session ".concat(d," out of recording due to optOut config.")),I.stopRecordingEvents(),void I.sendEvents();e.type===ve.Meta&&(e.data.href=ce(e.data.href,m)),I.eventCompressor&&I.eventCompressor.enqueueEvent(e,d)},inlineStylesheet:o.shouldInlineStylesheet,hooks:p,maskAllInputs:!0,maskTextClass:te,blockClass:"amp-block",blockSelector:this.getBlockSelectors(),applyBackgroundColorToBlockedElements:o.applyBackgroundColorToBlockedElements,maskInputFn:oe("input",v),maskTextFn:oe("text",v),maskTextSelector:this.getMaskTextSelectors(),recordCanvas:!1,slimDOMOptions:{script:null===(c=o.omitElementTags)||void 0===c?void 0:c.script,comment:null===(l=o.omitElementTags)||void 0===l?void 0:l.comment},errorHandler:function(e){var t=e;if(t.message.includes("insertRule")&&t.message.includes("CSSStyleSheet"))throw t;if(t._external_)throw t;return I.loggerProvider.warn("Error while capturing replay: ",t.toString()),!0}},[4,this.getRecordingPlugins(g)];case 4:return y.recordCancelCallback=b.apply(void 0,[(w.plugins=s.sent(),w)]),this.addCustomRRWebEvent(V.DEBUG_INFO),e&&this.addCustomRRWebEvent(V.METADATA,this.metadata),[3,6];case 5:return S=s.sent(),this.loggerProvider.warn("Failed to initialize session replay:",S),[3,6];case 6:return[2]}})})},e.prototype.getDeviceId=function(){var e;return null===(e=this.identifiers)||void 0===e?void 0:e.deviceId},e.prototype.getSessionId=function(){var e;return null===(e=this.identifiers)||void 0===e?void 0:e.sessionId},e.prototype.flush=function(e){var t;return void 0===e&&(e=!1),o(this,void 0,void 0,function(){return s(this,function(n){return[2,null===(t=this.eventsManager)||void 0===t?void 0:t.flush(e)]})})},e.prototype.shutdown=function(){this.teardownEventListeners(!0),this.stopRecordingEvents(),this.sendEvents()},e.prototype.mapSDKType=function(e){return"plugin"===e?"@amplitude/plugin-session-replay-browser":"segment"===e?"@amplitude/segment-session-replay-plugin":null},e.prototype.setMetadata=function(e,t,n,r,i,o,s){var a=(null==e?void 0:e.toString())?q(e.toString()):void 0;this.metadata={joinedConfig:t,localConfig:n,remoteConfig:r,sessionId:e,hashValue:a,sampleRate:t.sampleRate,replaySDKType:this.mapSDKType(s),replaySDKVersion:i,standaloneSDKType:"@amplitude/session-replay-browser",standaloneSDKVersion:o}},e.prototype.initializeNetworkObservers=function(){var e,t,n;return o(this,void 0,void 0,function(){var r,i;return s(this,function(o){switch(o.label){case 0:if(!(null===(n=null===(t=null===(e=this.config)||void 0===e?void 0:e.loggingConfig)||void 0===t?void 0:t.network)||void 0===n?void 0:n.enabled)||this.networkObservers)return[3,4];o.label=1;case 1:return o.trys.push([1,3,,4]),[4,import("./observers-min.js")];case 2:return r=o.sent().NetworkObservers,this.networkObservers=new r,[3,4];case 3:return i=o.sent(),this.loggerProvider.warn("Failed to import or instantiate NetworkObservers:",i),[3,4];case 4:return[2]}})})},e}(),hn=function(e){return function(){var t=e.config||de();return{logger:t.loggerProvider,logLevel:t.logLevel}}},gn=function(){var e=new vn;return{init:E(e.init.bind(e),"init",hn(e)),evaluateTargetingAndCapture:E(e.evaluateTargetingAndCapture.bind(e),"evaluateTargetingAndRecord",hn(e)),setSessionId:E(e.setSessionId.bind(e),"setSessionId",hn(e)),getSessionId:E(e.getSessionId.bind(e),"getSessionId",hn(e)),getSessionReplayProperties:E(e.getSessionReplayProperties.bind(e),"getSessionReplayProperties",hn(e)),flush:E(e.flush.bind(e),"flush",hn(e)),shutdown:E(e.shutdown.bind(e),"shutdown",hn(e))}}(),pn=gn.init,mn=gn.setSessionId,yn=gn.getSessionId,bn=gn.getSessionReplayProperties,Sn=gn.flush,wn=gn.shutdown,In=gn.evaluateTargetingAndCapture;!function(e){e.SET="$set",e.SET_ONCE="$setOnce",e.ADD="$add",e.APPEND="$append",e.PREPEND="$prepend",e.REMOVE="$remove",e.PREINSERT="$preInsert",e.POSTINSERT="$postInsert",e.UNSET="$unset",e.CLEAR_ALL="$clearAll"}(un||(un={})),function(e){e.REVENUE_PRODUCT_ID="$productId",e.REVENUE_QUANTITY="$quantity",e.REVENUE_PRICE="$price",e.REVENUE_TYPE="$revenueType",e.REVENUE_CURRENCY="$currency",e.REVENUE="$revenue"}(dn||(dn={})),function(e){e.IDENTIFY="$identify",e.GROUP_IDENTIFY="$groupidentify",e.REVENUE="revenue_amount"}(fn||(fn={}));const Cn=[un.SET,un.SET_ONCE,un.ADD,un.APPEND,un.PREPEND,un.POSTINSERT],En="1.25.20";class Pn{constructor(e){this.name=Pn.pluginName,this.type="enrichment",this.config=null,this.sessionReplay={flush:Sn,getSessionId:yn,getSessionReplayProperties:bn,init:pn,setSessionId:mn,shutdown:wn,evaluateTargetingAndCapture:In},this.options=Object.assign({forceSessionTracking:!1},e),this.srInitOptions=this.options}setup(e,t){var n,r,i,s,a,c,l,u;return o(this,void 0,void 0,function*(){try{null==e||e.loggerProvider.log(`Installing @amplitude/plugin-session-replay, version ${En}.`),this.config=e,this.options.forceSessionTracking&&("boolean"==typeof e.defaultTracking?!1===e.defaultTracking&&(e.defaultTracking={pageViews:!1,formInteractions:!1,fileDownloads:!1,sessions:!0}):e.defaultTracking=Object.assign(Object.assign({},e.defaultTracking),{sessions:!0}));const o=(t=this.config.instanceName,void 0===t&&(t="$default_instance"),N.getInstance(t)).identityStore.getIdentity().userProperties;this.srInitOptions={instanceName:this.config.instanceName,deviceId:null!==(n=this.options.deviceId)&&void 0!==n?n:this.config.deviceId,optOut:this.config.optOut,sessionId:this.options.customSessionId?void 0:this.config.sessionId,loggerProvider:this.config.loggerProvider,logLevel:this.config.logLevel,flushMaxRetries:this.config.flushMaxRetries,serverZone:this.config.serverZone,configServerUrl:this.options.configServerUrl||(null===(r=this.config.remoteConfig)||void 0===r?void 0:r.serverUrl),trackServerUrl:this.options.trackServerUrl,sampleRate:this.options.sampleRate,privacyConfig:{blockSelector:null===(i=this.options.privacyConfig)||void 0===i?void 0:i.blockSelector,maskSelector:null===(s=this.options.privacyConfig)||void 0===s?void 0:s.maskSelector,unmaskSelector:null===(a=this.options.privacyConfig)||void 0===a?void 0:a.unmaskSelector,defaultMaskLevel:null===(c=this.options.privacyConfig)||void 0===c?void 0:c.defaultMaskLevel},debugMode:this.options.debugMode,shouldInlineStylesheet:this.options.shouldInlineStylesheet,version:{type:"plugin",version:En},performanceConfig:this.options.performanceConfig,storeType:this.options.storeType,useWebWorker:null!==(l=this.options.useWebWorker)&&void 0!==l?l:null===(u=this.options.experimental)||void 0===u?void 0:u.useWebWorker,userProperties:o,omitElementTags:this.options.omitElementTags,applyBackgroundColorToBlockedElements:this.options.applyBackgroundColorToBlockedElements,interactionConfig:this.options.interactionConfig,captureDocumentTitle:this.options.captureDocumentTitle,enableUrlChangePolling:this.options.enableUrlChangePolling,urlChangePollingInterval:this.options.urlChangePollingInterval},yield this.sessionReplay.init(e.apiKey,this.srInitOptions).promise}catch(t){null==e||e.loggerProvider.error(`Session Replay: Failed to initialize due to ${t.message}`)}var t})}onSessionIdChanged(e){var t;return o(this,void 0,void 0,function*(){null===(t=this.config)||void 0===t||t.loggerProvider.debug(`Analytics session id is changed to ${e}, SR session id is ${String(this.sessionReplay.getSessionId())}.`),yield this.sessionReplay.setSessionId(e).promise})}onOptOutChanged(e){var t;return o(this,void 0,void 0,function*(){null===(t=this.config)||void 0===t||t.loggerProvider.debug(`optOut is changed to ${String(e)}, calling ${e?"sessionReplay.shutdown()":"sessionReplay.init()"}.`),e?this.sessionReplay.shutdown():null!=this.config&&(yield this.sessionReplay.init(this.config.apiKey,this.srInitOptions).promise)})}execute(e){var t,n;return o(this,void 0,void 0,function*(){try{if(this.options.customSessionId){const t=this.options.customSessionId(e);if(t){t!==this.sessionReplay.getSessionId()&&(yield this.sessionReplay.setSessionId(t).promise);const n=this.sessionReplay.getSessionReplayProperties();e.event_properties=Object.assign(Object.assign({},e.event_properties),n)}}else{const n=null===(t=this.config)||void 0===t?void 0:t.sessionId;if(n&&n!==this.sessionReplay.getSessionId()&&(yield this.sessionReplay.setSessionId(n).promise),n&&n===e.session_id){let t;e.event_type===r.IDENTIFY&&(t=(e=>{if(!e.user_properties)return;let t={};return Object.keys(e.user_properties).forEach(n=>{if(Cn.includes(n)){const r=e.user_properties&&e.user_properties[n];t=Object.assign(Object.assign({},t),r)}}),t})(e)),yield this.sessionReplay.evaluateTargetingAndCapture({event:e,userProperties:t});const n=this.sessionReplay.getSessionReplayProperties();e.event_properties=Object.assign(Object.assign({},e.event_properties),n)}}return e.event_type===r.IDENTIFY&&e.event_properties&&delete e.event_properties["[Amplitude] Session Replay ID"],Promise.resolve(e)}catch(t){return null===(n=this.config)||void 0===n||n.loggerProvider.error(`Session Replay: Failed to enrich event due to ${t.message}`),Promise.resolve(e)}})}teardown(){var e;return o(this,void 0,void 0,function*(){try{this.sessionReplay.shutdown(),this.config=null}catch(t){null===(e=this.config)||void 0===e||e.loggerProvider.error(`Session Replay: teardown failed due to ${t.message}`)}})}getSessionReplayProperties(){return this.sessionReplay.getSessionReplayProperties()}}Pn.pluginName="@amplitude/plugin-session-replay-browser";const kn=e=>new Pn(e);export{Pn as S,o as _,s as a,i as b,h as g,vt as o,kn as s};
1
+ var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};function t(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}var n,r,i=function(){return i=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},i.apply(this,arguments)};function o(e,t,n,r){return new(n||(n=Promise))(function(i,o){function s(e){try{c(r.next(e))}catch(e){o(e)}}function a(e){try{c(r.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}c((r=r.apply(e,t||[])).next())})}function s(e,t){var n,r,i,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(o=0)),o;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,r=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!(i=o.trys,(i=i.length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){o.label=a[1];break}if(6===a[0]&&o.label<i[1]){o.label=i[1],i=a;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(a);break}i[2]&&o.ops.pop(),o.trys.pop();continue}a=t.call(e,o)}catch(e){a=[6,e],r=0}finally{n=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}function a(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function c(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,i,o=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(r=o.next()).done;)s.push(r.value)}catch(e){i={error:e}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(i)throw i.error}}return s}function l(e,t,n){if(n||2===arguments.length)for(var r,i=0,o=t.length;i<o;i++)!r&&i in t||(r||(r=Array.prototype.slice.call(t,0,i)),r[i]=t[i]);return e.concat(r||Array.prototype.slice.call(t))}"function"==typeof SuppressedError&&SuppressedError,function(e){e.SET="$set",e.SET_ONCE="$setOnce",e.ADD="$add",e.APPEND="$append",e.PREPEND="$prepend",e.REMOVE="$remove",e.PREINSERT="$preInsert",e.POSTINSERT="$postInsert",e.UNSET="$unset",e.CLEAR_ALL="$clearAll"}(n||(n={})),function(e){e.IDENTIFY="$identify",e.GROUP_IDENTIFY="$groupidentify",e.REVENUE="revenue_amount"}(r||(r={}));var u,d="$default_instance",v="https://api2.amplitude.com/2/httpapi";!function(e){e.Unknown="unknown",e.Skipped="skipped",e.Success="success",e.RateLimit="rate_limit",e.PayloadTooLarge="payload_too_large",e.Invalid="invalid",e.Failed="failed",e.Timeout="Timeout",e.SystemError="SystemError"}(u||(u={}));var g,h=function(){var e="ampIntegrationContext";return"undefined"!=typeof globalThis&&void 0!==globalThis[e]?globalThis[e]:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof self?self:"undefined"!=typeof global?global:void 0},f=l([],c(Array(256).keys()),!1).map(function(e){return e.toString(16).padStart(2,"0")}),p=function(e){var t,n=h();if(!(null===(t=null==n?void 0:n.crypto)||void 0===t?void 0:t.getRandomValues))return function(e){return e?(e^16*Math.random()>>e/4).toString(16):(String(1e7)+String(-1e3)+String(-4e3)+String(-8e3)+String(-1e11)).replace(/[018]/g,p)}(e);var r=n.crypto.getRandomValues(new Uint8Array(16));return r[6]=15&r[6]|64,r[8]=63&r[8]|128,l([],c(r.entries()),!1).map(function(e){var t=c(e,2),n=t[0],r=t[1];return[4,6,8,10].includes(n)?"-".concat(f[r]):f[r]}).join("")},m=function(e){return{promise:e||Promise.resolve()}};!function(e){e[e.None=0]="None",e[e.Error=1]="Error",e[e.Warn=2]="Warn",e[e.Verbose=3]="Verbose",e[e.Debug=4]="Debug"}(g||(g={}));var y="Amplitude Logger ",b=function(){function e(){this.logLevel=g.None}return e.prototype.disable=function(){this.logLevel=g.None},e.prototype.enable=function(e){void 0===e&&(e=g.Warn),this.logLevel=e},e.prototype.log=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this.logLevel<g.Verbose||console.log("".concat(y,"[Log]: ").concat(e.join(" ")))},e.prototype.warn=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this.logLevel<g.Warn||console.warn("".concat(y,"[Warn]: ").concat(e.join(" ")))},e.prototype.error=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this.logLevel<g.Error||console.error("".concat(y,"[Error]: ").concat(e.join(" ")))},e.prototype.debug=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this.logLevel<g.Debug||console.log("".concat(y,"[Debug]: ").concat(e.join(" ")))},e}(),S=function(){return{flushMaxRetries:12,flushQueueSize:200,flushIntervalMillis:1e4,instanceName:d,logLevel:g.Warn,loggerProvider:new b,offline:!1,optOut:!1,serverUrl:v,serverZone:"US",useBatch:!1}},w=function(){function e(e){var t,n,r,i;this._optOut=!1;var o=S();this.apiKey=e.apiKey,this.flushIntervalMillis=null!==(t=e.flushIntervalMillis)&&void 0!==t?t:o.flushIntervalMillis,this.flushMaxRetries=e.flushMaxRetries||o.flushMaxRetries,this.flushQueueSize=e.flushQueueSize||o.flushQueueSize,this.instanceName=e.instanceName||o.instanceName,this.loggerProvider=e.loggerProvider||o.loggerProvider,this.logLevel=null!==(n=e.logLevel)&&void 0!==n?n:o.logLevel,this.minIdLength=e.minIdLength,this.plan=e.plan,this.ingestionMetadata=e.ingestionMetadata,this.offline=void 0!==e.offline?e.offline:o.offline,this.optOut=null!==(r=e.optOut)&&void 0!==r?r:o.optOut,this.serverUrl=e.serverUrl,this.serverZone=e.serverZone||o.serverZone,this.storageProvider=e.storageProvider,this.transportProvider=e.transportProvider,this.useBatch=null!==(i=e.useBatch)&&void 0!==i?i:o.useBatch,this.loggerProvider.enable(this.logLevel);var s=C(e.serverUrl,e.serverZone,e.useBatch);this.serverZone=s.serverZone,this.serverUrl=s.serverUrl}return Object.defineProperty(e.prototype,"optOut",{get:function(){return this._optOut},set:function(e){this._optOut=e},enumerable:!1,configurable:!0}),e}(),I=function(e,t){return"EU"===e?t?"https://api.eu.amplitude.com/batch":"https://api.eu.amplitude.com/2/httpapi":t?"https://api2.amplitude.com/batch":v},C=function(e,t,n){if(void 0===e&&(e=""),void 0===t&&(t=S().serverZone),void 0===n&&(n=S().useBatch),e)return{serverUrl:e,serverZone:void 0};var r=["US","EU"].includes(t)?t:S().serverZone;return{serverZone:r,serverUrl:I(r,n)}};var E=function(e,t,n,r,i){return void 0===i&&(i=null),function(){for(var o=[],s=0;s<arguments.length;s++)o[s]=arguments[s];var a=n(),c=a.logger,l=a.logLevel;if(l&&l<g.Debug||!l||!c)return e.apply(i,o);var u,d={type:"invoke public method",name:t,args:o,stacktrace:(u=1,void 0===u&&(u=0),((new Error).stack||"").split("\n").slice(2+u).map(function(e){return e.trim()})),time:{start:(new Date).toISOString()},states:{}};r&&d.states&&(d.states.before=r());var v=e.apply(i,o);return v&&v.promise?v.promise.then(function(){r&&d.states&&(d.states.after=r()),d.time&&(d.time.end=(new Date).toISOString()),c.debug(JSON.stringify(d,null,2))}):(r&&d.states&&(d.states.after=r()),d.time&&(d.time.end=(new Date).toISOString()),c.debug(JSON.stringify(d,null,2))),v}},P=function(){function e(){}return e.prototype.getApplicationContext=function(){return{versionName:this.versionName,language:k(),platform:"Web",os:void 0,deviceModel:void 0}},e}(),k=function(){return"undefined"!=typeof navigator&&(navigator.languages&&navigator.languages[0]||navigator.language)||""},R=function(){function e(){this.queue=[]}return e.prototype.logEvent=function(e){this.receiver?this.receiver(e):this.queue.length<512&&this.queue.push(e)},e.prototype.setEventReceiver=function(e){this.receiver=e,this.queue.length>0&&(this.queue.forEach(function(t){e(t)}),this.queue=[])},e}(),T=function(){return T=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},T.apply(this,arguments)};function _(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function O(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,i,o=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(r=o.next()).done;)s.push(r.value)}catch(e){i={error:e}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(i)throw i.error}}return s}"function"==typeof SuppressedError&&SuppressedError;var x=function(e,t){var n,r,i=typeof e;if(i!==typeof t)return!1;try{for(var o=_(["string","number","boolean","undefined"]),s=o.next();!s.done;s=o.next()){if(s.value===i)return e===t}}catch(e){n={error:e}}finally{try{s&&!s.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}if(null==e&&null==t)return!0;if(null==e||null==t)return!1;if(e.length!==t.length)return!1;var a=Array.isArray(e),c=Array.isArray(t);if(a!==c)return!1;if(!a||!c){var l=Object.keys(e).sort(),u=Object.keys(t).sort();if(!x(l,u))return!1;var d=!0;return Object.keys(e).forEach(function(n){x(e[n],t[n])||(d=!1)}),d}for(var v=0;v<e.length;v++)if(!x(e[v],t[v]))return!1;return!0};Object.entries||(Object.entries=function(e){for(var t=Object.keys(e),n=t.length,r=new Array(n);n--;)r[n]=[t[n],e[t[n]]];return r});var M,D=function(){function e(){this.identity={userProperties:{}},this.listeners=new Set}return e.prototype.editIdentity=function(){var e=this,t=T({},this.identity.userProperties),n=T(T({},this.identity),{userProperties:t});return{setUserId:function(e){return n.userId=e,this},setDeviceId:function(e){return n.deviceId=e,this},setUserProperties:function(e){return n.userProperties=e,this},setOptOut:function(e){return n.optOut=e,this},updateUserProperties:function(e){var t,r,i,o,s,a,c=n.userProperties||{};try{for(var l=_(Object.entries(e)),u=l.next();!u.done;u=l.next()){var d=O(u.value,2),v=d[0],g=d[1];switch(v){case"$set":try{for(var h=(i=void 0,_(Object.entries(g))),f=h.next();!f.done;f=h.next()){var p=O(f.value,2),m=p[0],y=p[1];c[m]=y}}catch(e){i={error:e}}finally{try{f&&!f.done&&(o=h.return)&&o.call(h)}finally{if(i)throw i.error}}break;case"$unset":try{for(var b=(s=void 0,_(Object.keys(g))),S=b.next();!S.done;S=b.next()){delete c[m=S.value]}}catch(e){s={error:e}}finally{try{S&&!S.done&&(a=b.return)&&a.call(b)}finally{if(s)throw s.error}}break;case"$clearAll":c={}}}}catch(e){t={error:e}}finally{try{u&&!u.done&&(r=l.return)&&r.call(l)}finally{if(t)throw t.error}}return n.userProperties=c,this},commit:function(){return e.setIdentity(n),this}}},e.prototype.getIdentity=function(){return T({},this.identity)},e.prototype.setIdentity=function(e){var t=T({},this.identity);this.identity=T({},e),x(t,this.identity)||this.listeners.forEach(function(t){t(e)})},e.prototype.addIdentityListener=function(e){this.listeners.add(e)},e.prototype.removeIdentityListener=function(e){this.listeners.delete(e)},e}(),L="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof global?global:self,N=function(){function e(){this.identityStore=new D,this.eventBridge=new R,this.applicationContextProvider=new P}return e.getInstance=function(t){return L.analyticsConnectorInstances||(L.analyticsConnectorInstances={}),L.analyticsConnectorInstances[t]||(L.analyticsConnectorInstances[t]=new e),L.analyticsConnectorInstances[t]},e}(),U=function(e){var t=0;if(0===e.length)return t;for(var n=0;n<e.length;n++){t=(t<<5)-t+e.charCodeAt(n),t|=0}return t},q=function(){function e(){}return e.prototype.send=function(e,t,n){return Promise.resolve(null)},e.prototype.buildResponse=function(e){var t,n,r,i,o,s,a,c,l,d,v,g,h,f,p,m,y,b,S,w,I,C;if("object"!=typeof e)return null;var E=e.code||0,P=this.buildStatus(E);switch(P){case u.Success:return{status:P,statusCode:E,body:{eventsIngested:null!==(t=e.events_ingested)&&void 0!==t?t:0,payloadSizeBytes:null!==(n=e.payload_size_bytes)&&void 0!==n?n:0,serverUploadTime:null!==(r=e.server_upload_time)&&void 0!==r?r:0}};case u.Invalid:return{status:P,statusCode:E,body:{error:null!==(i=e.error)&&void 0!==i?i:"",missingField:null!==(o=e.missing_field)&&void 0!==o?o:"",eventsWithInvalidFields:null!==(s=e.events_with_invalid_fields)&&void 0!==s?s:{},eventsWithMissingFields:null!==(a=e.events_with_missing_fields)&&void 0!==a?a:{},eventsWithInvalidIdLengths:null!==(c=e.events_with_invalid_id_lengths)&&void 0!==c?c:{},epsThreshold:null!==(l=e.eps_threshold)&&void 0!==l?l:0,exceededDailyQuotaDevices:null!==(d=e.exceeded_daily_quota_devices)&&void 0!==d?d:{},silencedDevices:null!==(v=e.silenced_devices)&&void 0!==v?v:[],silencedEvents:null!==(g=e.silenced_events)&&void 0!==g?g:[],throttledDevices:null!==(h=e.throttled_devices)&&void 0!==h?h:{},throttledEvents:null!==(f=e.throttled_events)&&void 0!==f?f:[]}};case u.PayloadTooLarge:return{status:P,statusCode:E,body:{error:null!==(p=e.error)&&void 0!==p?p:""}};case u.RateLimit:return{status:P,statusCode:E,body:{error:null!==(m=e.error)&&void 0!==m?m:"",epsThreshold:null!==(y=e.eps_threshold)&&void 0!==y?y:0,throttledDevices:null!==(b=e.throttled_devices)&&void 0!==b?b:{},throttledUsers:null!==(S=e.throttled_users)&&void 0!==S?S:{},exceededDailyQuotaDevices:null!==(w=e.exceeded_daily_quota_devices)&&void 0!==w?w:{},exceededDailyQuotaUsers:null!==(I=e.exceeded_daily_quota_users)&&void 0!==I?I:{},throttledEvents:null!==(C=e.throttled_events)&&void 0!==C?C:[]}};case u.Timeout:default:return{status:P,statusCode:E}}},e.prototype.buildStatus=function(e){return function(e){return e>=200&&e<300}(e)?u.Success:429===e?u.RateLimit:413===e?u.PayloadTooLarge:408===e?u.Timeout:e>=400&&e<500?u.Invalid:e>=500?u.Failed:u.Unknown},e}(),A=function(e){function n(t){void 0===t&&(t={});var n=e.call(this)||this;return n.customHeaders=t,n}return t(n,e),n.prototype.send=function(e,t){return o(this,void 0,void 0,function(){var n,r,o;return s(this,function(s){switch(s.label){case 0:if("undefined"==typeof fetch)throw new Error("FetchTransport is not supported");return n={headers:i({"Content-Type":"application/json",Accept:"*/*"},this.customHeaders),body:JSON.stringify(t),method:"POST"},[4,fetch(e,n)];case 1:return[4,(r=s.sent()).text()];case 2:o=s.sent();try{return[2,this.buildResponse(JSON.parse(o))]}catch(e){return[2,this.buildResponse({code:r.status})]}return[2]}})})},n}(q),j=function(){function e(e,t){this.key="AMP_remote_config_".concat(e.substring(0,10)),this.logger=t}return e.prototype.fetchConfig=function(){var e=null,t={remoteConfig:null,lastFetch:new Date};try{e=localStorage.getItem(this.key)}catch(e){return this.logger.debug("Remote config localstorage failed to access: ",e),Promise.resolve(t)}if(null===e)return this.logger.debug("Remote config localstorage gets null because the key does not exist"),Promise.resolve(t);try{var n=JSON.parse(e);return this.logger.debug("Remote config localstorage parsed successfully: ".concat(JSON.stringify(n))),Promise.resolve({remoteConfig:n.remoteConfig,lastFetch:new Date(n.lastFetch)})}catch(e){return this.logger.debug("Remote config localstorage failed to parse: ",e),localStorage.removeItem(this.key),Promise.resolve(t)}},e.prototype.setConfig=function(e){try{return localStorage.setItem(this.key,JSON.stringify(e)),this.logger.debug("Remote config localstorage set successfully."),Promise.resolve(!0)}catch(e){this.logger.debug("Remote config localstorage failed to set: ",e)}return Promise.resolve(!1)},e}(),F=function(){function e(e,t,n,r){void 0===n&&(n="US"),this.callbackInfos=[],this.lastSuccessfulFetch=null,this.fetchPromise=null,this.apiKey=e,this.serverUrl=r||("US"===n?"https://sr-client-cfg.amplitude.com/config":"https://sr-client-cfg.eu.amplitude.com/config"),this.logger=t,this.storage=new j(e,t)}return e.prototype.subscribe=function(e,t,n){var r=p(),i={id:r,key:e,deliveryMode:t,callback:n};return this.callbackInfos.push(i),"all"===t?this.subscribeAll(i):this.subscribeWaitForRemote(i,t.timeout),r},e.prototype.unsubscribe=function(e){var t=this.callbackInfos.findIndex(function(t){return t.id===e});return-1===t?(this.logger.debug("Remote config client unsubscribe failed because callback with id ".concat(e," doesn't exist.")),!1):(this.callbackInfos.splice(t,1),this.logger.debug("Remote config client unsubscribe succeeded removing callback with id ".concat(e,".")),!0)},e.prototype.updateConfigs=function(){return o(this,void 0,void 0,function(){var e,t=this;return s(this,function(n){switch(n.label){case 0:return this.lastSuccessfulFetch&&Date.now()-this.lastSuccessfulFetch<3e5?(this.logger.debug("Remote config client skipping updateConfigs: Too recent"),[2]):[4,this.getOrCreateFetchPromise()];case 1:return e=n.sent(),this.storage.setConfig(e),this.callbackInfos.forEach(function(n){t.sendCallback(n,e,"remote")}),[2]}})})},e.prototype.getOrCreateFetchPromise=function(){var e=this;return this.fetchPromise||(this.fetchPromise=this.fetch().then(function(t){return null!==t.remoteConfig&&(e.lastSuccessfulFetch=Date.now()),t}).finally(function(){e.fetchPromise=null})),this.fetchPromise},e.prototype.subscribeAll=function(e){return o(this,void 0,void 0,function(){var t,n,r,i=this;return s(this,function(o){switch(o.label){case 0:return t=this.getOrCreateFetchPromise().then(function(t){i.logger.debug("Remote config client subscription all mode fetched from remote: ".concat(JSON.stringify(t))),i.sendCallback(e,t,"remote"),i.storage.setConfig(t)}),n=this.storage.fetchConfig().then(function(e){return e}),[4,Promise.race([t,n])];case 1:return void 0!==(r=o.sent())&&(this.logger.debug("Remote config client subscription all mode fetched from cache: ".concat(JSON.stringify(r))),null!==r.remoteConfig?this.sendCallback(e,r,"cache"):this.logger.debug("Remote config client skips sending callback because cache is empty (first time user).")),[4,t];case 2:return o.sent(),[2]}})})},e.prototype.subscribeWaitForRemote=function(e,t){return o(this,void 0,void 0,function(){var n,r;return s(this,function(i){switch(i.label){case 0:n=new Promise(function(e,n){setTimeout(function(){n("Timeout exceeded")},t)}),i.label=1;case 1:return i.trys.push([1,3,,5]),[4,Promise.race([this.getOrCreateFetchPromise(),n])];case 2:return r=i.sent(),this.logger.debug("Remote config client subscription wait for remote mode returns from remote."),this.sendCallback(e,r,"remote"),this.storage.setConfig(r),[3,5];case 3:return i.sent(),this.logger.debug("Remote config client subscription wait for remote mode exceeded timeout. Try to fetch from cache."),[4,this.storage.fetchConfig()];case 4:return null!==(r=i.sent()).remoteConfig?(this.logger.debug("Remote config client subscription wait for remote mode returns a cached copy."),this.sendCallback(e,r,"cache")):(this.logger.debug("Remote config client subscription wait for remote mode failed to fetch cache."),this.sendCallback(e,r,"remote")),[3,5];case 5:return[2]}})})},e.prototype.sendCallback=function(e,t,n){var r;e.lastCallback=new Date,r=e.key?e.key.split(".").reduce(function(e,t){return null===e?e:t in e?e[t]:null},t.remoteConfig):t.remoteConfig,e.callback(r,n,t.lastFetch)},e.prototype.fetch=function(e,t){return void 0===e&&(e=3),void 0===t&&(t=1e3),o(this,void 0,void 0,function(){var n,r,i,o,a,c,l=this;return s(this,function(u){switch(u.label){case 0:n=t/e,r={remoteConfig:null,lastFetch:new Date},i=function(r){var i,a,c,u,d;return s(this,function(s){switch(s.label){case 0:i=new AbortController,a=setTimeout(function(){return i.abort()},t),s.label=1;case 1:return s.trys.push([1,7,8,9]),[4,fetch(o.getUrlParams(),{method:"GET",headers:{Accept:"*/*"},signal:i.signal})];case 2:return(c=s.sent()).ok?[3,4]:[4,c.text()];case 3:return u=s.sent(),o.logger.debug("Remote config client fetch with retry time ".concat(e," failed with ").concat(c.status,": ").concat(u)),[3,6];case 4:return[4,c.json()];case 5:return[2,{value:{remoteConfig:s.sent(),lastFetch:new Date}}];case 6:return[3,9];case 7:return(d=s.sent())instanceof Error&&"AbortError"===d.name?o.logger.debug("Remote config client fetch with retry time ".concat(e," timed out after ").concat(t,"ms")):o.logger.debug("Remote config client fetch with retry time ".concat(e," is rejected because: "),d),[3,9];case 8:return clearTimeout(a),[7];case 9:return r<e-1?[4,new Promise(function(e){return setTimeout(e,l.getJitterDelay(n))})]:[3,11];case 10:s.sent(),s.label=11;case 11:return[2]}})},o=this,a=0,u.label=1;case 1:return a<e?[5,i(a)]:[3,4];case 2:if("object"==typeof(c=u.sent()))return[2,c.value];u.label=3;case 3:return a++,[3,1];case 4:return[2,r]}})})},e.prototype.getJitterDelay=function(e){return Math.floor(Math.random()*e)},e.prototype.getUrlParams=function(){var t=encodeURIComponent(this.apiKey),n=new URLSearchParams;return n.append("config_group",e.CONFIG_GROUP),"".concat(this.serverUrl,"/").concat(t,"?").concat(n.toString())},e.CONFIG_GROUP="browser",e}();!function(e){e.US="US",e.EU="EU",e.STAGING="STAGING"}(M||(M={}));var B,W="https://app.amplitude.com",$={US:W,EU:"https://app.eu.amplitude.com",STAGING:"https://apps.stag2.amplitude.com"};var H="__AMPLITUDE_MESSENGER_INSTANCE__",z="__AMPLITUDE_MESSENGER__",K=function(){function e(e){var t=(void 0===e?{}:e).origin,n=void 0===t?W:t;this[B]=!0,this.isSetup=!1,this.messageHandler=null,this.requestCallbacks={},this.actionHandlers=new Map,this.pendingMessages=new Map,this.scriptLoadPromises=new Map,this.endpoint=n}return e.prototype.notify=function(e){var t,n,r,i;null===(n=null===(t=this.logger)||void 0===t?void 0:t.debug)||void 0===n||n.call(t,"Message sent: ",JSON.stringify(e)),null===(i=null===(r=window.opener)||void 0===r?void 0:r.postMessage)||void 0===i||i.call(r,e,this.endpoint)},e.prototype.sendRequest=function(e,t,n){var r=this;void 0===n&&(n={timeout:15e3});var i="".concat(Date.now(),"-").concat(Math.random().toString(36).substr(2,9)),o={id:i,action:e,args:t};return new Promise(function(t,s){r.requestCallbacks[i]={resolve:t,reject:s},r.notify(o),n.timeout>0&&setTimeout(function(){s(new Error("".concat(e," timed out (id: ").concat(i,")"))),delete r.requestCallbacks[i]},n.timeout)})},e.prototype.handleResponse=function(e){var t;this.requestCallbacks[e.id]?(this.requestCallbacks[e.id].resolve(e.responseData),delete this.requestCallbacks[e.id]):null===(t=this.logger)||void 0===t||t.warn("No callback found for request id: ".concat(e.id))},e.prototype.registerActionHandler=function(e,t){var n,r,i,o;this.actionHandlers.has(e)&&(null===(o=null===(i=this.logger)||void 0===i?void 0:i.warn)||void 0===o||o.call(i,"Overwriting existing action handler for: ".concat(e))),this.actionHandlers.set(e,t);var s=this.pendingMessages.get(e);if(s){this.pendingMessages.delete(e);try{for(var c=a(s),l=c.next();!l.done;l=c.next()){t(l.value)}}catch(e){n={error:e}}finally{try{l&&!l.done&&(r=c.return)&&r.call(c)}finally{if(n)throw n.error}}}},e.prototype.loadScriptOnce=function(e){return o(this,void 0,void 0,function(){var t,n,r;return s(this,function(i){switch(i.label){case 0:if(t=this.scriptLoadPromises.get(e))return[2,t];n=function(e){return document.querySelector('script[src="'.concat(CSS.escape(e),'"]'))?Promise.resolve({status:!0}):new Promise(function(t,n){var r;try{var i=document.createElement("script");i.type="text/javascript",i.async=!0,i.src=e,i.addEventListener("load",function(){t({status:!0})},{once:!0}),i.addEventListener("error",function(){n({status:!1,message:"Failed to load the script ".concat(e)})}),null===(r=document.head)||void 0===r||r.appendChild(i)}catch(e){n(e)}})}(e).then(function(){}),this.scriptLoadPromises.set(e,n),i.label=1;case 1:return i.trys.push([1,3,,4]),[4,n];case 2:return i.sent(),[3,4];case 3:throw r=i.sent(),this.scriptLoadPromises.delete(e),r;case 4:return[2]}})})},e.prototype.setup=function(e){var t,n,r=this,i=void 0===e?{}:e,o=i.logger,s=i.endpoint;o&&(this.logger=o),s&&this.endpoint===W&&(this.endpoint=s),this.isSetup||(this.isSetup=!0,null===(n=null===(t=this.logger)||void 0===t?void 0:t.debug)||void 0===n||n.call(t,"Setting up messenger"),this.messageHandler=function(e){var t,n,i,o,s;if(null===(n=null===(t=r.logger)||void 0===t?void 0:t.debug)||void 0===n||n.call(t,"Message received: ",JSON.stringify(e)),r.endpoint===e.origin){var a=e.data,c=null==a?void 0:a.action;if(c)if("id"in a&&a.id)null===(o=null===(i=r.logger)||void 0===i?void 0:i.debug)||void 0===o||o.call(i,"Received Response to previous request: ",JSON.stringify(e)),r.handleResponse(a);else{if("ping"===c)return void r.notify({action:"pong"});var l=r.actionHandlers.get(c);if(l)l(a.data);else{var u=null!==(s=r.pendingMessages.get(c))&&void 0!==s?s:[];u.push(a.data),r.pendingMessages.set(c,u)}}}},window.addEventListener("message",this.messageHandler),this.notify({action:"page-loaded"}))},e.prototype.destroy=function(){this.messageHandler&&(window.removeEventListener("message",this.messageHandler),this.messageHandler=null),this.isSetup=!1,this.actionHandlers.clear(),this.pendingMessages.clear(),this.requestCallbacks={},this.scriptLoadPromises.clear();var e=h();(null==e?void 0:e[z])===this&&delete e[z]},e}();function J(e){var t,n=h(),r=null==n?void 0:n[z];if("object"==typeof(t=r)&&null!==t&&H in t&&!0===t[H])return r;var i=new K(e);return n&&(n[z]=i),i}B=H;var G="__AMPLITUDE_BACKGROUND_CAPTURE__";var V,Q="[Amplitude]",Z="".concat(Q," Session Replay ID"),Y=M.US,X={enabled:!0},ee=1e3,te="".concat(Q," Session Replay Debug"),ne="amp-mask";!function(e){e.GET_SR_PROPS="get-sr-props",e.DEBUG_INFO="debug-info",e.FETCH_REQUEST="fetch-request",e.METADATA="metadata",e.TARGETING_DECISION="targeting-decision"}(V||(V={}));var re=function(){function e(e){this.logger=e,this.log=this.getSafeMethod("log"),this.warn=this.getSafeMethod("warn"),this.error=this.getSafeMethod("error"),this.debug=this.getSafeMethod("debug")}return e.prototype.getSafeMethod=function(e){var t;if(!this.logger)return function(){};var n=this.logger[e];return"function"==typeof n?(null!==(t=n.__rrweb_original__)&&void 0!==t?t:n).bind(this.logger):function(){}},e.prototype.enable=function(e){this.logger.enable(e)},e.prototype.disable=function(){this.logger.disable()},e}(),ie="medium";var oe=function(e,t,n){switch(t){case"light":if("input"!==e)return!0;var r=n?function(e){var t=e.type;return e.hasAttribute("data-rr-is-password")?"password":t?t.toLowerCase():null}(n):"";return!!r&&(!!["password","hidden","email","tel"].includes(r)||!!n.autocomplete.startsWith("cc-"));case"medium":case"conservative":return!0;default:return oe(e,ie,n)}},se=function(e,t){return function(n,r){return function(e,t,n){var r,i,o;if(void 0===t&&(t={defaultMaskLevel:ie}),n){if(n.closest("."+ne))return!0;var s=(null!==(r=t.maskSelector)&&void 0!==r?r:[]).some(function(e){return n.closest(e)});if(s)return!0;if(n.closest(".amp-unmask"))return!1;var a=(null!==(i=t.unmaskSelector)&&void 0!==i?i:[]).some(function(e){return n.closest(e)});if(a)return!1}return oe(e,null!==(o=t.defaultMaskLevel)&&void 0!==o?o:ie,n)}(e,t,r)?n.replace(/[^\s]/g,"*"):n}},ae=function(e,t){return t||(e===M.STAGING?"https://api-sr.stag2.amplitude.com/sessions/v2/track":e===M.EU?"https://api-sr.eu.amplitude.com/sessions/v2/track":"https://api-sr.amplitude.com/sessions/v2/track")},ce=function(e){var t=e.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*").replace(/\?/g,".");return new RegExp("^".concat(t,"$"))},le=function(e,t){var n,r;try{for(var i=a(t),o=i.next();!o.done;o=i.next()){var s=o.value,c=ce(s.selector);if(c.test(e))return e.replace(c,s.replacement)}}catch(e){n={error:e}}finally{try{o&&!o.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.error}}return e},ue=function(){return o(void 0,void 0,void 0,function(){var e,t,n,r,i,o,a;return s(this,function(s){switch(s.label){case 0:return s.trys.push([0,3,,4]),(e=h())?[4,e.navigator.storage.estimate()]:[3,2];case 1:return t=s.sent(),n=t.usage,r=t.quota,i=t.usageDetails,o=n?Math.round(n/1024):0,a=n&&r?Math.round(1e3*(n/r+Number.EPSILON))/1e3:0,[2,{totalStorageSize:o,percentOfQuota:a,usageDetails:JSON.stringify(i)}];case 2:return[3,4];case 3:return s.sent(),[3,4];case 4:return[2,{totalStorageSize:0,percentOfQuota:0,usageDetails:""}]}})})},de=function(e){var t=i({},e),n=t.apiKey;return t.apiKey="****".concat(n.substring(n.length-4)),t},ve=function(){return{flushMaxRetries:2,logLevel:g.Warn,loggerProvider:new b,transportProvider:new A}},ge=function(e){function n(t,n){var r,o,s,a,c,l,u=this,d=ve();if((u=e.call(this,i(i({transportProvider:d.transportProvider,loggerProvider:new re(n.loggerProvider||d.loggerProvider)},n),{apiKey:t}))||this).flushMaxRetries=void 0!==n.flushMaxRetries&&n.flushMaxRetries<=d.flushMaxRetries?n.flushMaxRetries:d.flushMaxRetries,u.apiKey=t,u.sampleRate=n.sampleRate||0,u.serverZone=n.serverZone||Y,u.configServerUrl=n.configServerUrl,u.trackServerUrl=n.trackServerUrl,u.shouldInlineStylesheet=n.shouldInlineStylesheet,u.version=n.version,u.performanceConfig=n.performanceConfig||X,u.storeType=null!==(r=n.storeType)&&void 0!==r?r:"idb",u.applyBackgroundColorToBlockedElements=null!==(o=n.applyBackgroundColorToBlockedElements)&&void 0!==o&&o,u.enableUrlChangePolling=null!==(s=n.enableUrlChangePolling)&&void 0!==s&&s,u.urlChangePollingInterval=null!==(a=n.urlChangePollingInterval)&&void 0!==a?a:ee,u.captureDocumentTitle=null!==(c=n.captureDocumentTitle)&&void 0!==c&&c,n.privacyConfig&&(u.privacyConfig=n.privacyConfig),n.interactionConfig&&(u.interactionConfig=n.interactionConfig,u.interactionConfig.ugcFilterRules&&function(e){if(!e.every(function(e){return"string"==typeof e.selector&&"string"==typeof e.replacement}))throw new Error("ugcFilterRules must be an array of objects with selector and replacement properties");if(!e.every(function(e){return"string"==typeof(t=e.selector)&&""!==t.trim()&&!!/^\/|^https?:\/\/[^\s]+$/.test(t);var t}))throw new Error("ugcFilterRules must be an array of objects with valid globs")}(u.interactionConfig.ugcFilterRules)),n.debugMode&&(u.debugMode=n.debugMode),void 0!==n.useWebWorker)u.useWebWorker=n.useWebWorker;else{var v=n;void 0!==(null===(l=v.experimental)||void 0===l?void 0:l.useWebWorker)&&(u.useWebWorker=v.experimental.useWebWorker)}return n.omitElementTags&&(u.omitElementTags=n.omitElementTags),u}return t(n,e),n}(w),he=(e=>(e[e.DomContentLoaded=0]="DomContentLoaded",e[e.Load=1]="Load",e[e.FullSnapshot=2]="FullSnapshot",e[e.IncrementalSnapshot=3]="IncrementalSnapshot",e[e.Meta=4]="Meta",e[e.Custom=5]="Custom",e[e.Plugin=6]="Plugin",e))(he||{}),fe=(e=>(e[e.MouseUp=0]="MouseUp",e[e.MouseDown=1]="MouseDown",e[e.Click=2]="Click",e[e.ContextMenu=3]="ContextMenu",e[e.DblClick=4]="DblClick",e[e.Focus=5]="Focus",e[e.Blur=6]="Blur",e[e.TouchStart=7]="TouchStart",e[e.TouchMove_Departed=8]="TouchMove_Departed",e[e.TouchEnd=9]="TouchEnd",e[e.TouchCancel=10]="TouchCancel",e))(fe||{}),pe=function(){function e(e,t){this.localConfig=t,this.remoteConfigClient=e}return e.prototype.generateJoinedConfig=function(){var e,t,n;return o(this,void 0,void 0,function(){var r,o,l,u,d,v,g,h,f,p,m,y,b,S,w,I,C,E=this;return s(this,function(s){switch(s.label){case 0:(r=i({},this.localConfig)).optOut=this.localConfig.optOut,r.captureEnabled=!0,s.label=1;case 1:return s.trys.push([1,3,,4]),[4,new Promise(function(e,t){E.remoteConfigClient.subscribe("configs.sessionReplay","all",function(n,i){var s;if(E.localConfig.loggerProvider.debug("Session Replay remote configuration received from ".concat(i,":"),JSON.stringify(n,null,2)),n){var a=n,c=a.sr_sampling_config,l=a.sr_privacy_config,u=a.sr_targeting_config,d=null===(s=r.interactionConfig)||void 0===s?void 0:s.ugcFilterRules;r.interactionConfig=a.sr_interaction_config,r.interactionConfig&&d&&(r.interactionConfig.ugcFilterRules=d),r.loggingConfig=a.sr_logging_config,(c||l||u)&&(o={},c&&(o.sr_sampling_config=c),l&&(o.sr_privacy_config=l),u&&(o.sr_targeting_config=u)),e()}else t(new Error("No remote config received"))})})];case 2:return s.sent(),[3,4];case 3:return l=s.sent(),this.localConfig.loggerProvider.error("Failed to generate joined config: ",l),r.captureEnabled=!1,[2,{localConfig:this.localConfig,joinedConfig:r,remoteConfig:void 0}];case 4:if(!o)return[2,{localConfig:this.localConfig,joinedConfig:r,remoteConfig:o}];if(u=o.sr_sampling_config,d=o.sr_privacy_config,v=o.sr_targeting_config,u&&Object.keys(u).length>0?(Object.prototype.hasOwnProperty.call(u,"capture_enabled")?r.captureEnabled=u.capture_enabled:r.captureEnabled=!1,Object.prototype.hasOwnProperty.call(u,"sample_rate")&&(r.sampleRate=u.sample_rate)):(r.captureEnabled=!0,this.localConfig.loggerProvider.debug("Remote config successfully fetched, but no values set for project, Session Replay capture enabled.")),d){g=null!==(e=r.privacyConfig)&&void 0!==e?e:{},h={defaultMaskLevel:null!==(n=null!==(t=d.defaultMaskLevel)&&void 0!==t?t:g.defaultMaskLevel)&&void 0!==n?n:"medium",blockSelector:[],maskSelector:[],unmaskSelector:[]},f=function(e){var t,n,r,i,o,s,c,l,u,d={};"string"==typeof e.blockSelector&&(e.blockSelector=[e.blockSelector]);try{for(var v=a(null!==(c=e.blockSelector)&&void 0!==c?c:[]),g=v.next();!g.done;g=v.next()){d[g.value]="block"}}catch(e){t={error:e}}finally{try{g&&!g.done&&(n=v.return)&&n.call(v)}finally{if(t)throw t.error}}try{for(var h=a(null!==(l=e.maskSelector)&&void 0!==l?l:[]),f=h.next();!f.done;f=h.next()){d[f.value]="mask"}}catch(e){r={error:e}}finally{try{f&&!f.done&&(i=h.return)&&i.call(h)}finally{if(r)throw r.error}}try{for(var p=a(null!==(u=e.unmaskSelector)&&void 0!==u?u:[]),m=p.next();!m.done;m=p.next()){d[m.value]="unmask"}}catch(e){o={error:e}}finally{try{m&&!m.done&&(s=p.return)&&s.call(p)}finally{if(o)throw o.error}}return d},p=i(i({},f(g)),f(d));try{for(m=a(Object.entries(p)),y=m.next();!y.done;y=m.next())b=c(y.value,2),S=b[0],"mask"===(w=b[1])?h.maskSelector.push(S):"block"===w?h.blockSelector.push(S):"unmask"===w&&h.unmaskSelector.push(S)}catch(e){I={error:e}}finally{try{y&&!y.done&&(C=m.return)&&C.call(m)}finally{if(I)throw I.error}}r.privacyConfig=(P=h,k=this.localConfig.loggerProvider,R=document.createDocumentFragment(),T=function(e){if(void 0===e&&(e=[]),"string"==typeof e&&(e=[e]),e=e.filter(function(e){try{R.querySelector(e)}catch(t){return k.warn('[session-replay-browser] omitting selector "'.concat(e,'" because it is invalid')),!1}return!0}),0!==e.length)return e},P.blockSelector=T(P.blockSelector),P.maskSelector=T(P.maskSelector),P.unmaskSelector=T(P.unmaskSelector),P)}return v&&Object.keys(v).length>0&&(r.targetingConfig=v),this.localConfig.loggerProvider.debug(JSON.stringify({name:"session replay joined config",config:de(r)},null,2)),[2,{localConfig:this.localConfig,joinedConfig:r,remoteConfig:o}]}var P,k,R,T})})},e}(),me=function(e,t){return o(void 0,void 0,void 0,function(){var n,r;return s(this,function(i){return n=new ge(e,t),r=new F(e,n.loggerProvider,n.serverZone,t.configServerUrl),[2,new pe(r,n)]})})},ye=Uint8Array,be=Uint16Array,Se=Uint32Array,we=new ye([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),Ie=new ye([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),Ce=new ye([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Ee=function(e,t){for(var n=new be(31),r=0;r<31;++r)n[r]=t+=1<<e[r-1];var i=new Se(n[30]);for(r=1;r<30;++r)for(var o=n[r];o<n[r+1];++o)i[o]=o-n[r]<<5|r;return[n,i]},Pe=Ee(we,2),ke=Pe[0],Re=Pe[1];ke[28]=258,Re[258]=28;for(var Te=Ee(Ie,0)[1],_e=new be(32768),Oe=0;Oe<32768;++Oe){var xe=(43690&Oe)>>>1|(21845&Oe)<<1;xe=(61680&(xe=(52428&xe)>>>2|(13107&xe)<<2))>>>4|(3855&xe)<<4,_e[Oe]=((65280&xe)>>>8|(255&xe)<<8)>>>1}var Me=function(e,t,n){for(var r=e.length,i=0,o=new be(t);i<r;++i)++o[e[i]-1];var s,a=new be(t);for(i=0;i<t;++i)a[i]=a[i-1]+o[i-1]<<1;if(n){s=new be(1<<t);var c=15-t;for(i=0;i<r;++i)if(e[i])for(var l=i<<4|e[i],u=t-e[i],d=a[e[i]-1]++<<u,v=d|(1<<u)-1;d<=v;++d)s[_e[d]>>>c]=l}else for(s=new be(r),i=0;i<r;++i)s[i]=_e[a[e[i]-1]++]>>>15-e[i];return s},De=new ye(288);for(Oe=0;Oe<144;++Oe)De[Oe]=8;for(Oe=144;Oe<256;++Oe)De[Oe]=9;for(Oe=256;Oe<280;++Oe)De[Oe]=7;for(Oe=280;Oe<288;++Oe)De[Oe]=8;var Le=new ye(32);for(Oe=0;Oe<32;++Oe)Le[Oe]=5;var Ne=Me(De,9,0),Ue=Me(Le,5,0),qe=function(e){return(e/8|0)+(7&e&&1)},Ae=function(e,t,n){(null==n||n>e.length)&&(n=e.length);var r=new(e instanceof be?be:e instanceof Se?Se:ye)(n-t);return r.set(e.subarray(t,n)),r},je=function(e,t,n){n<<=7&t;var r=t/8|0;e[r]|=n,e[r+1]|=n>>>8},Fe=function(e,t,n){n<<=7&t;var r=t/8|0;e[r]|=n,e[r+1]|=n>>>8,e[r+2]|=n>>>16},Be=function(e,t){for(var n=[],r=0;r<e.length;++r)e[r]&&n.push({s:r,f:e[r]});var i=n.length,o=n.slice();if(!i)return[new ye(0),0];if(1==i){var s=new ye(n[0].s+1);return s[n[0].s]=1,[s,1]}n.sort(function(e,t){return e.f-t.f}),n.push({s:-1,f:25001});var a=n[0],c=n[1],l=0,u=1,d=2;for(n[0]={s:-1,f:a.f+c.f,l:a,r:c};u!=i-1;)a=n[n[l].f<n[d].f?l++:d++],c=n[l!=u&&n[l].f<n[d].f?l++:d++],n[u++]={s:-1,f:a.f+c.f,l:a,r:c};var v=o[0].s;for(r=1;r<i;++r)o[r].s>v&&(v=o[r].s);var g=new be(v+1),h=We(n[u-1],g,0);if(h>t){r=0;var f=0,p=h-t,m=1<<p;for(o.sort(function(e,t){return g[t.s]-g[e.s]||e.f-t.f});r<i;++r){var y=o[r].s;if(!(g[y]>t))break;f+=m-(1<<h-g[y]),g[y]=t}for(f>>>=p;f>0;){var b=o[r].s;g[b]<t?f-=1<<t-g[b]++-1:++r}for(;r>=0&&f;--r){var S=o[r].s;g[S]==t&&(--g[S],++f)}h=t}return[new ye(g),h]},We=function(e,t,n){return-1==e.s?Math.max(We(e.l,t,n+1),We(e.r,t,n+1)):t[e.s]=n},$e=function(e){for(var t=e.length;t&&!e[--t];);for(var n=new be(++t),r=0,i=e[0],o=1,s=function(e){n[r++]=e},a=1;a<=t;++a)if(e[a]==i&&a!=t)++o;else{if(!i&&o>2){for(;o>138;o-=138)s(32754);o>2&&(s(o>10?o-11<<5|28690:o-3<<5|12305),o=0)}else if(o>3){for(s(i),--o;o>6;o-=6)s(8304);o>2&&(s(o-3<<5|8208),o=0)}for(;o--;)s(i);o=1,i=e[a]}return[n.subarray(0,r),t]},He=function(e,t){for(var n=0,r=0;r<t.length;++r)n+=e[r]*t[r];return n},ze=function(e,t,n){var r=n.length,i=qe(t+2);e[i]=255&r,e[i+1]=r>>>8,e[i+2]=255^e[i],e[i+3]=255^e[i+1];for(var o=0;o<r;++o)e[i+o+4]=n[o];return 8*(i+4+r)},Ke=function(e,t,n,r,i,o,s,a,c,l,u){je(t,u++,n),++i[256];for(var d=Be(i,15),v=d[0],g=d[1],h=Be(o,15),f=h[0],p=h[1],m=$e(v),y=m[0],b=m[1],S=$e(f),w=S[0],I=S[1],C=new be(19),E=0;E<y.length;++E)C[31&y[E]]++;for(E=0;E<w.length;++E)C[31&w[E]]++;for(var P=Be(C,7),k=P[0],R=P[1],T=19;T>4&&!k[Ce[T-1]];--T);var _,O,x,M,D=l+5<<3,L=He(i,De)+He(o,Le)+s,N=He(i,v)+He(o,f)+s+14+3*T+He(C,k)+(2*C[16]+3*C[17]+7*C[18]);if(D<=L&&D<=N)return ze(t,u,e.subarray(c,c+l));if(je(t,u,1+(N<L)),u+=2,N<L){_=Me(v,g,0),O=v,x=Me(f,p,0),M=f;var U=Me(k,R,0);je(t,u,b-257),je(t,u+5,I-1),je(t,u+10,T-4),u+=14;for(E=0;E<T;++E)je(t,u+3*E,k[Ce[E]]);u+=3*T;for(var q=[y,w],A=0;A<2;++A){var j=q[A];for(E=0;E<j.length;++E){var F=31&j[E];je(t,u,U[F]),u+=k[F],F>15&&(je(t,u,j[E]>>>5&127),u+=j[E]>>>12)}}}else _=Ne,O=De,x=Ue,M=Le;for(E=0;E<a;++E)if(r[E]>255){F=r[E]>>>18&31;Fe(t,u,_[F+257]),u+=O[F+257],F>7&&(je(t,u,r[E]>>>23&31),u+=we[F]);var B=31&r[E];Fe(t,u,x[B]),u+=M[B],B>3&&(Fe(t,u,r[E]>>>5&8191),u+=Ie[B])}else Fe(t,u,_[r[E]]),u+=O[r[E]];return Fe(t,u,_[256]),u+O[256]},Je=new Se([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),Ge=function(e,t,n,r,i){return function(e,t,n,r,i,o){var s=e.length,a=new ye(r+s+5*(1+Math.floor(s/7e3))+i),c=a.subarray(r,a.length-i),l=0;if(!t||s<8)for(var u=0;u<=s;u+=65535){var d=u+65535;d<s?l=ze(c,l,e.subarray(u,d)):(c[u]=o,l=ze(c,l,e.subarray(u,s)))}else{for(var v=Je[t-1],g=v>>>13,h=8191&v,f=(1<<n)-1,p=new be(32768),m=new be(f+1),y=Math.ceil(n/3),b=2*y,S=function(t){return(e[t]^e[t+1]<<y^e[t+2]<<b)&f},w=new Se(25e3),I=new be(288),C=new be(32),E=0,P=0,k=(u=0,0),R=0,T=0;u<s;++u){var _=S(u),O=32767&u,x=m[_];if(p[O]=x,m[_]=O,R<=u){var M=s-u;if((E>7e3||k>24576)&&M>423){l=Ke(e,c,0,w,I,C,P,k,T,u-T,l),k=E=P=0,T=u;for(var D=0;D<286;++D)I[D]=0;for(D=0;D<30;++D)C[D]=0}var L=2,N=0,U=h,q=O-x&32767;if(M>2&&_==S(u-q))for(var A=Math.min(g,M)-1,j=Math.min(32767,u),F=Math.min(258,M);q<=j&&--U&&O!=x;){if(e[u+L]==e[u+L-q]){for(var B=0;B<F&&e[u+B]==e[u+B-q];++B);if(B>L){if(L=B,N=q,B>A)break;var W=Math.min(q,B-2),$=0;for(D=0;D<W;++D){var H=u-q+D+32768&32767,z=H-p[H]+32768&32767;z>$&&($=z,x=H)}}}q+=(O=x)-(x=p[O])+32768&32767}if(N){w[k++]=268435456|Re[L]<<18|Te[N];var K=31&Re[L],J=31&Te[N];P+=we[K]+Ie[J],++I[257+K],++C[J],R=u+L,++E}else w[k++]=e[u],++I[e[u]]}}l=Ke(e,c,o,w,I,C,P,k,T,u-T,l)}return Ae(a,0,r+qe(l)+i)}(e,null==t.level?6:t.level,null==t.mem?Math.ceil(1.5*Math.max(8,Math.min(13,Math.log(e.length)))):12+t.mem,n,r,!0)};function Ve(e,t){void 0===t&&(t={});var n=function(){var e=1,t=0;return{p:function(n){for(var r=e,i=t,o=n.length,s=0;s!=o;){for(var a=Math.min(s+5552,o);s<a;++s)i+=r+=n[s];r%=65521,i%=65521}e=r,t=i},d:function(){return(e>>>8<<16|(255&t)<<8|t>>>8)+2*((255&e)<<23)}}}();n.p(e);var r,i,o,s=Ge(e,t,2,4);return r=s,i=t.level,o=0==i?0:i<6?1:9==i?3:2,r[0]=120,r[1]=o<<6|(o?32-2*o:1),function(e,t,n){for(;n;++t)e[t]=n,n>>>=8}(s,s.length-4,n.d()),s}const Qe=e=>{const t={...e,v:"v1"};return function(e,t){var n="";if(!t&&"undefined"!=typeof TextDecoder)return(new TextDecoder).decode(e);for(var r=0;r<e.length;){var i=e[r++];i<128||t?n+=String.fromCharCode(i):i<224?n+=String.fromCharCode((31&i)<<6|63&e[r++]):i<240?n+=String.fromCharCode((15&i)<<12|(63&e[r++])<<6|63&e[r++]):(i=((15&i)<<18|(63&e[r++])<<12|(63&e[r++])<<6|63&e[r++])-65536,n+=String.fromCharCode(55296|i>>10,56320|1023&i))}return n}(Ve(function(e,t){var n=e.length;if(!t&&"undefined"!=typeof TextEncoder)return(new TextEncoder).encode(e);for(var r=new ye(e.length+(e.length>>>1)),i=0,o=function(e){r[i++]=e},s=0;s<n;++s){if(i+5>r.length){var a=new ye(i+8+(n-s<<1));a.set(r),r=a}var c=e.charCodeAt(s);c<128||t?o(c):c<2048?(o(192|c>>>6),o(128|63&c)):c>55295&&c<57344?(o(240|(c=65536+(1047552&c)|1023&e.charCodeAt(++s))>>>18),o(128|c>>>12&63),o(128|c>>>6&63),o(128|63&c)):(o(224|c>>>12),o(128|c>>>6&63),o(128|63&c))}return Ae(r,0,i)}(JSON.stringify(t))),!0)};var Ze=function(){function e(e,t,n,r){var i,o=this;this.taskQueue=[],this.isProcessing=!1,this.compressEvent=function(e){var t=Qe(e);return JSON.stringify(t)},this.addCompressedEventToManager=function(e,t){o.eventsManager&&o.deviceId&&o.eventsManager.addEvent({event:{type:"replay",data:e},sessionId:t,deviceId:o.deviceId})},this.addCompressedEvent=function(e,t){if(o.worker)try{o.worker.postMessage({event:e,sessionId:t})}catch(n){"DataCloneError"===n.name?o.worker.postMessage(JSON.stringify({event:e,sessionId:t})):o.config.loggerProvider.warn("Unexpected error while posting message to worker:",n)}else{var n=o.compressEvent(e);o.addCompressedEventToManager(n,t)}},this.terminate=function(){var e;null===(e=o.worker)||void 0===e||e.terminate()};var s=h();if(this.canUseIdleCallback=s&&"requestIdleCallback"in s,this.eventsManager=e,this.config=t,this.deviceId=n,this.timeout=(null===(i=t.performanceConfig)||void 0===i?void 0:i.timeout)||2e3,r){t.loggerProvider.log("Enabling web worker for compression");try{var a=new Blob([r],{type:"application/javascript"}),c=URL.createObjectURL(a),l=new Worker(c);l.onerror=function(e){t.loggerProvider.error("Worker failed, falling back to non-worker compression:",e),l.terminate(),o.worker=void 0},l.onmessage=function(e){var t=e.data,n=t.compressedEvent,r=t.sessionId;o.addCompressedEventToManager(n,r)},this.worker=l}catch(e){t.loggerProvider.error("Failed to create worker, falling back to non-worker compression:",e)}}}return e.prototype.scheduleIdleProcessing=function(){var e=this;this.isProcessing||(this.isProcessing=!0,requestIdleCallback(function(t){e.processQueue(t)},{timeout:this.timeout}))},e.prototype.enqueueEvent=function(e,t){var n;this.canUseIdleCallback&&(null===(n=this.config.performanceConfig)||void 0===n?void 0:n.enabled)?(this.config.loggerProvider.debug("Enqueuing event for processing during idle time."),this.taskQueue.push({event:e,sessionId:t}),this.scheduleIdleProcessing()):(this.config.loggerProvider.debug("Processing event without idle callback."),this.addCompressedEvent(e,t))},e.prototype.processQueue=function(e){for(var t=this;this.taskQueue.length>0&&(e.timeRemaining()>0||e.didTimeout);){var n=this.taskQueue.shift();if(n){var r=n.event,i=n.sessionId;this.addCompressedEvent(r,i)}}this.taskQueue.length>0?requestIdleCallback(function(e){t.processQueue(e)},{timeout:this.timeout}):this.isProcessing=!1},e}(),Ye="Session replay event batch rejected due to exceeded retry count",Xe="Failed to store session replay events in IndexedDB",et="1.32.0",tt=function(){function e(e){var t=e.trackServerUrl,n=e.loggerProvider,r=e.payloadBatcher;this.storageKey="",this.retryTimeout=1e3,this.scheduled=null,this.queue=[],this.loggerProvider=n,this.payloadBatcher=r||function(e){return e},this.trackServerUrl=t}return e.prototype.sendEventsList=function(e){this.addToQueue(i(i({},e),{attempts:0,timeout:0}))},e.prototype.addToQueue=function(){for(var e=this,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];t.filter(function(t){return t.attempts<(t.flushMaxRetries||0)?(t.attempts+=1,!0):(e.completeRequest({context:t,err:Ye}),!1)}).forEach(function(t){e.queue=e.queue.concat(t),e.schedule(0)})},e.prototype.schedule=function(e){var t=this;this.scheduled||(this.scheduled=setTimeout(function(){t.flush(!0).then(function(){t.queue.length>0&&t.schedule(e)})},e))},e.prototype.flush=function(e){return void 0===e&&(e=!1),o(this,void 0,void 0,function(){var t,n,r,i,o,c,l;return s(this,function(s){switch(s.label){case 0:t=this.queue,this.queue=[],this.scheduled&&(clearTimeout(this.scheduled),this.scheduled=null),s.label=1;case 1:s.trys.push([1,6,7,8]),n=a(t),r=n.next(),s.label=2;case 2:return r.done?[3,5]:(i=r.value,[4,this.send(i,e)]);case 3:s.sent(),s.label=4;case 4:return r=n.next(),[3,2];case 5:return[3,8];case 6:return o=s.sent(),c={error:o},[3,8];case 7:try{r&&!r.done&&(l=n.return)&&l.call(n)}finally{if(c)throw c.error}return[7];case 8:return[2]}})})},e.prototype.send=function(e,t){var n,r;return void 0===t&&(t=!0),o(this,void 0,void 0,function(){var i,o,a,c,l,u,d,v,g,f,p,m,y;return s(this,function(s){switch(s.label){case 0:if(!(i=e.apiKey))return[2,this.completeRequest({context:e,err:"Session replay event batch not sent due to missing api key"})];if(!(o=e.deviceId))return[2,this.completeRequest({context:e,err:"Session replay event batch not sent due to missing device ID"})];if(b=h(),a=(null==b?void 0:b.location)?b.location.href:"",c=et,l=e.sampleRate,u=new URLSearchParams({device_id:o,session_id:"".concat(e.sessionId),type:"".concat(e.type)}),d="".concat((null===(n=e.version)||void 0===n?void 0:n.type)||"standalone","/").concat((null===(r=e.version)||void 0===r?void 0:r.version)||c),0===(v=this.payloadBatcher({version:1,events:e.events})).events.length)return this.completeRequest({context:e}),[2];s.label=1;case 1:return s.trys.push([1,6,,7]),g={headers:{"Content-Type":"application/json",Accept:"*/*",Authorization:"Bearer ".concat(i),"X-Client-Version":c,"X-Client-Library":d,"X-Client-Url":a.substring(0,1e3),"X-Client-Sample-Rate":"".concat(l)},body:JSON.stringify(v),method:"POST"},f="".concat(ae(e.serverZone,this.trackServerUrl),"?").concat(u.toString()),[4,fetch(f,g)];case 2:if(null===(p=s.sent()))return this.completeRequest({context:e,err:"Unexpected error occurred"}),[2];if(t)return[3,3];m="";try{m=JSON.stringify(p.body,null,2)}catch(e){}return this.completeRequest({context:e,success:"".concat(p.status,": ").concat(m)}),[3,5];case 3:return[4,this.handleReponse(p.status,e)];case 4:s.sent(),s.label=5;case 5:return[3,7];case 6:return y=s.sent(),this.completeRequest({context:e,err:y}),[3,7];case 7:return[2]}var b})})},e.prototype.handleReponse=function(e,t){return o(this,void 0,void 0,function(){var n;return s(this,function(r){switch(r.label){case 0:switch(n=(new q).buildStatus(e),n){case u.Success:return[3,1];case u.Failed:return[3,2]}return[3,4];case 1:return this.handleSuccessResponse(t),[3,5];case 2:return[4,this.handleOtherResponse(t)];case 3:return r.sent(),[3,5];case 4:this.completeRequest({context:t,err:"Network error occurred, event batch rejected"}),r.label=5;case 5:return[2]}})})},e.prototype.handleSuccessResponse=function(e){var t=Math.round(new Blob(e.events).size/1024);this.completeRequest({context:e,success:"Session replay event batch tracked successfully for session id ".concat(e.sessionId,", size of events: ").concat(t," KB")})},e.prototype.handleOtherResponse=function(e){return o(this,void 0,void 0,function(){var t;return s(this,function(n){switch(n.label){case 0:return t=e.attempts*this.retryTimeout,e.attempts++,e.attempts>(e.flushMaxRetries||0)?(this.completeRequest({context:e,err:Ye}),[2]):[4,new Promise(function(e){return setTimeout(e,t)})];case 1:return n.sent(),[4,this.send(e,!0)];case 2:return n.sent(),[2]}})})},e.prototype.completeRequest=function(e){var t=e.context,n=e.err,r=e.success;t.onComplete(),n?this.loggerProvider.warn(n):r&&this.loggerProvider.log(r)},e}();const nt=(e,t)=>t.some(t=>e instanceof t);let rt,it;const ot=new WeakMap,st=new WeakMap,at=new WeakMap;let ct={get(e,t,n){if(e instanceof IDBTransaction){if("done"===t)return ot.get(e);if("store"===t)return n.objectStoreNames[1]?void 0:n.objectStore(n.objectStoreNames[0])}return vt(e[t])},set:(e,t,n)=>(e[t]=n,!0),has:(e,t)=>e instanceof IDBTransaction&&("done"===t||"store"===t)||t in e};function lt(e){ct=e(ct)}function ut(e){return(it||(it=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])).includes(e)?function(...t){return e.apply(gt(this),t),vt(this.request)}:function(...t){return vt(e.apply(gt(this),t))}}function dt(e){return"function"==typeof e?ut(e):(e instanceof IDBTransaction&&function(e){if(ot.has(e))return;const t=new Promise((t,n)=>{const r=()=>{e.removeEventListener("complete",i),e.removeEventListener("error",o),e.removeEventListener("abort",o)},i=()=>{t(),r()},o=()=>{n(e.error||new DOMException("AbortError","AbortError")),r()};e.addEventListener("complete",i),e.addEventListener("error",o),e.addEventListener("abort",o)});ot.set(e,t)}(e),nt(e,rt||(rt=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction]))?new Proxy(e,ct):e)}function vt(e){if(e instanceof IDBRequest)return function(e){const t=new Promise((t,n)=>{const r=()=>{e.removeEventListener("success",i),e.removeEventListener("error",o)},i=()=>{t(vt(e.result)),r()},o=()=>{n(e.error),r()};e.addEventListener("success",i),e.addEventListener("error",o)});return at.set(t,e),t}(e);if(st.has(e))return st.get(e);const t=dt(e);return t!==e&&(st.set(e,t),at.set(t,e)),t}const gt=e=>at.get(e);function ht(e,t,{blocked:n,upgrade:r,blocking:i,terminated:o}={}){const s=indexedDB.open(e,t),a=vt(s);return r&&s.addEventListener("upgradeneeded",e=>{r(vt(s.result),e.oldVersion,e.newVersion,vt(s.transaction),e)}),n&&s.addEventListener("blocked",e=>n(e.oldVersion,e.newVersion,e)),a.then(e=>{o&&e.addEventListener("close",()=>o()),i&&e.addEventListener("versionchange",e=>i(e.oldVersion,e.newVersion,e))}).catch(()=>{}),a}const ft=["get","getKey","getAll","getAllKeys","count"],pt=["put","add","delete","clear"],mt=new Map;function yt(e,t){if(!(e instanceof IDBDatabase)||t in e||"string"!=typeof t)return;if(mt.get(t))return mt.get(t);const n=t.replace(/FromIndex$/,""),r=t!==n,i=pt.includes(n);if(!(n in(r?IDBIndex:IDBObjectStore).prototype)||!i&&!ft.includes(n))return;const o=async function(e,...t){const o=this.transaction(e,i?"readwrite":"readonly");let s=o.store;return r&&(s=s.index(t.shift())),(await Promise.all([s[n](...t),i&&o.done]))[0]};return mt.set(t,o),o}lt(e=>({...e,get:(t,n,r)=>yt(t,n)||e.get(t,n,r),has:(t,n)=>!!yt(t,n)||e.has(t,n)}));const bt=["continue","continuePrimaryKey","advance"],St={},wt=new WeakMap,It=new WeakMap,Ct={get(e,t){if(!bt.includes(t))return e[t];let n=St[t];return n||(n=St[t]=function(...e){wt.set(this,It.get(this)[t](...e))}),n}};async function*Et(...e){let t=this;if(t instanceof IDBCursor||(t=await t.openCursor(...e)),!t)return;const n=new Proxy(t,Ct);for(It.set(n,t),at.set(n,gt(t));t;)yield n,t=await(wt.get(n)||t.continue()),wt.delete(n)}function Pt(e,t){return t===Symbol.asyncIterator&&nt(e,[IDBIndex,IDBObjectStore,IDBCursor])||"iterate"===t&&nt(e,[IDBIndex,IDBObjectStore])}lt(e=>({...e,get:(t,n,r)=>Pt(t,n)?Et:e.get(t,n,r),has:(t,n)=>Pt(t,n)||e.has(t,n)}));var kt,Rt,Tt,_t=function(){function e(e){var t,n,r,i=this;this.minInterval=500,this.maxInterval=1e4,this.maxPersistedEventsSize=1e6,this.interval=this.minInterval,this._timeAtLastSplit=Date.now(),this.shouldSplitEventsList=function(e,t){var n=i.getStringSize(t);return i.getEventsArraySize(e)+n>=i.maxPersistedEventsSize||!!(Date.now()-i.timeAtLastSplit>i.interval&&e.length)&&(i.interval=Math.min(i.maxInterval,i.interval+i.minInterval),i._timeAtLastSplit=Date.now(),!0)},this.loggerProvider=e.loggerProvider,this.minInterval=null!==(t=e.minInterval)&&void 0!==t?t:this.minInterval,this.maxInterval=null!==(n=e.maxInterval)&&void 0!==n?n:this.maxInterval,this.maxPersistedEventsSize=null!==(r=e.maxPersistedEventsSize)&&void 0!==r?r:this.maxPersistedEventsSize}return Object.defineProperty(e.prototype,"timeAtLastSplit",{get:function(){return this._timeAtLastSplit},enumerable:!1,configurable:!0}),e.prototype.getStringSize=function(e){return e.length},e.prototype.getEventsArraySize=function(e){var t,n,r=0;try{for(var i=a(e),o=i.next();!o.done;o=i.next()){var s=o.value;r+=this.getStringSize(s)}}catch(e){t={error:e}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(t)throw t.error}}return r+(2+Math.max(0,e.length-1)+2*e.length)},e}(),Ot=function(e,t,n){var r;"object"==typeof(r=n)&&null!==r&&"AbortError"===r.name?e.debug(t):e.warn(t)},xt="sessionCurrentSequence",Mt="sequencesToSend",Dt=function(e){var t,n;return e.objectStoreNames.contains(xt)||(n=e.createObjectStore(xt,{keyPath:"sessionId"})),e.objectStoreNames.contains(Mt)||(t=e.createObjectStore(Mt,{keyPath:"sequenceId",autoIncrement:!0})).createIndex("sessionId","sessionId"),{sequencesStore:t,currentSequenceStore:n}},Lt=function(e){return o(void 0,void 0,void 0,function(){return s(this,function(t){switch(t.label){case 0:return[4,ht(e,1,{upgrade:Dt})];case 1:return[2,t.sent()]}})})},Nt=function(e){function n(t){var n=e.call(this,t)||this;return n.getSequencesToSend=function(){return o(n,void 0,void 0,function(){var e,t,n,r,i,o;return s(this,function(s){switch(s.label){case 0:return s.trys.push([0,5,,6]),e=[],[4,this.db.transaction("sequencesToSend").store.openCursor()];case 1:t=s.sent(),s.label=2;case 2:return t?(n=t.value,r=n.sessionId,i=n.events,e.push({events:i,sequenceId:t.key,sessionId:r}),[4,t.continue()]):[3,4];case 3:return t=s.sent(),[3,2];case 4:return[2,e];case 5:return o=s.sent(),Ot(this.loggerProvider,"".concat(Xe,": ").concat(o),o),[3,6];case 6:return[2,void 0]}})})},n.storeCurrentSequence=function(e){return o(n,void 0,void 0,function(){var t,n,r;return s(this,function(o){switch(o.label){case 0:return o.trys.push([0,4,,5]),[4,this.db.get(xt,e)];case 1:return(t=o.sent())?[4,this.db.put(Mt,{sessionId:e,events:t.events})]:[2,void 0];case 2:return n=o.sent(),[4,this.db.put(xt,{sessionId:e,events:[]})];case 3:return o.sent(),[2,i(i({},t),{sessionId:e,sequenceId:n})];case 4:return r=o.sent(),Ot(this.loggerProvider,"".concat(Xe,": ").concat(r),r),[3,5];case 5:return[2,void 0]}})})},n.addEventToCurrentSequence=function(e,t){return o(n,void 0,void 0,function(){var n,r,i,o,a,c;return s(this,function(s){switch(s.label){case 0:return s.trys.push([0,10,,11]),[4,(n=this.db.transaction(xt,"readwrite")).store.get(e)];case 1:return(r=s.sent())?[3,3]:[4,n.store.put({sessionId:e,events:[t]})];case 2:return s.sent(),[2];case 3:return i=void 0,this.shouldSplitEventsList(r.events,t)?(i=r.events,[4,n.store.put({sessionId:e,events:[t]})]):[3,5];case 4:return s.sent(),[3,7];case 5:return o=r.events.concat(t),[4,n.store.put({sessionId:e,events:o})];case 6:s.sent(),s.label=7;case 7:return[4,n.done];case 8:return s.sent(),i?[4,this.storeSendingEvents(e,i)]:[2,void 0];case 9:return(a=s.sent())?[2,{events:i,sessionId:e,sequenceId:a}]:[2,void 0];case 10:return c=s.sent(),Ot(this.loggerProvider,"".concat(Xe,": ").concat(c),c),[3,11];case 11:return[2,void 0]}})})},n.storeSendingEvents=function(e,t){return o(n,void 0,void 0,function(){var n;return s(this,function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,this.db.put(Mt,{sessionId:e,events:t})];case 1:return[2,r.sent()];case 2:return n=r.sent(),Ot(this.loggerProvider,"".concat(Xe,": ").concat(n),n),[3,3];case 3:return[2,void 0]}})})},n.cleanUpSessionEventsStore=function(e,t){return o(n,void 0,void 0,function(){var e;return s(this,function(n){switch(n.label){case 0:if(!t)return[2];n.label=1;case 1:return n.trys.push([1,3,,4]),[4,this.db.delete(Mt,t)];case 2:return n.sent(),[3,4];case 3:return e=n.sent(),Ot(this.loggerProvider,"".concat(Xe,": ").concat(e),e),[3,4];case 4:return[2]}})})},n.db=t.db,n}return t(n,e),n.new=function(e,t){return o(this,void 0,void 0,function(){var r,o,a,c;return s(this,function(s){switch(s.label){case 0:return s.trys.push([0,2,,3]),r="replay"===e?"":"_".concat(e),o="".concat(t.apiKey.substring(0,10),"_amp_session_replay_events").concat(r),[4,Lt(o)];case 1:return a=s.sent(),[2,new n(i(i({},t),{db:a}))];case 2:return c=s.sent(),Ot(t.loggerProvider,"".concat(Xe,": ").concat(c),c),[3,3];case 3:return[2]}})})},n.prototype.getCurrentSequenceEvents=function(e){return o(this,void 0,void 0,function(){var t,n,r,i,o,c,l;return s(this,function(s){switch(s.label){case 0:return e?[4,this.db.get("sessionCurrentSequence",e)]:[3,2];case 1:return(i=s.sent())?[2,[i]]:[2,void 0];case 2:t=[],s.label=3;case 3:return s.trys.push([3,8,9,10]),[4,this.db.getAll("sessionCurrentSequence")];case 4:n=a.apply(void 0,[s.sent()]),r=n.next(),s.label=5;case 5:if(r.done)return[3,7];i=r.value,t.push(i),s.label=6;case 6:return r=n.next(),[3,5];case 7:return[3,10];case 8:return o=s.sent(),c={error:o},[3,10];case 9:try{r&&!r.done&&(l=n.return)&&l.call(n)}finally{if(c)throw c.error}return[7];case 10:return[2,t]}})})},n}(_t),Ut=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t.finalizedSequences={},t.sequences={},t.sequenceId=0,t}return t(n,e),n.prototype.resetCurrentSequence=function(e){this.sequences[e]=[]},n.prototype.addSequence=function(e){var t=this.sequenceId++,n=l([],c(this.sequences[e]),!1);return this.finalizedSequences[t]={sessionId:e,events:n},this.resetCurrentSequence(e),{sequenceId:t,events:n,sessionId:e}},n.prototype.getSequencesToSend=function(){return o(this,void 0,void 0,function(){return s(this,function(e){return[2,Object.entries(this.finalizedSequences).map(function(e){var t=c(e,2),n=t[0],r=t[1],i=r.sessionId,o=r.events;return{sequenceId:Number(n),sessionId:i,events:o}})]})})},n.prototype.storeCurrentSequence=function(e){return o(this,void 0,void 0,function(){return s(this,function(t){return this.sequences[e]?[2,this.addSequence(e)]:[2,void 0]})})},n.prototype.addEventToCurrentSequence=function(e,t){return o(this,void 0,void 0,function(){var n;return s(this,function(r){return this.sequences[e]||this.resetCurrentSequence(e),this.shouldSplitEventsList(this.sequences[e],t)&&(n=this.addSequence(e)),this.sequences[e].push(t),[2,n]})})},n.prototype.storeSendingEvents=function(e,t){return o(this,void 0,void 0,function(){return s(this,function(n){return this.finalizedSequences[this.sequenceId]={sessionId:e,events:t},[2,this.sequenceId++]})})},n.prototype.cleanUpSessionEventsStore=function(e,t){return o(this,void 0,void 0,function(){return s(this,function(e){return void 0!==t&&delete this.finalizedSequences[t],[2]})})},n}(_t),qt=function(e){var t=e.config,n=e.minInterval,r=e.maxInterval,a=e.type,c=e.payloadBatcher,l=e.storeType;return o(void 0,void 0,void 0,function(){function e(e){return void 0===e&&(e=!1),o(this,void 0,void 0,function(){return s(this,function(t){return[2,u.flush(e)]})})}var u,d,v,g,h,f,p,m,y;return s(this,function(b){switch(b.label){case 0:return u=new tt(i(i({},t),{loggerProvider:t.loggerProvider,payloadBatcher:c})),d=function(){return new Ut({loggerProvider:t.loggerProvider,maxInterval:r,minInterval:n})},v=function(){return o(void 0,void 0,void 0,function(){var e;return s(this,function(i){switch(i.label){case 0:return[4,Nt.new(a,{loggerProvider:t.loggerProvider,minInterval:n,maxInterval:r,apiKey:t.apiKey})];case 1:return(e=i.sent())?[2,e]:(t.loggerProvider.log("Failed to initialize idb store, falling back to memory store."),[2,d()])}})})},"idb"!==l?[3,2]:[4,v()];case 1:return h=b.sent(),[3,3];case 2:h=d(),b.label=3;case 3:return g=h,f=function(e){var n=e.events,r=e.sessionId,i=e.deviceId,c=e.sequenceId;t.debugMode&&ue().then(function(e){var n=e.totalStorageSize,r=e.percentOfQuota,i=e.usageDetails;t.loggerProvider.debug("Total storage size: ".concat(n," KB, percentage of quota: ").concat(r,"%, usage details: ").concat(i))}).catch(function(){}),u.sendEventsList({events:n,sessionId:r,flushMaxRetries:t.flushMaxRetries,apiKey:t.apiKey,deviceId:i,sampleRate:t.sampleRate,serverZone:t.serverZone,version:t.version,type:a,onComplete:function(){return o(void 0,void 0,void 0,function(){return s(this,function(e){switch(e.label){case 0:return[4,g.cleanUpSessionEventsStore(r,c)];case 1:return e.sent(),[2]}})})}})},p=function(e){var n=e.sessionId,r=e.deviceId;g.storeCurrentSequence(n).then(function(e){e&&f({sequenceId:e.sequenceId,events:e.events,sessionId:e.sessionId,deviceId:r})}).catch(function(e){t.loggerProvider.warn("Failed to get current sequence of session replay events for session:",e)})},m=function(e){var t=e.deviceId;return o(void 0,void 0,void 0,function(){var e;return s(this,function(n){switch(n.label){case 0:return[4,g.getSequencesToSend()];case 1:return(e=n.sent())&&e.forEach(function(e){f({sequenceId:e.sequenceId,events:e.events,sessionId:e.sessionId,deviceId:t})}),[2]}})})},y=function(e){var n=e.event,r=e.sessionId,i=e.deviceId;g.addEventToCurrentSequence(r,n.data).then(function(e){return e&&f({sequenceId:e.sequenceId,events:e.events,sessionId:e.sessionId,deviceId:i})}).catch(function(e){t.loggerProvider.warn("Failed to add event to session replay capture:",e)})},[2,{sendCurrentSequenceEvents:p,addEvent:y,sendStoredEvents:m,flush:e}]}})})},At=function(){function e(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=new Map;e.forEach(function(e){n.set(e.name,e.manager)}),this.managers=n}return e.prototype.sendStoredEvents=function(e){return o(this,void 0,void 0,function(){var t;return s(this,function(n){switch(n.label){case 0:return t=[],this.managers.forEach(function(n){t.push(n.sendStoredEvents(e))}),[4,Promise.all(t)];case 1:return n.sent(),[2]}})})},e.prototype.addEvent=function(e){var t,n=e.sessionId,r=e.event,i=e.deviceId;null===(t=this.managers.get(r.type))||void 0===t||t.addEvent({sessionId:n,event:r,deviceId:i})},e.prototype.sendCurrentSequenceEvents=function(e){var t=e.sessionId,n=e.deviceId;this.managers.forEach(function(e){e.sendCurrentSequenceEvents({sessionId:t,deviceId:n})})},e.prototype.flush=function(e){return o(this,void 0,void 0,function(){var t;return s(this,function(n){switch(n.label){case 0:return t=[],this.managers.forEach(function(n){t.push(n.flush(e))}),[4,Promise.all(t)];case 1:return n.sent(),[2]}})})},e}();function jt(e,t){if(Tt=new Date,e.nodeType!==Node.ELEMENT_NODE)throw new Error("Can't generate CSS selector for non-element node type.");if("html"===e.tagName.toLowerCase())return"html";var n={root:document.body,idName:function(e){return!0},className:function(e){return!0},tagName:function(e){return!0},attr:function(e,t){return!1},seedMinLength:1,optimizedMinLength:2,threshold:1e3,maxNumberOfTries:1e4,timeoutMs:void 0};kt=i(i({},n),t),Rt=function(e,t){if(e.nodeType===Node.DOCUMENT_NODE)return e;if(e===t.root)return e.ownerDocument;return e}(kt.root,n);var r=Ft(e,"all",function(){return Ft(e,"two",function(){return Ft(e,"one",function(){return Ft(e,"none")})})});if(r){var o=Qt(Zt(r,e));return o.length>0&&(r=o[0]),Wt(r)}throw new Error("Selector was not found.")}function Ft(e,t,n){for(var r=null,i=[],o=e,s=0,u=function(){var e,u,d=(new Date).getTime()-Tt.getTime();if(void 0!==kt.timeoutMs&&d>kt.timeoutMs)throw new Error("Timeout: Can't find a unique selector after ".concat(d,"ms"));var v=Jt(function(e){var t=e.getAttribute("id");if(t&&kt.idName(t))return{name:"#"+CSS.escape(t),penalty:0};return null}(o))||Jt.apply(void 0,l([],c(function(e){var t=Array.from(e.attributes).filter(function(e){return kt.attr(e.name,e.value)});return t.map(function(e){return{name:"[".concat(CSS.escape(e.name),'="').concat(CSS.escape(e.value),'"]'),penalty:.5}})}(o)),!1))||Jt.apply(void 0,l([],c(function(e){var t=Array.from(e.classList).filter(kt.className);return t.map(function(e){return{name:"."+CSS.escape(e),penalty:1}})}(o)),!1))||Jt(function(e){var t=e.tagName.toLowerCase();if(kt.tagName(t))return{name:t,penalty:2};return null}(o))||[{name:"*",penalty:3}],g=function(e){var t=e.parentNode;if(!t)return null;var n=t.firstChild;if(!n)return null;var r=0;for(;n&&(n.nodeType===Node.ELEMENT_NODE&&r++,n!==e);)n=n.nextSibling;return r}(o);if("all"==t)g&&(v=v.concat(v.filter(Kt).map(function(e){return zt(e,g)})));else if("two"==t)v=v.slice(0,1),g&&(v=v.concat(v.filter(Kt).map(function(e){return zt(e,g)})));else if("one"==t){var h=c(v=v.slice(0,1),1)[0];g&&Kt(h)&&(v=[zt(h,g)])}else"none"==t&&(v=[{name:"*",penalty:3}],g&&(v=[zt(v[0],g)]));try{for(var f=(e=void 0,a(v)),p=f.next();!p.done;p=f.next()){(h=p.value).level=s}}catch(t){e={error:t}}finally{try{p&&!p.done&&(u=f.return)&&u.call(f)}finally{if(e)throw e.error}}if(i.push(v),i.length>=kt.seedMinLength&&(r=Bt(i,n)))return"break";o=o.parentElement,s++};o;){if("break"===u())break}return r||(r=Bt(i,n)),!r&&n?n():r}function Bt(e,t){var n,r,i=Qt(Vt(e));if(i.length>kt.threshold)return t?t():null;try{for(var o=a(i),s=o.next();!s.done;s=o.next()){var c=s.value;if(Ht(c))return c}}catch(e){n={error:e}}finally{try{s&&!s.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}return null}function Wt(e){for(var t=e[0],n=t.name,r=1;r<e.length;r++){var i=e[r].level||0;n=t.level===i-1?"".concat(e[r].name," > ").concat(n):"".concat(e[r].name," ").concat(n),t=e[r]}return n}function $t(e){return e.map(function(e){return e.penalty}).reduce(function(e,t){return e+t},0)}function Ht(e){var t=Wt(e);switch(Rt.querySelectorAll(t).length){case 0:throw new Error("Can't select any node with this selector: ".concat(t));case 1:return!0;default:return!1}}function zt(e,t){return{name:e.name+":nth-child(".concat(t,")"),penalty:e.penalty+1}}function Kt(e){return"html"!==e.name&&!e.name.startsWith("#")}function Jt(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=e.filter(Gt);return n.length>0?n:null}function Gt(e){return null!=e}function Vt(e,t){var n,r,i,o,c,l;return void 0===t&&(t=[]),s(this,function(s){switch(s.label){case 0:if(!(e.length>0))return[3,9];s.label=1;case 1:s.trys.push([1,6,7,8]),n=a(e[0]),r=n.next(),s.label=2;case 2:return r.done?[3,5]:(i=r.value,[5,a(Vt(e.slice(1,e.length),t.concat(i)))]);case 3:s.sent(),s.label=4;case 4:return r=n.next(),[3,2];case 5:return[3,8];case 6:return o=s.sent(),c={error:o},[3,8];case 7:try{r&&!r.done&&(l=n.return)&&l.call(n)}finally{if(c)throw c.error}return[7];case 8:return[3,11];case 9:return[4,t];case 10:s.sent(),s.label=11;case 11:return[2]}})}function Qt(e){return l([],c(e),!1).sort(function(e,t){return $t(e)-$t(t)})}function Zt(e,t,n){var r,i,o;return void 0===n&&(n={counter:0,visited:new Map}),s(this,function(s){switch(s.label){case 0:if(!(e.length>2&&e.length>kt.optimizedMinLength))return[3,5];r=1,s.label=1;case 1:return r<e.length-1?n.counter>kt.maxNumberOfTries?[2]:(n.counter+=1,(i=l([],c(e),!1)).splice(r,1),o=Wt(i),n.visited.has(o)?[2]:Ht(i)&&function(e,t){return Rt.querySelector(Wt(e))===t}(i,t)?[4,i]:[3,4]):[3,5];case 2:return s.sent(),n.visited.set(o,!0),[5,a(Zt(i,t,n))];case 3:s.sent(),s.label=4;case 4:return r++,[3,1];case 5:return[2]}})}var Yt=function(e){var t=e.version,n=e.events,r=[];return n.forEach(function(e){var t=JSON.parse(e);t.count=1,"click"===t.type&&r.push(t)}),{version:t,events:r}},Xt=function(e){var t=e.version,n=e.events,r=[];n.forEach(function(e){var t=JSON.parse(e);"click"===t.type&&r.push(t)});var o=r.reduce(function(e,t){var n=t.x,r=t.y,o=t.selector,s=t.timestamp,a=s-s%36e5,c="".concat(n,":").concat(r,":").concat(null!=o?o:"",":").concat(a);return e[c]?e[c].count+=1:e[c]=i(i({},t),{timestamp:a,count:1}),e},{});return{version:t,events:Object.values(o)}},en=function(e,t){var n=this;this.createHook=function(e){var t=e.eventsManager,r=e.sessionId,i=e.deviceIdFn,o=e.mirror,s=e.ugcFilterRules,a=e.performanceOptions;return function(e){if(e.type===fe.Click){var c=h();if(c){var l=c.location,u=c.innerHeight,d=c.innerWidth;if(l){var v=e.x,g=e.y;if(void 0!==v&&void 0!==g){var f,p=o.getNode(e.id);if(p)try{f=jt(p,a)}catch(e){n.logger.debug("error resolving selector from finder")}var m=le(l.href,s),y={x:v+n.scrollWatcher.currentScrollX,y:g+n.scrollWatcher.currentScrollY,selector:f,viewportHeight:u,viewportWidth:d,pageUrl:m,timestamp:Date.now(),type:"click"},b=i();b&&t.addEvent({sessionId:r,event:{type:"interaction",data:JSON.stringify(y)},deviceId:b})}}}}}},this.logger=e,this.scrollWatcher=t};function tn(){var e=h();return(null==e?void 0:e.innerHeight)||document.documentElement&&document.documentElement.clientHeight||0}function nn(){var e=h();return(null==e?void 0:e.innerWidth)||document.documentElement&&document.documentElement.clientWidth||0}var rn=function(){function e(e,t){var n=h();n&&n.navigator&&"function"==typeof n.navigator.sendBeacon?this.sendBeacon=function(e,t){try{if(n.navigator.sendBeacon(e,JSON.stringify(t)))return!0}catch(e){}return!1}:this.sendBeacon=function(){return!1},this.sendXhr=function(e,t){var n=new XMLHttpRequest;return n.open("POST",e,!0),n.setRequestHeader("Accept","*/*"),n.send(JSON.stringify(t)),!0},this.basePageUrl=ae(t.serverZone,t.trackServerUrl),this.apiKey=t.apiKey,this.context=e}return e.prototype.send=function(e,t){var n=this.context,r=n.sessionId,i=n.type,o=new URLSearchParams({device_id:e,session_id:String(r),type:String(i),api_key:this.apiKey}),s="".concat(this.basePageUrl,"?").concat(o.toString());this.sendBeacon(s,t)||this.sendXhr(s,t)},e}(),on=function(){function e(e,t){var n=this;this.timestamp=Date.now(),this.hook=function(e){n.update(e)},this.send=function(e){return function(t){var r,i,o=e(),s=h();s&&o&&n.transport.send(o,{version:1,events:[{maxScrollX:n._maxScrollX,maxScrollY:n._maxScrollY,maxScrollWidth:n._maxScrollWidth,maxScrollHeight:n._maxScrollHeight,viewportHeight:tn(),viewportWidth:nn(),pageUrl:le(s.location.href,null!==(i=null===(r=n.config.interactionConfig)||void 0===r?void 0:r.ugcFilterRules)&&void 0!==i?i:[]),timestamp:n.timestamp,type:"scroll"}]})}},this._maxScrollX=0,this._maxScrollY=0,this._currentScrollX=0,this._currentScrollY=0,this._maxScrollWidth=nn(),this._maxScrollHeight=tn(),this.config=t,this.transport=e}return e.default=function(t,n){return new e(new rn(t,n),n)},Object.defineProperty(e.prototype,"maxScrollX",{get:function(){return this._maxScrollX},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"maxScrollY",{get:function(){return this._maxScrollY},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"maxScrollWidth",{get:function(){return this._maxScrollWidth},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"maxScrollHeight",{get:function(){return this._maxScrollHeight},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"currentScrollX",{get:function(){return this._currentScrollX},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"currentScrollY",{get:function(){return this._currentScrollY},enumerable:!1,configurable:!0}),e.prototype.update=function(e){var t=Date.now();if(this._currentScrollX=e.x,this._currentScrollY=e.y,e.x>this._maxScrollX){var n=nn();this._maxScrollX=e.x;var r=e.x+n;r>this._maxScrollWidth&&(this._maxScrollWidth=r),this.timestamp=t}if(e.y>this._maxScrollY){var i=tn();this._maxScrollY=e.y;var o=e.y+i;o>this._maxScrollHeight&&(this._maxScrollHeight=o),this.timestamp=t}},e}(),sn=function(e){var t=e.sessionId,n=e.deviceId;this.deviceId=n,this.sessionId=t,t&&n&&(this.sessionReplayId=function(e,t){return"".concat(t,"/").concat(e)}(t,n))},an=function(){var e=this;this.dbs={},this.createStore=function(t){return o(e,void 0,void 0,function(){return s(this,function(e){switch(e.label){case 0:return[4,ht(t,1,{upgrade:function(e){e.objectStoreNames.contains("sessionTargetingMatch")||e.createObjectStore("sessionTargetingMatch",{keyPath:"sessionId"})}})];case 1:return[2,e.sent()]}})})},this.openOrCreateDB=function(t){return o(e,void 0,void 0,function(){var e,n;return s(this,function(r){switch(r.label){case 0:return this.dbs&&this.dbs[t]?[2,this.dbs[t]]:(e="".concat(t.substring(0,10),"_amp_session_replay_targeting"),[4,this.createStore(e)]);case 1:return n=r.sent(),this.dbs[t]=n,[2,n]}})})},this.getTargetingMatchForSession=function(t){var n=t.loggerProvider,r=t.apiKey,i=t.sessionId;return o(e,void 0,void 0,function(){var e,t,o,a;return s(this,function(s){switch(s.label){case 0:return s.trys.push([0,3,,4]),[4,this.openOrCreateDB(r)];case 1:return e=s.sent(),t=String(i),[4,e.get("sessionTargetingMatch",t)];case 2:return[2,null==(o=s.sent())?void 0:o.targetingMatch];case 3:return a=s.sent(),Ot(n,"Failed to get targeting match for session id ".concat(i,": ").concat(a),a),[3,4];case 4:return[2,void 0]}})})},this.storeTargetingMatchForSession=function(t){var n=t.loggerProvider,r=t.apiKey,i=t.sessionId,a=t.targetingMatch;return o(e,void 0,void 0,function(){var e,t,o;return s(this,function(s){switch(s.label){case 0:return s.trys.push([0,3,,4]),[4,this.openOrCreateDB(r)];case 1:return e=s.sent(),t=String(i),[4,e.put("sessionTargetingMatch",{targetingMatch:a,sessionId:t,lastUpdated:Date.now()})];case 2:return[2,s.sent()];case 3:return o=s.sent(),Ot(n,"Failed to store targeting match for session id ".concat(i,": ").concat(o),o),[3,4];case 4:return[2,void 0]}})})},this.clearStoreOfOldSessions=function(t){var n=t.loggerProvider,r=t.apiKey,i=t.currentSessionId;return o(e,void 0,void 0,function(){var e,t,o,a,c,l,u,d;return s(this,function(s){switch(s.label){case 0:return s.trys.push([0,8,,9]),[4,this.openOrCreateDB(r)];case 1:return e=s.sent(),t=String(i),[4,(o=e.transaction("sessionTargetingMatch","readwrite")).store.getAll()];case 2:a=s.sent(),c=0,s.label=3;case 3:return c<a.length?(l=a[c],u=Date.now()-l.lastUpdated,l.sessionId!==t&&u>1728e5?[4,o.store.delete(l.sessionId)]:[3,5]):[3,6];case 4:s.sent(),s.label=5;case 5:return c++,[3,3];case 6:return[4,o.done];case 7:return s.sent(),[3,9];case 8:return d=s.sent(),Ot(n,"Failed to clear old targeting matches for sessions: ".concat(d),d),[3,9];case 9:return[2]}})})}},cn=new an,ln=function(e){var t=e.sessionId,n=e.targetingConfig,r=e.loggerProvider,a=e.apiKey,c=e.targetingParams,l=e.urlChange,u=void 0!==l&&l;return o(void 0,void 0,void 0,function(){var e,o,l,d,v,g;return s(this,function(s){switch(s.label){case 0:return[4,cn.clearStoreOfOldSessions({loggerProvider:r,apiKey:a,currentSessionId:t})];case 1:return s.sent(),[4,cn.getTargetingMatchForSession({loggerProvider:r,apiKey:a,sessionId:t})];case 2:if(!0===s.sent()&&!u)return[2,!0];e=!0,s.label=3;case 3:return s.trys.push([3,6,,7]),[4,import("./index-min3.js")];case 4:return o=s.sent().evaluateTargeting,l=i(i({},c),{flag:n,sessionId:"string"==typeof t?parseInt(t,10):t,apiKey:a,loggerProvider:r}),[4,o(l)];case 5:return(d=s.sent())&&d.sr_targeting_config&&(e="on"===d.sr_targeting_config.key),cn.storeTargetingMatchForSession({loggerProvider:r,apiKey:a,sessionId:t,targetingMatch:e}),[3,7];case 6:return v=s.sent(),g=v,r.warn(g.message),[3,7];case 7:return[2,e]}})})},un="__amplitude_url_tracking_patched__",dn=new WeakMap;function vn(e,t,n){if(void 0===n&&(n={}),!(null==e?void 0:e.location))return function(){};var r=n.enablePolling,i=void 0!==r&&r,o=n.pollingInterval,s=void 0===o?ee:o;if(i){var a=function(){var t;return null!==(t=e.location.href)&&void 0!==t?t:""},c=a(),l=e.setInterval(function(){var e=a();e!==c&&(c=e,t(e))},s);return function(){null!=l&&e.clearInterval(l)}}var u=dn.get(e);if(!u){var d=void 0,v=new Set,g=function(){var t=function(){var t;return null!==(t=e.location.href)&&void 0!==t?t:""}();void 0!==d&&t===d||(d=t,v.forEach(function(e){return e(t)}))},h=function(e){var t=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];var r=e.apply(this,t);return g(),r};return t[un]=!0,t},f=e.history;if(null==f?void 0:f.pushState){var p=Reflect.get(f,"pushState");p[un]||(f.pushState=h(p))}if(null==f?void 0:f.replaceState){var m=Reflect.get(f,"replaceState");m[un]||(f.replaceState=h(m))}u={callbacks:v,notify:g,onPopStateOrHashChange:function(){return g()},listenersAttached:!1},dn.set(e,u)}var y=u;return y.listenersAttached||(e.addEventListener("popstate",y.onPopStateOrHashChange),e.addEventListener("hashchange",y.onPopStateOrHashChange),y.listenersAttached=!0),y.callbacks.add(t),function(){y.callbacks.delete(t),0===y.callbacks.size&&y.listenersAttached&&(e.removeEventListener("popstate",y.onPopStateOrHashChange),e.removeEventListener("hashchange",y.onPopStateOrHashChange),y.listenersAttached=!1)}}function gn(e){return void 0===e&&(e={}),{name:"amplitude/url-tracking@1",observer:function(t,n,r){var o,s,a,c=i(i({},e),r),l=c.ugcFilterRules||[],u=null!==(o=c.enablePolling)&&void 0!==o&&o,d=null!==(s=c.pollingInterval)&&void 0!==s?s:ee,v=null!==(a=c.captureDocumentTitle)&&void 0!==a&&a;if(!n)return function(){};var g=void 0,h=function(){return n.location&&n.location.href||""},f=function(){var e=h();if(void 0===g||e!==g){g=e;var r=function(){var e=n.innerHeight,t=n.innerWidth,r=n.document,i=h(),o="";return v&&(o=(null==r?void 0:r.title)||""),{href:l.length>0?le(i,l):i,title:o,viewportHeight:e,viewportWidth:t,type:"url-change-event"}}();t(r)}},p=vn(n,function(){return f()},u?{enablePolling:!0,pollingInterval:d}:{});return f(),function(){return p()}},options:e}}gn();var hn,fn,pn,mn=function(){function e(){var e=this;this.name="@amplitude/session-replay-browser",this.recordCancelCallback=null,this.eventCount=0,this.sessionTargetingMatch=!1,this.pageLeaveFns=[],this.recordFunction=null,this.urlChangeCleanup=null,this.latestUrlChangeTargetingEvaluationId=0,this.teardownEventListeners=function(t){var n=h();n&&(n.removeEventListener("blur",e.blurListener),n.removeEventListener("focus",e.focusListener),!t&&n.addEventListener("blur",e.blurListener),!t&&n.addEventListener("focus",e.focusListener),n.self&&"onpagehide"in n.self?(n.removeEventListener("pagehide",e.pageLeaveListener),!t&&n.addEventListener("pagehide",e.pageLeaveListener)):(n.removeEventListener("beforeunload",e.pageLeaveListener),!t&&n.addEventListener("beforeunload",e.pageLeaveListener)))},this.blurListener=function(){e.sendEvents()},this.focusListener=function(){e.recordEvents(!1)},this.pageLeaveListener=function(t){e.pageLeaveFns.forEach(function(e){e(t)})},this.evaluateTargetingAndCapture=function(t,n,i,a){return void 0===n&&(n=!1),void 0===i&&(i=!1),void 0===a&&(a=!1),o(e,void 0,void 0,function(){var e,o,c,l,u,d,v,g,f,p,m,y;return s(this,function(s){switch(s.label){case 0:if(!this.identifiers||!this.identifiers.sessionId||!this.config)return this.identifiers&&!this.identifiers.sessionId?this.loggerProvider.log("Session ID has not been set yet, cannot evaluate targeting for Session Replay."):this.loggerProvider.warn("Session replay init has not been called, cannot evaluate targeting."),[2];if(!this.config.targetingConfig){if(!n)return this.loggerProvider.log("No targeting config set, skipping initialization/recording for event."),[2];this.loggerProvider.log("Targeting config has not been set yet, cannot evaluate targeting.")}return this.lastTargetingParams=t,e=this.config.targetingConfig,e&&!this.sessionTargetingMatch?(o=a?this.latestUrlChangeTargetingEvaluationId:void 0,(c=t.event)&&Object.values(r).includes(c.event_type)&&(c=void 0),l=null!==(m=null!==(g=null===(v=t.page)||void 0===v?void 0:v.url)&&void 0!==g?g:null===(p=null===(f=h())||void 0===f?void 0:f.location)||void 0===p?void 0:p.href)&&void 0!==m?m:"",u=null!==(y=t.page)&&void 0!==y?y:""!==l?{url:l}:void 0,[4,ln({sessionId:this.identifiers.sessionId,targetingConfig:e,loggerProvider:this.loggerProvider,apiKey:this.config.apiKey,targetingParams:{userProperties:t.userProperties,event:c,page:u},urlChange:a})]):[3,2];case 1:if(d=s.sent(),a&&void 0!==o&&o!==this.latestUrlChangeTargetingEvaluationId)return this.loggerProvider.debug("Ignoring stale URL-change targeting result #".concat(o,"; latest is #").concat(this.latestUrlChangeTargetingEvaluationId,".")),[2];this.sessionTargetingMatch=this.sessionTargetingMatch||d,this.loggerProvider.debug(JSON.stringify({name:"targeted replay capture config",sessionTargetingMatch:this.sessionTargetingMatch,event:c,targetingParams:t},null,2)),s.label=2;case 2:return n?(this.initialize(!0),[3,5]):[3,3];case 3:return!i&&this.recordCancelCallback?[3,5]:(this.loggerProvider.log("Recording events for session due to forceRestart or no ongoing recording."),[4,this.recordEvents()]);case 4:s.sent(),s.label=5;case 5:return[2]}})})},this.addCustomRRWebEvent=function(t,n,r){return void 0===n&&(n={}),void 0===r&&(r=!0),o(e,void 0,void 0,function(){var e,o,a,c;return s(this,function(s){switch(s.label){case 0:return s.trys.push([0,3,,4]),e=void 0,(o=this.config)&&t!==V.METADATA?(e={config:de(o),version:et},r?[4,ue()]:[3,2]):[3,2];case 1:a=s.sent(),e=i(i({},a),e),s.label=2;case 2:return this.recordCancelCallback&&this.recordFunction?this.recordFunction.addCustomEvent(t,i(i({},n),e)):this.loggerProvider.debug("Not able to add custom replay capture event ".concat(t," due to no ongoing recording.")),[3,4];case 3:return c=s.sent(),this.loggerProvider.debug("Error while adding custom replay capture event: ",c),[3,4];case 4:return[2]}})})},this.stopRecordingEvents=function(){var t;try{e.loggerProvider.log("Session Replay capture stopping."),e.recordCancelCallback&&e.recordCancelCallback(),e.recordCancelCallback=null,null===(t=e.networkObservers)||void 0===t||t.stop()}catch(t){var n=t;e.loggerProvider.warn("Error occurred while stopping replay capture: ".concat(n.toString()))}},this.loggerProvider=new re(new b)}return e.prototype.init=function(e,t){return m(this._init(e,t))},e.prototype.setupUrlChangeListenerForTargeting=function(){var e,t=this;null===(e=this.urlChangeCleanup)||void 0===e||e.call(this);var n=h();if(null==n?void 0:n.location){var r=vn(n,function(e){var n=++t.latestUrlChangeTargetingEvaluationId;t.evaluateTargetingAndCapture({userProperties:{},event:void 0,page:{url:e}},!1,!1,!0),t.loggerProvider.debug("Queued URL-change targeting re-evaluation #".concat(n," for ").concat(e,"."))});this.urlChangeCleanup=function(){r(),t.urlChangeCleanup=null}}},e.prototype.getCurrentPageForTargeting=function(){var e,t,n=null===(t=null===(e=h())||void 0===e?void 0:e.location)||void 0===t?void 0:t.href;return null!=n?{url:n}:void 0},e.prototype._init=function(e,t){var n,r,a,u,d,v,g,f;return o(this,void 0,void 0,function(){var o,p,m,y,S,w,I,C,E,P,k,R,T,_,O,x,M,D;return s(this,function(s){switch(s.label){case 0:return null===(n=this.urlChangeCleanup)||void 0===n||n.call(this),this.loggerProvider=new re(t.loggerProvider||new b),Object.prototype.hasOwnProperty.call(t,"logLevel")&&this.loggerProvider.enable(t.logLevel),this.identifiers=new sn({sessionId:t.sessionId,deviceId:t.deviceId}),o=this,[4,me(e,t)];case 1:return o.joinedConfigGenerator=s.sent(),[4,this.joinedConfigGenerator.generateJoinedConfig()];case 2:p=s.sent(),m=p.joinedConfig,y=p.localConfig,S=p.remoteConfig,this.config=m,this.setMetadata(t.sessionId,m,y,S,null===(r=t.version)||void 0===r?void 0:r.version,et,null===(a=t.version)||void 0===a?void 0:a.type),t.sessionId&&(null===(u=this.config.interactionConfig)||void 0===u?void 0:u.enabled)&&(w=on.default({sessionId:t.sessionId,type:"interaction"},this.config),this.pageLeaveFns=[w.send(this.getDeviceId.bind(this)).bind(w)],this.scrollHook=w.hook.bind(w),this.clickHandler=new en(this.loggerProvider,w)),I=[],"idb"!==(C=this.config.storeType)||(null===(d=h())||void 0===d?void 0:d.indexedDB)||(C="memory",this.loggerProvider.warn("Could not use preferred indexedDB storage, reverting to in memory option.")),this.loggerProvider.log("Using ".concat(C," for event storage.")),s.label=3;case 3:return s.trys.push([3,5,,6]),[4,qt({config:this.config,type:"replay",storeType:C})];case 4:return E=s.sent(),I.push({name:"replay",manager:E}),[3,6];case 5:return P=s.sent(),_=P,this.loggerProvider.warn("Error occurred while creating replay events manager: ".concat(_.toString())),[3,6];case 6:if(!(null===(v=this.config.interactionConfig)||void 0===v?void 0:v.enabled))return[3,10];k=this.config.interactionConfig.batch?Xt:Yt,s.label=7;case 7:return s.trys.push([7,9,,10]),[4,qt({config:this.config,type:"interaction",minInterval:null!==(g=this.config.interactionConfig.trackEveryNms)&&void 0!==g?g:3e4,maxInterval:6e4,payloadBatcher:k,storeType:C})];case 8:return R=s.sent(),I.push({name:"interaction",manager:R}),[3,10];case 9:return T=s.sent(),_=T,this.loggerProvider.warn("Error occurred while creating interaction events manager: ".concat(_.toString())),[3,10];case 10:return this.eventsManager=new(At.bind.apply(At,l([void 0],c(I),!1))),this.eventCompressor&&this.eventCompressor.terminate(),O=void 0,x=h(),this.config.useWebWorker&&x&&x.Worker?[4,import("./index-min2.js")]:[3,12];case 11:M=s.sent().compressionScript,O=M,s.label=12;case 12:return this.eventCompressor=new Ze(this.eventsManager,this.config,this.getDeviceId(),O),[4,this.initializeNetworkObservers()];case 13:return s.sent(),(null===(f=h())||void 0===f?void 0:f.opener)&&(function(e,t){var n,r=e;if(!0!==r[G]){r[G]=!0;var i=null!==(n=null==t?void 0:t.scriptUrl)&&void 0!==n?n:"https://cdn.amplitude.com/libs/background-capture-1.0.0-alpha.2.js.gz",o=null,s=function(t,n){var r,i;"background-capture-complete"===t&&(null===(i=null===(r=e.logger)||void 0===r?void 0:r.debug)||void 0===i||i.call(r,"Background capture complete"),e.notify({action:"background-capture-complete",data:n}))};e.registerActionHandler("initialize-background-capture",function(){var t,n;null===(n=null===(t=e.logger)||void 0===t?void 0:t.debug)||void 0===n||n.call(t,"Initializing background capture (external script)");var r=new URL(i,e.endpoint).toString();e.loadScriptOnce(r).then(function(){var t,n,r;null===(n=null===(t=e.logger)||void 0===t?void 0:t.debug)||void 0===n||n.call(t,"Background capture script loaded (external)"),o=null===(r=null===window||void 0===window?void 0:window.amplitudeBackgroundCapture)||void 0===r?void 0:r.call(window,{messenger:e,onBackgroundCapture:s}),e.notify({action:"background-capture-loaded"})}).catch(function(){var t;null===(t=e.logger)||void 0===t||t.warn("Failed to initialize background capture")})}),e.registerActionHandler("close-background-capture",function(){var e;null===(e=null==o?void 0:o.close)||void 0===e||e.call(o),o=null})}}(D=J()),D.setup(i({logger:this.loggerProvider},this.config.serverZone&&{endpoint:$[this.config.serverZone]}))),this.loggerProvider.log("Installing @amplitude/session-replay-browser."),this.teardownEventListeners(!1),[4,this.evaluateTargetingAndCapture({userProperties:t.userProperties,page:this.getCurrentPageForTargeting()},!0)];case 14:return s.sent(),this.config.targetingConfig&&this.setupUrlChangeListenerForTargeting(),[2]}})})},e.prototype.setSessionId=function(e,t){return m(this.asyncSetSessionId(e,t))},e.prototype.asyncSetSessionId=function(e,t,n){var r;return o(this,void 0,void 0,function(){var i,o,a;return s(this,function(s){switch(s.label){case 0:return this.latestUrlChangeTargetingEvaluationId++,this.sessionTargetingMatch=!1,this.lastShouldRecordDecision=void 0,(i=this.identifiers&&this.identifiers.sessionId)&&this.sendEvents(i),o=t||this.getDeviceId(),this.identifiers=new sn({sessionId:e,deviceId:o}),this.joinedConfigGenerator&&i?[4,this.joinedConfigGenerator.generateJoinedConfig()]:[3,2];case 1:a=s.sent().joinedConfig,this.config=a,s.label=2;case 2:return(null===(r=this.config)||void 0===r?void 0:r.targetingConfig)?[4,this.evaluateTargetingAndCapture({userProperties:null==n?void 0:n.userProperties,page:this.getCurrentPageForTargeting()},!1,!0)]:[3,4];case 3:return s.sent(),[3,6];case 4:return[4,this.recordEvents()];case 5:s.sent(),s.label=6;case 6:return[2]}})})},e.prototype.getSessionReplayProperties=function(){var e,t=this.config,n=this.identifiers;if(!t||!n)return this.loggerProvider.warn("Session replay init has not been called, cannot get session replay properties."),{};var r=this.getShouldRecord(),i={};return r&&((e={})[Z]=n.sessionReplayId?n.sessionReplayId:null,i=e,t.debugMode&&(i[te]=JSON.stringify({appHash:U(t.apiKey).toString()}))),this.addCustomRRWebEvent(V.GET_SR_PROPS,{shouldRecord:r,eventProperties:i},10===this.eventCount),10===this.eventCount&&(this.eventCount=0),this.eventCount++,i},e.prototype.sendEvents=function(e){var t,n=e||(null===(t=this.identifiers)||void 0===t?void 0:t.sessionId),r=this.getDeviceId();this.eventsManager&&n&&r&&this.eventsManager.sendCurrentSequenceEvents({sessionId:n,deviceId:r})},e.prototype.initialize=function(e){var t;return void 0===e&&(e=!1),o(this,void 0,void 0,function(){var n;return s(this,function(r){return(null===(t=this.identifiers)||void 0===t?void 0:t.sessionId)?(n=this.getDeviceId())?(this.eventsManager&&e&&this.eventsManager.sendStoredEvents({deviceId:n}),[2,this.recordEvents()]):(this.loggerProvider.log("Session is not being recorded due to lack of device id."),[2,Promise.resolve()]):(this.loggerProvider.log("Session is not being recorded due to lack of session id."),[2,Promise.resolve()])})})},e.prototype.shouldOptOut=function(){var e,t,n,r;(null===(e=this.config)||void 0===e?void 0:e.instanceName)&&(n=(r=this.config.instanceName,void 0===r&&(r=d),N.getInstance(r)).identityStore.getIdentity().optOut);return void 0!==n?n:null===(t=this.config)||void 0===t?void 0:t.optOut},e.prototype.getShouldRecord=function(){if(!this.identifiers||!this.config||!this.identifiers.sessionId)return this.loggerProvider.warn("Session is not being recorded due to lack of config, please call sessionReplay.init."),!1;if(!this.config.captureEnabled)return this.loggerProvider.log("Session ".concat(this.identifiers.sessionId," not being captured due to capture being disabled for project or because the remote config could not be fetched.")),!1;if(this.shouldOptOut())return this.loggerProvider.log("Opting session ".concat(this.identifiers.sessionId," out of recording due to optOut config.")),!1;var e,t,n,r=!1,i="",o=!1;this.config.targetingConfig?this.sessionTargetingMatch?(i="Capturing replays for session ".concat(this.identifiers.sessionId," due to matching targeting conditions."),this.loggerProvider.log(i),r=!0,o=!0):(i="Not capturing replays for session ".concat(this.identifiers.sessionId," due to not matching targeting conditions."),this.loggerProvider.log(i),r=!1,o=!1):(e=this.identifiers.sessionId,t=this.config.sampleRate,n=U(e.toString()),31*Math.abs(n)%1e6/1e6<t)?(r=!0,o=!0):(i="Opting session ".concat(this.identifiers.sessionId," out of recording due to sample rate."),this.loggerProvider.log(i),r=!1,o=!1);return this.lastShouldRecordDecision!==r&&this.config.targetingConfig&&(this.addCustomRRWebEvent(V.TARGETING_DECISION,{message:i,sessionId:this.identifiers.sessionId,matched:o,targetingParams:this.lastTargetingParams}),this.lastShouldRecordDecision=r),r},e.prototype.getBlockSelectors=function(){var e,t,n,r=null!==(n=null===(t=null===(e=this.config)||void 0===e?void 0:e.privacyConfig)||void 0===t?void 0:t.blockSelector)&&void 0!==n?n:[];if(0!==r.length)return r},e.prototype.getMaskTextSelectors=function(){var e,t,n,r;if("conservative"===(null===(t=null===(e=this.config)||void 0===e?void 0:e.privacyConfig)||void 0===t?void 0:t.defaultMaskLevel))return"*";var i=null===(r=null===(n=this.config)||void 0===n?void 0:n.privacyConfig)||void 0===r?void 0:r.maskSelector;return i||void 0},e.prototype.getRecordingPlugins=function(e){var t,n,r,i,a,c;return o(this,void 0,void 0,function(){var o,l,u,d;return s(this,function(s){switch(s.label){case 0:o=[];try{l=gn({ugcFilterRules:(null===(n=null===(t=this.config)||void 0===t?void 0:t.interactionConfig)||void 0===n?void 0:n.ugcFilterRules)||[],enablePolling:(null===(r=this.config)||void 0===r?void 0:r.enableUrlChangePolling)||!1,pollingInterval:null===(i=this.config)||void 0===i?void 0:i.urlChangePollingInterval,captureDocumentTitle:null===(a=this.config)||void 0===a?void 0:a.captureDocumentTitle}),o.push(l)}catch(e){this.loggerProvider.warn("Failed to create URL tracking plugin:",e)}if(!(null===(c=null==e?void 0:e.console)||void 0===c?void 0:c.enabled))return[3,4];s.label=1;case 1:return s.trys.push([1,3,,4]),[4,import("./console-plugin-min.js")];case 2:return u=s.sent().getRecordConsolePlugin,o.push(u({level:e.console.levels})),[3,4];case 3:return d=s.sent(),this.loggerProvider.warn("Failed to load console plugin:",d),[3,4];case 4:return[2,o.length>0?o:void 0]}})})},e.prototype.getRecordFunction=function(){return o(this,void 0,void 0,function(){var e,t;return s(this,function(n){switch(n.label){case 0:if(this.recordFunction)return[2,this.recordFunction];n.label=1;case 1:return n.trys.push([1,3,,4]),[4,import("./rrweb-record-min.js")];case 2:return e=n.sent().record,this.recordFunction=e,[2,e];case 3:return t=n.sent(),this.loggerProvider.warn("Failed to load rrweb-record module:",t),[2,null];case 4:return[2]}})})},e.prototype.recordEvents=function(e){var t,n,r,i,a,c,l;return void 0===e&&(e=!0),o(this,void 0,void 0,function(){var o,u,d,v,g,h,f,p,m,y,b,S,w,I=this;return s(this,function(s){switch(s.label){case 0:return o=this.config,u=this.getShouldRecord(),d=null===(t=this.identifiers)||void 0===t?void 0:t.sessionId,u&&d&&o?(this.stopRecordingEvents(),[4,this.getRecordFunction()]):[2];case 1:return(v=s.sent())?[4,this.initializeNetworkObservers()]:[2];case 2:s.sent(),null===(n=this.networkObservers)||void 0===n||n.start(function(e){I.addCustomRRWebEvent(V.FETCH_REQUEST,e)}),g=o.privacyConfig,h=o.interactionConfig,f=o.loggingConfig,p=(null==h?void 0:h.enabled)?{mouseInteraction:this.eventsManager&&(null===(r=this.clickHandler)||void 0===r?void 0:r.createHook({eventsManager:this.eventsManager,sessionId:d,deviceIdFn:this.getDeviceId.bind(this),mirror:v.mirror,ugcFilterRules:null!==(i=h.ugcFilterRules)&&void 0!==i?i:[],performanceOptions:null===(a=o.performanceConfig)||void 0===a?void 0:a.interaction})),scroll:this.scrollHook}:{},m=(null==h?void 0:h.enabled)&&h.ugcFilterRules?h.ugcFilterRules:[],this.loggerProvider.log("Session Replay capture beginning for ".concat(d,".")),s.label=3;case 3:return s.trys.push([3,5,,6]),y=this,b=v,w={emit:function(e){if(I.shouldOptOut())return I.loggerProvider.log("Opting session ".concat(d," out of recording due to optOut config.")),I.stopRecordingEvents(),void I.sendEvents();e.type===he.Meta&&(e.data.href=le(e.data.href,m)),I.eventCompressor&&I.eventCompressor.enqueueEvent(e,d)},inlineStylesheet:o.shouldInlineStylesheet,hooks:p,maskAllInputs:!0,maskTextClass:ne,blockClass:"amp-block",blockSelector:this.getBlockSelectors(),applyBackgroundColorToBlockedElements:o.applyBackgroundColorToBlockedElements,maskInputFn:se("input",g),maskTextFn:se("text",g),maskTextSelector:this.getMaskTextSelectors(),recordCanvas:!1,slimDOMOptions:{script:null===(c=o.omitElementTags)||void 0===c?void 0:c.script,comment:null===(l=o.omitElementTags)||void 0===l?void 0:l.comment},errorHandler:function(e){var t=e;if(t.message.includes("insertRule")&&t.message.includes("CSSStyleSheet"))throw t;if(t._external_)throw t;return I.loggerProvider.warn("Error while capturing replay: ",t.toString()),!0}},[4,this.getRecordingPlugins(f)];case 4:return y.recordCancelCallback=b.apply(void 0,[(w.plugins=s.sent(),w)]),this.addCustomRRWebEvent(V.DEBUG_INFO),e&&this.addCustomRRWebEvent(V.METADATA,this.metadata),[3,6];case 5:return S=s.sent(),this.loggerProvider.warn("Failed to initialize session replay:",S),[3,6];case 6:return[2]}})})},e.prototype.getDeviceId=function(){var e;return null===(e=this.identifiers)||void 0===e?void 0:e.deviceId},e.prototype.getSessionId=function(){var e;return null===(e=this.identifiers)||void 0===e?void 0:e.sessionId},e.prototype.flush=function(e){var t;return void 0===e&&(e=!1),o(this,void 0,void 0,function(){return s(this,function(n){return[2,null===(t=this.eventsManager)||void 0===t?void 0:t.flush(e)]})})},e.prototype.shutdown=function(){var e;null===(e=this.urlChangeCleanup)||void 0===e||e.call(this),this.teardownEventListeners(!0),this.stopRecordingEvents(),this.sendEvents()},e.prototype.mapSDKType=function(e){return"plugin"===e?"@amplitude/plugin-session-replay-browser":"segment"===e?"@amplitude/segment-session-replay-plugin":null},e.prototype.setMetadata=function(e,t,n,r,i,o,s){var a=(null==e?void 0:e.toString())?U(e.toString()):void 0;this.metadata={joinedConfig:t,localConfig:n,remoteConfig:r,sessionId:e,hashValue:a,sampleRate:t.sampleRate,replaySDKType:this.mapSDKType(s),replaySDKVersion:i,standaloneSDKType:"@amplitude/session-replay-browser",standaloneSDKVersion:o}},e.prototype.initializeNetworkObservers=function(){var e,t,n;return o(this,void 0,void 0,function(){var r,i;return s(this,function(o){switch(o.label){case 0:if(!(null===(n=null===(t=null===(e=this.config)||void 0===e?void 0:e.loggingConfig)||void 0===t?void 0:t.network)||void 0===n?void 0:n.enabled)||this.networkObservers)return[3,4];o.label=1;case 1:return o.trys.push([1,3,,4]),[4,import("./observers-min.js")];case 2:return r=o.sent().NetworkObservers,this.networkObservers=new r,[3,4];case 3:return i=o.sent(),this.loggerProvider.warn("Failed to import or instantiate NetworkObservers:",i),[3,4];case 4:return[2]}})})},e}(),yn=function(e){return function(){var t=e.config||ve();return{logger:t.loggerProvider,logLevel:t.logLevel}}},bn=function(){var e=new mn;return{init:E(e.init.bind(e),"init",yn(e)),evaluateTargetingAndCapture:E(e.evaluateTargetingAndCapture.bind(e),"evaluateTargetingAndRecord",yn(e)),setSessionId:E(e.setSessionId.bind(e),"setSessionId",yn(e)),getSessionId:E(e.getSessionId.bind(e),"getSessionId",yn(e)),getSessionReplayProperties:E(e.getSessionReplayProperties.bind(e),"getSessionReplayProperties",yn(e)),flush:E(e.flush.bind(e),"flush",yn(e)),shutdown:E(e.shutdown.bind(e),"shutdown",yn(e))}}(),Sn=bn.init,wn=bn.setSessionId,In=bn.getSessionId,Cn=bn.getSessionReplayProperties,En=bn.flush,Pn=bn.shutdown,kn=bn.evaluateTargetingAndCapture;!function(e){e.SET="$set",e.SET_ONCE="$setOnce",e.ADD="$add",e.APPEND="$append",e.PREPEND="$prepend",e.REMOVE="$remove",e.PREINSERT="$preInsert",e.POSTINSERT="$postInsert",e.UNSET="$unset",e.CLEAR_ALL="$clearAll"}(hn||(hn={})),function(e){e.REVENUE_PRODUCT_ID="$productId",e.REVENUE_QUANTITY="$quantity",e.REVENUE_PRICE="$price",e.REVENUE_TYPE="$revenueType",e.REVENUE_CURRENCY="$currency",e.REVENUE="$revenue"}(fn||(fn={})),function(e){e.IDENTIFY="$identify",e.GROUP_IDENTIFY="$groupidentify",e.REVENUE="revenue_amount"}(pn||(pn={}));const Rn=[hn.SET,hn.SET_ONCE,hn.ADD,hn.APPEND,hn.PREPEND,hn.POSTINSERT],Tn="1.26.0";class _n{constructor(e){this.name=_n.pluginName,this.type="enrichment",this.config=null,this.sessionReplay={flush:En,getSessionId:In,getSessionReplayProperties:Cn,init:Sn,setSessionId:wn,shutdown:Pn,evaluateTargetingAndCapture:kn},this.options=Object.assign({forceSessionTracking:!1},e),this.srInitOptions=this.options}setup(e,t){return o(this,void 0,void 0,function*(){var t,n,r,i,o,s,a,c,l;try{null==e||e.loggerProvider.log(`Installing @amplitude/plugin-session-replay, version ${Tn}.`),this.config=e,this.options.forceSessionTracking&&("boolean"==typeof e.defaultTracking?!1===e.defaultTracking&&(e.defaultTracking={pageViews:!1,formInteractions:!1,fileDownloads:!1,sessions:!0}):e.defaultTracking=Object.assign(Object.assign({},e.defaultTracking),{sessions:!0}));const u=(l=this.config.instanceName,void 0===l&&(l="$default_instance"),N.getInstance(l)).identityStore.getIdentity().userProperties;this.srInitOptions={instanceName:this.config.instanceName,deviceId:null!==(t=this.options.deviceId)&&void 0!==t?t:this.config.deviceId,optOut:this.config.optOut,sessionId:this.options.customSessionId?void 0:this.config.sessionId,loggerProvider:this.config.loggerProvider,logLevel:this.config.logLevel,flushMaxRetries:this.config.flushMaxRetries,serverZone:this.config.serverZone,configServerUrl:this.options.configServerUrl||(null===(n=this.config.remoteConfig)||void 0===n?void 0:n.serverUrl),trackServerUrl:this.options.trackServerUrl,sampleRate:this.options.sampleRate,privacyConfig:{blockSelector:null===(r=this.options.privacyConfig)||void 0===r?void 0:r.blockSelector,maskSelector:null===(i=this.options.privacyConfig)||void 0===i?void 0:i.maskSelector,unmaskSelector:null===(o=this.options.privacyConfig)||void 0===o?void 0:o.unmaskSelector,defaultMaskLevel:null===(s=this.options.privacyConfig)||void 0===s?void 0:s.defaultMaskLevel},debugMode:this.options.debugMode,shouldInlineStylesheet:this.options.shouldInlineStylesheet,version:{type:"plugin",version:Tn},performanceConfig:this.options.performanceConfig,storeType:this.options.storeType,useWebWorker:null!==(a=this.options.useWebWorker)&&void 0!==a?a:null===(c=this.options.experimental)||void 0===c?void 0:c.useWebWorker,userProperties:u,omitElementTags:this.options.omitElementTags,applyBackgroundColorToBlockedElements:this.options.applyBackgroundColorToBlockedElements,interactionConfig:this.options.interactionConfig,captureDocumentTitle:this.options.captureDocumentTitle,enableUrlChangePolling:this.options.enableUrlChangePolling,urlChangePollingInterval:this.options.urlChangePollingInterval},yield this.sessionReplay.init(e.apiKey,this.srInitOptions).promise}catch(t){null==e||e.loggerProvider.error(`Session Replay: Failed to initialize due to ${t.message}`)}})}onSessionIdChanged(e){return o(this,void 0,void 0,function*(){var t;null===(t=this.config)||void 0===t||t.loggerProvider.debug(`Analytics session id is changed to ${e}, SR session id is ${String(this.sessionReplay.getSessionId())}.`),yield this.sessionReplay.setSessionId(e).promise})}onOptOutChanged(e){return o(this,void 0,void 0,function*(){var t;null===(t=this.config)||void 0===t||t.loggerProvider.debug(`optOut is changed to ${String(e)}, calling ${e?"sessionReplay.shutdown()":"sessionReplay.init()"}.`),e?this.sessionReplay.shutdown():null!=this.config&&(yield this.sessionReplay.init(this.config.apiKey,this.srInitOptions).promise)})}execute(e){return o(this,void 0,void 0,function*(){var t,n,i;try{if(this.options.customSessionId){const t=this.options.customSessionId(e);if(t){t!==this.sessionReplay.getSessionId()&&(yield this.sessionReplay.setSessionId(t).promise);const n=this.sessionReplay.getSessionReplayProperties();e.event_properties=Object.assign(Object.assign({},e.event_properties),n)}}else{const i=null===(t=this.config)||void 0===t?void 0:t.sessionId;if(i&&i!==this.sessionReplay.getSessionId()&&(yield this.sessionReplay.setSessionId(i).promise),i&&i===e.session_id){let t;e.event_type===r.IDENTIFY&&(t=(e=>{if(!e.user_properties)return;let t={};return Object.keys(e.user_properties).forEach(n=>{if(Rn.includes(n)){const r=e.user_properties&&e.user_properties[n];t=Object.assign(Object.assign({},t),r)}}),t})(e));const i=h();yield this.sessionReplay.evaluateTargetingAndCapture({event:e,userProperties:t,page:null!=(null===(n=null==i?void 0:i.location)||void 0===n?void 0:n.href)?{url:i.location.href}:void 0});const o=this.sessionReplay.getSessionReplayProperties();e.event_properties=Object.assign(Object.assign({},e.event_properties),o)}}return e.event_type===r.IDENTIFY&&e.event_properties&&delete e.event_properties["[Amplitude] Session Replay ID"],Promise.resolve(e)}catch(t){return null===(i=this.config)||void 0===i||i.loggerProvider.error(`Session Replay: Failed to enrich event due to ${t.message}`),Promise.resolve(e)}})}teardown(){return o(this,void 0,void 0,function*(){var e;try{this.sessionReplay.shutdown(),this.config=null}catch(t){null===(e=this.config)||void 0===e||e.loggerProvider.error(`Session Replay: teardown failed due to ${t.message}`)}})}getSessionReplayProperties(){return this.sessionReplay.getSessionReplayProperties()}}_n.pluginName="@amplitude/plugin-session-replay-browser";const On=e=>new _n(e);export{_n as S,o as _,s as a,i as b,h as g,ht as o,On as s};
2
2
  //# sourceMappingURL=index-min.js.map
Binary file