@devskin/browser-sdk 1.0.37 → 1.0.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -47,5 +47,5 @@ var A=function(e,t){return A=Object.setPrototypeOf||{__proto__:[]}instanceof Arr
47
47
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
48
48
  PERFORMANCE OF THIS SOFTWARE.
49
49
  ***************************************************************************** */
50
- function A(A,e,t,r){return new(t||(t=Promise))(function(e,n){function s(A){try{i(r.next(A))}catch(A){n(A)}}function o(A){try{i(r.throw(A))}catch(A){n(A)}}function i(A){var r;A.done?e(A.value):(r=A.value,r instanceof t?r:new t(function(A){A(r)})).then(s,o)}i((r=r.apply(A,[])).next())})}for(var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",t="undefined"==typeof Uint8Array?[]:new Uint8Array(256),r=0;r<64;r++)t[e.charCodeAt(r)]=r;var n=function(A){var t,r=new Uint8Array(A),n=r.length,s="";for(t=0;t<n;t+=3)s+=e[r[t]>>2],s+=e[(3&r[t])<<4|r[t+1]>>4],s+=e[(15&r[t+1])<<2|r[t+2]>>6],s+=e[63&r[t+2]];return n%3==2?s=s.substring(0,s.length-1)+"=":n%3==1&&(s=s.substring(0,s.length-2)+"=="),s};const s=new Map,o=new Map,i=self;i.onmessage=function(e){return A(this,0,void 0,function*(){if(!("OffscreenCanvas"in globalThis))return i.postMessage({id:e.data.id});{const{id:t,bitmap:r,width:a,height:c,dataURLOptions:B}=e.data,l=function(e,t,r){return A(this,0,void 0,function*(){const A=`${e}-${t}`;if("OffscreenCanvas"in globalThis){if(o.has(A))return o.get(A);const s=new OffscreenCanvas(e,t);s.getContext("2d");const i=yield s.convertToBlob(r),a=yield i.arrayBuffer(),c=n(a);return o.set(A,c),c}return""})}(a,c,B),u=new OffscreenCanvas(a,c);u.getContext("2d").drawImage(r,0,0),r.close();const g=yield u.convertToBlob(B),d=g.type,h=yield g.arrayBuffer(),w=n(h);if(!s.has(t)&&(yield l)===w)return s.set(t,w),i.postMessage({id:t});if(s.get(t)===w)return i.postMessage({id:t});i.postMessage({id:t,type:d,base64:w,width:a,height:c}),s.set(t,w)}})}}()},function(A){return Ge=Ge||function(A){var e=function(A){var e=A.toString().split("\n");e.pop(),e.shift();for(var t=e[0].search(/\S/),r=/(['"])__worker_loader_strict__(['"])/g,n=0,s=e.length;n<s;++n)e[n]=e[n].substring(t).replace(r,"$1use strict$2")+"\n";return e}(A),t=new Blob(e,{type:"application/javascript"});return URL.createObjectURL(t)}(Ne),new Worker(Ge,A)});class Pe{reset(){this.pendingCanvasMutations.clear(),this.resetObservers&&this.resetObservers()}freeze(){this.frozen=!0}unfreeze(){this.frozen=!1}lock(){this.locked=!0}unlock(){this.locked=!1}constructor(A){this.pendingCanvasMutations=new Map,this.rafStamps={latestId:0,invokeId:null},this.frozen=!1,this.locked=!1,this.processMutation=(A,e)=>{!(this.rafStamps.invokeId&&this.rafStamps.latestId!==this.rafStamps.invokeId)&&this.rafStamps.invokeId||(this.rafStamps.invokeId=this.rafStamps.latestId),this.pendingCanvasMutations.has(A)||this.pendingCanvasMutations.set(A,[]),this.pendingCanvasMutations.get(A).push(e)};const{sampling:e="all",win:t,blockClass:r,blockSelector:n,recordCanvas:s,dataURLOptions:o}=A;this.mutationCb=A.mutationCb,this.mirror=A.mirror,s&&"all"===e&&this.initCanvasMutationObserver(t,r,n),s&&"number"==typeof e&&this.initCanvasFPSObserver(e,t,r,n,{dataURLOptions:o})}initCanvasFPSObserver(A,e,t,r,n){const s=xe(e,t,r,!0),o=new Map,i=new Ve;i.onmessage=A=>{const{id:e}=A.data;if(o.set(e,!1),!("base64"in A.data))return;const{base64:t,type:r,width:n,height:s}=A.data;this.mutationCb({id:e,type:$A["2D"],commands:[{property:"clearRect",args:[0,0,n,s]},{property:"drawImage",args:[{rr_type:"ImageBitmap",args:[{rr_type:"Blob",data:[{rr_type:"ArrayBuffer",base64:t}],type:r}]},0,0]}]})};const a=1e3/A;let c,B=0;const l=A=>{B&&A-B<a||(B=A,(()=>{const A=[];return e.document.querySelectorAll("canvas").forEach(e=>{xA(e,t,r,!0)||A.push(e)}),A})().forEach(A=>be(this,0,void 0,function*(){var e;const t=this.mirror.getId(A);if(o.get(t))return;if(0===A.width||0===A.height)return;if(o.set(t,!0),["webgl","webgl2"].includes(A.__context)){const t=A.getContext(A.__context);!1===(null===(e=null==t?void 0:t.getContextAttributes())||void 0===e?void 0:e.preserveDrawingBuffer)&&t.clear(t.COLOR_BUFFER_BIT)}const r=yield createImageBitmap(A);i.postMessage({id:t,bitmap:r,width:A.width,height:A.height,dataURLOptions:n.dataURLOptions},[r])}))),c=requestAnimationFrame(l)};c=requestAnimationFrame(l),this.resetObservers=()=>{s(),cancelAnimationFrame(c)}}initCanvasMutationObserver(A,e,t){this.startRAFTimestamping(),this.startPendingCanvasMutationFlusher();const r=xe(A,e,t,!1),n=function(A,e,t,r){const n=[],s=Object.getOwnPropertyNames(e.CanvasRenderingContext2D.prototype);for(const o of s)try{if("function"!=typeof e.CanvasRenderingContext2D.prototype[o])continue;const s=KA(e.CanvasRenderingContext2D.prototype,o,function(n){return function(...s){return xA(this.canvas,t,r,!0)||setTimeout(()=>{const t=Te(s,e,this);A(this.canvas,{type:$A["2D"],property:o,args:t})},0),n.apply(this,s)}});n.push(s)}catch(t){const r=LA(e.CanvasRenderingContext2D.prototype,o,{set(e){A(this.canvas,{type:$A["2D"],property:o,args:[e],setter:!0})}});n.push(r)}return()=>{n.forEach(A=>A())}}(this.processMutation.bind(this),A,e,t),s=function(A,e,t,r){const n=[];return n.push(...Re(e.WebGLRenderingContext.prototype,$A.WebGL,A,t,r,0,e)),void 0!==e.WebGL2RenderingContext&&n.push(...Re(e.WebGL2RenderingContext.prototype,$A.WebGL2,A,t,r,0,e)),()=>{n.forEach(A=>A())}}(this.processMutation.bind(this),A,e,t,this.mirror);this.resetObservers=()=>{r(),n(),s()}}startPendingCanvasMutationFlusher(){requestAnimationFrame(()=>this.flushPendingCanvasMutations())}startRAFTimestamping(){const A=e=>{this.rafStamps.latestId=e,requestAnimationFrame(A)};requestAnimationFrame(A)}flushPendingCanvasMutations(){this.pendingCanvasMutations.forEach((A,e)=>{const t=this.mirror.getId(e);this.flushPendingCanvasMutationFor(e,t)}),requestAnimationFrame(()=>this.flushPendingCanvasMutations())}flushPendingCanvasMutationFor(A,e){if(this.frozen||this.locked)return;const t=this.pendingCanvasMutations.get(A);if(!t||-1===e)return;const r=t.map(A=>{const e=function(A,e){var t={};for(var r in A)Object.prototype.hasOwnProperty.call(A,r)&&e.indexOf(r)<0&&(t[r]=A[r]);if(null!=A&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(r=Object.getOwnPropertySymbols(A);n<r.length;n++)e.indexOf(r[n])<0&&Object.prototype.propertyIsEnumerable.call(A,r[n])&&(t[r[n]]=A[r[n]])}return t}(A,["type"]);return e}),{type:n}=t[0];this.mutationCb({id:e,type:n,commands:r}),this.pendingCanvasMutations.delete(A)}}class Xe{constructor(A){this.trackedLinkElements=new WeakSet,this.styleMirror=new JA,this.mutationCb=A.mutationCb,this.adoptedStyleSheetCb=A.adoptedStyleSheetCb}attachLinkElement(A,e){"_cssText"in e.attributes&&this.mutationCb({adds:[],removes:[],texts:[],attributes:[{id:e.id,attributes:e.attributes}]}),this.trackLinkElement(A)}trackLinkElement(A){this.trackedLinkElements.has(A)||(this.trackedLinkElements.add(A),this.trackStylesheetInLinkElement(A))}adoptStyleSheets(A,e){if(0===A.length)return;const t={id:e,styleIds:[]},r=[];for(const e of A){let A;this.styleMirror.has(e)?A=this.styleMirror.getId(e):(A=this.styleMirror.add(e),r.push({styleId:A,rules:Array.from(e.rules||CSSRule,(A,e)=>({rule:z(A),index:e}))})),t.styleIds.push(A)}r.length>0&&(t.styles=r),this.adoptedStyleSheetCb(t)}reset(){this.styleMirror.reset(),this.trackedLinkElements=new WeakSet}trackStylesheetInLinkElement(A){}}class Je{constructor(){this.nodeMap=new WeakMap,this.loop=!0,this.periodicallyClear()}periodicallyClear(){requestAnimationFrame(()=>{this.clear(),this.loop&&this.periodicallyClear()})}inOtherBuffer(A,e){const t=this.nodeMap.get(A);return t&&Array.from(t).some(A=>A!==e)}add(A,e){this.nodeMap.set(A,(this.nodeMap.get(A)||new Set).add(e))}clear(){this.nodeMap=new WeakMap}destroy(){this.loop=!1}}function We(A){return Object.assign(Object.assign({},A),{timestamp:DA()})}let Ye,_e,Ze,je=!1;const qe=new $;function ze(A={}){const{emit:e,checkoutEveryNms:t,checkoutEveryNth:r,blockClass:n="rr-block",blockSelector:s=null,ignoreClass:o="rr-ignore",ignoreSelector:i=null,maskTextClass:a="rr-mask",maskTextSelector:c=null,inlineStylesheet:B=!0,maskAllInputs:l,maskInputOptions:u,slimDOMOptions:g,maskInputFn:d,maskTextFn:h,hooks:w,packFn:Q,sampling:p={},dataURLOptions:C={},mousemoveWait:f,recordDOM:U=!0,recordCanvas:F=!1,recordCrossOriginIframes:m=!1,recordAfter:y=("DOMContentLoaded"===A.recordAfter?A.recordAfter:"load"),userTriggeredOnInput:I=!1,collectFonts:E=!1,inlineImages:H=!1,plugins:v,keepIframeSrcFn:b=()=>!1,ignoreCSSAttributes:S=new Set([]),errorHandler:L}=A;Be(L);const K=!m||window.parent===window;let D=!1;if(!K)try{window.parent.document&&(D=!1)}catch(A){D=!0}if(K&&!e)throw new Error("emit function is required");void 0!==f&&void 0===p.mousemove&&(p.mousemove=f),qe.reset();const M=!0===l?{color:!0,date:!0,"datetime-local":!0,email:!0,month:!0,number:!0,range:!0,search:!0,tel:!0,text:!0,time:!0,url:!0,week:!0,textarea:!0,select:!0,password:!0}:void 0!==u?u:{password:!0},k=!0===g||"all"===g?{script:!0,comment:!0,headFavicon:!0,headWhitespace:!0,headMetaSocial:!0,headMetaRobots:!0,headMetaHttpEquiv:!0,headMetaVerification:!0,headMetaAuthorship:"all"===g,headMetaDescKeywords:"all"===g}:g||{};let T;!function(A=window){"NodeList"in A&&!A.NodeList.prototype.forEach&&(A.NodeList.prototype.forEach=Array.prototype.forEach),"DOMTokenList"in A&&!A.DOMTokenList.prototype.forEach&&(A.DOMTokenList.prototype.forEach=Array.prototype.forEach),Node.prototype.contains||(Node.prototype.contains=(...A)=>{let e=A[0];if(!(0 in A))throw new TypeError("1 argument is required");do{if(this===e)return!0}while(e=e&&e.parentNode);return!1})}();let O=0;const x=A=>{for(const e of v||[])e.eventProcessor&&(A=e.eventProcessor(A));return Q&&!D&&(A=Q(A)),A};Ye=(A,n)=>{var s;if(!(null===(s=ge[0])||void 0===s?void 0:s.isFrozen())||A.type===ZA.FullSnapshot||A.type===ZA.IncrementalSnapshot&&A.data.source===jA.Mutation||ge.forEach(A=>A.unfreeze()),K)null==e||e(x(A),n);else if(D){const e={type:"rrweb",event:x(A),origin:window.location.origin,isCheckout:n};window.parent.postMessage(e,"*")}if(A.type===ZA.FullSnapshot)T=A,O=0;else if(A.type===ZA.IncrementalSnapshot){if(A.data.source===jA.Mutation&&A.data.isAttachIframe)return;O++;const e=r&&O>=r,n=t&&A.timestamp-T.timestamp>t;(e||n)&&_e(!0)}};const R=A=>{Ye(We({type:ZA.IncrementalSnapshot,data:Object.assign({source:jA.Mutation},A)}))},N=A=>Ye(We({type:ZA.IncrementalSnapshot,data:Object.assign({source:jA.Scroll},A)})),G=A=>Ye(We({type:ZA.IncrementalSnapshot,data:Object.assign({source:jA.CanvasMutation},A)})),V=new Xe({mutationCb:R,adoptedStyleSheetCb:A=>Ye(We({type:ZA.IncrementalSnapshot,data:Object.assign({source:jA.AdoptedStyleSheet},A)}))}),P=new He({mirror:qe,mutationCb:R,stylesheetManager:V,recordCrossOriginIframes:m,wrappedEmit:Ye});for(const A of v||[])A.getMirror&&A.getMirror({nodeMirror:qe,crossOriginIframeMirror:P.crossOriginIframeMirror,crossOriginIframeStyleMirror:P.crossOriginIframeStyleMirror});const X=new Je;Ze=new Pe({recordCanvas:F,mutationCb:G,win:window,blockClass:n,blockSelector:s,mirror:qe,sampling:p.canvas,dataURLOptions:C});const J=new ve({mutationCb:R,scrollCb:N,bypassOptions:{blockClass:n,blockSelector:s,maskTextClass:a,maskTextSelector:c,inlineStylesheet:B,maskInputOptions:M,dataURLOptions:C,maskTextFn:h,maskInputFn:d,recordCanvas:F,inlineImages:H,sampling:p,slimDOMOptions:k,iframeManager:P,stylesheetManager:V,canvasManager:Ze,keepIframeSrcFn:b,processedNodeManager:X},mirror:qe});_e=(A=!1)=>{if(!U)return;Ye(We({type:ZA.Meta,data:{href:window.location.href,width:TA(),height:kA()}}),A),V.reset(),J.init(),ge.forEach(A=>A.lock());const e=function(A,e){const{mirror:t=new $,blockClass:r="rr-block",blockSelector:n=null,maskTextClass:s="rr-mask",maskTextSelector:o=null,inlineStylesheet:i=!0,inlineImages:a=!1,recordCanvas:c=!1,maskAllInputs:B=!1,maskTextFn:l,maskInputFn:u,slimDOM:g=!1,dataURLOptions:d,preserveWhiteSpace:h,onSerialize:w,onIframeLoad:Q,iframeLoadTimeout:p,onStylesheetLoad:C,stylesheetLoadTimeout:f,keepIframeSrcFn:U=()=>!1}=e||{};return EA(A,{doc:A,mirror:t,blockClass:r,blockSelector:n,maskTextClass:s,maskTextSelector:o,skipChild:!1,inlineStylesheet:i,maskInputOptions:!0===B?{color:!0,date:!0,"datetime-local":!0,email:!0,month:!0,number:!0,range:!0,search:!0,tel:!0,text:!0,time:!0,url:!0,week:!0,textarea:!0,select:!0,password:!0}:!1===B?{password:!0}:B,maskTextFn:l,maskInputFn:u,slimDOMOptions:!0===g||"all"===g?{script:!0,comment:!0,headFavicon:!0,headWhitespace:!0,headMetaDescKeywords:"all"===g,headMetaSocial:!0,headMetaRobots:!0,headMetaHttpEquiv:!0,headMetaAuthorship:!0,headMetaVerification:!0}:!1===g?{}:g,dataURLOptions:d,inlineImages:a,recordCanvas:c,preserveWhiteSpace:h,onSerialize:w,onIframeLoad:Q,iframeLoadTimeout:p,onStylesheetLoad:C,stylesheetLoadTimeout:f,keepIframeSrcFn:U,newlyAddedElement:!1})}(document,{mirror:qe,blockClass:n,blockSelector:s,maskTextClass:a,maskTextSelector:c,inlineStylesheet:B,maskAllInputs:M,maskTextFn:h,slimDOM:k,dataURLOptions:C,recordCanvas:F,inlineImages:H,onSerialize:A=>{VA(A,qe)&&P.addIframe(A),PA(A,qe)&&V.trackLinkElement(A),XA(A)&&J.addShadowRoot(A.shadowRoot,document)},onIframeLoad:(A,e)=>{P.attachIframe(A,e),J.observeAttachShadow(A)},onStylesheetLoad:(A,e)=>{V.attachLinkElement(A,e)},keepIframeSrcFn:b});if(!e)return console.warn("Failed to snapshot the document");Ye(We({type:ZA.FullSnapshot,data:{node:e,initialOffset:MA(window)}}),A),ge.forEach(A=>A.unlock()),document.adoptedStyleSheets&&document.adoptedStyleSheets.length>0&&V.adoptStyleSheets(document.adoptedStyleSheets,qe.getId(document))};try{const A=[],e=A=>{var e;return ue(me)({mutationCb:R,mousemoveCb:(A,e)=>Ye(We({type:ZA.IncrementalSnapshot,data:{source:e,positions:A}})),mouseInteractionCb:A=>Ye(We({type:ZA.IncrementalSnapshot,data:Object.assign({source:jA.MouseInteraction},A)})),scrollCb:N,viewportResizeCb:A=>Ye(We({type:ZA.IncrementalSnapshot,data:Object.assign({source:jA.ViewportResize},A)})),inputCb:A=>Ye(We({type:ZA.IncrementalSnapshot,data:Object.assign({source:jA.Input},A)})),mediaInteractionCb:A=>Ye(We({type:ZA.IncrementalSnapshot,data:Object.assign({source:jA.MediaInteraction},A)})),styleSheetRuleCb:A=>Ye(We({type:ZA.IncrementalSnapshot,data:Object.assign({source:jA.StyleSheetRule},A)})),styleDeclarationCb:A=>Ye(We({type:ZA.IncrementalSnapshot,data:Object.assign({source:jA.StyleDeclaration},A)})),canvasMutationCb:G,fontCb:A=>Ye(We({type:ZA.IncrementalSnapshot,data:Object.assign({source:jA.Font},A)})),selectionCb:A=>{Ye(We({type:ZA.IncrementalSnapshot,data:Object.assign({source:jA.Selection},A)}))},customElementCb:A=>{Ye(We({type:ZA.IncrementalSnapshot,data:Object.assign({source:jA.CustomElement},A)}))},blockClass:n,ignoreClass:o,ignoreSelector:i,maskTextClass:a,maskTextSelector:c,maskInputOptions:M,inlineStylesheet:B,sampling:p,recordDOM:U,recordCanvas:F,inlineImages:H,userTriggeredOnInput:I,collectFonts:E,doc:A,maskInputFn:d,maskTextFn:h,keepIframeSrcFn:b,blockSelector:s,slimDOMOptions:k,dataURLOptions:C,mirror:qe,iframeManager:P,stylesheetManager:V,shadowDomManager:J,processedNodeManager:X,canvasManager:Ze,ignoreCSSAttributes:S,plugins:(null===(e=null==v?void 0:v.filter(A=>A.observer))||void 0===e?void 0:e.map(A=>({observer:A.observer,options:A.options,callback:e=>Ye(We({type:ZA.Plugin,data:{plugin:A.name,payload:e}}))})))||[]},w)};P.addLoadListener(t=>{try{A.push(e(t.contentDocument))}catch(A){console.warn(A)}});const t=()=>{_e(),A.push(e(document)),je=!0};return"interactive"===document.readyState||"complete"===document.readyState?t():(A.push(HA("DOMContentLoaded",()=>{Ye(We({type:ZA.DomContentLoaded,data:{}})),"DOMContentLoaded"===y&&t()})),A.push(HA("load",()=>{Ye(We({type:ZA.Load,data:{}})),"load"===y&&t()},window))),()=>{A.forEach(A=>A()),X.destroy(),je=!1,le()}}catch(A){console.warn(A)}}ze.addCustomEvent=(A,e)=>{if(!je)throw new Error("please add custom event after start recording");Ye(We({type:ZA.Custom,data:{tag:A,payload:e}}))},ze.freezePage=()=>{ge.forEach(A=>A.freeze())},ze.takeFullSnapshot=A=>{if(!je)throw new Error("please take full snapshot after start recording");_e(A)},ze.mirror=qe;class $e{constructor(A,e,t,r=0){this.stopFn=null,this.events=[],this.onEventsReady=null,this.flushInterval=null,this.hasFullSnapshot=!1,this.sessionStartTime=0,this.recordingStartTime=0,this.sessionId=A,this.config=e,this.onEventsReady=t,this.sessionStartTime=r||Date.now(),this.recordingStartTime=Date.now(),console.log(`[RRWeb] Recording initialized - session started at ${this.sessionStartTime}, recording started at ${this.recordingStartTime}`)}start(){if(this.config.enabled)if(this.stopFn)console.warn("[RRWeb] Recording already started");else try{this.stopFn=ze({emit:A=>{const e=A.timestamp;A.timestamp=A.timestamp-this.sessionStartTime,this.config.enabled&&2===A.type&&console.log(`[RRWeb] FullSnapshot - original: ${e}, relative: ${A.timestamp}, session start: ${this.sessionStartTime}`),this.events.push(A),2===A.type?(this.hasFullSnapshot=!0,this.flush()):this.hasFullSnapshot&&this.events.length>=20&&this.flush()},sampling:{mousemove:void 0===this.config.sampleRate||Math.floor(100/this.config.sampleRate),mouseInteraction:!0,scroll:150,media:800,input:"last"},checkoutEveryNms:this.config.checkoutEveryNms||3e5,checkoutEveryNth:this.config.checkoutEveryNth||200,blockClass:this.config.blockClass||"rr-block",ignoreClass:this.config.ignoreClass||"rr-ignore",maskAllInputs:void 0===this.config.maskAllInputs||this.config.maskAllInputs,maskInputOptions:this.config.maskInputOptions||{password:!0,email:!0,tel:!0},maskTextClass:"rr-mask",inlineStylesheet:void 0===this.config.inlineStylesheet||this.config.inlineStylesheet,recordCanvas:this.config.recordCanvas||!1,collectFonts:void 0===this.config.collectFonts||this.config.collectFonts,recordCrossOriginIframes:!1}),this.flushInterval=window.setInterval(()=>{this.hasFullSnapshot&&this.events.length>0&&this.flush()},2e3),setTimeout(()=>{if(!this.hasFullSnapshot)try{ze.takeFullSnapshot()}catch(A){this.events.length>0&&(this.hasFullSnapshot=!0,this.flush())}},2e3)}catch(A){console.error("[RRWeb] Failed to start recording:",A)}else console.log("[RRWeb] Recording disabled in config")}stop(){this.stopFn&&(this.stopFn(),this.stopFn=null),this.flushInterval&&(clearInterval(this.flushInterval),this.flushInterval=null),this.events.length>0&&this.flush()}flush(){if(0===this.events.length)return;const A=[...this.events];this.events=[],this.onEventsReady&&this.onEventsReady(A)}getEventCount(){return this.events.length}isRecording(){return null!==this.stopFn}}class At{constructor(A){this.config=A,this.queue=[],this.flushInterval=null,this.maxQueueSize=20,this.flushIntervalMs=2e3,this.sessionId=null,this.apiUrl=A.apiUrl||"https://api.devskin.com",this.startPeriodicFlush(),"undefined"!=typeof window&&(window.addEventListener("beforeunload",()=>{this.flush()}),window.addEventListener("visibilitychange",()=>{document.hidden&&this.flush(!0)}))}setSessionId(A){this.sessionId=A}sendEvent(A){this.enqueue("event",A)}identifyUser(A){this.sendToBackend("/v1/analytics/identify",A)}startSession(e){return A(this,arguments,void 0,function*(A,e=!1){yield this.sendToBackend("/v1/rum/sessions",A,e)})}sendError(A){this.enqueue("error",A)}sendNetworkRequest(A){this.enqueue("network",A)}sendPerformanceMetric(A){this.enqueue("performance",A)}sendPageView(e){return A(this,void 0,void 0,function*(){this.sendToBackend("/v1/rum/page-views",e)})}sendRecordingEvents(e,t){return A(this,void 0,void 0,function*(){const A={session_id:e,events:t,timestamp:(new Date).toISOString(),apiKey:this.config.apiKey,appId:this.config.appId},r=new Blob([JSON.stringify(A)]).size,n=t.some(A=>2===A.type),s=n?3:1;let o=null;for(let A=1;A<=s;A++)try{return void(r>1e5?yield this.sendToBackendXHR("/v1/rum/recordings",{session_id:e,events:t,timestamp:(new Date).toISOString()}):yield this.sendToBackend("/v1/rum/recordings",{session_id:e,events:t,timestamp:(new Date).toISOString()}))}catch(e){if(o=e,A<s){const e=1e3*A;yield new Promise(A=>setTimeout(A,e))}}this.config.debug&&console.error(`[DevSkin SDK] Failed to send recording events after ${s} attempts:`,o)})}sendHeatmapData(A){this.enqueue("heatmap",A)}sendScreenshot(e){return A(this,void 0,void 0,function*(){yield this.sendToBackend("/v1/sdk/screenshot",{screenshot:e})})}flush(A=!1){if(0===this.queue.length)return;const e=[...this.queue];this.queue=[];const t={};e.forEach(A=>{t[A.type]||(t[A.type]=[]),t[A.type].push(A.data)}),Object.entries(t).forEach(([e,t])=>{const r=this.getEndpointForType(e);"event"===e&&t.length>1?this.sendToBackend("/v1/rum/events/batch",{events:t},A):"heatmap"===e?this.sendToBackend(r,{heatmaps:t},A):t.forEach(e=>{this.sendToBackend(r,e,A)})}),this.config.debug&&console.log(`[DevSkin] Flushed ${e.length} items to backend`)}enqueue(A,e){let t=e;"heatmap"!==A&&(t=Object.assign(Object.assign({},e),{applicationId:this.config.appId}),"network"!==A&&"performance"!==A||!this.sessionId||(t.sessionId=this.sessionId)),this.queue.push({type:A,data:t,timestamp:Date.now()}),this.queue.length>=this.maxQueueSize&&this.flush()}startPeriodicFlush(){this.flushInterval=setInterval(()=>{this.flush()},this.flushIntervalMs)}getEndpointForType(A){switch(A){case"event":default:return"/v1/rum/events";case"error":return"/v1/errors/errors";case"network":return"/v1/rum/network-requests";case"performance":return"/v1/rum/web-vitals";case"heatmap":return"/v1/sdk/heatmap"}}sendToBackendXHR(e,t){return A(this,void 0,void 0,function*(){const A=`${this.apiUrl}${e}`,r=Object.assign(Object.assign({},t),{apiKey:this.config.apiKey,applicationId:this.config.appId,environment:this.config.environment,release:this.config.release});if(this.config.beforeSend){if(!this.config.beforeSend(r))return}return new Promise((t,n)=>{const s=new XMLHttpRequest;s.open("POST",A,!0),s.setRequestHeader("Content-Type","application/json"),s.setRequestHeader("Authorization",`Bearer ${this.config.apiKey}`),s.onload=()=>{s.status>=200&&s.status<300?(this.config.debug&&console.log("[DevSkin] Data sent successfully via XHR:",e),t()):(console.error("[DevSkin] XHR HTTP Error:",s.status,s.responseText),n(new Error(`HTTP ${s.status}: ${s.statusText}`)))},s.onerror=()=>{console.error("[DevSkin] XHR network error:",e),n(new Error("Network error"))},s.ontimeout=()=>{console.error("[DevSkin] XHR timeout:",e),n(new Error("Request timeout"))},s.timeout=3e4;try{const A=JSON.stringify(r);s.send(A)}catch(A){console.error("[DevSkin] Failed to send XHR request:",A),n(A)}})})}sendToBackend(e,t){return A(this,arguments,void 0,function*(A,e,t=!1){const r=`${this.apiUrl}${A}`,n=Object.assign(Object.assign({},e),{apiKey:this.config.apiKey,applicationId:this.config.appId,environment:this.config.environment,release:this.config.release});if(this.config.beforeSend){if(!this.config.beforeSend(n))return}if(t&&navigator.sendBeacon){const A=new Blob([JSON.stringify(n)],{type:"application/json"});return void navigator.sendBeacon(r,A)}try{const e=yield fetch(r,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.config.apiKey}`},body:JSON.stringify(n),keepalive:!0});if(!e.ok){const A=yield e.text();throw console.error("[DevSkin] HTTP Error:",e.status,A),new Error(`HTTP ${e.status}: ${e.statusText}`)}this.config.debug&&console.log("[DevSkin] Data sent successfully:",A)}catch(e){throw console.error("[DevSkin] Failed to send data to",A,":",e),e}})}destroy(){this.flushInterval&&(clearInterval(this.flushInterval),this.flushInterval=null),this.flush()}}return new class{constructor(){this.config=null,this.transport=null,this.sessionId=null,this.userId=null,this.anonymousId=null,this.sessionStartTime=0,this.initialized=!1,this.heartbeatInterval=null,this.deviceCollector=null,this.locationCollector=null,this.browserCollector=null,this.performanceCollector=null,this.errorCollector=null,this.networkCollector=null,this.heatmapCollector=null,this.screenshotCollector=null,this.rrwebRecorder=null}init(A){this.initialized?console.warn("[DevSkin] SDK already initialized"):(this.config=Object.assign({debug:!1,captureWebVitals:!0,captureNetworkRequests:!0,captureErrors:!0,captureUserAgent:!0,captureLocation:!0,captureDevice:!0,heatmapOptions:{enabled:!0,trackClicks:!0,trackScroll:!0,trackMouseMovement:!1}},A),this.config.debug&&console.log("[DevSkin] Initializing SDK with config:",this.config),this.transport=new At(this.config),this.anonymousId=this.getOrCreateAnonymousId(),this.deviceCollector=new e(this.config),this.locationCollector=new t(this.config),this.browserCollector=new r(this.config),this.startSession().then(()=>{var A,e;this.config.captureWebVitals&&(this.performanceCollector=new N(this.config,this.transport),this.performanceCollector.start()),this.config.captureErrors&&(this.errorCollector=new G(this.config,this.transport),this.errorCollector.start()),this.config.captureNetworkRequests&&(this.networkCollector=new V(this.config,this.transport),this.networkCollector.start());const t=Object.assign({enabled:!0,trackClicks:!0,trackScroll:!0,trackMouseMovement:!0,mouseMoveSampling:.1},this.config.heatmapOptions);this.config.heatmapOptions=t,this.heatmapCollector=new P(this.config,this.transport),this.heatmapCollector.start(),this.screenshotCollector=new _(this.config,this.transport),this.screenshotCollector.captureAndSend(this.sessionId,window.location.pathname),this.config.debug&&console.log("[DevSkin] Heatmap collection enabled (always on)"),(null===(A=this.config.sessionRecording)||void 0===A?void 0:A.enabled)&&(this.rrwebRecorder=new $e(this.sessionId,{enabled:!0,sampleRate:this.config.sessionRecording.sampling||.5,blockClass:"rr-block",ignoreClass:this.config.sessionRecording.ignoreClass||"rr-ignore",maskAllInputs:void 0===this.config.sessionRecording.maskAllInputs||this.config.sessionRecording.maskAllInputs,maskInputOptions:{password:!0,email:!0,tel:!0},recordCanvas:this.config.sessionRecording.recordCanvas||!1,collectFonts:!0,inlineStylesheet:!0,checkoutEveryNms:3e5,checkoutEveryNth:200},A=>{var e;null===(e=this.transport)||void 0===e||e.sendRecordingEvents(this.sessionId,A)},this.sessionStartTime),this.rrwebRecorder.start(),(null===(e=this.config)||void 0===e?void 0:e.debug)&&console.log("[DevSkin] RRWeb recording started for session:",this.sessionId)),this.trackPageView(),this.startHeartbeat()}).catch(A=>{console.error("[DevSkin] Failed to create session:",A)}),this.setupVisibilityTracking(),this.setupUnloadTracking(),this.initialized=!0,this.config.debug&&console.log("[DevSkin] SDK initialized successfully"))}track(A,e){var t,r;if(!this.initialized)return void console.warn("[DevSkin] SDK not initialized. Call init() first.");const n={eventName:A,eventType:"track",timestamp:(new Date).toISOString(),sessionId:this.sessionId,userId:this.userId||void 0,anonymousId:this.anonymousId||void 0,properties:Object.assign(Object.assign({},e),this.getContextData()),pageUrl:window.location.href,pageTitle:document.title};null===(t=this.transport)||void 0===t||t.sendEvent(n),(null===(r=this.config)||void 0===r?void 0:r.debug)&&console.log("[DevSkin] Event tracked:",n)}trackPageView(A){var e,t;if(!this.initialized)return void console.warn("[DevSkin] SDK not initialized. Call init() first.");const r=this.generateId();null===(e=this.transport)||void 0===e||e.sendPageView(Object.assign({sessionId:this.sessionId,pageViewId:r,url:window.location.href,path:window.location.pathname,queryParams:window.location.search,referrer:document.referrer,title:document.title,timestamp:(new Date).toISOString()},A)),this.track("page_view",Object.assign({path:window.location.pathname,search:window.location.search,hash:window.location.hash,referrer:document.referrer},A)),(null===(t=this.config)||void 0===t?void 0:t.debug)&&console.log("[DevSkin] Page view tracked:",{sessionId:this.sessionId,pageViewId:r,url:window.location.href})}identify(A,e){var t,r;if(!this.initialized)return void console.warn("[DevSkin] SDK not initialized. Call init() first.");this.userId=A;const n={userId:A,anonymousId:this.anonymousId||void 0,traits:Object.assign(Object.assign({},e),this.getContextData()),sessionId:this.sessionId,timestamp:(new Date).toISOString()};null===(t=this.transport)||void 0===t||t.identifyUser(n),(null===(r=this.config)||void 0===r?void 0:r.debug)&&console.log("[DevSkin] User identified:",n)}captureError(A,e){var t;this.initialized?null===(t=this.errorCollector)||void 0===t||t.captureError(A,Object.assign(Object.assign({},e),{session_id:this.sessionId,user_id:this.userId||void 0})):console.warn("[DevSkin] SDK not initialized. Call init() first.")}addBreadcrumb(A){var e;this.initialized&&(null===(e=this.errorCollector)||void 0===e||e.addBreadcrumb(A))}startRecording(){var A;null===(A=this.rrwebRecorder)||void 0===A||A.start()}stopRecording(){var A;null===(A=this.rrwebRecorder)||void 0===A||A.stop()}optOut(){localStorage.setItem("devskin_opt_out","true"),this.initialized=!1}optIn(){localStorage.removeItem("devskin_opt_out")}startSession(){return A(this,void 0,void 0,function*(){var A,e,t,r,n;const s=sessionStorage.getItem("devskin_session_id"),o=sessionStorage.getItem("devskin_session_start");if(s&&o)return this.sessionId=s,this.sessionStartTime=parseInt(o,10),null===(A=this.transport)||void 0===A||A.setSessionId(this.sessionId),void((null===(e=this.config)||void 0===e?void 0:e.debug)&&console.log("[DevSkin] Resuming existing session:",this.sessionId));this.sessionId=this.generateId(),this.sessionStartTime=Date.now(),sessionStorage.setItem("devskin_session_id",this.sessionId),sessionStorage.setItem("devskin_session_start",this.sessionStartTime.toString()),null===(t=this.transport)||void 0===t||t.setSessionId(this.sessionId);const i=Object.assign({sessionId:this.sessionId,userId:this.userId||void 0,anonymousId:this.anonymousId,startedAt:(new Date).toISOString(),platform:"web"},this.getContextData());yield null===(r=this.transport)||void 0===r?void 0:r.startSession(i),(null===(n=this.config)||void 0===n?void 0:n.debug)&&console.log("[DevSkin] New session created:",this.sessionId)})}getContextData(){var A,e,t,r;const n={};if(this.deviceCollector){const s=this.deviceCollector.collect();n.deviceType=s.type,n.deviceModel=s.model,n.osName=null===(A=s.os)||void 0===A?void 0:A.name,n.osVersion=null===(e=s.os)||void 0===e?void 0:e.version,n.screenWidth=null===(t=s.screen)||void 0===t?void 0:t.width,n.screenHeight=null===(r=s.screen)||void 0===r?void 0:r.height,n.viewportWidth=window.innerWidth,n.viewportHeight=window.innerHeight}if(this.browserCollector){const A=this.browserCollector.collect();n.browserName=A.name,n.browserVersion=A.version,n.userAgent=A.userAgent}if(this.locationCollector){const A=this.locationCollector.collect();n.country=A.country,n.city=A.city,n.ipAddress=void 0}return n}getOrCreateAnonymousId(){let A=localStorage.getItem("devskin_anonymous_id");return A||(A=this.generateId(),localStorage.setItem("devskin_anonymous_id",A)),A}generateId(){return`${Date.now()}-${Math.random().toString(36).substr(2,9)}`}setupVisibilityTracking(){document.addEventListener("visibilitychange",()=>{document.hidden?this.track("page_hidden"):this.track("page_visible")})}setupUnloadTracking(){document.addEventListener("visibilitychange",()=>{var A,e;document.hidden&&(this.updateSessionDuration(),null===(A=this.rrwebRecorder)||void 0===A||A.stop(),null===(e=this.transport)||void 0===e||e.flush(!0))}),window.addEventListener("pagehide",()=>{var A,e;this.track("page_navigation"),this.updateSessionDuration(!1),null===(A=this.rrwebRecorder)||void 0===A||A.stop(),null===(e=this.transport)||void 0===e||e.flush(!0)}),window.addEventListener("beforeunload",()=>{var A,e;this.updateSessionDuration(!1),null===(A=this.rrwebRecorder)||void 0===A||A.stop(),null===(e=this.transport)||void 0===e||e.flush(!0)})}startHeartbeat(){this.heartbeatInterval=setInterval(()=>{this.updateSessionDuration()},3e4)}updateSessionDuration(A=!1){var e,t;if(!this.sessionId||!this.sessionStartTime)return;const r=Date.now()-this.sessionStartTime,n=Object.assign({sessionId:this.sessionId,userId:this.userId||void 0,anonymousId:this.anonymousId,durationMs:r,platform:"web"},this.getContextData());A&&(n.endedAt=(new Date).toISOString()),null===(e=this.transport)||void 0===e||e.startSession(n,A),(null===(t=this.config)||void 0===t?void 0:t.debug)&&console.log("[DevSkin] Session duration updated:",r,"ms",A?"(ending)":"")}}});
50
+ function A(A,e,t,r){return new(t||(t=Promise))(function(e,n){function s(A){try{i(r.next(A))}catch(A){n(A)}}function o(A){try{i(r.throw(A))}catch(A){n(A)}}function i(A){var r;A.done?e(A.value):(r=A.value,r instanceof t?r:new t(function(A){A(r)})).then(s,o)}i((r=r.apply(A,[])).next())})}for(var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",t="undefined"==typeof Uint8Array?[]:new Uint8Array(256),r=0;r<64;r++)t[e.charCodeAt(r)]=r;var n=function(A){var t,r=new Uint8Array(A),n=r.length,s="";for(t=0;t<n;t+=3)s+=e[r[t]>>2],s+=e[(3&r[t])<<4|r[t+1]>>4],s+=e[(15&r[t+1])<<2|r[t+2]>>6],s+=e[63&r[t+2]];return n%3==2?s=s.substring(0,s.length-1)+"=":n%3==1&&(s=s.substring(0,s.length-2)+"=="),s};const s=new Map,o=new Map,i=self;i.onmessage=function(e){return A(this,0,void 0,function*(){if(!("OffscreenCanvas"in globalThis))return i.postMessage({id:e.data.id});{const{id:t,bitmap:r,width:a,height:c,dataURLOptions:B}=e.data,l=function(e,t,r){return A(this,0,void 0,function*(){const A=`${e}-${t}`;if("OffscreenCanvas"in globalThis){if(o.has(A))return o.get(A);const s=new OffscreenCanvas(e,t);s.getContext("2d");const i=yield s.convertToBlob(r),a=yield i.arrayBuffer(),c=n(a);return o.set(A,c),c}return""})}(a,c,B),u=new OffscreenCanvas(a,c);u.getContext("2d").drawImage(r,0,0),r.close();const g=yield u.convertToBlob(B),d=g.type,h=yield g.arrayBuffer(),w=n(h);if(!s.has(t)&&(yield l)===w)return s.set(t,w),i.postMessage({id:t});if(s.get(t)===w)return i.postMessage({id:t});i.postMessage({id:t,type:d,base64:w,width:a,height:c}),s.set(t,w)}})}}()},function(A){return Ge=Ge||function(A){var e=function(A){var e=A.toString().split("\n");e.pop(),e.shift();for(var t=e[0].search(/\S/),r=/(['"])__worker_loader_strict__(['"])/g,n=0,s=e.length;n<s;++n)e[n]=e[n].substring(t).replace(r,"$1use strict$2")+"\n";return e}(A),t=new Blob(e,{type:"application/javascript"});return URL.createObjectURL(t)}(Ne),new Worker(Ge,A)});class Pe{reset(){this.pendingCanvasMutations.clear(),this.resetObservers&&this.resetObservers()}freeze(){this.frozen=!0}unfreeze(){this.frozen=!1}lock(){this.locked=!0}unlock(){this.locked=!1}constructor(A){this.pendingCanvasMutations=new Map,this.rafStamps={latestId:0,invokeId:null},this.frozen=!1,this.locked=!1,this.processMutation=(A,e)=>{!(this.rafStamps.invokeId&&this.rafStamps.latestId!==this.rafStamps.invokeId)&&this.rafStamps.invokeId||(this.rafStamps.invokeId=this.rafStamps.latestId),this.pendingCanvasMutations.has(A)||this.pendingCanvasMutations.set(A,[]),this.pendingCanvasMutations.get(A).push(e)};const{sampling:e="all",win:t,blockClass:r,blockSelector:n,recordCanvas:s,dataURLOptions:o}=A;this.mutationCb=A.mutationCb,this.mirror=A.mirror,s&&"all"===e&&this.initCanvasMutationObserver(t,r,n),s&&"number"==typeof e&&this.initCanvasFPSObserver(e,t,r,n,{dataURLOptions:o})}initCanvasFPSObserver(A,e,t,r,n){const s=xe(e,t,r,!0),o=new Map,i=new Ve;i.onmessage=A=>{const{id:e}=A.data;if(o.set(e,!1),!("base64"in A.data))return;const{base64:t,type:r,width:n,height:s}=A.data;this.mutationCb({id:e,type:$A["2D"],commands:[{property:"clearRect",args:[0,0,n,s]},{property:"drawImage",args:[{rr_type:"ImageBitmap",args:[{rr_type:"Blob",data:[{rr_type:"ArrayBuffer",base64:t}],type:r}]},0,0]}]})};const a=1e3/A;let c,B=0;const l=A=>{B&&A-B<a||(B=A,(()=>{const A=[];return e.document.querySelectorAll("canvas").forEach(e=>{xA(e,t,r,!0)||A.push(e)}),A})().forEach(A=>be(this,0,void 0,function*(){var e;const t=this.mirror.getId(A);if(o.get(t))return;if(0===A.width||0===A.height)return;if(o.set(t,!0),["webgl","webgl2"].includes(A.__context)){const t=A.getContext(A.__context);!1===(null===(e=null==t?void 0:t.getContextAttributes())||void 0===e?void 0:e.preserveDrawingBuffer)&&t.clear(t.COLOR_BUFFER_BIT)}const r=yield createImageBitmap(A);i.postMessage({id:t,bitmap:r,width:A.width,height:A.height,dataURLOptions:n.dataURLOptions},[r])}))),c=requestAnimationFrame(l)};c=requestAnimationFrame(l),this.resetObservers=()=>{s(),cancelAnimationFrame(c)}}initCanvasMutationObserver(A,e,t){this.startRAFTimestamping(),this.startPendingCanvasMutationFlusher();const r=xe(A,e,t,!1),n=function(A,e,t,r){const n=[],s=Object.getOwnPropertyNames(e.CanvasRenderingContext2D.prototype);for(const o of s)try{if("function"!=typeof e.CanvasRenderingContext2D.prototype[o])continue;const s=KA(e.CanvasRenderingContext2D.prototype,o,function(n){return function(...s){return xA(this.canvas,t,r,!0)||setTimeout(()=>{const t=Te(s,e,this);A(this.canvas,{type:$A["2D"],property:o,args:t})},0),n.apply(this,s)}});n.push(s)}catch(t){const r=LA(e.CanvasRenderingContext2D.prototype,o,{set(e){A(this.canvas,{type:$A["2D"],property:o,args:[e],setter:!0})}});n.push(r)}return()=>{n.forEach(A=>A())}}(this.processMutation.bind(this),A,e,t),s=function(A,e,t,r){const n=[];return n.push(...Re(e.WebGLRenderingContext.prototype,$A.WebGL,A,t,r,0,e)),void 0!==e.WebGL2RenderingContext&&n.push(...Re(e.WebGL2RenderingContext.prototype,$A.WebGL2,A,t,r,0,e)),()=>{n.forEach(A=>A())}}(this.processMutation.bind(this),A,e,t,this.mirror);this.resetObservers=()=>{r(),n(),s()}}startPendingCanvasMutationFlusher(){requestAnimationFrame(()=>this.flushPendingCanvasMutations())}startRAFTimestamping(){const A=e=>{this.rafStamps.latestId=e,requestAnimationFrame(A)};requestAnimationFrame(A)}flushPendingCanvasMutations(){this.pendingCanvasMutations.forEach((A,e)=>{const t=this.mirror.getId(e);this.flushPendingCanvasMutationFor(e,t)}),requestAnimationFrame(()=>this.flushPendingCanvasMutations())}flushPendingCanvasMutationFor(A,e){if(this.frozen||this.locked)return;const t=this.pendingCanvasMutations.get(A);if(!t||-1===e)return;const r=t.map(A=>{const e=function(A,e){var t={};for(var r in A)Object.prototype.hasOwnProperty.call(A,r)&&e.indexOf(r)<0&&(t[r]=A[r]);if(null!=A&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(r=Object.getOwnPropertySymbols(A);n<r.length;n++)e.indexOf(r[n])<0&&Object.prototype.propertyIsEnumerable.call(A,r[n])&&(t[r[n]]=A[r[n]])}return t}(A,["type"]);return e}),{type:n}=t[0];this.mutationCb({id:e,type:n,commands:r}),this.pendingCanvasMutations.delete(A)}}class Xe{constructor(A){this.trackedLinkElements=new WeakSet,this.styleMirror=new JA,this.mutationCb=A.mutationCb,this.adoptedStyleSheetCb=A.adoptedStyleSheetCb}attachLinkElement(A,e){"_cssText"in e.attributes&&this.mutationCb({adds:[],removes:[],texts:[],attributes:[{id:e.id,attributes:e.attributes}]}),this.trackLinkElement(A)}trackLinkElement(A){this.trackedLinkElements.has(A)||(this.trackedLinkElements.add(A),this.trackStylesheetInLinkElement(A))}adoptStyleSheets(A,e){if(0===A.length)return;const t={id:e,styleIds:[]},r=[];for(const e of A){let A;this.styleMirror.has(e)?A=this.styleMirror.getId(e):(A=this.styleMirror.add(e),r.push({styleId:A,rules:Array.from(e.rules||CSSRule,(A,e)=>({rule:z(A),index:e}))})),t.styleIds.push(A)}r.length>0&&(t.styles=r),this.adoptedStyleSheetCb(t)}reset(){this.styleMirror.reset(),this.trackedLinkElements=new WeakSet}trackStylesheetInLinkElement(A){}}class Je{constructor(){this.nodeMap=new WeakMap,this.loop=!0,this.periodicallyClear()}periodicallyClear(){requestAnimationFrame(()=>{this.clear(),this.loop&&this.periodicallyClear()})}inOtherBuffer(A,e){const t=this.nodeMap.get(A);return t&&Array.from(t).some(A=>A!==e)}add(A,e){this.nodeMap.set(A,(this.nodeMap.get(A)||new Set).add(e))}clear(){this.nodeMap=new WeakMap}destroy(){this.loop=!1}}function We(A){return Object.assign(Object.assign({},A),{timestamp:DA()})}let Ye,_e,Ze,je=!1;const qe=new $;function ze(A={}){const{emit:e,checkoutEveryNms:t,checkoutEveryNth:r,blockClass:n="rr-block",blockSelector:s=null,ignoreClass:o="rr-ignore",ignoreSelector:i=null,maskTextClass:a="rr-mask",maskTextSelector:c=null,inlineStylesheet:B=!0,maskAllInputs:l,maskInputOptions:u,slimDOMOptions:g,maskInputFn:d,maskTextFn:h,hooks:w,packFn:Q,sampling:p={},dataURLOptions:C={},mousemoveWait:f,recordDOM:U=!0,recordCanvas:F=!1,recordCrossOriginIframes:m=!1,recordAfter:y=("DOMContentLoaded"===A.recordAfter?A.recordAfter:"load"),userTriggeredOnInput:I=!1,collectFonts:E=!1,inlineImages:H=!1,plugins:v,keepIframeSrcFn:b=()=>!1,ignoreCSSAttributes:S=new Set([]),errorHandler:L}=A;Be(L);const K=!m||window.parent===window;let D=!1;if(!K)try{window.parent.document&&(D=!1)}catch(A){D=!0}if(K&&!e)throw new Error("emit function is required");void 0!==f&&void 0===p.mousemove&&(p.mousemove=f),qe.reset();const M=!0===l?{color:!0,date:!0,"datetime-local":!0,email:!0,month:!0,number:!0,range:!0,search:!0,tel:!0,text:!0,time:!0,url:!0,week:!0,textarea:!0,select:!0,password:!0}:void 0!==u?u:{password:!0},k=!0===g||"all"===g?{script:!0,comment:!0,headFavicon:!0,headWhitespace:!0,headMetaSocial:!0,headMetaRobots:!0,headMetaHttpEquiv:!0,headMetaVerification:!0,headMetaAuthorship:"all"===g,headMetaDescKeywords:"all"===g}:g||{};let T;!function(A=window){"NodeList"in A&&!A.NodeList.prototype.forEach&&(A.NodeList.prototype.forEach=Array.prototype.forEach),"DOMTokenList"in A&&!A.DOMTokenList.prototype.forEach&&(A.DOMTokenList.prototype.forEach=Array.prototype.forEach),Node.prototype.contains||(Node.prototype.contains=(...A)=>{let e=A[0];if(!(0 in A))throw new TypeError("1 argument is required");do{if(this===e)return!0}while(e=e&&e.parentNode);return!1})}();let O=0;const x=A=>{for(const e of v||[])e.eventProcessor&&(A=e.eventProcessor(A));return Q&&!D&&(A=Q(A)),A};Ye=(A,n)=>{var s;if(!(null===(s=ge[0])||void 0===s?void 0:s.isFrozen())||A.type===ZA.FullSnapshot||A.type===ZA.IncrementalSnapshot&&A.data.source===jA.Mutation||ge.forEach(A=>A.unfreeze()),K)null==e||e(x(A),n);else if(D){const e={type:"rrweb",event:x(A),origin:window.location.origin,isCheckout:n};window.parent.postMessage(e,"*")}if(A.type===ZA.FullSnapshot)T=A,O=0;else if(A.type===ZA.IncrementalSnapshot){if(A.data.source===jA.Mutation&&A.data.isAttachIframe)return;O++;const e=r&&O>=r,n=t&&A.timestamp-T.timestamp>t;(e||n)&&_e(!0)}};const R=A=>{Ye(We({type:ZA.IncrementalSnapshot,data:Object.assign({source:jA.Mutation},A)}))},N=A=>Ye(We({type:ZA.IncrementalSnapshot,data:Object.assign({source:jA.Scroll},A)})),G=A=>Ye(We({type:ZA.IncrementalSnapshot,data:Object.assign({source:jA.CanvasMutation},A)})),V=new Xe({mutationCb:R,adoptedStyleSheetCb:A=>Ye(We({type:ZA.IncrementalSnapshot,data:Object.assign({source:jA.AdoptedStyleSheet},A)}))}),P=new He({mirror:qe,mutationCb:R,stylesheetManager:V,recordCrossOriginIframes:m,wrappedEmit:Ye});for(const A of v||[])A.getMirror&&A.getMirror({nodeMirror:qe,crossOriginIframeMirror:P.crossOriginIframeMirror,crossOriginIframeStyleMirror:P.crossOriginIframeStyleMirror});const X=new Je;Ze=new Pe({recordCanvas:F,mutationCb:G,win:window,blockClass:n,blockSelector:s,mirror:qe,sampling:p.canvas,dataURLOptions:C});const J=new ve({mutationCb:R,scrollCb:N,bypassOptions:{blockClass:n,blockSelector:s,maskTextClass:a,maskTextSelector:c,inlineStylesheet:B,maskInputOptions:M,dataURLOptions:C,maskTextFn:h,maskInputFn:d,recordCanvas:F,inlineImages:H,sampling:p,slimDOMOptions:k,iframeManager:P,stylesheetManager:V,canvasManager:Ze,keepIframeSrcFn:b,processedNodeManager:X},mirror:qe});_e=(A=!1)=>{if(!U)return;Ye(We({type:ZA.Meta,data:{href:window.location.href,width:TA(),height:kA()}}),A),V.reset(),J.init(),ge.forEach(A=>A.lock());const e=function(A,e){const{mirror:t=new $,blockClass:r="rr-block",blockSelector:n=null,maskTextClass:s="rr-mask",maskTextSelector:o=null,inlineStylesheet:i=!0,inlineImages:a=!1,recordCanvas:c=!1,maskAllInputs:B=!1,maskTextFn:l,maskInputFn:u,slimDOM:g=!1,dataURLOptions:d,preserveWhiteSpace:h,onSerialize:w,onIframeLoad:Q,iframeLoadTimeout:p,onStylesheetLoad:C,stylesheetLoadTimeout:f,keepIframeSrcFn:U=()=>!1}=e||{};return EA(A,{doc:A,mirror:t,blockClass:r,blockSelector:n,maskTextClass:s,maskTextSelector:o,skipChild:!1,inlineStylesheet:i,maskInputOptions:!0===B?{color:!0,date:!0,"datetime-local":!0,email:!0,month:!0,number:!0,range:!0,search:!0,tel:!0,text:!0,time:!0,url:!0,week:!0,textarea:!0,select:!0,password:!0}:!1===B?{password:!0}:B,maskTextFn:l,maskInputFn:u,slimDOMOptions:!0===g||"all"===g?{script:!0,comment:!0,headFavicon:!0,headWhitespace:!0,headMetaDescKeywords:"all"===g,headMetaSocial:!0,headMetaRobots:!0,headMetaHttpEquiv:!0,headMetaAuthorship:!0,headMetaVerification:!0}:!1===g?{}:g,dataURLOptions:d,inlineImages:a,recordCanvas:c,preserveWhiteSpace:h,onSerialize:w,onIframeLoad:Q,iframeLoadTimeout:p,onStylesheetLoad:C,stylesheetLoadTimeout:f,keepIframeSrcFn:U,newlyAddedElement:!1})}(document,{mirror:qe,blockClass:n,blockSelector:s,maskTextClass:a,maskTextSelector:c,inlineStylesheet:B,maskAllInputs:M,maskTextFn:h,slimDOM:k,dataURLOptions:C,recordCanvas:F,inlineImages:H,onSerialize:A=>{VA(A,qe)&&P.addIframe(A),PA(A,qe)&&V.trackLinkElement(A),XA(A)&&J.addShadowRoot(A.shadowRoot,document)},onIframeLoad:(A,e)=>{P.attachIframe(A,e),J.observeAttachShadow(A)},onStylesheetLoad:(A,e)=>{V.attachLinkElement(A,e)},keepIframeSrcFn:b});if(!e)return console.warn("Failed to snapshot the document");Ye(We({type:ZA.FullSnapshot,data:{node:e,initialOffset:MA(window)}}),A),ge.forEach(A=>A.unlock()),document.adoptedStyleSheets&&document.adoptedStyleSheets.length>0&&V.adoptStyleSheets(document.adoptedStyleSheets,qe.getId(document))};try{const A=[],e=A=>{var e;return ue(me)({mutationCb:R,mousemoveCb:(A,e)=>Ye(We({type:ZA.IncrementalSnapshot,data:{source:e,positions:A}})),mouseInteractionCb:A=>Ye(We({type:ZA.IncrementalSnapshot,data:Object.assign({source:jA.MouseInteraction},A)})),scrollCb:N,viewportResizeCb:A=>Ye(We({type:ZA.IncrementalSnapshot,data:Object.assign({source:jA.ViewportResize},A)})),inputCb:A=>Ye(We({type:ZA.IncrementalSnapshot,data:Object.assign({source:jA.Input},A)})),mediaInteractionCb:A=>Ye(We({type:ZA.IncrementalSnapshot,data:Object.assign({source:jA.MediaInteraction},A)})),styleSheetRuleCb:A=>Ye(We({type:ZA.IncrementalSnapshot,data:Object.assign({source:jA.StyleSheetRule},A)})),styleDeclarationCb:A=>Ye(We({type:ZA.IncrementalSnapshot,data:Object.assign({source:jA.StyleDeclaration},A)})),canvasMutationCb:G,fontCb:A=>Ye(We({type:ZA.IncrementalSnapshot,data:Object.assign({source:jA.Font},A)})),selectionCb:A=>{Ye(We({type:ZA.IncrementalSnapshot,data:Object.assign({source:jA.Selection},A)}))},customElementCb:A=>{Ye(We({type:ZA.IncrementalSnapshot,data:Object.assign({source:jA.CustomElement},A)}))},blockClass:n,ignoreClass:o,ignoreSelector:i,maskTextClass:a,maskTextSelector:c,maskInputOptions:M,inlineStylesheet:B,sampling:p,recordDOM:U,recordCanvas:F,inlineImages:H,userTriggeredOnInput:I,collectFonts:E,doc:A,maskInputFn:d,maskTextFn:h,keepIframeSrcFn:b,blockSelector:s,slimDOMOptions:k,dataURLOptions:C,mirror:qe,iframeManager:P,stylesheetManager:V,shadowDomManager:J,processedNodeManager:X,canvasManager:Ze,ignoreCSSAttributes:S,plugins:(null===(e=null==v?void 0:v.filter(A=>A.observer))||void 0===e?void 0:e.map(A=>({observer:A.observer,options:A.options,callback:e=>Ye(We({type:ZA.Plugin,data:{plugin:A.name,payload:e}}))})))||[]},w)};P.addLoadListener(t=>{try{A.push(e(t.contentDocument))}catch(A){console.warn(A)}});const t=()=>{_e(),A.push(e(document)),je=!0};return"interactive"===document.readyState||"complete"===document.readyState?t():(A.push(HA("DOMContentLoaded",()=>{Ye(We({type:ZA.DomContentLoaded,data:{}})),"DOMContentLoaded"===y&&t()})),A.push(HA("load",()=>{Ye(We({type:ZA.Load,data:{}})),"load"===y&&t()},window))),()=>{A.forEach(A=>A()),X.destroy(),je=!1,le()}}catch(A){console.warn(A)}}ze.addCustomEvent=(A,e)=>{if(!je)throw new Error("please add custom event after start recording");Ye(We({type:ZA.Custom,data:{tag:A,payload:e}}))},ze.freezePage=()=>{ge.forEach(A=>A.freeze())},ze.takeFullSnapshot=A=>{if(!je)throw new Error("please take full snapshot after start recording");_e(A)},ze.mirror=qe;class $e{constructor(A,e,t,r=0){this.stopFn=null,this.events=[],this.onEventsReady=null,this.flushInterval=null,this.hasFullSnapshot=!1,this.sessionStartTime=0,this.recordingStartTime=0,this.sessionId=A,this.config=e,this.onEventsReady=t,this.sessionStartTime=r||Date.now(),this.recordingStartTime=Date.now(),console.log(`[RRWeb] Recording initialized - session started at ${this.sessionStartTime}, recording started at ${this.recordingStartTime}`)}start(){if(this.config.enabled)if(this.stopFn)console.warn("[RRWeb] Recording already started");else try{this.stopFn=ze({emit:A=>{const e=A.timestamp;A.timestamp=A.timestamp-this.sessionStartTime,this.config.enabled&&2===A.type&&console.log(`[RRWeb] FullSnapshot - original: ${e}, relative: ${A.timestamp}, session start: ${this.sessionStartTime}`),this.events.push(A),2===A.type?(this.hasFullSnapshot=!0,this.flush()):this.hasFullSnapshot&&this.events.length>=20&&this.flush()},sampling:{mousemove:void 0===this.config.sampleRate||Math.floor(100/this.config.sampleRate),mouseInteraction:!0,scroll:150,media:800,input:"last"},checkoutEveryNms:this.config.checkoutEveryNms||3e5,checkoutEveryNth:this.config.checkoutEveryNth||200,blockClass:this.config.blockClass||"rr-block",ignoreClass:this.config.ignoreClass||"rr-ignore",maskAllInputs:void 0===this.config.maskAllInputs||this.config.maskAllInputs,maskInputOptions:this.config.maskInputOptions||{password:!0,email:!0,tel:!0},maskTextClass:"rr-mask",inlineStylesheet:void 0===this.config.inlineStylesheet||this.config.inlineStylesheet,recordCanvas:this.config.recordCanvas||!1,collectFonts:void 0===this.config.collectFonts||this.config.collectFonts,recordCrossOriginIframes:!1}),this.flushInterval=window.setInterval(()=>{this.hasFullSnapshot&&this.events.length>0&&this.flush()},2e3),setTimeout(()=>{if(!this.hasFullSnapshot)try{ze.takeFullSnapshot()}catch(A){this.events.length>0&&(this.hasFullSnapshot=!0,this.flush())}},2e3)}catch(A){console.error("[RRWeb] Failed to start recording:",A)}else console.log("[RRWeb] Recording disabled in config")}stop(){this.stopFn&&(this.stopFn(),this.stopFn=null),this.flushInterval&&(clearInterval(this.flushInterval),this.flushInterval=null),this.events.length>0&&this.flush()}flush(){if(0===this.events.length)return;const A=[...this.events];this.events=[],this.onEventsReady&&this.onEventsReady(A)}getEventCount(){return this.events.length}isRecording(){return null!==this.stopFn}}class At{constructor(A){this.config=A,this.queue=[],this.flushInterval=null,this.maxQueueSize=20,this.flushIntervalMs=2e3,this.sessionId=null,this.apiUrl=A.apiUrl||"https://api.devskin.com",this.startPeriodicFlush(),"undefined"!=typeof window&&(window.addEventListener("beforeunload",()=>{this.flush()}),window.addEventListener("visibilitychange",()=>{document.hidden&&this.flush(!0)}))}setSessionId(A){this.sessionId=A}sendEvent(A){this.enqueue("event",A)}identifyUser(A){this.sendToBackend("/v1/analytics/identify",A)}startSession(e){return A(this,arguments,void 0,function*(A,e=!1){yield this.sendToBackend("/v1/rum/sessions",A,e)})}sendError(A){this.enqueue("error",A)}sendNetworkRequest(A){this.enqueue("network",A)}sendPerformanceMetric(A){this.enqueue("performance",A)}sendPageView(e){return A(this,void 0,void 0,function*(){this.sendToBackend("/v1/rum/page-views",e)})}sendRecordingEvents(e,t){return A(this,void 0,void 0,function*(){const A={session_id:e,events:t,timestamp:(new Date).toISOString(),apiKey:this.config.apiKey,appId:this.config.appId},r=new Blob([JSON.stringify(A)]).size,n=t.some(A=>2===A.type),s=n?3:1;let o=null;for(let A=1;A<=s;A++)try{return void(r>1e5?yield this.sendToBackendXHR("/v1/rum/recordings",{session_id:e,events:t,timestamp:(new Date).toISOString()}):yield this.sendToBackend("/v1/rum/recordings",{session_id:e,events:t,timestamp:(new Date).toISOString()}))}catch(e){if(o=e,A<s){const e=1e3*A;yield new Promise(A=>setTimeout(A,e))}}this.config.debug&&console.error(`[DevSkin SDK] Failed to send recording events after ${s} attempts:`,o)})}sendHeatmapData(A){this.enqueue("heatmap",A)}sendScreenshot(e){return A(this,void 0,void 0,function*(){yield this.sendToBackend("/v1/sdk/screenshot",{screenshot:e})})}flush(A=!1){if(0===this.queue.length)return;const e=[...this.queue];this.queue=[];const t={};e.forEach(A=>{t[A.type]||(t[A.type]=[]),t[A.type].push(A.data)}),Object.entries(t).forEach(([e,t])=>{const r=this.getEndpointForType(e);"event"===e&&t.length>1?this.sendToBackend("/v1/rum/events/batch",{events:t},A):"heatmap"===e?this.sendToBackend(r,{heatmaps:t,apiKey:this.config.apiKey,appId:this.config.appId},A):t.forEach(e=>{this.sendToBackend(r,e,A)})}),this.config.debug&&console.log(`[DevSkin] Flushed ${e.length} items to backend`)}enqueue(A,e){let t=e;"heatmap"!==A&&(t=Object.assign(Object.assign({},e),{applicationId:this.config.appId}),"network"!==A&&"performance"!==A||!this.sessionId||(t.sessionId=this.sessionId)),this.queue.push({type:A,data:t,timestamp:Date.now()}),this.queue.length>=this.maxQueueSize&&this.flush()}startPeriodicFlush(){this.flushInterval=setInterval(()=>{this.flush()},this.flushIntervalMs)}getEndpointForType(A){switch(A){case"event":default:return"/v1/rum/events";case"error":return"/v1/errors/errors";case"network":return"/v1/rum/network-requests";case"performance":return"/v1/rum/web-vitals";case"heatmap":return"/v1/sdk/heatmap"}}sendToBackendXHR(e,t){return A(this,void 0,void 0,function*(){const A=`${this.apiUrl}${e}`,r=Object.assign(Object.assign({},t),{apiKey:this.config.apiKey,applicationId:this.config.appId,environment:this.config.environment,release:this.config.release});if(this.config.beforeSend){if(!this.config.beforeSend(r))return}return new Promise((t,n)=>{const s=new XMLHttpRequest;s.open("POST",A,!0),s.setRequestHeader("Content-Type","application/json"),s.setRequestHeader("Authorization",`Bearer ${this.config.apiKey}`),s.onload=()=>{s.status>=200&&s.status<300?(this.config.debug&&console.log("[DevSkin] Data sent successfully via XHR:",e),t()):(console.error("[DevSkin] XHR HTTP Error:",s.status,s.responseText),n(new Error(`HTTP ${s.status}: ${s.statusText}`)))},s.onerror=()=>{console.error("[DevSkin] XHR network error:",e),n(new Error("Network error"))},s.ontimeout=()=>{console.error("[DevSkin] XHR timeout:",e),n(new Error("Request timeout"))},s.timeout=3e4;try{const A=JSON.stringify(r);s.send(A)}catch(A){console.error("[DevSkin] Failed to send XHR request:",A),n(A)}})})}sendToBackend(e,t){return A(this,arguments,void 0,function*(A,e,t=!1){const r=`${this.apiUrl}${A}`,n=Object.assign(Object.assign({},e),{apiKey:this.config.apiKey,applicationId:this.config.appId,environment:this.config.environment,release:this.config.release});if(this.config.beforeSend){if(!this.config.beforeSend(n))return}if(t&&navigator.sendBeacon){const A=new Blob([JSON.stringify(n)],{type:"application/json"});return void navigator.sendBeacon(r,A)}try{const e=yield fetch(r,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.config.apiKey}`},body:JSON.stringify(n),keepalive:!0});if(!e.ok){const A=yield e.text();throw console.error("[DevSkin] HTTP Error:",e.status,A),new Error(`HTTP ${e.status}: ${e.statusText}`)}this.config.debug&&console.log("[DevSkin] Data sent successfully:",A)}catch(e){throw console.error("[DevSkin] Failed to send data to",A,":",e),e}})}destroy(){this.flushInterval&&(clearInterval(this.flushInterval),this.flushInterval=null),this.flush()}}return new class{constructor(){this.config=null,this.transport=null,this.sessionId=null,this.userId=null,this.anonymousId=null,this.sessionStartTime=0,this.initialized=!1,this.heartbeatInterval=null,this.deviceCollector=null,this.locationCollector=null,this.browserCollector=null,this.performanceCollector=null,this.errorCollector=null,this.networkCollector=null,this.heatmapCollector=null,this.screenshotCollector=null,this.rrwebRecorder=null}init(A){this.initialized?console.warn("[DevSkin] SDK already initialized"):(this.config=Object.assign({debug:!1,captureWebVitals:!0,captureNetworkRequests:!0,captureErrors:!0,captureUserAgent:!0,captureLocation:!0,captureDevice:!0,heatmapOptions:{enabled:!0,trackClicks:!0,trackScroll:!0,trackMouseMovement:!1}},A),this.config.debug&&console.log("[DevSkin] Initializing SDK with config:",this.config),this.transport=new At(this.config),this.anonymousId=this.getOrCreateAnonymousId(),this.deviceCollector=new e(this.config),this.locationCollector=new t(this.config),this.browserCollector=new r(this.config),this.startSession().then(()=>{var A,e;this.config.captureWebVitals&&(this.performanceCollector=new N(this.config,this.transport),this.performanceCollector.start()),this.config.captureErrors&&(this.errorCollector=new G(this.config,this.transport),this.errorCollector.start()),this.config.captureNetworkRequests&&(this.networkCollector=new V(this.config,this.transport),this.networkCollector.start());const t=Object.assign({enabled:!0,trackClicks:!0,trackScroll:!0,trackMouseMovement:!0,mouseMoveSampling:.1},this.config.heatmapOptions);this.config.heatmapOptions=t,this.heatmapCollector=new P(this.config,this.transport),this.heatmapCollector.start(),this.screenshotCollector=new _(this.config,this.transport),this.screenshotCollector.captureAndSend(this.sessionId,window.location.href),this.config.debug&&console.log("[DevSkin] Heatmap collection enabled (always on)"),(null===(A=this.config.sessionRecording)||void 0===A?void 0:A.enabled)&&(this.rrwebRecorder=new $e(this.sessionId,{enabled:!0,sampleRate:this.config.sessionRecording.sampling||.5,blockClass:"rr-block",ignoreClass:this.config.sessionRecording.ignoreClass||"rr-ignore",maskAllInputs:void 0===this.config.sessionRecording.maskAllInputs||this.config.sessionRecording.maskAllInputs,maskInputOptions:{password:!0,email:!0,tel:!0},recordCanvas:this.config.sessionRecording.recordCanvas||!1,collectFonts:!0,inlineStylesheet:!0,checkoutEveryNms:3e5,checkoutEveryNth:200},A=>{var e;null===(e=this.transport)||void 0===e||e.sendRecordingEvents(this.sessionId,A)},this.sessionStartTime),this.rrwebRecorder.start(),(null===(e=this.config)||void 0===e?void 0:e.debug)&&console.log("[DevSkin] RRWeb recording started for session:",this.sessionId)),this.trackPageView(),this.startHeartbeat()}).catch(A=>{console.error("[DevSkin] Failed to create session:",A)}),this.setupVisibilityTracking(),this.setupUnloadTracking(),this.initialized=!0,this.config.debug&&console.log("[DevSkin] SDK initialized successfully"))}track(A,e){var t,r;if(!this.initialized)return void console.warn("[DevSkin] SDK not initialized. Call init() first.");const n={eventName:A,eventType:"track",timestamp:(new Date).toISOString(),sessionId:this.sessionId,userId:this.userId||void 0,anonymousId:this.anonymousId||void 0,properties:Object.assign(Object.assign({},e),this.getContextData()),pageUrl:window.location.href,pageTitle:document.title};null===(t=this.transport)||void 0===t||t.sendEvent(n),(null===(r=this.config)||void 0===r?void 0:r.debug)&&console.log("[DevSkin] Event tracked:",n)}trackPageView(A){var e,t;if(!this.initialized)return void console.warn("[DevSkin] SDK not initialized. Call init() first.");const r=this.generateId();null===(e=this.transport)||void 0===e||e.sendPageView(Object.assign({sessionId:this.sessionId,pageViewId:r,url:window.location.href,path:window.location.pathname,queryParams:window.location.search,referrer:document.referrer,title:document.title,timestamp:(new Date).toISOString()},A)),this.track("page_view",Object.assign({path:window.location.pathname,search:window.location.search,hash:window.location.hash,referrer:document.referrer},A)),(null===(t=this.config)||void 0===t?void 0:t.debug)&&console.log("[DevSkin] Page view tracked:",{sessionId:this.sessionId,pageViewId:r,url:window.location.href})}identify(A,e){var t,r;if(!this.initialized)return void console.warn("[DevSkin] SDK not initialized. Call init() first.");this.userId=A;const n={userId:A,anonymousId:this.anonymousId||void 0,traits:Object.assign(Object.assign({},e),this.getContextData()),sessionId:this.sessionId,timestamp:(new Date).toISOString()};null===(t=this.transport)||void 0===t||t.identifyUser(n),(null===(r=this.config)||void 0===r?void 0:r.debug)&&console.log("[DevSkin] User identified:",n)}captureError(A,e){var t;this.initialized?null===(t=this.errorCollector)||void 0===t||t.captureError(A,Object.assign(Object.assign({},e),{session_id:this.sessionId,user_id:this.userId||void 0})):console.warn("[DevSkin] SDK not initialized. Call init() first.")}addBreadcrumb(A){var e;this.initialized&&(null===(e=this.errorCollector)||void 0===e||e.addBreadcrumb(A))}startRecording(){var A;null===(A=this.rrwebRecorder)||void 0===A||A.start()}stopRecording(){var A;null===(A=this.rrwebRecorder)||void 0===A||A.stop()}optOut(){localStorage.setItem("devskin_opt_out","true"),this.initialized=!1}optIn(){localStorage.removeItem("devskin_opt_out")}startSession(){return A(this,void 0,void 0,function*(){var A,e,t,r,n;const s=sessionStorage.getItem("devskin_session_id"),o=sessionStorage.getItem("devskin_session_start");if(s&&o)return this.sessionId=s,this.sessionStartTime=parseInt(o,10),null===(A=this.transport)||void 0===A||A.setSessionId(this.sessionId),void((null===(e=this.config)||void 0===e?void 0:e.debug)&&console.log("[DevSkin] Resuming existing session:",this.sessionId));this.sessionId=this.generateId(),this.sessionStartTime=Date.now(),sessionStorage.setItem("devskin_session_id",this.sessionId),sessionStorage.setItem("devskin_session_start",this.sessionStartTime.toString()),null===(t=this.transport)||void 0===t||t.setSessionId(this.sessionId);const i=Object.assign({sessionId:this.sessionId,userId:this.userId||void 0,anonymousId:this.anonymousId,startedAt:(new Date).toISOString(),platform:"web"},this.getContextData());yield null===(r=this.transport)||void 0===r?void 0:r.startSession(i),(null===(n=this.config)||void 0===n?void 0:n.debug)&&console.log("[DevSkin] New session created:",this.sessionId)})}getContextData(){var A,e,t,r;const n={};if(this.deviceCollector){const s=this.deviceCollector.collect();n.deviceType=s.type,n.deviceModel=s.model,n.osName=null===(A=s.os)||void 0===A?void 0:A.name,n.osVersion=null===(e=s.os)||void 0===e?void 0:e.version,n.screenWidth=null===(t=s.screen)||void 0===t?void 0:t.width,n.screenHeight=null===(r=s.screen)||void 0===r?void 0:r.height,n.viewportWidth=window.innerWidth,n.viewportHeight=window.innerHeight}if(this.browserCollector){const A=this.browserCollector.collect();n.browserName=A.name,n.browserVersion=A.version,n.userAgent=A.userAgent}if(this.locationCollector){const A=this.locationCollector.collect();n.country=A.country,n.city=A.city,n.ipAddress=void 0}return n}getOrCreateAnonymousId(){let A=localStorage.getItem("devskin_anonymous_id");return A||(A=this.generateId(),localStorage.setItem("devskin_anonymous_id",A)),A}generateId(){return`${Date.now()}-${Math.random().toString(36).substr(2,9)}`}setupVisibilityTracking(){document.addEventListener("visibilitychange",()=>{document.hidden?this.track("page_hidden"):this.track("page_visible")})}setupUnloadTracking(){document.addEventListener("visibilitychange",()=>{var A,e;document.hidden&&(this.updateSessionDuration(),null===(A=this.rrwebRecorder)||void 0===A||A.stop(),null===(e=this.transport)||void 0===e||e.flush(!0))}),window.addEventListener("pagehide",()=>{var A,e;this.track("page_navigation"),this.updateSessionDuration(!1),null===(A=this.rrwebRecorder)||void 0===A||A.stop(),null===(e=this.transport)||void 0===e||e.flush(!0)}),window.addEventListener("beforeunload",()=>{var A,e;this.updateSessionDuration(!1),null===(A=this.rrwebRecorder)||void 0===A||A.stop(),null===(e=this.transport)||void 0===e||e.flush(!0)})}startHeartbeat(){this.heartbeatInterval=setInterval(()=>{this.updateSessionDuration()},3e4)}updateSessionDuration(A=!1){var e,t;if(!this.sessionId||!this.sessionStartTime)return;const r=Date.now()-this.sessionStartTime,n=Object.assign({sessionId:this.sessionId,userId:this.userId||void 0,anonymousId:this.anonymousId,durationMs:r,platform:"web"},this.getContextData());A&&(n.endedAt=(new Date).toISOString()),null===(e=this.transport)||void 0===e||e.startSession(n,A),(null===(t=this.config)||void 0===t?void 0:t.debug)&&console.log("[DevSkin] Session duration updated:",r,"ms",A?"(ending)":"")}}});
51
51
  //# sourceMappingURL=devskin.umd.min.js.map