PageSourceSearch

https://router.xiu.ai/assets/session-replay-qNXjuYc-.js

js xiu.ai collected 2026-10-05 13:21:04 UTC 121,362 bytes, 2 lines download raw bytes

1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-Dft-NVkw.js","assets/background-capture-D8h22wie.js","assets/index-DTJFtNZr.js","assets/index-CXNA-4gb.css","assets/observers-B7xO7AUU.js","assets/json-query-Baa-i0b2.js"])))=>i.map(i=>d[i]);
2import{_ as Oe,a as C,b as I,c as E,B as Bt,S as pr,g as G,d as U,L as Ye,e as mr,f as X,h as K,C as yr,R as Sr,i as ye,j as Fe,k as Qe,r as Ne,l as br,m as Er,A as Ir,n as ht,o as zt,p as se}from"./background-capture-D8h22wie.js";import{cf as be}from"./index-DTJFtNZr.js";var Cr=(function(r){Oe(e,r);function e(t){t===void 0&&(t={});var n=r.call(this)||this;return n.customHeaders=t,n}return e.prototype.send=function(t,n){return C(this,void 0,void 0,function(){var i,s,o;return I(this,function(l){switch(l.label){case 0:if(typeof fetch>"u")throw new Error("FetchTransport is not supported");return i={headers:E({"Content-Type":"application/json",Accept:"*/*"},this.customHeaders),body:JSON.stringify(n),method:"POST"},[4,fetch(t,i)];case 1:return s=l.sent(),[4,s.text()];case 2:o=l.sent();try{return[2,this.buildResponse(JSON.parse(o))]}catch{return[2,this.buildResponse({code:s.status})]}return[2]}})})},e})(Bt),Wt="[Amplitude]",Pr="".concat(Wt," Session Replay ID"),Tr=0,wr=pr.US,Rr={enabled:!0},at=1e3,Mr="".concat(Wt," Session Replay Debug"),kr="amp-block",Kt="amp-mask",jt="amp-unmask",Gt="https://api-sr.amplitude.com/sessions/v2/track",Vt="https://api-sr.eu.amplitude.com/sessions/v2/track",Ht="https://api-sr.stag2.amplitude.com/sessions/v2/track",Or=2e6,xr=6e6,Xt=9*1e6,Lr=/payload.*exceed/i,_r=3e4,Dr=6e4,$e=500,Je=10*1e3,Ar=1e3,Fr=10*1e3,Ze=1024,Nr=1e3,Ur=64*1024,qr=1e4,gt="X-Session-Replay-Event-Skipped",Br="429",zr="4004",Wr="4005",pt=6e4,Kr=2*Or,we="amplitude-sr-iframe",ae;(function(r){r.GET_SR_PROPS="get-sr-props",r.DEBUG_INFO="debug-info",r.FETCH_REQUEST="fetch-request",r.METADATA="metadata",r.TARGETING_DECISION="targeting-decision",r.REPLAY_GATE_DECISION="replay-gate-decision"})(ae||(ae={}));var et=(function(){function r(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 r.prototype.getSafeMethod=function(e){var t;if(!this.logger)return(function(){});var n=this.logger[e];if(typeof n=="function"){var i=(t=n.__rrweb_original__)!==null&&t!==void 0?t:n;return i.bind(this.logger)}return(function(){})},r.prototype.enable=function(e){this.logger.enable(e)},r.prototype.disable=function(){this.logger.disable()},r})(),lt="medium";function jr(r){return r.toLowerCase()}function Gr(r){var e=r.type;return r.hasAttribute("data-rr-is-password")?"password":e?jr(e):null}function Ee(r,e){return e||(r==="STAGING"?Ht:r==="EU"?Vt:Gt)}var Yt=function(r,e,t){switch(e){case"light":{if(r!=="input")return!1;var n=t?Gr(t):"";return n?!!(["password","hidden","email","tel"].includes(n)||t.autocomplete.startsWith("cc-")):!1}case"medium":return r==="input";case"conservative":return!0;default:return Yt(r,lt,t)}},Qt=function(r,e){var t,n,i;if(r&&e.urlMaskLevels)try{for(var s=U(e.urlMaskLevels),o=s.next();!o.done;o=s.next()){var l=o.value;if(Jt(l.match).test(r))return l.maskLevel}}catch(a){t={error:a}}finally{try{o&&!o.done&&(n=s.return)&&n.call(s)}finally{if(t)throw t.error}}return(i=e.defaultMaskLevel)!==null&&i!==void 0?i:lt},$t=function(r,e,t,n){var i,s;if(e===void 0&&(e={defaultMaskLevel:lt}),t){if(t.closest("."+Kt))return!0;var o=((i=e.maskSelector)!==null&&i!==void 0?i:[]).some(function(a){return t.closest(a)});if(o)return!0;if(t.closest("."+jt))return!1;var l=((s=e.unmaskSelector)!==null&&s!==void 0?s:[]).some(function(a){return t.closest(a)});if(l)return!1}return Yt(r,Qt(n,e),t)},mt=function(r,e,t){return function(n,i){return $t(r,e,i,t?.())?n.replace(/[^\s]/g,"*"):n}},Vr=function(r,e){return function(t,n,i){var s;if(t==="style"||!((s=r?.maskAttributes)!==null&&s!==void 0?s:[]).includes(t))return n;var o=["INPUT","SELECT","TEXTAREA"].includes(i.tagName)?"input":"text";return $t(o,r,i,e?.())?n.replace(/[^\s]/g,"*"):n}},tt=function(){var r=G();return r?.location?r.location.href:""},Hr=function(r,e){return"".concat(e,"/").concat(r)},Xr=function(r){if(typeof r!="string"||r.trim()==="")return!1;var e=/^\/|^https?:\/\/[^\s]+$/;return!!e.test(r)}
2,yt=new Map,Jt=function(r){var e=yt.get(r);if(e)return e;var t="\0TRAIL\0",n="\0MID\0",i="\0DS\0",s="\0ST\0",o="\0QU\0",l=r;l=l.replace(/\/\*\*$/,t),l=l.replace(/\/\*\*\//g,n),l=l.replace(/\*\*/g,i),l=l.replace(/\*/g,s),l=l.replace(/\?/g,o),l=l.replace(/[.+^${}()|[\]\\]/g,"\\$&"),l=l.split(t).join("(/.*)?"),l=l.split(n).join("/(.*\\/)?"),l=l.split(i).join(".*"),l=l.split(s).join(".*"),l=l.split(o).join(".");var a=new RegExp("^".concat(l,"$"));return yt.set(r,a),a},Yr=function(r){if(!r.every(function(e){return typeof e.selector=="string"&&typeof e.replacement=="string"}))throw new Error("ugcFilterRules must be an array of objects with selector and replacement properties");if(!r.every(function(e){return Xr(e.selector)}))throw new Error("ugcFilterRules must be an array of objects with valid globs")},xe=function(r,e){var t,n;try{for(var i=U(e),s=i.next();!s.done;s=i.next()){var o=s.value,l=Jt(o.selector);if(l.test(r))return r.replace(l,o.replacement)}}catch(a){t={error:a}}finally{try{s&&!s.done&&(n=i.return)&&n.call(i)}finally{if(t)throw t.error}}return r},Zt=function(){return C(void 0,void 0,void 0,function(){var r,e,t,n,i,s,o;return I(this,function(l){switch(l.label){case 0:return l.trys.push([0,3,,4]),r=G(),r?[4,r.navigator.storage.estimate()]:[3,2];case 1:return e=l.sent(),t=e.usage,n=e.quota,i=e.usageDetails,s=t?Math.round(t/Ze):0,o=t&&n?Math.round((t/n+Number.EPSILON)*1e3)/1e3:0,[2,{totalStorageSize:s,percentOfQuota:o,usageDetails:JSON.stringify(i)}];case 2:return[3,4];case 3:return l.sent(),[3,4];case 4:return[2,{totalStorageSize:0,percentOfQuota:0,usageDetails:""}]}})})},er=function(r){var e=E({},r),t=e.apiKey;return e.apiKey="****".concat(t.substring(t.length-4)),e},tr=function(){return{flushMaxRetries:2,logLevel:mr.Warn,loggerProvider:new Ye,transportProvider:new Cr}},Qr=(function(r){Oe(e,r);function e(t,n){var i=this,s,o,l,a,u,d,v,c,f,h,p,m,g,y,b=tr();i=r.call(this,E(E({transportProvider:b.transportProvider,loggerProvider:new et(n.loggerProvider||b.loggerProvider)},n),{apiKey:t}))||this,i.flushMaxRetries=n.flushMaxRetries!==void 0&&n.flushMaxRetries<=b.flushMaxRetries?n.flushMaxRetries:b.flushMaxRetries,i.apiKey=t,i.sampleRate=n.sampleRate||Tr,i.serverZone=n.serverZone||wr,i.configServerUrl=n.configServerUrl,i.trackServerUrl=n.trackServerUrl,i.shouldInlineStylesheet=n.shouldInlineStylesheet,i.version=n.version,i.performanceConfig=n.performanceConfig||Rr,i.storeType=(s=n.storeType)!==null&&s!==void 0?s:"memory",i.applyBackgroundColorToBlockedElements=(o=n.applyBackgroundColorToBlockedElements)!==null&&o!==void 0?o:!1,i.enableUrlChangePolling=(l=n.enableUrlChangePolling)!==null&&l!==void 0?l:!1,i.urlChangePollingInterval=(a=n.urlChangePollingInterval)!==null&&a!==void 0?a:at,i.captureDocumentTitle=(u=n.captureDocumentTitle)!==null&&u!==void 0?u:!1,n.fullSnapshotIntervalMs!==void 0&&(i.fullSnapshotIntervalMs=n.fullSnapshotIntervalMs),n.eagerFullSnapshotSend!==void 0&&(i.eagerFullSnapshotSend=n.eagerFullSnapshotSend),i.captureFullSnapshotOnFocus=(d=n.captureFullSnapshotOnFocus)!==null&&d!==void 0?d:!1,n.maxPersistedEventsSizeBytes!==void 0&&(i.maxPersistedEventsSizeBytes=bt(n.maxPersistedEventsSizeBytes,St,$r,"maxPersistedEventsSizeBytes",i.loggerProvider)),n.maxSingleEventSizeBytes!==void 0&&(i.maxSingleEventSizeBytes=bt(n.maxSingleEventSizeBytes,St,Jr,"maxSingleEventSizeBytes",i.loggerProvider)),i.privacyConfig=E(E({},(v=n.privacyConfig)!==null&&v!==void 0?v:{}),{unmaskSelector:Array.from(new Set(X([".".concat(jt)],K((f=(c=n.privacyConfig)===null||c===void 0?void 0:c.unmaskSelector)!==null&&f!==void 0?f:[]),!1)))}),n.interactionConfig&&(i.interactionConfig=n.interactionConfig,i.interactionConfig.ugcFilterRules&&Yr(i.interactionConfig.ugcFilterRules)),n.debugMode&&(i.debugMode=n.debugMode);var S=n;return i.useWebWorker=(m=(h=n.useWebWorker)!==null&&h!==void 0?h:(p=S.experimental)===null||p===void 0?void 0:p.useWebWorker)!==null&&m!==void 0?m:!0,i.enableTransportCompression=(g=n.enableTransportCompression)!==null&&g!==void 0?g:!0,i.sendTimeoutMs=n.sendTimeoutMs,i.captureAdoptedStyleSheets=(y=n.captureAdoptedStyleSheets)!==null&&y!==void 0?y:!0,n.crossOriginIframes&&(i.crossOriginIframes=n.crossOriginIframes),n.flushIntervalConfig?i.flushIntervalConfig=Zr(n.flushIntervalConfig,i.loggerProvider):i.flushIntervalConfig={minIntervalMs:Ar,maxIntervalMs:Fr},i.handleSendEvents=n.handleSendEvents,i.handleFetchConfig=n.handleFetchConfig,i}return e})(yr),pe=100,St=1e3,$r=8e6,Jr=1e7;function bt(r,e,t,n,i){if(!Number.isFinite(r)){i.warn("".concat(n," value is not a finite number (got ").concat(String(r),"); ignoring."));return}return r<e?(i.warn("".concat(n," ").concat(r," is below floor ").concat(e,"; clamping.")),e):r>t?(i.warn("".concat(n," ").concat(r," exceeds ceiling ").concat(t,"; clamping.")),t):r}function Zr(r,e){var t,n,i={};if(r.minIntervalMs!==void 0&&(!Number.isFinite(r.minIntervalMs)||r.minIntervalMs<pe?(e.warn("flushIntervalConfig.minIntervalMs ".concat(r.minIntervalMs," is below floor ").concat(pe,"ms; clamping.")),i.minIntervalMs=pe):i.minIntervalMs=r.minIntervalMs),r.maxIntervalMs!==void 0&&(Number.isNaN(r.maxIntervalMs)||r.maxIntervalMs<pe?(e.warn("flushIntervalConfig.maxIntervalMs ".concat(r.maxIntervalMs," is below floor ").concat(pe,"ms; clamping.")),i.maxIntervalMs=pe):i.maxIntervalMs=r.maxIntervalMs),i.minIntervalMs!==void 0||i.maxIntervalMs!==void 0){var s=(t=i.minIntervalMs)!==null&&t!==void 0?t:$e,o=(n=i.maxIntervalMs)!==null&&n!==void 0?n:Je;o<s&&(i.maxIntervalMs===void 0?(e.warn("flushIntervalConfig.minIntervalMs (".concat(s,") exceeds the default maxIntervalMs (").concat(Je,"); raising max to match min.")),i.maxIntervalMs=s):i.minIntervalMs===void 0?(e.warn("flushIntervalConfig.maxIntervalMs (".concat(o,") is below the default minIntervalMs (").concat($e,");
2 lowering min to match max.")),i.minIntervalMs=o):(e.warn("flushIntervalConfig.maxIntervalMs (".concat(i.maxIntervalMs,") is less than minIntervalMs (").concat(i.minIntervalMs,"); raising max to match min.")),i.maxIntervalMs=i.minIntervalMs))}return i}var Le=(r=>(r[r.DomContentLoaded=0]="DomContentLoaded",r[r.Load=1]="Load",r[r.FullSnapshot=2]="FullSnapshot",r[r.IncrementalSnapshot=3]="IncrementalSnapshot",r[r.Meta=4]="Meta",r[r.Custom=5]="Custom",r[r.Plugin=6]="Plugin",r))(Le||{}),ut=(r=>(r[r.Mutation=0]="Mutation",r[r.MouseMove=1]="MouseMove",r[r.MouseInteraction=2]="MouseInteraction",r[r.Scroll=3]="Scroll",r[r.ViewportResize=4]="ViewportResize",r[r.Input=5]="Input",r[r.TouchMove=6]="TouchMove",r[r.MediaInteraction=7]="MediaInteraction",r[r.StyleSheetRule=8]="StyleSheetRule",r[r.CanvasMutation=9]="CanvasMutation",r[r.Font=10]="Font",r[r.Log=11]="Log",r[r.Drag=12]="Drag",r[r.StyleDeclaration=13]="StyleDeclaration",r[r.Selection=14]="Selection",r[r.AdoptedStyleSheet=15]="AdoptedStyleSheet",r[r.CustomElement=16]="CustomElement",r))(ut||{}),rr=(r=>(r[r.MouseUp=0]="MouseUp",r[r.MouseDown=1]="MouseDown",r[r.Click=2]="Click",r[r.ContextMenu=3]="ContextMenu",r[r.DblClick=4]="DblClick",r[r.Focus=5]="Focus",r[r.Blur=6]="Blur",r[r.TouchStart=7]="TouchStart",r[r.TouchMove_Departed=8]="TouchMove_Departed",r[r.TouchEnd=9]="TouchEnd",r[r.TouchCancel=10]="TouchCancel",r))(rr||{}),en=1500,tn=function(r,e){var t=document.createDocumentFragment(),n=function(i){if(i===void 0&&(i=[]),typeof i=="string"&&(i=[i]),i=i.filter(function(s){try{t.querySelector(s)}catch{return e.warn('[session-replay-browser] omitting selector "'.concat(s,'" because it is invalid')),!1}return!0}),i.length!==0)return i};return r.blockSelector=n(r.blockSelector),r.maskSelector=n(r.maskSelector),r.unmaskSelector=n(r.unmaskSelector),r},rn=(function(){function r(e,t){this.localConfig=t,this.remoteConfigClient=e}return r.prototype.generateJoinedConfig=function(){var e,t,n,i,s,o,l;return C(this,void 0,void 0,function(){var a,u,d,v,c,f,h,p,m,g,y,b,S,T,L,O,W,q=this;return I(this,function(z){switch(z.label){case 0:a=E({},this.localConfig),a.optOut=this.localConfig.optOut,a.captureEnabled=!0,z.label=1;case 1:return z.trys.push([1,3,,4]),[4,new Promise(function(x,A){q.remoteConfigClient.subscribe("configs.sessionReplay",{timeout:en},function(F,N){var M;if(q.localConfig.loggerProvider.debug("Session Replay remote configuration received from ".concat(N,":"),JSON.stringify(F,null,2)),!F){A(new Error("No remote config received"));return}var w=F,R=w.sr_sampling_config,B=w.sr_privacy_config,k=w.sr_targeting_config,_=(M=a.interactionConfig)===null||M===void 0?void 0:M.ugcFilterRules;a.interactionConfig=w.sr_interaction_config,a.interactionConfig&&_&&(a.interactionConfig.ugcFilterRules=_),a.loggingConfig=w.sr_logging_config,(R||B||k)&&(u={},R&&(u.sr_sampling_config=R),B&&(u.sr_privacy_config=B),k&&(u.sr_targeting_config=k)),x()})})];case 2:return z.sent(),[3,4];case 3:return d=z.sent(),this.localConfig.loggerProvider.error("Failed to generate joined config: ",d),a.captureEnabled=!1,[2,{localConfig:this.localConfig,joinedConfig:a,remoteConfig:void 0}];case 4:if(!u)return[2,{localConfig:this.localConfig,joinedConfig:a,remoteConfig:u}];if(v=u.sr_sampling_config,c=u.sr_privacy_config,f=u.sr_targeting_config,v&&Object.keys(v).length>0?(Object.prototype.hasOwnProperty.call(v,"capture_enabled")?a.captureEnabled=v.capture_enabled:a.captureEnabled=!1,Object.prototype.hasOwnProperty.call(v,"sample_rate")&&(a.sampleRate=v.sample_rate),Object.prototype.hasOwnProperty.call(v,"min_session_duration_ms")&&(a.minSessionDurationMs=this.sanitizeMinSessionDurationMs(v.min_session_duration_ms))):(a.captureEnabled=!0,this.localConfig.loggerProvider.debug("Remote config successfully fetched, but no values set for project, Session Replay capture enabled.")),c){h=(e=a.privacyConfig)!==null&&e!==void 0?e:{},p={defaultMaskLevel:(n=(t=c.defaultMaskLevel)!==null&&t!==void 0?t:h.defaultMaskLevel)!==null&&n!==void 0?n:"medium",blockSelector:[],maskSelector:[],unmaskSelector:[],maskAttributes:X([],K(new Set(X(X([],K((i=h.maskAttributes)!==null&&i!==void 0?i:[]),!1),K((s=c.maskAttributes)!==null&&s!==void 0?s:[]),!1))),!1),urlMaskLevels:X(X([],K((o=c.urlMaskLevels)!==null&&o!==void 0?o:[]),!1),K((l=h.urlMaskLevels)!==null&&l!==void 0?l:[]),!1)},m=function(x){var A,F,N,M,w,R,B,k,_,P={};typeof x.blockSelector=="string"&&(x.blockSelector=[x.blockSelector]);try{for(var V=U((B=x.blockSelector)!==null&&B!==void 0?B:[]),D=V.next();!D.done;D=V.next()){var H=D.value;P[H]="block"}}catch(Z){A={error:Z}}finally{try{D&&!D.done&&(F=V.return)&&F.call(V)}finally{if(A)throw A.error}}try{for(var j=U((k=x.maskSelector)!==null&&k!==void 0?k:[]),Y=j.next();!Y.done;Y=j.next()){var H=Y.value;P[H]="mask"}}catch(Z){N={error:Z}}finally{try{Y&&!Y.done&&(M=j.return)&&M.call(j)}finally{if(N)throw N.error}}try{for(var Q=U((_=x.unmaskSelector)!==null&&_!==void 0?_:[]),J=Q.next();!J.done;J=Q.next()){var H=J.value;P[H]="unmask"}}catch(Z){w={error:Z}}finally{try{J&&!J.done&&(R=Q.return)&&R.call(Q)}finally{if(w)throw w.error}}return P},g=E(E({},m(h)),m(c));try{for(y=U(Object.entries(g)),b=y.next();!b.done;b=y.next())S=K(b.value,2),T=S[0],L=S[1],L==="mask"?p.maskSelector.push(T):L==="block"?p.blockSelector.push(T):L==="unmask"&&p.unmaskSelector.push(T)}catch(x){O={error:x}}finally{try{b&&!b.done&&(W=y.return)&&W.call(y)}finally{if(O)throw O.error}}a.privacyConfig=tn(p,this.localConfig.loggerProvider)}return f&&Object.keys(f).length>0&&(a.targetingConfig=f),this.localConfig.loggerProvider.debug(JSON.stringify({name:"session replay joined config",config:er(a)},null,2)),[2,{localConfig:this.localConfig,joinedConfig:a,remoteConfig:u}]}})})},r.prototype.sanitizeMinSessionDurationMs=function(e){if(typeof e!="number"||!Number.isFinite(e)){this.localConfig.loggerProvider.warn("min_session_duration_ms remote value is not a finite number (got ".concat(String(e),"); ignoring."));return}if(e<0){this.localConfig.loggerProvider.warn("min_session_duration_ms remote value is negative (".concat(e,"); ignoring."));return}return e>Ue?(this.localConfig.loggerProvider.warn("min_session_duration_ms remote value ".concat(e," exceeds ").concat(Ue,"ms ceiling; clamping.")),Ue):e},r})(),Ue=6e4,nn=function(r,e){return C(void 0,void 0,void 0,function(){var t,n;return I(this,function(i){return t=new Qr(r,e),n=new Sr(r,t.loggerProvider,t.serverZone,e.configServerUrl,e.handleFetchConfig),[2,new rn(n,t)]})})};function Et(r){if(r.type!==Le.IncrementalSnapshot)return!1;var e=r.data;return e.source===ut.Mutation&&!e.isAttachIframe}function sn(r){return typeof r=="object"&&r!==null}function on(r){var e,t,n,i,s={};try{for(var o=U(r),l=o.next();!l.done;l=o.next()){var a=l.value;try{for(var u=(n=void 0,U(Object.keys(a))),d=u.next();!d.done;d=u.next()){var v=d.value;s[v]=a[v]}}catch(c){n={error:c}}finally{try{d&&!d.done&&(i=u.return)&&i.call(u)}finally{if(n)throw n.error}}}}catch(c){e={error:c}}finally{try{l&&!l.done&&(t=o.return)&&t.call(o)}finally{if(e)throw e.error}}return s}function an(r){var e,t,n=new Map;if(r.forEach(function(c,f){if(c.attributes&&"style"in c.attributes){var h=n.get(c.id);h?h.push(f):n.set(c.id,[f])}}),n.size===0)return r;var i=function(c){return r[c].attributes.style},s=new Set,o=new Map,l=function(c){if(c.length===1)return"continue";var f=-1;
2c.forEach(function(g,y){sn(i(g))||(f=y)});var h=[];if(c.forEach(function(g,y){y!==f&&(s.add(g),y>f&&h.push(g))}),h.length>0){var p=h[h.length-1],m=on(h.map(function(g){return i(g)}));s.delete(p),o.set(p,m)}};try{for(var a=U(n.values()),u=a.next();!u.done;u=a.next()){var d=u.value;l(d)}}catch(c){e={error:c}}finally{try{u&&!u.done&&(t=a.return)&&t.call(a)}finally{if(e)throw e.error}}if(s.size===0&&o.size===0)return r;var v=[];return r.forEach(function(c,f){var h=o.get(f);if(h!==void 0){v.push(E(E({},c),{attributes:E(E({},c.attributes),{style:h})}));return}if(!s.has(f)){v.push(c);return}var p=E({},c.attributes);delete p.style,Object.keys(p).length>0&&v.push(E(E({},c),{attributes:p}))}),v}function ln(r){var e,t,n,i,s=r[0],o=new Map,l=new Map,a=new Map,u=new Map,d=new Map;r.forEach(function(P,V){var D,H,j,Y,Q=P.data;try{for(var J=U(Q.adds),Z=J.next();!Z.done;Z=J.next()){var ce=Z.value;o.has(ce.node.id)||o.set(ce.node.id,V),l.set(ce.node.id,V),d.set(ce.node.id,ce.parentId)}}catch($){D={error:$}}finally{try{Z&&!Z.done&&(H=J.return)&&H.call(J)}finally{if(D)throw D.error}}try{for(var de=U(Q.removes),ve=de.next();!ve.done;ve=de.next()){var te=ve.value;a.has(te.id)||a.set(te.id,V),u.set(te.id,V)}}catch($){j={error:$}}finally{try{ve&&!ve.done&&(Y=de.return)&&Y.call(de)}finally{if(j)throw j.error}}});var v=new Set,c=new Set;try{for(var f=U(o),h=f.next();!h.done;h=f.next()){var p=K(h.value,2),m=p[0],g=p[1],y=a.get(m);if(y!==void 0){var b=l.get(m),S=u.get(m);b>=S||(g<y?v.add(m):y<g&&c.add(m))}}}catch(P){e={error:P}}finally{try{h&&!h.done&&(t=f.return)&&t.call(f)}finally{if(e)throw e.error}}var T=new Set;if(v.size>0||c.size>0)for(var L=!0;L;){L=!1;try{for(var O=(n=void 0,U(d)),W=O.next();!W.done;W=O.next()){var q=K(W.value,2),z=q[0],x=q[1];if(!v.has(z)&&!c.has(z)&&!T.has(z)&&(v.has(x)||c.has(x)||T.has(x))){var A=a.get(z),F=o.get(z);A!==void 0&&F!==void 0&&A<F?c.add(z):A!==void 0&&F!==void 0&&A===F?T.add(z):v.add(z),L=!0}}}catch(P){n={error:P}}finally{try{W&&!W.done&&(i=O.return)&&i.call(O)}finally{if(n)throw n.error}}}var N=v.size>0||c.size>0||T.size>0,M=[];r.forEach(function(P,V){var D,H;try{for(var j=U(P.data.removes),Y=j.next();!Y.done;Y=j.next()){var Q=Y.value;v.has(Q.id)||c.has(Q.id)&&V>=o.get(Q.id)||T.has(Q.id)&&(v.has(Q.parentId)||c.has(Q.parentId)||T.has(Q.parentId))||M.push(Q)}}catch(J){D={error:J}}finally{try{Y&&!Y.done&&(H=j.return)&&H.call(j)}finally{if(D)throw D.error}}});var w=r.flatMap(function(P){return P.data.adds}),R=r.flatMap(function(P){return P.data.texts}),B=r.flatMap(function(P){return P.data.attributes}),k=N?B.filter(function(P){return!v.has(P.id)&&!c.has(P.id)&&!T.has(P.id)}):B,_={source:ut.Mutation,removes:M,adds:N?w.filter(function(P){return!v.has(P.node.id)&&!c.has(P.node.id)&&!T.has(P.node.id)}):w,texts:N?R.filter(function(P){return!v.has(P.id)&&!c.has(P.id)&&!T.has(P.id)}):R,attributes:an(k)};return E(E({},s),{data:_})}function un(r){if(r.length<=1)return r;for(var e=[],t=0;t<r.length;){if(!Et(r[t])){e.push(r[t]),t++;continue}for(var n=t+1;n<r.length&&Et(r[n]);)n++;e.push(n>t+1?ln(r.slice(t,n)):r[t]),t=n}return e}var cn=2e3,dn=(function(){function r(e,t,n,i,s){var o=this,l;this.taskQueue=[],this.pendingQueue=[],this.isProcessing=!1,this.compressEvent=function(c){var f=c,h=f.type,p=f.timestamp,m=f.delay,g=f.data;return m!=null?JSON.stringify({type:h,timestamp:p,delay:m,data:g}):JSON.stringify({type:h,timestamp:p,data:g})},this.addCompressedEventToManager=function(c,f){var h,p=new Blob([c]).size;if(p>((h=o.config.maxSingleEventSizeBytes)!==null&&h!==void 0?h:Xt)){o.config.loggerProvider.warn("Session replay event dropped: serialized size ".concat(Math.round(p/1024)," KB exceeds maximum allowed event size. If this recurs, please open a GitHub issue at https://github.com/amplitude/Amplitude-TypeScript/issues or contact Amplitude support."));return}o.eventsManager&&o.deviceId&&o.eventsManager.addEvent({event:{type:"replay",data:c},sessionId:f,deviceId:o.deviceId})},this.addCompressedEvent=function(c,f){if(o.worker)try{o.worker.postMessage({event:c,sessionId:f})}catch(p){p.name==="DataCloneError"?o.worker.postMessage(JSON.stringify({event:c,sessionId:f})):o.config.loggerProvider.warn("Unexpected error while posting message to worker:",p)}else{var h=o.compressEvent(c);o.addCompressedEventToManager(h,f)}},this.flushQueue=function(){var c;for(o.pendingQueue.length>0&&(c=o.taskQueue).push.apply(c,X([],K(o.mergeMutationTasks(o.pendingQueue.splice(0))),!1));o.taskQueue.length>0;){var f=o.taskQueue.shift();if(f){var h=f.event,p=f.sessionId,m=o.compressEvent(h);o.addCompressedEventToManager(m,p)}}o.isProcessing=!1},this.terminate=function(){var c;(c=o.worker)===null||c===void 0||c.terminate()};var a=G();if(this.canUseIdleCallback=a&&"requestIdleCallback"in a,this.eventsManager=e,this.config=t,this.deviceId=n,this.timeout=((l=t.performanceConfig)===null||l===void 0?void 0:l.timeout)||cn,this.onFullSnapshotProcessed=s,i){t.loggerProvider.log("Enabling web worker for compression");try{var u=new Blob([i],{type:"application/javascript"}),d=URL.createObjectURL(u),v=new Worker(d);v.onerror=function(c){c.preventDefault(),t.loggerProvider.error("Worker failed, falling back to non-worker compression: ".concat(c.message," (").concat(c.filename,":").concat(c.lineno,")")),v.terminate(),o.worker=void 0},v.onmessage=function(c){var f=c.data,h=f.compressedEvent,p=f.sessionId;o.addCompressedEventToManager(h,p)},this.worker=v}catch(c){t.loggerProvider.error("Failed to create worker, falling back to non-worker compression:",c)}}}return r.prototype.scheduleIdleProcessing=function(){var e=this;this.isProcessing||(this.isProcessing=!0,requestIdleCallback(function(t){e.processQueue(t)},{timeout:this.timeout}))},r.prototype.enqueueEvent=function(e,t){var n,i,s,o;if(e.type===Le.FullSnapshot){if(this.config.loggerProvider.debug("Processing full snapshot immediately."),this.taskQueue.length>0||this.pendingQueue.length>0){var l=X(X([],K(this.taskQueue.splice(0)),!1),K(this.mergeMutationTasks(this.pendingQueue.splice(0))),!1);try{for(var a=U(l),u=a.next();!u.done;u=a.next()){var d=u.value,v=this.compressEvent(d.event);this.addCompressedEventToManager(v,d.sessionId)}}catch(f){n={error:f}}finally{try{u&&!u.done&&(i=a.return)&&i.call(a)}finally{if(n)throw n.error}}this.isProcessing=!1}var c=this.compressEvent(e);this.addCompressedEventToManager(c,t),(s=this.onFullSnapshotProcessed)===null||s===void 0||s.call(this);return}this.canUseIdleCallback&&(!((o=this.config.performanceConfig)===null||o===void 0)&&o.enabled)?(this.config.loggerProvider.debug("Enqueuing event for processing during idle time."),this.pendingQueue.push({event:e,sessionId:t}),this.scheduleIdleProcessing()):(this.config.loggerProvider.debug("Processing event without idle callback."),this.addCompressedEvent(e,t))},r.prototype.processQueue=function(e){var t,n=this;for(this.pendingQueue.length>0&&(t=this.taskQueue).push.apply(t,X([],K(this.mergeMutationTasks(this.pendingQueue.splice(0))),!1));this.taskQueue.length>0&&(e.timeRemaining()>0||e.didTimeout);){var i=this.taskQueue.shift();if(i){var s=i.event,o=i.sessionId;this.addCompressedEvent(s,o)}}this.taskQueue.length>0||this.pendingQueue.length>0?requestIdleCallback(function(l){n.processQueue(l)},{timeout:this.timeout}):this.isProcessing=!1},r.prototype.mergeMutationTasks=function(e){var t,n,i;if(((i=this.config.performanceConfig)===null||i===void 0?void 0:i.mergeMutations)===!1||e.length<=1)return e;for(var s=[],o=0;o<e.length;){for(var l=e[o].sessionId,a=o+1;a<e.length&&e[a].sessionId===l;)a++;var u=un(e.slice(o,a).map(function(f){return f.event}));try{for(var d=(t=void 0,U(u)),v=d.next();!v.done;v=d.next()){var c=v.value;s.push({event:c,sessionId:l})}}catch(f){t={error:f}}finally{try{v&&!v.done&&(n=d.return)&&n.call(d)}finally{if(t)throw t.error}}o=a}return s},r})(),vn="Unexpected error occurred",fn="Network error occurred, event batch rejected",It="Session replay event batch rejected due to exceeded retry count",re="Failed to store session replay events in IndexedDB",hn="Session replay event batch not sent due to missing device ID",gn="Session replay event batch not sent due to missing api key",qe="Session replay event batch dropped: server signalled capture disabled or session out of valid range for this session",ke="1.49.0";function pn(r,e){return C(this,void 0,void 0,function(){var t,n,i,s,o,l,a,u,d,v,c,f,h,p,m=this;return I(this,function(g){switch(g.label){case 0:return g.trys.push([0,4,,5]),t=e.CompressionStream,n=new t("gzip"),i=n.writable.getWriter(),s=n.readable.getReader(),o=[],l=(function(){return C(m,void 0,void 0,function(){var y,b,S;return I(this,function(T){switch(T.label){case 0:return[4,s.read()];case 1:if(y=T.sent(),b=y.done,S=y.value,b)return[3,3];o.push(S),T.label=2;case 2:return[3,0];case 3:return[2]}})})})(),[4,i.write(new TextEncoder().encode(r))];case 1:return g.sent(),[4,i.close()];case 2:return g.sent(),[4,l];case 3:g.sent(),a=o.reduce(function(y,b){return y+b.length},0),u=new Uint8Array(a),d=0;try{for(v=U(o),c=v.next();!c.done;c=v.next())f=c.value,u.set(f,d),d+=f.length}catch(y){h={error:y}}
2finally{try{c&&!c.done&&(p=v.return)&&p.call(v)}finally{if(h)throw h.error}}return[2,u];case 4:return g.sent(),[2,null];case 5:return[2]}})})}var mn=256,yn=256;function Sn(r,e){return new Promise(function(t,n){var i=function(){var s=new Error("Custom session replay transport aborted by send timeout");s.name="AbortError",n(s)};e.addEventListener("abort",i,{once:!0}),r.then(function(s){e.removeEventListener("abort",i),t(s)},function(s){e.removeEventListener("abort",i),n(s)})})}var bn=(function(){function r(e){var t=e.trackServerUrl,n=e.loggerProvider,i=e.payloadBatcher,s=e.workerScript,o=e.enableTransportCompression,l=e.sendTimeoutMs,a=e.handleSendEvents,u=this;if(this.storageKey="",this.retryTimeout=1e3,this.scheduled=null,this.queue=[],this.sendIdCounter=0,this.pendingWorkerRequests=new Map,this.timedOutWorkerRequests=new Map,this.flushPauseUntilMs=0,this.mergeOnNextFlush=!1,this.coalesceNextFlush=!1,this.mergeLogFiredThisPause=!1,this.killedSessions=new Set,this.loggerProvider=n,this.payloadBatcher=i||function(f){return f},this.trackServerUrl=t,this.enableTransportCompression=o??!0,this.sendTimeoutMs=l??qr,this.handleSendEvents=a,s)try{var d=new Blob([s],{type:"application/javascript"}),v=URL.createObjectURL(d),c=new Worker(v);c.onerror=function(f){var h,p;f.preventDefault(),n.error("Track destination worker failed, falling back to main-thread sending: ".concat(f.message," (").concat(f.filename,":").concat(f.lineno,")")),c.terminate(),u.worker=void 0;try{for(var m=U(u.pendingWorkerRequests),g=m.next();!g.done;g=m.next()){var y=K(g.value,2),b=y[1];b.timeout&&clearTimeout(b.timeout),n.warn("Session replay event send failed due to worker crash: ".concat(f.message)),b.resolve()}}catch(S){h={error:S}}finally{try{g&&!g.done&&(p=m.return)&&p.call(m)}finally{if(h)throw h.error}}u.pendingWorkerRequests.clear(),u.timedOutWorkerRequests.clear()},c.onmessage=function(f){var h=f.data;if(h.type==="log")n.log(h.message);else if(h.type==="warn")n.warn(h.message);else if(h.type==="payload_too_large"){var p=u.pendingWorkerRequests.get(h.id);if(p)p.timeout&&clearTimeout(p.timeout),u.handlePayloadTooLargeResponse(p.context,h.isWaf),p.resolve(),u.pendingWorkerRequests.delete(h.id);else{var m=u.timedOutWorkerRequests.get(h.id);m&&(u.timedOutWorkerRequests.delete(h.id),u.handlePayloadTooLargeResponse(m,h.isWaf))}}else if(h.type==="complete"){var g=u.pendingWorkerRequests.get(h.id);if(g)g.timeout&&clearTimeout(g.timeout),h.skipCode!==void 0&&u.applyServerDirective(g.context.sessionId,h.skipCode),u.completeRequest({context:g.context}),g.resolve(),u.pendingWorkerRequests.delete(h.id);else{var m=u.timedOutWorkerRequests.get(h.id);m&&(u.timedOutWorkerRequests.delete(h.id),h.skipCode!==void 0&&u.applyServerDirective(m.sessionId,h.skipCode),u.completeRequest({context:m}))}}else h.type==="fetch-request"&&u.handleDelegatedFetch(c,h).catch(function(y){n.warn("Failed to handle delegated session replay fetch:",y)})},this.worker=c}catch(f){n.error("Failed to create track destination worker, falling back to main-thread sending:",f)}}return r.prototype.sendEventsList=function(e){this.addToQueue(E(E({},e),{attempts:0,timeout:0}))},r.prototype.markCoalesceNextFlush=function(){this.coalesceNextFlush=!0,this.schedule(0)},r.prototype.sendBeacon=function(e){var t=this,n,i,s=e.events,o=e.sessionId,l=e.deviceId,a=e.apiKey,u=e.serverZone,d=64*1024,v=function(q){return new Blob([q]).size},c=s,f=JSON.stringify({version:2,events:c});if(v(f)>d){for(var h=0,p=c.length;h<p;){var m=Math.floor((h+p+1)/2);v(JSON.stringify({version:2,events:c.slice(0,m)}))<=d?h=m:p=m-1}c=c.slice(0,h),f=JSON.stringify({version:2,events:c}),this.loggerProvider.warn("sendBeacon payload exceeded 64 KB limit, trimmed from ".concat(s.length," to ").concat(c.length," events"))}if(c.length!==0){if(this.handleSendEvents){var g=new URLSearchParams({device_id:l,session_id:String(o),type:"replay"}),y="".concat(Ee(u,this.trackServerUrl),"?").concat(g.toString()),b={"Content-Type":"application/json",Accept:"*/*",Authorization:"Bearer ".concat(a)};this.loggerProvider.debug("Routing session replay exit batch (".concat(c.length," events) through custom transport for session id ").concat(o,"."));try{this.handleSendEvents({url:y,method:"POST",headers:b,body:f,keepalive:!0}
2).catch(function(q){t.loggerProvider.warn("Custom transport failed to send session replay exit batch:",q)})}catch(q){this.loggerProvider.warn("Custom transport threw while sending session replay exit batch:",q)}return}var S=new URLSearchParams({device_id:l,session_id:String(o),type:"replay",api_key:a}),T="".concat(Ee(u,this.trackServerUrl),"?").concat(S.toString()),L=G();try{var O=new Blob([f],{type:"application/json"}),W=(i=(n=L?.navigator)===null||n===void 0?void 0:n.sendBeacon)===null||i===void 0?void 0:i.call(n,T,O);W===!1&&this.loggerProvider.warn("sendBeacon failed to queue session replay payload")}catch{}}},r.prototype.addToQueue=function(){for(var e=this,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];var i=t.filter(function(s){return e.killedSessions.has(s.sessionId)?(e.completeRequest({context:s,err:qe}),!1):s.attempts<(s.flushMaxRetries||0)?(s.attempts+=1,!0):(e.completeRequest({context:s,err:It}),!1)});i.forEach(function(s){e.queue=e.queue.concat(s),e.schedule(0)})},r.prototype.schedule=function(e){var t=this;if(!this.scheduled){var n=this.flushPauseUntilMs-Date.now(),i=n>0,s=n>e?n:e;i&&(this.mergeOnNextFlush=!0),this.scheduled=setTimeout(function(){t.flush(!0).then(function(){t.queue.length>0&&t.schedule(e)})},s)}},r.prototype.flush=function(e){return e===void 0&&(e=!1),C(this,void 0,void 0,function(){var t,n,i,s,o,l,a;return I(this,function(u){switch(u.label){case 0:t=this.queue,this.queue=[],this.scheduled&&(clearTimeout(this.scheduled),this.scheduled=null),this.mergeOnNextFlush?(this.mergeOnNextFlush=!1,this.coalesceNextFlush=!1,t=this.mergeQueueAfterThrottle(t)):this.coalesceNextFlush&&(this.coalesceNextFlush=!1,t=this.mergeDrainBacklog(t)),u.label=1;case 1:u.trys.push([1,6,7,8]),n=U(t),i=n.next(),u.label=2;case 2:return i.done?[3,5]:(s=i.value,[4,this.send(s,e)]);case 3:u.sent(),u.label=4;case 4:return i=n.next(),[3,2];case 5:return[3,8];case 6:return o=u.sent(),l={error:o},[3,8];case 7:try{i&&!i.done&&(a=n.return)&&a.call(n)}finally{if(l)throw l.error}return[7];case 8:return[2]}})})},r.prototype.mergeQueueAfterThrottle=function(e){var t=this.coalesceByIdentity(e);return t.length<e.length&&!this.mergeLogFiredThisPause&&(this.mergeLogFiredThisPause=!0,this.loggerProvider.log("Session replay throttle pause ended; merged ".concat(e.length," queued batches into ").concat(t.length," request(s)"))),t},r.prototype.mergeDrainBacklog=function(e){var t=this.coalesceByIdentity(e);return t.length<e.length&&this.loggerProvider.log("Session replay coalesced ".concat(e.length," persisted page-load backlog batches into ").concat(t.length," request(s)")),t},r.prototype.coalesceByIdentity=function(e){var t,n,i,s,o=this,l,a,u,d,v,c,f;if(e.length<=1)return e;var h=new Map;try{for(var p=U(e),m=p.next();!m.done;m=p.next()){var g=m.value,y=[g.sessionId,(l=g.deviceId)!==null&&l!==void 0?l:"",(a=g.apiKey)!==null&&a!==void 0?a:"",g.type,(u=g.serverZone)!==null&&u!==void 0?u:"",g.sampleRate,(v=(d=g.version)===null||d===void 0?void 0:d.type)!==null&&v!==void 0?v:"",(f=(c=g.version)===null||c===void 0?void 0:c.version)!==null&&f!==void 0?f:""].join("|"),b=h.get(y);b?b.push(g):h.set(y,[g])}}catch(q){t={error:q}}finally{try{m&&!m.done&&(n=p.return)&&n.call(p)}finally{if(t)throw t.error}}var S=[],T=function(q){var z,x;if(q.length===1)return S.push(q[0]),"continue";var A=null,F=0,N=function(){A&&S.push(A),A=null,F=0},M=function(k){var _=k.events.reduce(function(D,H){return D+new Blob([H]).size},0);if(A===null)return A=E(E({},k),{events:X([],K(k.events),!1),attempts:0}),F=_,"continue";if(F+_>Kr)return N(),A=E(E({},k),{events:X([],K(k.events),!1),attempts:0}),F=_,"continue";var P=A.onComplete,V=k.onComplete;A.events=A.events.concat(k.events),F+=_,A.onComplete=function(){return C(o,void 0,void 0,function(){return I(this,function(D){switch(D.label){case 0:return[4,Promise.allSettled([P(),V()])];case 1:return D.sent(),[2]}})})}};try{for(var w=(z=void 0,U(q)),R=w.next();!R.done;R=w.next()){var B=R.value;M(B)}}catch(k){z={error:k}}finally{try{R&&!R.done&&(x=w.return)&&x.call(w)}finally{if(z)throw z.error}}N()};try{for(var L=U(h.values()),O=L.next();!O.done;O=L.next()){var W=O.value;T(W)}}catch(q){i={error:q}}finally{try{O&&!O.done&&(s=L.return)&&s.call(L)}finally{if(i)throw i.error}}return S},r.prototype.send=function(e,t){return t===void 0&&(t=!0),C(this,void 0,void 0,function(){var n,i,s,o;return I(this,function(l){return this.killedSessions.has(e.sessionId)?[2,this.completeRequest({context:e,err:qe})]:(n=e.apiKey,n?(i=e.deviceId,i?(s=this.payloadBatcher({version:1,events:e.events}),s.events.length===0?(this.completeRequest({context:e}),[2]):(o=this.worker,o?[2,this.sendViaWorker(o,e,s,t)]:[2,this.sendOnMainThread(n,i,e,s,t)])):[2,this.completeRequest({context:e,err:hn})]):[2,this.completeRequest({context:e,err:gn})])})})},r.prototype.sendViaWorker=function(e,t,n,i){return C(this,void 0,void 0,function(){var s,o=this;return I(this,function(l){return s="".concat(++this.sendIdCounter),[2,new Promise(function(a){var u,d=o.sendTimeoutMs>0?setTimeout(function(){var v=o.pendingWorkerRequests.get(s);
2v&&(o.pendingWorkerRequests.delete(s),o.rememberTimedOutRequest(s,v.context),o.loggerProvider.warn("Session replay worker send timed out after ".concat(o.sendTimeoutMs,"ms; leaving events for retry")),v.resolve())},o.sendTimeoutMs):void 0;o.pendingWorkerRequests.set(s,{context:t,resolve:a,timeout:d}),e.postMessage({type:"send",id:s,payload:n,useRetry:i,useCustomTransport:!!o.handleSendEvents,context:{apiKey:t.apiKey,deviceId:t.deviceId,sessionId:t.sessionId,events:t.events,eventType:t.type,flushMaxRetries:(u=t.flushMaxRetries)!==null&&u!==void 0?u:0,sampleRate:t.sampleRate,serverZone:t.serverZone,trackServerUrl:o.trackServerUrl,version:t.version,currentUrl:tt(),sdkVersion:ke,enableTransportCompression:o.enableTransportCompression,sendTimeoutMs:o.sendTimeoutMs}})})]})})},r.prototype.rememberTimedOutRequest=function(e,t){var n,i;if(this.timedOutWorkerRequests.set(e,t),this.timedOutWorkerRequests.size>yn)try{for(var s=U(this.timedOutWorkerRequests.keys()),o=s.next();!o.done;o=s.next()){var l=o.value;this.timedOutWorkerRequests.delete(l);break}}catch(a){n={error:a}}finally{try{o&&!o.done&&(i=s.return)&&i.call(s)}finally{if(n)throw n.error}}},r.prototype.handleDelegatedFetch=function(e,t){var n,i,s;return C(this,void 0,void 0,function(){var o,l,a,u,d,v,c,f,h,p,m;return I(this,function(g){switch(g.label){case 0:o=t.requestId,l=t.url,a=t.method,u=t.headers,d=t.body,v=t.keepalive,g.label=1;case 1:return g.trys.push([1,10,,11]),c=void 0,this.handleSendEvents?[4,this.handleSendEvents({url:l,method:a,headers:u,body:d,keepalive:v})]:[3,3];case 2:return c=g.sent(),[3,5];case 3:return this.loggerProvider.warn("Delegated session replay fetch received without a custom transport configured; falling back to built-in fetch."),[4,fetch(l,{method:a,headers:u,body:d,keepalive:v})];case 4:c=g.sent(),g.label=5;case 5:if(f=c.status,h=null,p="",f>=200&&f<300&&(h=(s=(i=(n=c.headers)===null||n===void 0?void 0:n.get)===null||i===void 0?void 0:i.call(n,gt))!==null&&s!==void 0?s:null),f!==413)return[3,9];g.label=6;case 6:return g.trys.push([6,8,,9]),[4,c.text()];case 7:return p=g.sent(),[3,9];case 8:return g.sent(),[3,9];case 9:return this.loggerProvider.debug("Delegated session replay fetch (request ".concat(o,") returned status ").concat(f,".")),e.postMessage({type:"fetch-response",requestId:o,status:f,skipHeader:h,body:p}),[3,11];case 10:return m=g.sent(),this.loggerProvider.debug("Delegated session replay fetch (request ".concat(o,") failed:"),m),e.postMessage({type:"fetch-response",requestId:o,status:0,skipHeader:null,body:String(m),error:!0}),[3,11];case 11:return[2]}})})},r.prototype.sendOnMainThread=function(e,t,n,i,s){var o,l,a,u,d,v,c;return C(this,void 0,void 0,function(){var f,h,p,m,g,y,b,S,T,L,O,W,q,z,x,A,F,N,M,w,R,R,B,k;return I(this,function(_){switch(_.label){case 0:f=tt(),h=ke,p=n.sampleRate,m=new URLSearchParams({device_id:t,session_id:"".concat(n.sessionId),type:"".concat(n.type)}),g="".concat((l=(o=n.version)===null||o===void 0?void 0:o.type)!==null&&l!==void 0?l:"standalone","/").concat((u=(a=n.version)===null||a===void 0?void 0:a.version)!==null&&u!==void 0?u:h),_.label=1;case 1:return _.trys.push([1,19,,23]),y=JSON.stringify(i),b=G(),this.enableTransportCompression&&b&&"CompressionStream"in b?[4,pn(y,b)]:[3,3];case 2:return T=_.sent(),[3,4];case 3:T=null,_.label=4;case 4:if(S=T,L=S?S.byteLength:new Blob([y]).size,O=new AbortController,W=E({"Content-Type":"application/json",Accept:"*/*",Authorization:"Bearer ".concat(e),"X-Client-Version":h,"X-Client-Library":g,"X-Client-Url":f.substring(0,Nr),"X-Client-Sample-Rate":"".concat(p),"X-Sampling-Hash-Alg":"xxhash32"},S?{"Content-Encoding":"gzip"}:{}),q=S??y,z=L<=Ur,x={headers:W,body:q,method:"POST",keepalive:z,signal:O.signal},A="".concat(Ee(n.serverZone,this.trackServerUrl),"?").concat(m.toString()),i.events.length===0)return this.completeRequest({context:n}),[2];F=this.sendTimeoutMs>0?setTimeout(function(){O.abort()},this.sendTimeoutMs):void 0,N=void 0,_.label=5;case 5:return _.trys.push([5,,10,11]),this.handleSendEvents?[4,Sn(this.handleSendEvents({url:A,method:"POST",headers:W,body:q,keepalive:z}),O.signal)]:[3,7];case 6:return M=_.sent(),[3,9];case 7:return[4,fetch(A,x)];case 8:M=_.sent(),_.label=9;case 9:return N=M,[3,11];case 10:return F&&clearTimeout(F),[7];case 11:if(N===null)return this.completeRequest({context:n,err:vn}),[2];if(N.status>=200&&N.status<300&&(w=(c=(v=(d=N.headers)===null||d===void 0?void 0:d.get)===null||v===void 0?void 0:v.call(d,gt))!==null&&c!==void 0?c:null,this.applyServerDirective(n.sessionId,w)),s)return[3,12];R="";try{R=JSON.stringify(N.body,null,2)}catch{}return this.completeRequest({context:n,success:"".concat(N.status,": ").concat(R)}),[3,18];
2case 12:if(R="",N.status!==413)return[3,16];_.label=13;case 13:return _.trys.push([13,15,,16]),[4,N.text()];case 14:return R=_.sent(),[3,16];case 15:return _.sent(),[3,16];case 16:return[4,this.handleReponse(N.status,n,R)];case 17:_.sent(),_.label=18;case 18:return[3,23];case 19:return B=_.sent(),k=!!B&&typeof B=="object"&&B.name==="AbortError",k&&s?[4,this.handleOtherResponse(n)]:[3,21];case 20:return _.sent(),[3,22];case 21:this.completeRequest({context:n,err:B}),_.label=22;case 22:return[3,23];case 23:return[2]}})})},r.prototype.handleReponse=function(e,t,n){return n===void 0&&(n=""),C(this,void 0,void 0,function(){var i,s;return I(this,function(o){switch(o.label){case 0:switch(i=new Bt().buildStatus(e),s=i,s){case ye.Success:return[3,1];case ye.Failed:return[3,2];case ye.Timeout:return[3,2];case ye.RateLimit:return[3,2];case ye.PayloadTooLarge:return[3,4]}return[3,5];case 1:return this.handleSuccessResponse(t),[3,8];case 2:return[4,this.handleOtherResponse(t)];case 3:return o.sent(),[3,8];case 4:return this.handlePayloadTooLargeResponse(t,Lr.test(n)),[3,8];case 5:return e!==499?[3,7]:[4,this.handleOtherResponse(t)];case 6:return o.sent(),[3,8];case 7:this.completeRequest({context:t,err:fn}),o.label=8;case 8:return[2]}})})},r.prototype.handlePayloadTooLargeResponse=function(e,t){var n=t?"WAF (compressed payload too large)":"server (event too large)",i=Math.round(e.events.reduce(function(l,a){return l+a.length},0)/Ze);if(!t){this.completeRequest({context:e,err:"Session replay event batch dropped: ".concat(n," rejected payload (").concat(e.events.length," events, ").concat(i," KB) — not retrying non-WAF 413")});return}if(e.events.length===1){this.completeRequest({context:e,err:"Session replay event dropped: single event (".concat(i," KB, 1 event) rejected by ").concat(n," — cannot split further")});return}this.loggerProvider.warn("Session replay event batch rejected by ".concat(n," (").concat(e.events.length," events, ").concat(i," KB total) — splitting and retrying")),e.onComplete();var s=function(){return Promise.resolve()},o=Math.floor(e.events.length/2);this.sendEventsList(E(E({},e),{events:e.events.slice(0,o),onComplete:s})),this.sendEventsList(E(E({},e),{events:e.events.slice(o),onComplete:s}))},r.prototype.handleSuccessResponse=function(e){var t=Math.round(new Blob(e.events).size/Ze);this.completeRequest({context:e,success:"Session replay event batch tracked successfully for session id ".concat(e.sessionId,", size of events: ").concat(t," KB")})},r.prototype.handleOtherResponse=function(e){return C(this,void 0,void 0,function(){var t;return I(this,function(n){switch(n.label){case 0:return t=Math.random()*e.attempts*this.retryTimeout,e.attempts++,e.attempts>(e.flushMaxRetries||0)?(this.completeRequest({context:e,err:It}),[2]):[4,new Promise(function(i){return setTimeout(i,t)})];case 1:return n.sent(),[4,this.send(e,!0)];case 2:return n.sent(),[2]}})})},r.prototype.completeRequest=function(e){var t=e.context,n=e.err,i=e.success;t.onComplete(),n?this.loggerProvider.warn(n):i&&this.loggerProvider.log(i)},r.prototype.applyServerDirective=function(e,t){if(t===null){this.flushPauseUntilMs=0,this.mergeLogFiredThisPause=!1;return}if(t===Br){var n=this.flushPauseUntilMs>Date.now();this.flushPauseUntilMs=Date.now()+pt,n||this.loggerProvider.log("Session replay throttled by server; pausing flush schedule for ".concat(pt/1e3,"s"));return}(t===Wr||t===zr)&&this.killSession(e,t)},r.prototype.killSession=function(e,t){var n,i,s,o;if(!this.killedSessions.has(e)){if(this.killedSessions.add(e),this.killedSessions.size>mn)try{for(var l=U(this.killedSessions),a=l.next();!a.done;a=l.next()){var u=a.value;this.killedSessions.delete(u);break}}catch(h){n={error:h}}finally{try{a&&!a.done&&(i=l.return)&&i.call(l)}finally{if(n)throw n.error}}this.loggerProvider.log("Session replay capture stopped for session ".concat(e," by server directive ").concat(t,"; remaining events will be dropped"));var d=[];try{for(var v=U(this.queue),c=v.next();!c.done;c=v.next()){var f=c.value;f.sessionId===e?this.completeRequest({context:f,err:qe}):d.push(f)}}catch(h){s={error:h}}
2finally{try{c&&!c.done&&(o=v.return)&&o.call(v)}finally{if(s)throw s.error}}this.queue=d}},r})();const rt=(r,e)=>e.some(t=>r instanceof t);let Ct,Pt;function En(){return Ct||(Ct=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function In(){return Pt||(Pt=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}const nt=new WeakMap,Be=new WeakMap,_e=new WeakMap;function Cn(r){const e=new Promise((t,n)=>{const i=()=>{r.removeEventListener("success",s),r.removeEventListener("error",o)},s=()=>{t(ge(r.result)),i()},o=()=>{n(r.error),i()};r.addEventListener("success",s),r.addEventListener("error",o)});return _e.set(e,r),e}function Pn(r){if(nt.has(r))return;const e=new Promise((t,n)=>{const i=()=>{r.removeEventListener("complete",s),r.removeEventListener("error",o),r.removeEventListener("abort",o)},s=()=>{t(),i()},o=()=>{n(r.error||new DOMException("AbortError","AbortError")),i()};r.addEventListener("complete",s),r.addEventListener("error",o),r.addEventListener("abort",o)});nt.set(r,e)}let it={get(r,e,t){if(r instanceof IDBTransaction){if(e==="done")return nt.get(r);if(e==="store")return t.objectStoreNames[1]?void 0:t.objectStore(t.objectStoreNames[0])}return ge(r[e])},set(r,e,t){return r[e]=t,!0},has(r,e){return r instanceof IDBTransaction&&(e==="done"||e==="store")?!0:e in r}};function nr(r){it=r(it)}function Tn(r){return In().includes(r)?function(...e){return r.apply(st(this),e),ge(this.request)}:function(...e){return ge(r.apply(st(this),e))}}function wn(r){return typeof r=="function"?Tn(r):(r instanceof IDBTransaction&&Pn(r),rt(r,En())?new Proxy(r,it):r)}function ge(r){if(r instanceof IDBRequest)return Cn(r);if(Be.has(r))return Be.get(r);const e=wn(r);return e!==r&&(Be.set(r,e),_e.set(e,r)),e}const st=r=>_e.get(r);function ir(r,e,{blocked:t,upgrade:n,blocking:i,terminated:s}={}){const o=indexedDB.open(r,e),l=ge(o);return n&&o.addEventListener("upgradeneeded",a=>{n(ge(o.result),a.oldVersion,a.newVersion,ge(o.transaction),a)}),t&&o.addEventListener("blocked",a=>t(a.oldVersion,a.newVersion,a)),l.then(a=>{s&&a.addEventListener("close",()=>s()),i&&a.addEventListener("versionchange",u=>i(u.oldVersion,u.newVersion,u))}).catch(()=>{}),l}const Rn=["get","getKey","getAll","getAllKeys","count"],Mn=["put","add","delete","clear"],ze=new Map;function Tt(r,e){if(!(r instanceof IDBDatabase&&!(e in r)&&typeof e=="string"))return;if(ze.get(e))return ze.get(e);const t=e.replace(/FromIndex$/,""),n=e!==t,i=Mn.includes(t);if(!(t in(n?IDBIndex:IDBObjectStore).prototype)||!(i||Rn.includes(t)))return;const s=async function(o,...l){const a=this.transaction(o,i?"readwrite":"readonly");let u=a.store;return n&&(u=u.index(l.shift())),(await Promise.all([u[t](...l),i&&a.done]))[0]};return ze.set(e,s),s}nr(r=>({...r,get:(e,t,n)=>Tt(e,t)||r.get(e,t,n),has:(e,t)=>!!Tt(e,t)||r.has(e,t)}));const kn=["continue","continuePrimaryKey","advance"],wt={},ot=new WeakMap,sr=new WeakMap,On={get(r,e){if(!kn.includes(e))return r[e];let t=wt[e];return t||(t=wt[e]=function(...n){ot.set(this,sr.get(this)[e](...n))}),t}};async function*xn(...r){let e=this;if(e instanceof IDBCursor||(e=await e.openCursor(...r)),!e)return;e=e;const t=new Proxy(e,On);for(sr.set(t,e),_e.set(t,st(e));e;)yield t,e=await(ot.get(t)||e.continue()),ot.delete(t)}function Rt(r,e){return e===Symbol.asyncIterator&&rt(r,[IDBIndex,IDBObjectStore,IDBCursor])||e==="iterate"&&rt(r,[IDBIndex,IDBObjectStore])}nr(r=>({...r,get(e,t,n){return Rt(e,t)?xn:r.get(e,t,n)},has(e,t){return Rt(e,t)||r.has(e,t)}}));var or=(function(){function r(e){var t=this,n,i,s;this.minInterval=$e,this.maxInterval=Je,this.maxPersistedEventsSize=xr,this._timeAtLastSplit=Date.now(),this.shouldSplitEventsList=function(o,l){var a=t.getStringSize(l),u=t.getEventsArraySize(o);return u+a>=t.maxPersistedEventsSize?!0:Date.now()-t.timeAtLastSplit>t.interval&&o.length?(t.interval=Math.min(t.maxInterval,t.interval+t.minInterval),t._timeAtLastSplit=Date.now(),!0):!1},this.loggerProvider=e.loggerProvider,this.minInterval=(n=e.minInterval)!==null&&n!==void 0?n:this.minInterval,this.maxInterval=(i=e.maxInterval)!==null&&i!==void 0?i:this.maxInterval,this.maxPer
2sistedEventsSize=(s=e.maxPersistedEventsSize)!==null&&s!==void 0?s:this.maxPersistedEventsSize,this.interval=this.minInterval}return Object.defineProperty(r.prototype,"timeAtLastSplit",{get:function(){return this._timeAtLastSplit},enumerable:!1,configurable:!0}),r.prototype.getStringSize=function(e){for(var t=0,n=0;n<e.length;n++){var i=e.charCodeAt(n);if(i<=127)t++;else if(i<=2047)t+=2;else if(i>=55296&&i<=56319){var s=n+1<e.length?e.charCodeAt(n+1):NaN;s>=56320&&s<=57343?(t+=4,n++):t+=3}else i>=56320&&i<=57343,t+=3}return t},r.prototype.getEventsArraySize=function(e){var t,n,i=0;try{for(var s=U(e),o=s.next();!o.done;o=s.next()){var l=o.value;i+=this.getStringSize(l)}}catch(u){t={error:u}}finally{try{o&&!o.done&&(n=s.return)&&n.call(s)}finally{if(t)throw t.error}}var a=2+Math.max(0,e.length-1)+e.length*2;return i+a},r})(),Ln=function(r){return typeof r=="object"&&r!==null&&r.name==="AbortError"},ee=function(r,e,t){Ln(t)?r.debug(e):r.warn(e)};function _n(){try{return crypto.randomUUID()}catch{return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}}var ne="sessionCurrentSequence",le="sequencesToSend",Dn=2e3,We=5e3;function An(r,e,t){return new Promise(function(n,i){var s=setTimeout(function(){return i(new Error("".concat(t," after ").concat(e,"ms")))},e);r.then(function(o){clearTimeout(s),n(o)},function(o){clearTimeout(s),i(o)})})}function Ke(r,e,t){var n=setTimeout(t,e);return r.then(function(){return clearTimeout(n)},function(){return clearTimeout(n)}),function(){return clearTimeout(n)}}var Fn=function(r){var e,t;return r.objectStoreNames.contains(ne)||(t=r.createObjectStore(ne,{keyPath:"sessionId"})),r.objectStoreNames.contains(le)||(e=r.createObjectStore(le,{keyPath:"sequenceId",autoIncrement:!0}),e.createIndex("sessionId","sessionId")),{sequencesStore:e,currentSequenceStore:t}},Nn=function(r){return C(void 0,void 0,void 0,function(){return I(this,function(e){switch(e.label){case 0:return[4,An(ir(r,1,{upgrade:Fn}),Dn,"IDB openDB timed out")];case 1:return[2,e.sent()]}})})},Un=(function(r){Oe(e,r);function e(t){var n=this,i;return n=r.call(this,t)||this,n.consecutiveFailures=0,n.hasTriggeredFallback=!1,n.emptyFilteredCount=0,n.getSequencesToSend=function(){return C(n,void 0,void 0,function(){var s,o,l,a,u,d,v,c,f,h,p=this;return I(this,function(m){switch(m.label){case 0:s=!1,o=!1,m.label=1;case 1:return m.trys.push([1,9,,10]),l=[],a=this.db.transaction("sequencesToSend","readwrite"),a.done.catch(function(g){!s&&!o&&(ee(p.loggerProvider,"".concat(re,": ").concat(g),g),p.recordFailure())}),u=Ke(a.done,We,function(){!s&&!o&&(o=!0,ee(p.loggerProvider,"".concat(re,": transaction timed out")),p.recordFailure())}),[4,a.store.openCursor()];case 2:d=m.sent(),m.label=3;case 3:return d?(v=d.value,c=v.sessionId,f=v.events,f.length!==0?[3,5]:(this.maybeLogEmptyFiltered("getSequencesToSend"),[4,d.delete()])):[3,8];case 4:return m.sent(),[3,6];case 5:l.push({events:f,sequenceId:d.key,sessionId:c}),m.label=6;case 6:return[4,d.continue()];case 7:return d=m.sent(),[3,3];case 8:return this.recordSuccess(),u(),[2,l];case 9:return h=m.sent(),o||(s=!0,ee(this.loggerProvider,"".concat(re,": ").concat(h),h),this.recordFailure()),[3,10];case 10:return[2,void 0]}})})},n.storeCurrentSequence=function(s){return C(n,void 0,void 0,function(){var o,l,a,u,d,v,c,f,h=this;return I(this,function(p){switch(p.label){case 0:o=!1,l=!1,p.label=1;case 1:return p.trys.push([1,5,,6]),a=this.db.transaction([ne,le],"readwrite"),a.done.catch(function(m){!o&&!l&&(ee(h.loggerProvider,"".concat(re,": ").concat(m),m),h.recordFailure())}),u=Ke(a.done,We,function(){!o&&!l&&(l=!0,ee(h.loggerProvider,"".concat(re,": transaction timed out")),h.recordFailure())}),[4,a.objectStore(ne).get(s)];case 2:return d=p.sent(),!d||d.tabId&&d.tabId!==this.tabId?(u(),[2,void 0]):d.events.length===0?(this.maybeLogEmptyFiltered("storeCurrentSequence"),u(),[2,void 0]):[4,a.objectStore(le).put({sessionId:s,events:d.events,tabId:this.tabId})];case 3:return v=p.sent(),[4,a.objectStore(ne).put({sessionId:s,events:[],tabId:this.tabId})];case 4:return p.sent(),this.recordSuccess(),u(),d.tabId,c=Fe(d,["tabId"]),[2,E(E({},c),{sessionId:s,sequenceId:v})];case 5:return f=p.sent(),l||(o=!0,ee(this.loggerProvider,"".concat(re,": ").concat(f),f),this.recordFailure()),[3,6];case 6:return[2,void 0]}})})},n.addEventToCurrentSequence=function(s,o){return C(n,void 0,void 0,function(){var l,a,u,d,v,c,f,h,p,m=this;return I(this,function(g){switch(g.label){case 0:l=!1,a=!1,g.label=1;case 1:return g.trys.push([1,15,,16]),u=this.db.transaction([ne,le],"readwrite"),u.done.catch(function(y){!l&&!a&&(ee(m.loggerProvider,"".concat(re,": ").concat(y),y),m.recordFailure())}),d=Ke(u.done,We,function(){!l&&!a&&(a=!0,ee(m.loggerProvider,"".concat(re,": transaction timed out")),m.recordFailure())}),[4,u.objectStore(ne).get(s)];case 2:return v=g.sent(),v?.tabId&&v.tabId!==this.tabId?v.events.length>0?[4,u.objectStore(le).put({sessionId:s,events:v.events,tabId:v.tabId})]:[3,4]:[3,6];case 3:g.sent(),g.label=4;case 4:return[4,u.objectStore(ne).put({sessionId:s,events:[o],tabId:this.tabId})];case 5:return g.sent(),this.recordSuccess(),d(),[2,void 0];case 6:return c=v,c?[3,8]:[4,u.objectStore(ne).put({sessionId:s,events:[o],tabId:this.tabId})];case 7:return g.sent(),this.recordSuccess(),d(),[2,void 0];case 8:return this.shouldSplitEventsList(c.events,o)?[3,10]:[4,u.objectStore(ne).put({sessionId:s,events:c.events.concat(o),tabId:this.tabId})];case 9:return g.sent(),this.recordSuccess(),d(),[2,void 0];case 10:return f=c.events,f.length!==0?[3,12]:(this.maybeLogEmptyFiltered("addEventToCurrentSequence"),[4,u.objectStore(ne).put({sessionId:s,events:[o],tabId:this.tabId})]);case 11:return g.sent(),this.recordSuccess(),d(),[2,void 0];case 12:return[4,u.objectStore(ne).put({sessionId:s,events:[o],tabId:this.tabId})];case 13:return g.sent(),[4,u.objectStore(le).put({sessionId:s,events:f,tabId:this.tabId})];case 14:return h=g.sent(),this.recordSuccess(),d(),[2,{events:f,sessionId:s,sequenceId:h}];case 15:return p=g.sent(),a||(l=!0,ee(this.loggerProvider,"".concat(re,": ").concat(p),p),this.recordFailure()),[3,16];case 16:return[2,void 0]}})})},n.storeSendingEvents=function(s,o){return C(n,void 0,void 0,function(){var l,a;return I(this,function(u){switch(u.label){case 0:return u.trys.push([0,2,,3]),[4,this.db.put(le,{sessionId:s,events:o,tabId:this.tabId})];case 1:return l=u.sent(),this.recordSuccess(),[2,l];case 2:return a=u.sent(),ee(this.loggerProvider,"".concat(re,": ").concat(a),a),this.recordFailure(),[3,3];case 3:return[2,void 0]}})})},n.cleanUpSessionEventsStore=function(s,o){return C(n,void 0,void 0,function(){var l;return I(this,function(a){switch(a.label){case 0:if(!o)return[2];a.label=1;case 1:return a.trys.push([1,3,,4]),[4,this.db.delete(le,o)];case 2:return a.sent(),this.recordSuccess(),[3,4];case 3:return l=a.sent(),ee(this.loggerProvider,"".concat(re,": ").concat(l),l),this.recordFailure(),[3,4];case 4:return[2]}})})},n.db=t.db,n.tabId=t.tabId,n.onPersistentFailure=t.onPersistentFailure,n.consecutiveFailureThreshold=(i=t.consecutiveFailureThreshold)!==null&&i!==void 0?i:1,n}return e.prototype.maybeLogEmptyFiltered=function(t){this.emptyFilteredCount++%100===0&&this.loggerProvider.debug("Filtered empty session replay sequence at ".concat(t," (idb store)"))},e.prototype.recordFailure=function(){var t;this.consecutiveFailures++,!this.hasTriggeredFallback&&this.consecutiveFailures>=this.consecutiveFailureThreshold&&(this.hasTriggeredFallback=!0,(t=this.onPersistentFailure)===null||t===void 0||t.call(this))},e.prototype.recordSuccess=function(){this.consecutiveFailures=0},e.new=function(t,n){var i;return C(this,void 0,void 0,function(){var s,o,l,a,u;return I(this,function(d){switch(d.label){case 0:return d.trys.push([0,2,,3]),s=t==="replay"?"":"_".concat(t),o="".concat(n.apiKey.substring(0,10),"_amp_session_replay_events").concat(s),[4,Nn(o)];case 1:return l=d.sent(),a=(i=n.tabId)!==null&&i!==void 0?i:_n(),[2,new e(E(E({},n),{db:l,tabId:a}))];case 2:return u=d.sent(),ee(n.loggerProvider,"".concat(re,": ").concat(u),u),[3,3];case 3:return[2]}})})},e.prototype.getCurrentSequenceEvents=function(t){return C(this,void 0,void 0,function(){var o,l,n,i,s,o,l,a,u,d;return I(this,function(v){switch(v.label){case 0:return t?[4,this.db.get("sessionCurrentSequence",t)]:[3,2];case 1:return o=v.sent(),o?o.tabId&&o.tabId!==this.tabId?[2,void 0]:(o.tabId,l=Fe(o,["tabId"]),[2,[l]]):[2,void 0];case 2:n=[],v.label=3;case 3:return v.trys.push([3,8,9,10]),[4,this.db.getAll("sessionCurrentSequence")];case 4:i=U.apply(void 0,[v.sent()]),s=i.next(),v.label=5;case 5:if(s.done)return[3,7];if(o=s.value,o.tabId&&o.tabId!==this.tabId)return[3,6];o.tabId,l=Fe(o,["tabId"]),n.push(l),v.label=6;case 6:return s=i.next(),[3,5];case 7:return[3,10];case 8:return a=v.sent(),u={error:a},[3,10];case 9:try{s&&!s.done&&(d=i.return)&&d.call(i)}finally{if(u)throw u.error}
2return[7];case 10:return[2,n]}})})},e})(or),qn=(function(r){Oe(e,r);function e(){var t=r!==null&&r.apply(this,arguments)||this;return t.finalizedSequences={},t.sequences={},t.sequenceId=0,t.emptyFilteredCount=0,t}return e.prototype.resetCurrentSequence=function(t){this.sequences[t]=[]},e.prototype.addSequence=function(t){var n=this.sequenceId++,i=X([],K(this.sequences[t]),!1);return this.finalizedSequences[n]={sessionId:t,events:i},this.resetCurrentSequence(t),{sequenceId:n,events:i,sessionId:t}},e.prototype.maybeLogEmptyFiltered=function(t){this.emptyFilteredCount++%100===0&&this.loggerProvider.debug("Filtered empty session replay sequence at ".concat(t," (in-memory store)"))},e.prototype.getSequencesToSend=function(){return C(this,void 0,void 0,function(){var t,n,i,s,o,l,a,u,d,v;return I(this,function(c){t=[];try{for(n=U(Object.entries(this.finalizedSequences)),i=n.next();!i.done;i=n.next()){if(s=K(i.value,2),o=s[0],l=s[1],a=l.sessionId,u=l.events,u.length===0){this.maybeLogEmptyFiltered("getSequencesToSend"),delete this.finalizedSequences[Number(o)];continue}t.push({sequenceId:Number(o),sessionId:a,events:u})}}catch(f){d={error:f}}finally{try{i&&!i.done&&(v=n.return)&&v.call(n)}finally{if(d)throw d.error}}return[2,t]})})},e.prototype.storeCurrentSequence=function(t){return C(this,void 0,void 0,function(){var n;return I(this,function(i){return n=this.sequences[t],n?n.length===0?(this.maybeLogEmptyFiltered("storeCurrentSequence"),[2,void 0]):[2,this.addSequence(t)]:[2,void 0]})})},e.prototype.addEventToCurrentSequence=function(t,n){return C(this,void 0,void 0,function(){var i;return I(this,function(s){return this.sequences[t]||this.resetCurrentSequence(t),this.shouldSplitEventsList(this.sequences[t],n)&&(this.sequences[t].length===0?this.maybeLogEmptyFiltered("addEventToCurrentSequence"):i=this.addSequence(t)),this.sequences[t].push(n),[2,i]})})},e.prototype.storeSendingEvents=function(t,n){return C(this,void 0,void 0,function(){return I(this,function(i){return this.finalizedSequences[this.sequenceId]={sessionId:t,events:n},[2,this.sequenceId++]})})},e.prototype.cleanUpSessionEventsStore=function(t,n){return C(this,void 0,void 0,function(){return I(this,function(i){return n!==void 0&&delete this.finalizedSequences[n],[2]})})},e})(or),Mt=function(r){var e=r.config,t=r.minInterval,n=r.maxInterval,i=r.maxPersistedEventsSize,s=r.type,o=r.payloadBatcher,l=r.storeType,a=r.trackDestinationWorkerScript,u=r.shouldSend;return C(void 0,void 0,void 0,function(){function d(N){return N===void 0&&(N=!1),C(this,void 0,void 0,function(){return I(this,function(M){return[2,c.flush(N)]})})}var v,c,f,h,p,m,g,y,b,S,T,L,O,W,q,z,x,A,F;return I(this,function(N){switch(N.label){case 0:return v=(F=e.maxSingleEventSizeBytes)!==null&&F!==void 0?F:Xt,c=new bn(E(E({},e),{loggerProvider:e.loggerProvider,payloadBatcher:o,workerScript:a})),f=function(){return new qn({loggerProvider:e.loggerProvider,maxInterval:n,minInterval:t,maxPersistedEventsSize:i})},p=!1,g=function(){return C(void 0,void 0,void 0,function(){var M,w,R;return I(this,function(B){switch(B.label){case 0:return p?(p=!1,e.loggerProvider.warn("IDB store is experiencing repeated failures; falling back to in-memory event store."),h?[4,m.getSequencesToSend()]:[3,2]):[2];case 1:return w=B.sent(),[3,3];case 2:w=void 0,B.label=3;case 3:return M=w,m=f(),M&&h&&(R=h,M.forEach(function(k){O({sequenceId:k.sequenceId,events:k.events,sessionId:k.sessionId,deviceId:R})})),[2]}})})},y=function(){return C(void 0,void 0,void 0,function(){var M;return I(this,function(w){switch(w.label){case 0:return[4,Un.new(s,{loggerProvider:e.loggerProvider,minInterval:t,maxInterval:n,maxPersistedEventsSize:i,apiKey:e.apiKey,onPersistentFailure:function(){g()}})];case 1:return M=w.sent(),M?(p=!0,[2,M]):(e.loggerProvider.log("Failed to initialize idb store, falling back to memory store."),[2,f()])}})})},l!=="idb"?[3,2]:[4,y()];case 1:return b=N.sent(),[3,3];case 2:b=f(),N.label=3;case 3:return m=b,S=[],T=0,L=function(M){if(!(M<=T)){var w=Math.min(M-T,S.length);w>0&&(S.splice(0,w),T=M)}},O=function(M){var w=M.events,R=M.sessionId,B=M.deviceId,k=M.sequenceId,_=w.map(function(D){return{event:D,bytes:new Blob([D]
2).size}}),P=_.filter(function(D){return D.bytes>v});P.length>0&&e.loggerProvider.warn("Dropping ".concat(P.length," oversized event(s) from session replay sequence before send. Sizes: ").concat(P.map(function(D){return"".concat(Math.round(D.bytes/1024)," KB")}).join(", "),". If this recurs, please open a GitHub issue at https://github.com/amplitude/Amplitude-TypeScript/issues or contact Amplitude support."));var V=P.length>0?_.filter(function(D){return D.bytes<=v}).map(function(D){return D.event}):w;if(V.length===0){m.cleanUpSessionEventsStore(R,k).catch(function(D){e.loggerProvider.warn("Failed to clean up session replay events store:",D)});return}e.debugMode&&Zt().then(function(D){var H=D.totalStorageSize,j=D.percentOfQuota,Y=D.usageDetails;e.loggerProvider.debug("Total storage size: ".concat(H," KB, percentage of quota: ").concat(j,"%, usage details: ").concat(Y))}).catch(function(){}),c.sendEventsList({events:V,sessionId:R,flushMaxRetries:e.flushMaxRetries,apiKey:e.apiKey,deviceId:B,sampleRate:e.sampleRate,serverZone:e.serverZone,version:e.version,type:s,onComplete:function(){return C(void 0,void 0,void 0,function(){return I(this,function(D){switch(D.label){case 0:return[4,m.cleanUpSessionEventsStore(R,k)];case 1:return D.sent(),[2]}})})}})},W=function(M){var w=M.sessionId,R=M.deviceId;if(h=R,!(u&&!u())){var B=T+S.length;m.storeCurrentSequence(w).then(function(k){k&&(L(B),O({sequenceId:k.sequenceId,events:k.events,sessionId:k.sessionId,deviceId:R}))}).catch(function(k){e.loggerProvider.warn("Failed to get current sequence of session replay events for session:",k)})}},q=function(M){var w=M.deviceId;return C(void 0,void 0,void 0,function(){var R;return I(this,function(B){switch(B.label){case 0:return h=w,[4,m.getSequencesToSend()];case 1:return R=B.sent(),R?.length?(e.loggerProvider.log("Draining ".concat(R.length," stored sequence(s) from previous session.")),R.length>1&&c.markCoalesceNextFlush(),R.forEach(function(k){O({sequenceId:k.sequenceId,events:k.events,sessionId:k.sessionId,deviceId:w})}),[2]):[2]}})})},z=function(M){var w=M.event,R=M.sessionId,B=M.deviceId;h=B;var k=!u||u(),_=T+S.length;S.push(w.data),m.addEventToCurrentSequence(R,w.data).then(function(P){if(P){if(!k){m.cleanUpSessionEventsStore(P.sessionId,P.sequenceId).catch(function(V){e.loggerProvider.warn("Failed to clean up dropped session replay sequence:",V)}),L(_);return}L(_),O({sequenceId:P.sequenceId,events:P.events,sessionId:P.sessionId,deviceId:B})}}).catch(function(P){e.loggerProvider.warn("Failed to add event to session replay capture:",P)})},x=function(){return X([],K(S),!1)},A=function(){L(T+S.length)},[2,{sendCurrentSequenceEvents:W,addEvent:z,sendStoredEvents:q,flush:d,getBeaconEvents:x,dropPendingBeaconEvents:A,trackDestination:c}]}})})},kt=(function(){function r(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=new Map;e.forEach(function(i){n.set(i.name,i.manager)}),this.managers=n}return r.prototype.sendStoredEvents=function(e){return C(this,void 0,void 0,function(){var t;return I(this,function(n){switch(n.label){case 0:return t=[],this.managers.forEach(function(i){t.push(i.sendStoredEvents(e))}),[4,Promise.all(t)];case 1:return n.sent(),[2]}})})},r.prototype.addEvent=function(e){var t,n=e.sessionId,i=e.event,s=e.deviceId;(t=this.managers.get(i.type))===null||t===void 0||t.addEvent({sessionId:n,event:i,deviceId:s})},r.prototype.sendCurrentSequenceEvents=function(e){var t=e.sessionId,n=e.deviceId;this.managers.forEach(function(i){i.sendCurrentSequenceEvents({sessionId:t,deviceId:n})})},r.prototype.flush=function(e){return C(this,void 0,void 0,function(){var t;return I(this,function(n){switch(n.label){case 0:return t=[],this.managers.forEach(function(i){t.push(i.flush(e))}),[4,Promise.all(t)];case 1:return n.sent(),[2]}})})},r})(),ie,ct,ar;function Bn(r,e){if(ar=new Date,r.nodeType!==Node.ELEMENT_NODE)throw new Error("Can't generate CSS selector for non-element node type.");if(r.tagName.toLowerCase()==="html")return"html";var t={root:document.body,idName:function(s){return!0},className:function(s){return!0},tagName:function(s){return!0},attr:function(s,o){return!1},seedMinLength:1,optimizedMinLength:2,threshold:1e3,maxNumberOfTries:1e4,timeoutMs:void 0};ie=E(E({},t),e),ct=zn(ie.root,t);var n=Ie(r,"all",function(){return Ie(r,"two",function(){return Ie(r,"one",function(){return Ie(r,"none")})})});if(n){var i=cr(dr(n,r));return i.length>0&&(n=i[0]),De(n)}else throw new Error("Selector was not found.")}function zn(r,e){return r.nodeType===Node.DOCUMENT_NODE?r:r===e.root?r.ownerDocument:r}function Ie(r,e,t){for(var n=null,i=[],s=r,o=0,l=function(){var u,d,v=new Date().getTime()-ar.getTime();if(ie.timeoutMs!==void 0&&v>ie.timeoutMs)throw new Error("Timeout: Can't find a unique selector after ".concat(v,"ms"));var c=Pe(Wn(s))||Pe.apply(void 0,X([],K(Kn(s)),!1))||Pe.apply(void 0,X([],K(jn(s)),!1))||Pe(Gn(s))||[Lt()],f=Vn(s);if(e=="all")f&&(c=c.concat(c.filter(je).map(function(y){return Ce(y,f)})));else if(e=="two")c=c.slice(0,1),f&&(c=c.concat(c.filter(je).map(function(y){return Ce(y,f)})));
vendor: 4,542 bytes, line 2
2else if(e=="one"){var h=K(c=c.slice(0,1),1),p=h[0];f&&je(p)&&(c=[Ce(p,f)])}else e=="none"&&(c=[Lt()],f&&(c=[Ce(c[0],f)]));try{for(var m=(u=void 0,U(c)),g=m.next();!g.done;g=m.next()){var p=g.value;p.level=o}}catch(y){u={error:y}}finally{try{g&&!g.done&&(d=m.return)&&d.call(m)}finally{if(u)throw u.error}}if(i.push(c),i.length>=ie.seedMinLength&&(n=Ot(i,t),n))return"break";s=s.parentElement,o++};s;){var a=l();if(a==="break")break}return n||(n=Ot(i,t)),!n&&t?t():n}function Ot(r,e){var t,n,i=cr(ur(r));if(i.length>ie.threshold)return e?e():null;try{for(var s=U(i),o=s.next();!o.done;o=s.next()){var l=o.value;if(lr(l))return l}}catch(a){t={error:a}}finally{try{o&&!o.done&&(n=s.return)&&n.call(s)}finally{if(t)throw t.error}}return null}function De(r){for(var e=r[0],t=e.name,n=1;n<r.length;n++){var i=r[n].level||0;e.level===i-1?t="".concat(r[n].name," > ").concat(t):t="".concat(r[n].name," ").concat(t),e=r[n]}return t}function xt(r){return r.map(function(e){return e.penalty}).reduce(function(e,t){return e+t},0)}function lr(r){var e=De(r);switch(ct.querySelectorAll(e).length){case 0:throw new Error("Can't select any node with this selector: ".concat(e));case 1:return!0;default:return!1}}function Wn(r){var e=r.getAttribute("id");return e&&ie.idName(e)?{name:"#"+CSS.escape(e),penalty:0}:null}function Kn(r){var e=Array.from(r.attributes).filter(function(t){return ie.attr(t.name,t.value)});return e.map(function(t){return{name:"[".concat(CSS.escape(t.name),'="').concat(CSS.escape(t.value),'"]'),penalty:.5}})}function jn(r){var e=Array.from(r.classList).filter(ie.className);return e.map(function(t){return{name:"."+CSS.escape(t),penalty:1}})}function Gn(r){var e=r.tagName.toLowerCase();return ie.tagName(e)?{name:e,penalty:2}:null}function Lt(){return{name:"*",penalty:3}}function Vn(r){var e=r.parentNode;if(!e)return null;var t=e.firstChild;if(!t)return null;for(var n=0;t&&(t.nodeType===Node.ELEMENT_NODE&&n++,t!==r);)t=t.nextSibling;return n}function Ce(r,e){return{name:r.name+":nth-child(".concat(e,")"),penalty:r.penalty+1}}function je(r){return r.name!=="html"&&!r.name.startsWith("#")}function Pe(){for(var r=[],e=0;e<arguments.length;e++)r[e]=arguments[e];var t=r.filter(Hn);return t.length>0?t:null}function Hn(r){return r!=null}function ur(r,e){var t,n,i,s,o,l;return e===void 0&&(e=[]),I(this,function(a){switch(a.label){case 0:if(!(r.length>0))return[3,9];a.label=1;case 1:a.trys.push([1,6,7,8]),t=U(r[0]),n=t.next(),a.label=2;case 2:return n.done?[3,5]:(i=n.value,[5,U(ur(r.slice(1,r.length),e.concat(i)))]);case 3:a.sent(),a.label=4;case 4:return n=t.next(),[3,2];case 5:return[3,8];case 6:return s=a.sent(),o={error:s},[3,8];case 7:try{n&&!n.done&&(l=t.return)&&l.call(t)}finally{if(o)throw o.error}return[7];case 8:return[3,11];case 9:return[4,e];case 10:a.sent(),a.label=11;case 11:return[2]}})}function cr(r){return X([],K(r),!1).sort(function(e,t){return xt(e)-xt(t)})}function dr(r,e,t){var n,i,s;return t===void 0&&(t={counter:0,visited:new Map}),I(this,function(o){switch(o.label){case 0:if(!(r.length>2&&r.length>ie.optimizedMinLength))return[3,5];n=1,o.label=1;case 1:return n<r.length-1?t.counter>ie.maxNumberOfTries?[2]:(t.counter+=1,i=X([],K(r),!1),i.splice(n,1),s=De(i),t.visited.has(s)?[2]:lr(i)&&Xn(i,e)?[4,i]:[3,4]):[3,5];case 2:return o.sent(),t.visited.set(s,!0),[5,U(dr(i,e,t))];case 3:o.sent(),o.label=4;case 4:return n++,[3,1];case 5:return[2]}})}function Xn(r,e){return ct.querySelector(De(r))===e}var Yn=36e5,Qn=function(r){var e=r.version,t=r.events,n=[];return t.forEach(function(i){var s=JSON.parse(i);s.count=1,s.type==="click"&&n.push(s)}),{version:e,events:n}},$n=function(r){var e=r.version,t=r.events,n=[];t.forEach(function(s){var o=JSON.parse(s);o.type==="click"&&n.push(o)});var i=n.reduce(function(s,o){var l=o.x,a=o.y,u=o.selector,d=o.timestamp,v=d-d%Yn,c="".concat(l,":").concat(a,":").concat(u??"",":").concat(v);return s[c]?s[c].count+=1:s[c]=E(E({},o),{timestamp:v,count:1}),s},{});return{version:e,events:Object.values(i)}},Jn=(function(){function r(e,t){var n=this;this.createHook=function(i){var s=i.eventsManager,o=i.sessionId,l=i.deviceIdFn,a=i.mirror,u=i.ugcFilterRules,d=i.performanceOptions;return function(v){if(v.type===rr.Click){var c=G();if(c){var f=c.location,h=c.innerHeight,p=c.innerWidth;if(f){var m=v.x,g=v.y;if(!(m===void 0||g===void 0)){var y=a.getNode(v.id),b;if(y)try{b=Bn(y,d)}catch{n.logger.debug("error resolving selector from finder")}var S=xe(f.href,u),T={x:m+n.scrollWatcher.currentScrollX,y:g+n.scrollWatcher.currentScrollY,selector:b,viewportHe
2ight:h,viewportWidth:p,pageUrl:S,timestamp:Date.now(),type:"click"},L=l();L&&s.addEvent({sessionId:o,event:{type:"interaction",data:JSON.stringify(T)},deviceId:L})}}}}}},this.logger=e,this.scrollWatcher=t}return r})();function Ge(){var r=G();return r?.innerHeight||document.documentElement&&document.documentElement.clientHeight||0}function Ve(){var r=G();return r?.innerWidth||document.documentElement&&document.documentElement.clientWidth||0}var Zn=(function(){function r(e,t){var n=G();n&&n.navigator&&typeof n.navigator.sendBeacon=="function"?this.sendBeacon=function(i,s){try{if(n.navigator.sendBeacon(i,JSON.stringify(s)))return!0}catch{}return!1}:this.sendBeacon=function(){return!1},this.sendXhr=function(i,s){var o=new XMLHttpRequest;return o.open("POST",i,!0),o.setRequestHeader("Accept","*/*"),o.send(JSON.stringify(s)),!0},this.basePageUrl=Ee(t.serverZone,t.trackServerUrl),this.apiKey=t.apiKey,this.context=e,this.handleSendEvents=t.handleSendEvents,this.loggerProvider=t.loggerProvider}return r.prototype.send=function(e,t){var n=this,i,s=this.context,o=s.sessionId,l=s.type;if(this.handleSendEvents){var a=new URLSearchParams({device_id:e,session_id:String(o),type:String(l)}),u="".concat(this.basePageUrl,"?").concat(a.toString()),d={"Content-Type":"application/json",Accept:"*/*",Authorization:"Bearer ".concat(this.apiKey)};try{this.handleSendEvents({url:u,method:"POST",headers:d,body:JSON.stringify(t),keepalive:!0}).catch(function(f){var h;(h=n.loggerProvider)===null||h===void 0||h.warn("Custom transport failed to send session replay interaction beacon:",f)})}catch(f){(i=this.loggerProvider)===null||i===void 0||i.warn("Custom transport threw while sending session replay interaction beacon:",f)}return}var v=new URLSearchParams({device_id:e,session_id:String(o),type:String(l),api_key:this.apiKey}),c="".concat(this.basePageUrl,"?").concat(v.toString());this.sendBeacon(c,t)||this.sendXhr(c,t)},r})(),ei=(function(){function r(e,t){var n=this;this.timestamp=Date.now(),this.hook=function(i){n.update(i)},this.send=function(i){return function(s){var o,l,a,u,d=i(),v=G();if(v&&d){var c=(o=v.scrollX)!==null&&o!==void 0?o:0,f=(l=v.scrollY)!==null&&l!==void 0?l:0;(c>0||f>0)&&n.update({id:1,x:c,y:f}),n.transport.send(d,{version:1,events:[{maxScrollX:n._maxScrollX,maxScrollY:n._maxScrollY,maxScrollWidth:n._maxScrollWidth,maxScrollHeight:n._maxScrollHeight,viewportHeight:Ge(),viewportWidth:Ve(),pageUrl:xe(v.location.href,(u=(a=n.config.interactionConfig)===null||a===void 0?void 0:a.ugcFilterRules)!==null&&u!==void 0?u:[]),timestamp:n.timestamp,type:"scroll"}]})}}},this._maxScrollX=0,this._maxScrollY=0,this._currentScrollX=0,this._currentScrollY=0,this._maxScrollWidth=Ve(),this._maxScrollHeight=Ge(),this.config=t,this.transport=e}return r.default=function(e,t){return new r(new Zn(e,t),t)},Object.defineProperty(r.prototype,"maxScrollX",{get:function(){return this._maxScrollX},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"maxScrollY",{get:function(){return this._maxScrollY},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"maxScrollWidth",{get:function(){return this._maxScrollWidth},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"maxScrollHeight",{get:function(){return this._maxScrollHeight},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"currentScrollX",{get:function(){return this._currentScrollX},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"currentScrollY",{get:function(){return this._currentScrollY},enumerable:!1,configurable:!0}),r.prototype.update=function(e){var t=Date.now();if(this._currentScrollX=e.x,this._currentScrollY=e.y,e.x>this._maxScrollX){var n=Ve();this._maxScrollX=e.x;var i=e.x+n;i>this._maxScrollWidth&&(this._maxScrollWidth=i),this.timestamp=t}if(e.y>this._maxScrollY){var s=Ge();this._maxScrollY=e.y;var o=e.y+s;o>this._maxScrollHeight&&(this._maxScrollHeight=o),this.timestamp=t}},r})(),_t=(function(){function r(e){var t=e.sessionId,n=e.deviceId;this.deviceId=n,this.sessionId=t,t&&n&&(this.sessionReplayId=Hr(t,n))}return r})(),ti="AMP_SR_START_",ri=10,vr=1440*60*1e3,fr=function(r){return"".concat(ti).concat(r.substring(0,ri),"_")},dt=function(r,e){return"".concat(fr(r)).concat(e)},Ae=function(){try{var r=G();return r?.localStorage}catch{return}}
2,ni=function(r,e,t,n){var i=Ae();if(i){var s=dt(r,e);try{var o=i.getItem(s);if(o!==null){var l=Number(o);if(Number.isFinite(l)&&l>0&&l<=t&&t-l<vr)return l}return i.setItem(s,String(t)),t}catch(a){n?.debug("Failed to read/write replay start time from storage: ".concat(String(a)));return}}},ii=function(r,e,t,n){var i=Ae();if(i)try{i.setItem(dt(r,e),String(t))}catch(s){n?.debug("Failed to write replay start time to storage: ".concat(String(s)))}},si=function(r,e,t){var n=Ae();if(n)try{n.removeItem(dt(r,e))}catch(i){t?.debug("Failed to remove replay start time from storage: ".concat(String(i)))}},oi=function(r,e,t){var n,i,s=Ae();if(s){var o=fr(r);try{for(var l=[],a=0;a<s.length;a++){var u=s.key(a);if(!(!u||!u.startsWith(o))){var d=s.getItem(u);if(d!==null){var v=Number(d);(!Number.isFinite(v)||v<=0||e-v>=vr)&&l.push(u)}}}try{for(var c=U(l),f=c.next();!f.done;f=c.next()){var u=f.value;s.removeItem(u)}}catch(h){n={error:h}}finally{try{f&&!f.done&&(i=c.return)&&i.call(c)}finally{if(n)throw n.error}}}catch(h){t?.debug("Failed to prune stale replay start times: ".concat(String(h)))}}},ai=1e3*60*60*24*2,li=(function(){function r(){var e=this;this.dbs={},this.createStore=function(t){return C(e,void 0,void 0,function(){return I(this,function(n){switch(n.label){case 0:return[4,ir(t,1,{upgrade:function(i){i.objectStoreNames.contains("sessionTargetingMatch")||i.createObjectStore("sessionTargetingMatch",{keyPath:"sessionId"})}})];case 1:return[2,n.sent()]}})})},this.openOrCreateDB=function(t){return C(e,void 0,void 0,function(){var n,i;return I(this,function(s){switch(s.label){case 0:return this.dbs&&this.dbs[t]?[2,this.dbs[t]]:(n="".concat(t.substring(0,10),"_amp_session_replay_targeting"),[4,this.createStore(n)]);case 1:return i=s.sent(),this.dbs[t]=i,[2,i]}})})},this.getTargetingMatchForSession=function(t){var n=t.loggerProvider,i=t.apiKey,s=t.sessionId;return C(e,void 0,void 0,function(){var o,l,a,u;return I(this,function(d){switch(d.label){case 0:return d.trys.push([0,3,,4]),[4,this.openOrCreateDB(i)];case 1:return o=d.sent(),l=String(s),[4,o.get("sessionTargetingMatch",l)];case 2:return a=d.sent(),[2,a?.targetingMatch];case 3:return u=d.sent(),ee(n,"Failed to get targeting match for session id ".concat(s,": ").concat(u),u),[3,4];case 4:return[2,void 0]}})})},this.storeTargetingMatchForSession=function(t){var n=t.loggerProvider,i=t.apiKey,s=t.sessionId,o=t.targetingMatch;return C(e,void 0,void 0,function(){var l,a,u,d;return I(this,function(v){switch(v.label){case 0:return v.trys.push([0,3,,4]),[4,this.openOrCreateDB(i)];case 1:return l=v.sent(),a=String(s),[4,l.put("sessionTargetingMatch",{targetingMatch:o,sessionId:a,lastUpdated:Date.now()})];case 2:return u=v.sent(),[2,u];case 3:return d=v.sent(),ee(n,"Failed to store targeting match for session id ".concat(s,": ").concat(d),d),[3,4];case 4:return[2,void 0]}})})},this.clearStoreOfOldSessions=function(t){var n=t.loggerProvider,i=t.apiKey,s=t.currentSessionId;return C(e,void 0,void 0,function(){var o,l,a,u,d,v,c,f;return I(this,function(h){switch(h.label){case 0:return h.trys.push([0,8,,9]),[4,this.openOrCreateDB(i)];case 1:return o=h.sent(),l=String(s),a=o.transaction("sessionTargetingMatch","readwrite"),[4,a.store.getAll()];case 2:u=h.sent(),d=0,h.label=3;case 3:return d<u.length?(v=u[d],c=Date.now()-v.lastUpdated,v.sessionId!==l&&c>ai?[4,a.store.delete(v.sessionId)]:[3,5]):[3,6];case 4:h.sent(),h.label=5;case 5:return d++,[3,3];case 6:return[4,a.done];case 7:return h.sent(),[3,9];case 8:return f=h.sent(),ee(n,"Failed to clear old targeting matches for sessions: ".concat(f),f),[3,9];case 9:return[2]}})})}}return r})(),He=new li,ui=function(r){var e=r.sessionId,t=r.targetingConfig,n=r.loggerProvider,i=r.apiKey,s=r.targetingParams,o=r.urlChange,l=o===void 0?!1:o;return C(void 0,void 0,void 0,function(){var a,u,d,v,c,f,h;return I(this,function(p){switch(p.label){case 0:return[4,He.clearStoreOfOldSessions({loggerProvider:n,apiKey:i,currentSessionId:e})];case 1:return p.sent(),[4,He.getTargetingMatchForSession({loggerProvider:n,apiKey:i,sessionId:e})];case 2:if(a=p.sent(),a===!0&&!l)return[2,!0];u=!0,p.label=3;case 3:return p.trys.push([3,6,,7]),[4,be(()=>import("./index-Dft-NVkw.js"),__vite__mapDeps([0,1,2,3]))];case 4:return d=p.sent().evaluateTargeting,v=E(E({},s),{flag:t,sessionId:typeof e=="string"?parseInt(e,10):e,apiKey:i,loggerProvider:n}),[4,d(v)];case 5:return c=p.sent(),c&&c.sr_targeting_config&&(u=c.sr_targeting_config.key==="on"),He.storeTargetingMatchForSession({loggerProvider:n,apiKey:i,sessionId:e,targetingMatch:u}),[3,7];case 6:return f=p.sent(),h=f,n.warn(h.message),[3,7];case 7:return[2,u]}})})},Re=2654435761,Me=2246822519,Dt=3266489917,ci=668265263,At=374761393;function he(r,e){return(r<<e|r>>>32-e)>>>0}function Te(r,e){return r=r+Math.imul(e,Me)>>>0,r=he(r,13),r=Math.imul(r,Re)>>>0,r}function Se(r,e){return(r[e]|r[e+1]<<8|r[e+2]<<16|r[e+3]<<24)>>>0}function di(r){for(var e=[],t=0;t<r.length;t++){var n=r.charCodeAt(t);if(n>=55296&&n<=56319&&t+1<r.length){var i=r.charCodeAt(t+1);i>=56320&&i<=57343&&(n=(n-55296<<10)+(i-56320)+65536,t++)}n<128?e.push(n):n<2048?e.push(192|n>>6,128|n&63):n<65536?e.push(224|n>>12,128|n>>6&63,128|n&63):e.push(240|n>>18,128|n>>12&63,128|n>>6&63,128|n&63)}return new Uint8Array(e)}function vi(r,e){e===void 0&&(e=0);var t=di(r),n=t.length,i,s=0;if(n>=16){for(var o=e+Re+Me>>>0,l=e+Me>>>0,a=e>>>0,u=e-Re>>>0;s<=n-16;)o=Te(o,Se(t,s)),s+=4,l=Te(l,Se(t,s)),s+=4,a=Te(a,Se(t,s)),s+=4,u=Te(u,Se(t,s)),s+=4;i=he(o,1)+he(l,7)+he(a,12)+he(u,18)>>>0}else i=e+At>>>0;for(i=i+n>>>0;s<=n-4;)i=i+Math.imul(Se(t,s),Dt)>>>0,i=Math.imul(he(i,17),ci)>>>0,s+=4;for(;s<n;)i=i+Math.imul(t[s],At)>>>0,i=Math.imul(he(i,11),Re)>>>0,s++;return i^=i>>>15,i=Math.imul(i,Me)>>>0,i^=i>>>13,i=Math.imul(i,Dt)>>>0,i^=i>>>16,i>>>0}
2function fi(r,e){var t=vi(r.toString()),n=t%1e6;return n/1e6<e}var Xe="__amplitude_url_tracking_patched__",Ft=new WeakMap;function hr(r,e,t){if(t===void 0&&(t={}),!r?.location)return function(){};var n=t.enablePolling,i=n===void 0?!1:n,s=t.pollingInterval,o=s===void 0?at:s;if(i){var l=function(){var S;return(S=r.location.href)!==null&&S!==void 0?S:""},a=l(),u=r.setInterval(function(){var S=l();S!==a&&(a=S,e(S))},o);return function(){u!=null&&r.clearInterval(u)}}var d=Ft.get(r);if(!d){var v=void 0,c=new Set,f=function(){var S;return(S=r.location.href)!==null&&S!==void 0?S:""},h=function(){var S=f();v!==void 0&&S===v||(v=S,c.forEach(function(T){return T(S)}))},p=function(S){var T=function(){for(var L=[],O=0;O<arguments.length;O++)L[O]=arguments[O];var W=S.apply(this,L);return h(),W};return T[Xe]=!0,T},m=r.history;if(m?.pushState){var g=Reflect.get(m,"pushState");g[Xe]||(m.pushState=p(g))}if(m?.replaceState){var y=Reflect.get(m,"replaceState");y[Xe]||(m.replaceState=p(y))}d={callbacks:c,notify:h,onPopStateOrHashChange:function(){return h()},listenersAttached:!1},Ft.set(r,d)}var b=d;return b.listenersAttached||(r.addEventListener("popstate",b.onPopStateOrHashChange),r.addEventListener("hashchange",b.onPopStateOrHashChange),b.listenersAttached=!0),b.callbacks.add(e),function(){b.callbacks.delete(e),b.callbacks.size===0&&b.listenersAttached&&(r.removeEventListener("popstate",b.onPopStateOrHashChange),r.removeEventListener("hashchange",b.onPopStateOrHashChange),b.listenersAttached=!1)}}function gr(r){return r===void 0&&(r={}),{name:"amplitude/url-tracking@1",observer:function(e,t,n){var i,s,o,l=E(E({},r),n),a=l.ugcFilterRules||[],u=(i=l.enablePolling)!==null&&i!==void 0?i:!1,d=(s=l.pollingInterval)!==null&&s!==void 0?s:at,v=(o=l.captureDocumentTitle)!==null&&o!==void 0?o:!1;if(!t)return function(){};var c=void 0,f=function(){return t.location&&t.location.href||""},h=function(){var g=t.innerHeight,y=t.innerWidth,b=t.document,S=f(),T="";v&&(T=b?.title||"");var L=a.length>0?xe(S,a):S;return{href:L,title:T,viewportHeight:g,viewportWidth:y,type:"url-change-event"}},p=function(){var g=f();if(c===void 0||g!==c){c=g;var y=h();e(y)}},m=hr(t,function(){return p()},u?{enablePolling:!0,pollingInterval:d}:{});return p(),function(){return m()}},options:r}}gr();function hi(){try{var r=G();return r?r.parent!==r:!1}catch{return!0}}var gi=(function(){function r(){this.pendingLoadListeners=new Map}return r.prototype.start=function(){var e=this,t;(t=this.mutationObserver)===null||t===void 0||t.disconnect();var n=G();n&&(this.sendToAllIframes({type:we,action:"start"}),this.mutationObserver=new MutationObserver(function(i){var s,o,l,a,u,d;try{for(var v=U(i),c=v.next();!c.done;c=v.next()){var f=c.value;try{for(var h=(l=void 0,U(Array.from(f.addedNodes))),p=h.next();!p.done;p=h.next()){var m=p.value;m instanceof HTMLIFrameElement?e.sendToIframeAfterLoad(m):m instanceof Element&&m.querySelectorAll("iframe").forEach(function(S){e.sendToIframeAfterLoad(S)})}}catch(S){l={error:S}}finally{try{p&&!p.done&&(a=h.return)&&a.call(h)}finally{if(l)throw l.error}}try{for(var g=(u=void 0,U(Array.from(f.removedNodes))),y=g.next();!y.done;y=g.next()){var m=y.value;if(m instanceof HTMLIFrameElement){var b=e.pendingLoadListeners.get(m);b&&(m.removeEventListener("load",b),e.pendingLoadListeners.delete(m))}}}catch(S){u={error:S}}finally{try{y&&!y.done&&(d=g.return)&&d.call(g)}finally{if(u)throw u.error}}}}catch(S){s={error:S}}finally{try{c&&!c.done&&(o=v.return)&&o.call(v)}finally{if(s)throw s.error}}}),this.mutationObserver.observe(document.documentElement,{childList:!0,subtree:!0}))},r.prototype.stop=function(){var e;(e=this.mutationObserver)===null||e===void 0||e.disconnect(),this.mutationObserver=void 0,this.pendingLoadListeners.forEach(function(t,n){n.removeEventListener("load",t)}),this.pendingLoadListeners.clear(),this.sendToAllIframes({type:we,action:"stop"})},r.prototype.sendToIframeAfterLoad=function(e){var t=this,n=function(){t.pendingLoadListeners.delete(e),t.sendToIframe(e,{type:we,action:"start"})};this.pendingLoadListeners.set(e,n),e.addEventListener("load",n,{once:!0})},r.prototype.sendToAllIframes=function(e){var t=this,n=document.querySelectorAll("iframe");
2n.forEach(function(i){return t.sendToIframe(i,e)})},r.prototype.sendToIframe=function(e,t){var n;try{(n=e.contentWindow)===null||n===void 0||n.postMessage(t,"*")}catch{}},r})();function pi(r){var e=G();if(!e)return function(){};var t=e.parent;function n(i){if(i.source===t){var s=i.data;s?.type===we&&(s.action==="start"?r.onStart():s.action==="stop"&&r.onStop())}}return e.addEventListener("message",n),function(){return e.removeEventListener("message",n)}}var mi=(function(){function r(){var e=this;this.name="@amplitude/session-replay-browser",this.recordCancelCallback=null,this.eventCount=0,this.sessionTargetingMatch=!1,this.pageLeaveFns=[],this.suppressedSendCount=0,this.hasEmittedGateDecision=!1,this.recordFunction=null,this.recordEventsInFlight=!1,this.recordingEnabled=!0,this.recordingGeneration=0,this.startChildRecordingOnSetup=!1,this.pendingEmitEvents=[],this.currentPageUrl="",this.recordEventsPendingShouldLogMetadata=null,this.urlChangeCleanup=null,this.crossOriginIframeCoordinator=null,this.crossOriginParentSignalCleanup=null,this.latestUrlChangeTargetingEvaluationId=0,this.teardownEventListeners=function(t){var n=G();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(){var t;if(e.recordingEnabled)if(e.recordCancelCallback&&e.recordFunction){if(((t=e.config)===null||t===void 0?void 0:t.captureFullSnapshotOnFocus)===!1)return;try{e.recordFunction.takeFullSnapshot(!0)}catch(n){e.loggerProvider.warn("Failed to take full snapshot on focus:",n)}}else e.recordEventsInFlight||e.recordEvents(!1)},this.pageLeaveListener=function(t){var n;(n=e.eventCompressor)===null||n===void 0||n.flushQueue(),e.sendEvents(),e.pageLeaveFns.forEach(function(i){i(t)})},this.evaluateTargetingAndCapture=function(t,n,i,s){return n===void 0&&(n=!1),i===void 0&&(i=!1),s===void 0&&(s=!1),C(e,void 0,void 0,function(){var o,l,a,u,d,v,c,f,h,p,m,g,y;return I(this,function(b){switch(b.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)this.loggerProvider.log("Targeting config has not been set yet, cannot evaluate targeting.");else return this.loggerProvider.log("No targeting config set, skipping initialization/recording for event."),[2];return this.lastTargetingParams=t,o=this.config.targetingConfig,l=o&&!this.sessionTargetingMatch,l?(a=s?this.latestUrlChangeTargetingEvaluationId:void 0,u=t.event,u&&Object.values(Qe).includes(u.event_type)&&(u=void 0),d=(g=(h=(f=t.page)===null||f===void 0?void 0:f.url)!==null&&h!==void 0?h:(m=(p=G())===null||p===void 0?void 0:p.location)===null||m===void 0?void 0:m.href)!==null&&g!==void 0?g:"",v=(y=t.page)!==null&&y!==void 0?y:d!==""?{url:d}:void 0,[4,ui({sessionId:this.identifiers.sessionId,targetingConfig:o,loggerProvider:this.loggerProvider,apiKey:this.config.apiKey,targetingParams:{userProperties:t.userProperties,event:u,page:v},urlChange:s})]):[3,2];case 1:if(c=b.sent(),s&&a!==void 0&&a!==this.latestUrlChangeTargetingEvaluationId)return this.loggerProvider.debug("Ignoring stale URL-change targeting result #".concat(a,"; latest is #").concat(this.latestUrlChangeTargetingEvaluationId,".")),[2];this.sessionTargetingMatch=this.sessionTargetingMatch||c,this.loggerProvider.debug(JSON.stringify({name:"targeted replay capture config",sessionTargetingMatch:this.sessionTargetingMatch,event:u,targetingParams:t},null,2)),b.label=2;case 2:return n?(this.initialize(!0),[3,5]):[3,3];case 3:return i||!this.recordCancelCallback?(this.loggerProvider.log("Recording events for session due to forceRestart or no ongoing recording."),[4,this.recordEvents()]):[3,5];case 4:b.sent(),b.label=5;case 5:return[2]}})})},this.addCustomRRWebEvent=function(t,n,i){return n===void 0&&(n={}),i===void 0&&(i=!0),C(e,void 0,void 0,function(){var s,o,l,a;return I(this,function(u){switch(u.label){case 0:return u.trys.push([0,3,,4]),s=void 0,o=this.config,o&&t!==ae.METADATA?(s={config:er(o),version:ke},i?[4,Zt()]:[3,2]):[3,2];case 1:l=u.sent(),s=E(E({},l),s),u.label=2;case 2:return this.recordCancelCallback&&this.recordFunction?this.recordFunction.addCustomEvent(t,E(E({},n),s)):this.loggerProvider.debug("Not able to add custom replay capture event ".concat(t," due to no ongoing recording.")),[3,4];case 3:return a=u.sent(),this.loggerProvider.debug("Error while adding custom replay capture event: ",a),[3,4];case 4:return[2]}})})},this.stopRecordingEvents=function(){var t,n,i;try{e.loggerProvider.log("Session Replay capture stopping."),e.recordCancelCallback&&e.recordCancelCallback(),e.recordCancelCallback=null,(t=e.networkObservers)===null||t===void 0||t.stop(),(n=e.crossOriginIframeC
2oordinator)===null||n===void 0||n.stop(),e.crossOriginIframeCoordinator=null,(i=e.crossOriginParentSignalCleanup)===null||i===void 0||i.call(e),e.crossOriginParentSignalCleanup=null}catch(o){var s=o;e.loggerProvider.warn("Error occurred while stopping replay capture: ".concat(s.toString()))}},this.loggerProvider=new et(new Ye)}return r.prototype.init=function(e,t){return Ne(this._init(e,t))},r.prototype.setupUrlChangeListener=function(){var e=this,t,n;(t=this.urlChangeCleanup)===null||t===void 0||t.call(this);var i=G();if(i?.location){var s=!!(!((n=this.config)===null||n===void 0)&&n.targetingConfig),o=function(a){if(e.currentPageUrl=a,s){var u=++e.latestUrlChangeTargetingEvaluationId;e.evaluateTargetingAndCapture({userProperties:{},event:void 0,page:{url:a}},!1,!1,!0),e.loggerProvider.debug("Queued URL-change targeting re-evaluation #".concat(u," for ").concat(a,"."))}},l=hr(i,o);this.urlChangeCleanup=function(){l(),e.urlChangeCleanup=null}}},r.prototype.isBelowMinSessionDuration=function(){var e,t=(e=this.config)===null||e===void 0?void 0:e.minSessionDurationMs;return t===void 0||this.sessionStartTime===void 0?!1:Date.now()-this.sessionStartTime<t},r.prototype.getCurrentPageForTargeting=function(){var e,t,n=(t=(e=G())===null||e===void 0?void 0:e.location)===null||t===void 0?void 0:t.href;return n!=null?{url:n}:void 0},r.prototype._init=function(e,t){var n,i,s,o,l,a,u,d,v,c,f,h,p,m;return C(this,void 0,void 0,function(){var g,y,b,S,T,L,O,W,q,z,x,A,F,N,M,w,R,P,B,k,_,P,V,D,H,j,Y,Q,J,Z,ce,de,ve,te=this;return I(this,function($){switch($.label){case 0:return(n=this.urlChangeCleanup)===null||n===void 0||n.call(this),this.recordingEnabled=!0,this.startChildRecordingOnSetup=!1,this.loggerProvider=new et(t.loggerProvider||new Ye),Object.prototype.hasOwnProperty.call(t,"logLevel")&&this.loggerProvider.enable(t.logLevel),this.currentPageUrl=tt(),this.identifiers=new _t({sessionId:t.sessionId,deviceId:t.deviceId}),g=Date.now(),oi(e,g,this.loggerProvider),this.sessionStartTime=t.sessionId!==void 0&&(i=ni(e,t.sessionId,g,this.loggerProvider))!==null&&i!==void 0?i:g,y=this,[4,nn(e,t)];case 1:return y.joinedConfigGenerator=$.sent(),[4,this.joinedConfigGenerator.generateJoinedConfig()];case 2:return b=$.sent(),S=b.joinedConfig,T=b.localConfig,L=b.remoteConfig,this.config=S,this.setMetadata(t.sessionId,S,T,L,(s=t.version)===null||s===void 0?void 0:s.version,ke,(o=t.version)===null||o===void 0?void 0:o.type),this.pageLeaveFns=[],t.sessionId&&(!((l=this.config.interactionConfig)===null||l===void 0)&&l.enabled)&&(O=ei.default({sessionId:t.sessionId,type:"interaction"},this.config),this.pageLeaveFns=[O.send(this.getDeviceId.bind(this)).bind(O)],this.scrollHook=O.hook.bind(O),this.clickHandler=new Jn(this.loggerProvider,O)),W=[],q=this.config.storeType,q==="idb"&&!(!((a=G())===null||a===void 0)&&a.indexedDB)&&(q="memory",this.loggerProvider.warn("Could not use preferred indexedDB storage, reverting to in memory option.")),this.loggerProvider.log("Using ".concat(q," for event storage.")),A=G(),this.config.useWebWorker&&A&&A.Worker?[4,be(()=>import("./index-BUd4hCY-.js"),[])]:[3,4];case 3:F=$.sent(),N=F.compressionScript,M=F.trackDestinationScript,z=N,x=M,$.label=4;case 4:return $.trys.push([4,6,,7]),[4,Mt({config:this.config,type:"replay",minInterval:(u=this.config.flushIntervalConfig)===null||u===void 0?void 0:u.minIntervalMs,maxInterval:(d=this.config.flushIntervalConfig)===null||d===void 0?void 0:d.maxIntervalMs,maxPersistedEventsSize:this.config.maxPersistedEventsSizeBytes,storeType:q,trackDestinationWorkerScript:x,shouldSend:function(){return!te.isBelowMinSessionDuration()}})];case 5:return w=$.sent(),this.rrwebEventManager=w,W.push({name:"replay",manager:w}),[3,7];case 6:return R=$.sent(),P=R,this.loggerProvider.warn("Error occurred while creating replay events manager: ".concat(P.toString())),[3,7];case 7:if(!(!((v=this.config.interactionConfig)===null||v===void 0)&&v.enabled))return[3,11];B=this.config.interactionConfig.batch?$n:Qn,$.label=8;case 8:return $.trys.push([8,10,,11]),[4,Mt({config:this.config,type:"interaction",minInterval:(c=this.config.interactionConfig.trackEveryNms)!==null&&c!==void 0?c:_r,maxInterval:Dr,maxPersistedEventsSize:this.config.maxPersistedEventsSizeBytes,payloadBatcher:B,storeType:q,trackDestinationWorkerScript:x})];
2case 9:return k=$.sent(),W.push({name:"interaction",manager:k}),[3,11];case 10:return _=$.sent(),P=_,this.loggerProvider.warn("Error occurred while creating interaction events manager: ".concat(P.toString())),[3,11];case 11:if(this.eventsManager=new(kt.bind.apply(kt,X([void 0],K(W),!1))),this.eventCompressor&&this.eventCompressor.terminate(),V=this.config.eagerFullSnapshotSend===!0?function(){return te.sendEvents()}:void 0,this.eventCompressor=new dn(this.eventsManager,this.config,this.getDeviceId(),z,V),this.pendingEmitEvents.length>0){D=this.pendingEmitEvents.splice(0);try{for(H=U(D),j=H.next();!j.done;j=H.next())Y=j.value,Q=Y.event,J=Y.sessionId,this.eventCompressor.enqueueEvent(Q,J)}catch(me){de={error:me}}finally{try{j&&!j.done&&(ve=H.return)&&ve.call(H)}finally{if(de)throw de.error}}}return this.pageLeaveFns=X(X([],K(this.pageLeaveFns),!1),[function(){var me;if(!(!te.config||!(!((me=te.identifiers)===null||me===void 0)&&me.sessionId)||!w)){var vt=w.getBeaconEvents();if(vt.length){var ft=te.getDeviceId();ft&&(te.isBelowMinSessionDuration()||w.trackDestination.sendBeacon({events:vt,sessionId:te.identifiers.sessionId,deviceId:ft,apiKey:te.config.apiKey,serverZone:te.config.serverZone}))}}}],!1),[4,this.initializeNetworkObservers()];case 12:return $.sent(),!((f=G())===null||f===void 0)&&f.opener&&(Z=br(),Er(Z),Z.setup(E({logger:this.loggerProvider},this.config.serverZone&&{endpoint:Ir[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 13:return $.sent(),ce=this.config.targetingConfig||((m=(p=(h=this.config.privacyConfig)===null||h===void 0?void 0:h.urlMaskLevels)===null||p===void 0?void 0:p.length)!==null&&m!==void 0?m:0)>0,ce&&this.setupUrlChangeListener(),[2]}})})},r.prototype.setSessionId=function(e,t){return Ne(this.asyncSetSessionId(e,t))},r.prototype.asyncSetSessionId=function(e,t,n){var i,s,o,l;return C(this,void 0,void 0,function(){var a,u,d,v,c;return I(this,function(f){switch(f.label){case 0:return a=(i=this.identifiers)===null||i===void 0?void 0:i.sessionId,u=this.getDeviceId(),a!==void 0&&a===e&&(t===void 0||t===u)&&(n?.userProperties===void 0||Object.keys(n.userProperties).length===0)?[2]:(this.latestUrlChangeTargetingEvaluationId++,this.sessionTargetingMatch=!1,this.lastShouldRecordDecision=void 0,a&&this.sendEvents(a),d=a!==e,d&&((s=this.rrwebEventManager)===null||s===void 0||s.dropPendingBeaconEvents()),v=t||this.getDeviceId(),this.identifiers=new _t({sessionId:e,deviceId:v}),d&&(this.sessionStartTime=Date.now(),this.suppressedSendCount=0,this.hasEmittedGateDecision=!1,!((o=this.config)===null||o===void 0)&&o.apiKey&&(ii(this.config.apiKey,e,this.sessionStartTime,this.loggerProvider),a!==void 0&&si(this.config.apiKey,a,this.loggerProvider))),this.joinedConfigGenerator&&a?[4,this.joinedConfigGenerator.generateJoinedConfig()]:[3,2]);case 1:c=f.sent().joinedConfig,this.config=c,f.label=2;case 2:return!((l=this.config)===null||l===void 0)&&l.targetingConfig?[4,this.evaluateTargetingAndCapture({userProperties:n?.userProperties,page:this.getCurrentPageForTargeting()},!1,!0)]:[3,4];case 3:return f.sent(),[3,6];case 4:return[4,this.recordEvents()];case 5:f.sent(),f.label=6;case 6:return[2]}})})},r.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 i=this.getShouldRecord(),s={};return i&&(s=(e={},e[Pr]=n.sessionReplayId?n.sessionReplayId:null,e),t.debugMode&&(s[Mr]=JSON.stringify({appHash:ht(t.apiKey).toString()}))),this.addCustomRRWebEvent(ae.GET_SR_PROPS,{shouldRecord:i,eventProperties:s},this.eventCount===10),this.eventCount===10&&(this.eventCount=0),this.eventCount++,s},r.prototype.sendEvents=function(e){var t,n,i=e||((t=this.identifiers)===null||t===void 0?void 0:t.sessionId),s=this.getDeviceId();if(this.eventsManager&&i&&s){if(this.isBelowMinSessionDuration()){var o=this.sessionStartTime,l=this.config.minSessionDurationMs;this.loggerProvider.log("Session ".concat(i," not sent: duration ").concat(Date.now()-o,"ms is below minimum ").concat(l,"ms.")),this.suppressedSendCount++;return}if(!this.hasEmittedGateDecision&&((n=this.config)===null||n===void 0?void 0:n.minSessionDurationMs)!==void 0&&this.recordCancelCallback&&this.recordFunction){this.hasEmittedGateDecision=!0;var a=this.sessionStartTime!==void 0?Date.now()-this.sessionStartTime:void 0;this.addCustomRRWebEvent(ae.REPLAY_GATE_DECISION,{sessionId:i,suppressedSendCount:this.suppressedSendCount,elapsedMs:a,minSessionDurationMs:this.config.minSessionDurationMs},!1)}this.eventsManager.sendCurrentSequenceEvents({sessionId:i,deviceId:s})}},r.prototype.initialize=function(e){var t;return e===void 0&&(e=!1),C(this,void 0,void 0,function(){var n;return I(this,function(i){return!((t=this.identifiers)===null||t===void 0)&&t.sessionId?(n=this.getDeviceId(),n?(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()])})})},r.prototype.shouldOptOut=function(){var e,t,n;if(!((e=this.config)===null||e===void 0)&&e.instanceName){var i=zt(this.config.instanceName).identityStore;n=i.getIdentity().optOut}return n!==void 0?n:(t=this.config)===null||t===void 0?void 0:t.optOut},r.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.recordingEnabled)return this.loggerProvider.log("Session ".concat(this.identifiers.sessionId," not being captured because recording was stopped.")),!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=!1,t="",n=!1;if(this.config.targetingConfig)this.sessionTargetingMatch?(t="Capturing replays for session ".concat(this.identifiers.sessionId," due to matching targeting conditions."),this.loggerProvider.log(t),e=!0,n=!0):(t="Not capturing replays for session ".concat(this.identifiers.sessionId," due to not matching targeting conditions."),this.loggerProvider.log(t),e=!1,n=!1);else{var i=fi(this.identifiers.sessionId,this.config.sampleRate);i?(e=!0,n=!0):(t="Opting session ".concat(this.identifiers.sessionId," out of recording due to sample rate."),this.loggerProvider.log(t),e=!1,n=!1)}return this.lastShouldRecordDecision!==e&&this.config.targetingConfig&&(this.addCustomRRWebEvent(ae.TARGETING_DECISION,{message:t,sessionId:this.identifiers.sessionId,matched:n,targetingParams:this.lastTargetingParams}),this.lastShouldRecordDecision=e),e},r.prototype.getBlockSelectors=function(){var e,t,n,i=(n=(t=(e=this.config)===null||e===void 0?void 0:e.privacyConfig)===null||t===void 0?void 0:t.blockSelector)!==null&&n!==void 0?n:[];if(i.length!==0)return i},r.prototype.getMaskTextSelectors=function(){var e,t,n=(e=this.config)===null||e===void 0?void 0:e.privacyConfig,i=n?Qt(this.currentPageUrl,n):void 0;if(i==="conservative"||!((t=n?.urlMaskLevels)===null||t===void 0)&&t.some(function(l){return l.maskLevel==="conservative"}))return"*";var s=n?.urlMaskLevels;if(n?.defaultMaskLevel==="conservative"&&s&&s.length>0)return"*";var o=n?.maskSelector;if(o)return o},r.prototype.getRecordingPlugins=function(e){var t,n,i,s,o,l;return C(this,void 0,void 0,function(){var a,u,d,v;return I(this,function(c){switch(c.label){case 0:a=[];try{u=gr({ugcFilterRules:((n=(t=this.config)===null||t===void 0?void 0:t.interactionConfig)===null||n===void 0?void 0:n.ugcFilterRules)||[],enablePolling:((i=this.config)===null||i===void 0?void 0:i.enableUrlChangePolling)||!1,pollingInterval:(s=this.config)===null||s===void 0?void 0:s.urlChangePollingInterval,captureDocumentTitle:(o=this.config)===null||o===void 0?void 0:o.captureDocumentTitle}),a.push(u)}catch(f){this.loggerProvider.warn("Failed to create URL tracking plugin:",f)}if(!(!((l=e?.console)===null||l===void 0)&&l.enabled))return[3,4];c.label=1;case 1:return c.trys.push([1,3,,4]),[4,be(()=>import("./rrweb-plugin-console-record-sPdhR0i8.js"),[])];case 2:return d=c.sent().getRecordConsolePlugin,a.push(d({level:e.console.levels})),[3,4];case 3:return v=c.sent(),this.loggerProvider.warn("Failed to load console plugin:",v),[3,4];case 4:return[2,a.length>0?a:void 0]}})})},r.prototype.getRecordFunction=function(){return C(this,void 0,void 0,function(){var e,t;return I(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,be(()=>import("./rrweb-record-FZj7_RZS.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]}})})},r.prototype.recordEvents=function(e){return e===void 0&&(e=!0),C(this,void 0,void 0,function(){var t;return I(this,function(n){switch(n.label){case 0:if(this.recordEventsInFlight)return this.recordEventsPendingShouldLogMetadata=e,[2];this.recordEventsInFlight=!0,n.label=1;case 1:return n.trys.push([1,,6,7]),[4,this._recordEvents(e)];case 2:n.sent(),n.label=3;case 3:return this.recordEventsPendingShouldLogMetadata===null?[3,5]:(t=this.recordEventsPendingShouldLogMetadata,this.recordEventsPendingShouldLogMetadata=null,[4,this._recordEvents(t)]);case 4:return n.sent(),[3,3];case 5:return[3,7];case 6:return this.recordEventsInFlight=!1,this.recordEventsPendingShouldLogMetadata=null,[7];case 7:return[2]}})})},r.prototype.shouldAbandonRecordStart=function(e){return!this.recordingEnabled||e!==this.recordingGeneration},r.prototype._recordEvents=function(e){var t,n,i,s,o,l,a,u;return e===void 0&&(e=!0),C(this,void 0,void 0,function(){var d,v,c,f,h,p,m,g,y,b,S,T,L,O,W,q,z,x=this;return I(this,function(A){switch(A.label){case 0:return d=this.config,v=this.getShouldRecord(),c=(t=this.identifiers)===null||t===void 0?void 0:t.sessionId,!v||!c||!d?[2]:(this.stopRecordingEvents(),f=this.recordingGeneration,[4,this.getRecordFunction()]);case 1:return h=A.sent(),!h||this.shouldAbandonRecordStart(f)?[2]:[4,this.initializeNetworkObservers()];case 2:if(A.sent(),this.shouldAbandonRecordStart(f))return[2];p=(n=d.loggingConfig)===null||n===void 0?void 0:n.network,m=Ee(d.serverZone,d.trackServerUrl),g=[Gt,Vt,Ht,m],(i=this.networkObservers)===null||i===void 0||i.start(function(F){g.some(function(N){return F.url.startsWith(N)})||x.addCustomRRWebEvent(ae.FETCH_REQUEST,F)},p),y=d.interactionConfig,b=d.loggingConfig,S=y?.enabled?{mouseInteraction:this.eventsManager&&((s=this.clickHandler)===null||s===void 0?void 0:s.createHook({eventsManager:this.eventsManager,sessionId:c,deviceIdFn:this.getDeviceId.bind(this),mirror:h.mirror,ugcFilterRules:(o=y.ugcFilterRules)!==null&&o!==void 0?o:[],performanceOptions:(l=d.performanceConfig)===null||l===void 0?void 0:l.interaction})),scroll:this.scrollHook}:{},T=y?.enabled&&y.ugcFilterRules?y.ugcFilterRules:[],this.loggerProvider.log("Session Replay capture beginning for ".concat(c,".")),A.label=3;case 3:return A.trys.push([3,5,,6]),L=!!(!((a=d.crossOriginIframes)===null||a===void 0)&&a.enabled),O=((u=d.crossOriginIframes)===null||u===void 0?void 0:u.coordinateChildren)!==!1,W=L&&hi(),W&&O?(this.crossOriginParentSignalCleanup=pi({onStart:function(){x.recordingEnabled&&x._recordEventsInChildMode(h,c,d,S)},onStop:function(){try{x.recordCancelCallback&&x.recordCancelCallback(),x.recordCancelCallback=null}catch(N){var F=N;x.loggerProvider.warn("Error occurred while stopping child iframe replay capture: ".concat(F.toString()))}}}),this.startChildRecordingOnSetup&&(this.startChildRecordingOnSetup=!1,this._recordEventsInChildMode(h,c,d,S)
2),[2]):(this.startChildRecordingOnSetup=!1,[4,this.getRecordingPlugins(b)]);case 4:return q=A.sent(),this.shouldAbandonRecordStart(f)?[2]:(this.recordCancelCallback=h(E(E({},this.buildRRWebRecordOptions(d,S,function(F){if(x.shouldOptOut()||!x.recordingEnabled){x.loggerProvider.log(x.shouldOptOut()?"Opting session ".concat(c," out of recording due to optOut config."):"Session Replay capture stopping for ".concat(c,".")),x.stopRecordingEvents(),x.sendEvents();return}F.type===Le.Meta&&(F.data.href=xe(F.data.href,T)),x.eventCompressor?x.eventCompressor.enqueueEvent(F,c):x.pendingEmitEvents.push({event:F,sessionId:c})},"Error while capturing replay: ")),{plugins:q,recordCrossOriginIframes:L})),L&&!W&&O&&(this.crossOriginIframeCoordinator||(this.crossOriginIframeCoordinator=new gi),this.crossOriginIframeCoordinator.start()),this.addCustomRRWebEvent(ae.DEBUG_INFO),e&&this.addCustomRRWebEvent(ae.METADATA,this.metadata),[3,6]);case 5:return z=A.sent(),this.loggerProvider.warn("Failed to initialize session replay:",z),[3,6];case 6:return[2]}})})},r.prototype.buildRRWebRecordOptions=function(e,t,n,i){var s=this,o=e.privacyConfig;return E(E({emit:n,inlineStylesheet:e.shouldInlineStylesheet,hooks:t,maskAllInputs:!0,maskTextClass:Kt,blockClass:kr,blockSelector:this.getBlockSelectors(),applyBackgroundColorToBlockedElements:e.applyBackgroundColorToBlockedElements,maskInputFn:mt("input",o,function(){return s.currentPageUrl}),maskTextFn:mt("text",o,function(){return s.currentPageUrl}),maskAttributeFn:Vr(o,function(){return s.currentPageUrl}),maskTextSelector:this.getMaskTextSelectors()},e.fullSnapshotIntervalMs!==void 0&&{checkoutEveryNms:e.fullSnapshotIntervalMs}),{recordCanvas:!1,captureAdoptedStyleSheets:e.captureAdoptedStyleSheets,slimDOMOptions:{script:!0,comment:!0,headFavicon:!0,headWhitespace:!0,headMetaDescKeywords:!0,headMetaSocial:!0,headMetaRobots:!0,headMetaHttpEquiv:!0,headMetaAuthorship:!0,headMetaVerification:!0},errorHandler:function(l){var a=l;if(a.message.includes("insertRule")&&a.message.includes("CSSStyleSheet")||a._external_)throw a;return s.loggerProvider.warn(i,a.toString()),!0}})},r.prototype._recordEventsInChildMode=function(e,t,n,i){try{this.recordCancelCallback&&this.recordCancelCallback(),this.recordCancelCallback=null,this.recordCancelCallback=e(E(E({},this.buildRRWebRecordOptions(n,i,function(){},"Error while capturing replay (child iframe): ")),{recordCrossOriginIframes:!0})),this.loggerProvider.log("Session Replay child iframe capture beginning for session ".concat(t,"."))}catch(s){this.loggerProvider.warn("Failed to initialize session replay in child iframe mode:",s)}},r.prototype.getDeviceId=function(){var e;return(e=this.identifiers)===null||e===void 0?void 0:e.deviceId},r.prototype.getSessionId=function(){var e;return(e=this.identifiers)===null||e===void 0?void 0:e.sessionId},r.prototype.start=function(){return Ne(this._start())},r.prototype._start=function(){return C(this,void 0,void 0,function(){return I(this,function(e){switch(e.label){case 0:return this.recordingEnabled=!0,this.startChildRecordingOnSetup=!0,[4,this.recordEvents()];case 1:return e.sent(),[2]}})})},r.prototype.stop=function(){this.recordingEnabled=!1,this.startChildRecordingOnSetup=!1,this.recordingGeneration++,this.stopRecordingEvents(),this.sendEvents()},r.prototype.flush=function(e){var t;return e===void 0&&(e=!1),C(this,void 0,void 0,function(){return I(this,function(n){return[2,(t=this.eventsManager)===null||t===void 0?void 0:t.flush(e)]})})},r.prototype.shutdown=function(){var e,t;this.recordingEnabled=!1,this.startChildRecordingOnSetup=!1,this.recordingGeneration++,(e=this.urlChangeCleanup)===null||e===void 0||e.call(this),(t=this.crossOriginParentSignalCleanup)===null||t===void 0||t.call(this),this.crossOriginParentSignalCleanup=null,this.teardownEventListeners(!0),this.stopRecordingEvents(),this.sendEvents()},r.prototype.mapSDKType=function(e){return e==="plugin"?"@amplitude/plugin-session-replay-browser":e==="segment"?"@amplitude/segment-session-replay-plugin":null},r.prototype.setMetadata=function(e,t,n,i,s,o,l){var a=e?.toString()?ht(e.toString()):void 0;this.metadata={joinedConfig:t,localConfig:n,remoteConfig:i,sessionId:e,hashValue:a,sampleRate:t.sampleRate,replaySDKType:this.mapSDKType(l),replaySDKVersion:s,standaloneSDKType:"@amplitude/session-replay-browser",standaloneSDKVersion:o}},r.prototype.initializeNetworkObservers=function(){var e,t,n;return C(this,void 0,void 0,function(){var i,s;return I(this,function(o){switch(o.label){case 0:if(!(!((n=(t=(e=this.config)===null||e===void 0?void 0:e.loggingConfig)===null||t===void 0?void 0:t.network)===null||n===void 0)&&n.enabled&&!this.networkObservers))return[3,4];o.label=1;case 1:return o.trys.push([1,3,,4]),[4,be(()=>import("./observers-B7xO7AUU.js"),__vite__mapDeps([4,1,5]))];case 2:return i=o.sent().NetworkObservers,this.networkObservers=new i,[3,4];case 3:return s=o.sent(),this.loggerProvider.warn("Failed to import or instantiate NetworkObservers:",s),[3,4];case 4:return[2]}})})},r})(),oe=function(r){return function(){var e=r.config,t=e||tr(),n=t.loggerProvider,i=t.logLevel;return{logger:n,logLevel:i}}},yi=function(){var r=new mi;
2return{init:se(r.init.bind(r),"init",oe(r)),evaluateTargetingAndCapture:se(r.evaluateTargetingAndCapture.bind(r),"evaluateTargetingAndRecord",oe(r)),setSessionId:se(r.setSessionId.bind(r),"setSessionId",oe(r)),getSessionId:se(r.getSessionId.bind(r),"getSessionId",oe(r)),getSessionReplayProperties:se(r.getSessionReplayProperties.bind(r),"getSessionReplayProperties",oe(r)),flush:se(r.flush.bind(r),"flush",oe(r)),start:se(r.start.bind(r),"start",oe(r)),stop:se(r.stop.bind(r),"stop",oe(r)),shutdown:se(r.shutdown.bind(r),"shutdown",oe(r))}};const ue=yi();var Si=ue.init,bi=ue.setSessionId,Ei=ue.getSessionId,Ii=ue.getSessionReplayProperties,Ci=ue.flush,Pi=ue.start,Ti=ue.stop,wi=ue.shutdown,Ri=ue.evaluateTargetingAndCapture,fe;(function(r){r.SET="$set",r.SET_ONCE="$setOnce",r.ADD="$add",r.APPEND="$append",r.PREPEND="$prepend",r.REMOVE="$remove",r.PREINSERT="$preInsert",r.POSTINSERT="$postInsert",r.UNSET="$unset",r.CLEAR_ALL="$clearAll"})(fe||(fe={}));var Nt;(function(r){r.REVENUE_PRODUCT_ID="$productId",r.REVENUE_QUANTITY="$quantity",r.REVENUE_PRICE="$price",r.REVENUE_TYPE="$revenueType",r.REVENUE_CURRENCY="$currency",r.REVENUE="$revenue"})(Nt||(Nt={}));var Ut;(function(r){r.IDENTIFY="$identify",r.GROUP_IDENTIFY="$groupidentify",r.REVENUE="revenue_amount"})(Ut||(Ut={}));var Mi=[fe.SET,fe.SET_ONCE,fe.ADD,fe.APPEND,fe.PREPEND,fe.POSTINSERT],ki=function(r){if(r.user_properties){var e={},t=Object.keys(r.user_properties);return t.forEach(function(n){if(Mi.includes(n)){var i=r.user_properties&&r.user_properties[n];e=E(E({},e),i)}}),e}},qt="1.34.0",Oi="[Amplitude]",xi="".concat(Oi," Session Replay ID"),Li=(function(){function r(e){this.name=r.pluginName,this.type="enrichment",this.config=null,this.sessionReplay={flush:Ci,getSessionId:Ei,getSessionReplayProperties:Ii,init:Si,setSessionId:bi,start:Pi,stop:Ti,shutdown:wi,evaluateTargetingAndCapture:Ri},this.options=E({forceSessionTracking:!1},e),this.srInitOptions=this.options}return r.prototype.setup=function(e,t){var n,i,s,o,l,a,u,d;return C(this,void 0,void 0,function(){var v,c,f;return I(this,function(h){switch(h.label){case 0:return h.trys.push([0,2,,3]),e?.loggerProvider.log("Installing @amplitude/plugin-session-replay, version ".concat(qt,".")),this.config=e,this.options.forceSessionTracking&&(typeof e.defaultTracking=="boolean"?e.defaultTracking===!1&&(e.defaultTracking={pageViews:!1,formInteractions:!1,fileDownloads:!1,sessions:!0}):e.defaultTracking=E(E({},e.defaultTracking),{sessions:!0})),v=zt(this.config.instanceName).identityStore,c=v.getIdentity().userProperties,this.srInitOptions={instanceName:this.config.instanceName,deviceId:(n=this.options.deviceId)!==null&&n!==void 0?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||((i=this.config.remoteConfig)===null||i===void 0?void 0:i.serverUrl),trackServerUrl:this.options.trackServerUrl,sampleRate:this.options.sampleRate,privacyConfig:{blockSelector:(s=this.options.privacyConfig)===null||s===void 0?void 0:s.blockSelector,maskSelector:(o=this.options.privacyConfig)===null||o===void 0?void 0:o.maskSelector,unmaskSelector:(l=this.options.privacyConfig)===null||l===void 0?void 0:l.unmaskSelector,defaultMaskLevel:(a=this.options.privacyConfig)===null||a===void 0?void 0:a.defaultMaskLevel,maskAttributes:this.options.privacyConfig===null||this.options.privacyConfig===void 0?void 0:this.options.privacyConfig.maskAttributes},debugMode:this.options.debugMode,shouldInlineStylesheet:this.options.shouldInlineStylesheet,version:{type:"plugin",version:qt},performanceConfig:this.options.performanceConfig,storeType:this.options.storeType,useWebWorker:(u=this.options.useWebWorker)!==null&&u!==void 0?u:(d=this.options.experimental)===null||d===void 0?void 0:d.useWebWorker,userProperties:c,applyBackgroundColorToBlockedElements:this.options.applyBackgroundColorToBlockedElements,interactionConfig:this.options.interactionConfig,captureDocumentTitle:this.options.captureDocumentTitle,enableUrlChangePolling:this.options.enableUrlChangePolling,urlChangePollingInterval:this.options.urlChangePollingInterval,captureAdoptedStyleSheets:this.options.captureAdoptedStyleSheets,crossOriginIframes:this.options.crossOriginIframes,flushIntervalConfig:this.options.flushIntervalConfig,eagerFullSnapshotSend:this.options.eagerFullSnapshotSend,captureFullSnapshotOnFocus:this.options.captureFullSnapshotOnFocus,maxPersistedEventsSizeBytes:this.options.maxPer
2sistedEventsSizeBytes,maxSingleEventSizeBytes:this.options.maxSingleEventSizeBytes,sendTimeoutMs:this.options.sendTimeoutMs,handleSendEvents:this.options.handleSendEvents,handleFetchConfig:this.options.handleFetchConfig},[4,this.sessionReplay.init(e.apiKey,this.srInitOptions).promise];case 1:return h.sent(),[3,3];case 2:return f=h.sent(),e?.loggerProvider.error("Session Replay: Failed to initialize due to ".concat(f.message)),[3,3];case 3:return[2]}})})},r.prototype.onSessionIdChanged=function(e){var t;return C(this,void 0,void 0,function(){return I(this,function(n){switch(n.label){case 0:return(t=this.config)===null||t===void 0||t.loggerProvider.debug("Analytics session id is changed to ".concat(e,", SR session id is ").concat(String(this.sessionReplay.getSessionId()),".")),[4,this.sessionReplay.setSessionId(e).promise];case 1:return n.sent(),[2]}})})},r.prototype.onOptOutChanged=function(e){var t;return C(this,void 0,void 0,function(){var n;return I(this,function(i){switch(i.label){case 0:return(t=this.config)===null||t===void 0||t.loggerProvider.debug("optOut is changed to ".concat(String(e),", calling ").concat(e?"sessionReplay.shutdown()":"sessionReplay.init()",".")),e?(this.sessionReplay.shutdown(),[3,4]):[3,1];case 1:return n=this.config!=null,n?[4,this.sessionReplay.init(this.config.apiKey,this.srInitOptions).promise]:[3,3];case 2:n=i.sent(),i.label=3;case 3:i.label=4;case 4:return[2]}})})},r.prototype.execute=function(e){var t,n,i;return C(this,void 0,void 0,function(){var s,a,s,o,l,a,u;return I(this,function(d){switch(d.label){case 0:return d.trys.push([0,9,,10]),this.options.customSessionId?(s=this.options.customSessionId(e),s?s===this.sessionReplay.getSessionId()?[3,2]:[4,this.sessionReplay.setSessionId(s).promise]:[3,3]):[3,4];case 1:d.sent(),d.label=2;case 2:a=this.sessionReplay.getSessionReplayProperties(),e.event_properties=E(E({},e.event_properties),a),d.label=3;case 3:return[3,8];case 4:return s=(t=this.config)===null||t===void 0?void 0:t.sessionId,s&&s!==this.sessionReplay.getSessionId()?[4,this.sessionReplay.setSessionId(s).promise]:[3,6];case 5:d.sent(),d.label=6;case 6:return s&&s===e.session_id?(o=void 0,e.event_type===Qe.IDENTIFY&&(o=ki(e)),l=G(),[4,this.sessionReplay.evaluateTargetingAndCapture({event:e,userProperties:o,page:((n=l?.location)===null||n===void 0?void 0:n.href)!=null?{url:l.location.href}:void 0})]):[3,8];case 7:d.sent(),a=this.sessionReplay.getSessionReplayProperties(),e.event_properties=E(E({},e.event_properties),a),d.label=8;case 8:return e.event_type===Qe.IDENTIFY&&e.event_properties&&delete e.event_properties[xi],[2,Promise.resolve(e)];case 9:return u=d.sent(),(i=this.config)===null||i===void 0||i.loggerProvider.error("Session Replay: Failed to enrich event due to ".concat(u.message)),[2,Promise.resolve(e)];case 10:return[2]}})})},r.prototype.teardown=function(){var e;return C(this,void 0,void 0,function(){return I(this,function(t){try{this.sessionReplay.shutdown(),this.config=null}catch(n){(e=this.config)===null||e===void 0||e.loggerProvider.error("Session Replay: teardown failed due to ".concat(n.message))}return[2]})})},r.prototype.getSessionReplayProperties=function(){return this.sessionReplay.getSessionReplayProperties()},r.prototype.start=function(){return C(this,void 0,void 0,function(){return I(this,function(e){switch(e.label){case 0:return[4,this.sessionReplay.start().promise];case 1:return e.sent(),[2]}})})},r.prototype.stop=function(){this.sessionReplay.stop()},r.pluginName="@amplitude/plugin-session-replay-browser",r})(),_i=function(r){return new Li(r)}
2;const Di=r=>_i(r),Ni=Object.freeze(Object.defineProperty({__proto__:null,createSessionReplayPlugin:Di},Symbol.toStringTag,{value:"Module"}));export{ir as o,Ni as s};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.