@devskin/browser-sdk 1.0.12 → 1.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/devskin.cjs.js +16 -19
- package/dist/devskin.cjs.js.map +1 -1
- package/dist/devskin.esm.js +16 -19
- package/dist/devskin.esm.js.map +1 -1
- package/dist/devskin.umd.js +16 -19
- package/dist/devskin.umd.js.map +1 -1
- package/dist/devskin.umd.min.js +1 -1
- package/dist/devskin.umd.min.js.map +1 -1
- package/dist/recorder/rrweb.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/devskin.umd.min.js
CHANGED
|
@@ -27,5 +27,5 @@
|
|
|
27
27
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
28
28
|
PERFORMANCE OF THIS SOFTWARE.
|
|
29
29
|
***************************************************************************** */
|
|
30
|
-
function e(e,t,n,o){return new(n||(n=Promise))(function(t,r){function s(e){try{a(o.next(e))}catch(e){r(e)}}function i(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var o;e.done?t(e.value):(o=e.value,o instanceof n?o:new n(function(e){e(o)})).then(s,i)}a((o=o.apply(e,[])).next())})}for(var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n="undefined"==typeof Uint8Array?[]:new Uint8Array(256),o=0;o<64;o++)n[t.charCodeAt(o)]=o;var r=function(e){var n,o=new Uint8Array(e),r=o.length,s="";for(n=0;n<r;n+=3)s+=t[o[n]>>2],s+=t[(3&o[n])<<4|o[n+1]>>4],s+=t[(15&o[n+1])<<2|o[n+2]>>6],s+=t[63&o[n+2]];return r%3==2?s=s.substring(0,s.length-1)+"=":r%3==1&&(s=s.substring(0,s.length-2)+"=="),s};const s=new Map,i=new Map,a=self;a.onmessage=function(t){return e(this,0,void 0,function*(){if(!("OffscreenCanvas"in globalThis))return a.postMessage({id:t.data.id});{const{id:n,bitmap:o,width:l,height:c,dataURLOptions:d}=t.data,u=function(t,n,o){return e(this,0,void 0,function*(){const e=`${t}-${n}`;if("OffscreenCanvas"in globalThis){if(i.has(e))return i.get(e);const s=new OffscreenCanvas(t,n);s.getContext("2d");const a=yield s.convertToBlob(o),l=yield a.arrayBuffer(),c=r(l);return i.set(e,c),c}return""})}(l,c,d),h=new OffscreenCanvas(l,c);h.getContext("2d").drawImage(o,0,0),o.close();const p=yield h.convertToBlob(d),m=p.type,f=yield p.arrayBuffer(),g=r(f);if(!s.has(n)&&(yield u)===g)return s.set(n,g),a.postMessage({id:n});if(s.get(n)===g)return a.postMessage({id:n});a.postMessage({id:n,type:m,base64:g,width:l,height:c}),s.set(n,g)}})}}()},function(e){return Wt=Wt||function(e){var t=function(e){var t=e.toString().split("\n");t.pop(),t.shift();for(var n=t[0].search(/\S/),o=/(['"])__worker_loader_strict__(['"])/g,r=0,s=t.length;r<s;++r)t[r]=t[r].substring(n).replace(o,"$1use strict$2")+"\n";return t}(e),n=new Blob(t,{type:"application/javascript"});return URL.createObjectURL(n)}(_t),new Worker(Wt,e)});class jt{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(e){this.pendingCanvasMutations=new Map,this.rafStamps={latestId:0,invokeId:null},this.frozen=!1,this.locked=!1,this.processMutation=(e,t)=>{!(this.rafStamps.invokeId&&this.rafStamps.latestId!==this.rafStamps.invokeId)&&this.rafStamps.invokeId||(this.rafStamps.invokeId=this.rafStamps.latestId),this.pendingCanvasMutations.has(e)||this.pendingCanvasMutations.set(e,[]),this.pendingCanvasMutations.get(e).push(t)};const{sampling:t="all",win:n,blockClass:o,blockSelector:r,recordCanvas:s,dataURLOptions:i}=e;this.mutationCb=e.mutationCb,this.mirror=e.mirror,s&&"all"===t&&this.initCanvasMutationObserver(n,o,r),s&&"number"==typeof t&&this.initCanvasFPSObserver(t,n,o,r,{dataURLOptions:i})}initCanvasFPSObserver(e,t,n,o,r){const s=Ft(t,n,o,!0),i=new Map,a=new Pt;a.onmessage=e=>{const{id:t}=e.data;if(i.set(t,!1),!("base64"in e.data))return;const{base64:n,type:o,width:r,height:s}=e.data;this.mutationCb({id:t,type:Ke["2D"],commands:[{property:"clearRect",args:[0,0,r,s]},{property:"drawImage",args:[{rr_type:"ImageBitmap",args:[{rr_type:"Blob",data:[{rr_type:"ArrayBuffer",base64:n}],type:o}]},0,0]}]})};const l=1e3/e;let c,d=0;const u=e=>{d&&e-d<l||(d=e,(()=>{const e=[];return t.document.querySelectorAll("canvas").forEach(t=>{Fe(t,n,o,!0)||e.push(t)}),e})().forEach(e=>Mt(this,0,void 0,function*(){var t;const n=this.mirror.getId(e);if(i.get(n))return;if(0===e.width||0===e.height)return;if(i.set(n,!0),["webgl","webgl2"].includes(e.__context)){const n=e.getContext(e.__context);!1===(null===(t=null==n?void 0:n.getContextAttributes())||void 0===t?void 0:t.preserveDrawingBuffer)&&n.clear(n.COLOR_BUFFER_BIT)}const o=yield createImageBitmap(e);a.postMessage({id:n,bitmap:o,width:e.width,height:e.height,dataURLOptions:r.dataURLOptions},[o])}))),c=requestAnimationFrame(u)};c=requestAnimationFrame(u),this.resetObservers=()=>{s(),cancelAnimationFrame(c)}}initCanvasMutationObserver(e,t,n){this.startRAFTimestamping(),this.startPendingCanvasMutationFlusher();const o=Ft(e,t,n,!1),r=function(e,t,n,o){const r=[],s=Object.getOwnPropertyNames(t.CanvasRenderingContext2D.prototype);for(const i of s)try{if("function"!=typeof t.CanvasRenderingContext2D.prototype[i])continue;const s=Oe(t.CanvasRenderingContext2D.prototype,i,function(r){return function(...s){return Fe(this.canvas,n,o,!0)||setTimeout(()=>{const n=Lt(s,t,this);e(this.canvas,{type:Ke["2D"],property:i,args:n})},0),r.apply(this,s)}});r.push(s)}catch(n){const o=Te(t.CanvasRenderingContext2D.prototype,i,{set(t){e(this.canvas,{type:Ke["2D"],property:i,args:[t],setter:!0})}});r.push(o)}return()=>{r.forEach(e=>e())}}(this.processMutation.bind(this),e,t,n),s=function(e,t,n,o){const r=[];return r.push(...At(t.WebGLRenderingContext.prototype,Ke.WebGL,e,n,o,0,t)),void 0!==t.WebGL2RenderingContext&&r.push(...At(t.WebGL2RenderingContext.prototype,Ke.WebGL2,e,n,o,0,t)),()=>{r.forEach(e=>e())}}(this.processMutation.bind(this),e,t,n,this.mirror);this.resetObservers=()=>{o(),r(),s()}}startPendingCanvasMutationFlusher(){requestAnimationFrame(()=>this.flushPendingCanvasMutations())}startRAFTimestamping(){const e=t=>{this.rafStamps.latestId=t,requestAnimationFrame(e)};requestAnimationFrame(e)}flushPendingCanvasMutations(){this.pendingCanvasMutations.forEach((e,t)=>{const n=this.mirror.getId(t);this.flushPendingCanvasMutationFor(t,n)}),requestAnimationFrame(()=>this.flushPendingCanvasMutations())}flushPendingCanvasMutationFor(e,t){if(this.frozen||this.locked)return;const n=this.pendingCanvasMutations.get(e);if(!n||-1===t)return;const o=n.map(e=>{const t=function(e,t){var n={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(n[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(o=Object.getOwnPropertySymbols(e);r<o.length;r++)t.indexOf(o[r])<0&&Object.prototype.propertyIsEnumerable.call(e,o[r])&&(n[o[r]]=e[o[r]])}return n}(e,["type"]);return t}),{type:r}=n[0];this.mutationCb({id:t,type:r,commands:o}),this.pendingCanvasMutations.delete(e)}}class Ut{constructor(e){this.trackedLinkElements=new WeakSet,this.styleMirror=new Be,this.mutationCb=e.mutationCb,this.adoptedStyleSheetCb=e.adoptedStyleSheetCb}attachLinkElement(e,t){"_cssText"in t.attributes&&this.mutationCb({adds:[],removes:[],texts:[],attributes:[{id:t.id,attributes:t.attributes}]}),this.trackLinkElement(e)}trackLinkElement(e){this.trackedLinkElements.has(e)||(this.trackedLinkElements.add(e),this.trackStylesheetInLinkElement(e))}adoptStyleSheets(e,t){if(0===e.length)return;const n={id:t,styleIds:[]},o=[];for(const t of e){let e;this.styleMirror.has(t)?e=this.styleMirror.getId(t):(e=this.styleMirror.add(t),o.push({styleId:e,rules:Array.from(t.rules||CSSRule,(e,t)=>({rule:X(e),index:t}))})),n.styleIds.push(e)}o.length>0&&(n.styles=o),this.adoptedStyleSheetCb(n)}reset(){this.styleMirror.reset(),this.trackedLinkElements=new WeakSet}trackStylesheetInLinkElement(e){}}class Bt{constructor(){this.nodeMap=new WeakMap,this.loop=!0,this.periodicallyClear()}periodicallyClear(){requestAnimationFrame(()=>{this.clear(),this.loop&&this.periodicallyClear()})}inOtherBuffer(e,t){const n=this.nodeMap.get(e);return n&&Array.from(n).some(e=>e!==t)}add(e,t){this.nodeMap.set(e,(this.nodeMap.get(e)||new Set).add(t))}clear(){this.nodeMap=new WeakMap}destroy(){this.loop=!1}}function zt(e){return Object.assign(Object.assign({},e),{timestamp:De()})}let Ht,qt,$t,Vt=!1;const Gt=new K;function Xt(e={}){const{emit:t,checkoutEveryNms:n,checkoutEveryNth:o,blockClass:r="rr-block",blockSelector:s=null,ignoreClass:i="rr-ignore",ignoreSelector:a=null,maskTextClass:l="rr-mask",maskTextSelector:c=null,inlineStylesheet:d=!0,maskAllInputs:u,maskInputOptions:h,slimDOMOptions:p,maskInputFn:m,maskTextFn:f,hooks:g,packFn:v,sampling:y={},dataURLOptions:S={},mousemoveWait:b,recordDOM:w=!0,recordCanvas:k=!1,recordCrossOriginIframes:I=!1,recordAfter:C=("DOMContentLoaded"===e.recordAfter?e.recordAfter:"load"),userTriggeredOnInput:M=!1,collectFonts:E=!1,inlineImages:T=!1,plugins:O,keepIframeSrcFn:D=()=>!1,ignoreCSSAttributes:R=new Set([]),errorHandler:x}=e;it(x);const L=!I||window.parent===window;let N=!1;if(!L)try{window.parent.document&&(N=!1)}catch(e){N=!0}if(L&&!t)throw new Error("emit function is required");void 0!==b&&void 0===y.mousemove&&(y.mousemove=b),Gt.reset();const F=!0===u?{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!==h?h:{password:!0},A=!0===p||"all"===p?{script:!0,comment:!0,headFavicon:!0,headWhitespace:!0,headMetaSocial:!0,headMetaRobots:!0,headMetaHttpEquiv:!0,headMetaVerification:!0,headMetaAuthorship:"all"===p,headMetaDescKeywords:"all"===p}:p||{};let _;!function(e=window){"NodeList"in e&&!e.NodeList.prototype.forEach&&(e.NodeList.prototype.forEach=Array.prototype.forEach),"DOMTokenList"in e&&!e.DOMTokenList.prototype.forEach&&(e.DOMTokenList.prototype.forEach=Array.prototype.forEach),Node.prototype.contains||(Node.prototype.contains=(...e)=>{let t=e[0];if(!(0 in e))throw new TypeError("1 argument is required");do{if(this===t)return!0}while(t=t&&t.parentNode);return!1})}();let W=0;const P=e=>{for(const t of O||[])t.eventProcessor&&(e=t.eventProcessor(e));return v&&!N&&(e=v(e)),e};Ht=(e,r)=>{var s;if(!(null===(s=ct[0])||void 0===s?void 0:s.isFrozen())||e.type===$e.FullSnapshot||e.type===$e.IncrementalSnapshot&&e.data.source===Ve.Mutation||ct.forEach(e=>e.unfreeze()),L)null==t||t(P(e),r);else if(N){const t={type:"rrweb",event:P(e),origin:window.location.origin,isCheckout:r};window.parent.postMessage(t,"*")}if(e.type===$e.FullSnapshot)_=e,W=0;else if(e.type===$e.IncrementalSnapshot){if(e.data.source===Ve.Mutation&&e.data.isAttachIframe)return;W++;const t=o&&W>=o,r=n&&e.timestamp-_.timestamp>n;(t||r)&&qt(!0)}};const j=e=>{Ht(zt({type:$e.IncrementalSnapshot,data:Object.assign({source:Ve.Mutation},e)}))},U=e=>Ht(zt({type:$e.IncrementalSnapshot,data:Object.assign({source:Ve.Scroll},e)})),B=e=>Ht(zt({type:$e.IncrementalSnapshot,data:Object.assign({source:Ve.CanvasMutation},e)})),z=new Ut({mutationCb:j,adoptedStyleSheetCb:e=>Ht(zt({type:$e.IncrementalSnapshot,data:Object.assign({source:Ve.AdoptedStyleSheet},e)}))}),H=new It({mirror:Gt,mutationCb:j,stylesheetManager:z,recordCrossOriginIframes:I,wrappedEmit:Ht});for(const e of O||[])e.getMirror&&e.getMirror({nodeMirror:Gt,crossOriginIframeMirror:H.crossOriginIframeMirror,crossOriginIframeStyleMirror:H.crossOriginIframeStyleMirror});const q=new Bt;$t=new jt({recordCanvas:k,mutationCb:B,win:window,blockClass:r,blockSelector:s,mirror:Gt,sampling:y.canvas,dataURLOptions:S});const $=new Ct({mutationCb:j,scrollCb:U,bypassOptions:{blockClass:r,blockSelector:s,maskTextClass:l,maskTextSelector:c,inlineStylesheet:d,maskInputOptions:F,dataURLOptions:S,maskTextFn:f,maskInputFn:m,recordCanvas:k,inlineImages:T,sampling:y,slimDOMOptions:A,iframeManager:H,stylesheetManager:z,canvasManager:$t,keepIframeSrcFn:D,processedNodeManager:q},mirror:Gt});qt=(e=!1)=>{if(!w)return;Ht(zt({type:$e.Meta,data:{href:window.location.href,width:Le(),height:xe()}}),e),z.reset(),$.init(),ct.forEach(e=>e.lock());const t=function(e,t){const{mirror:n=new K,blockClass:o="rr-block",blockSelector:r=null,maskTextClass:s="rr-mask",maskTextSelector:i=null,inlineStylesheet:a=!0,inlineImages:l=!1,recordCanvas:c=!1,maskAllInputs:d=!1,maskTextFn:u,maskInputFn:h,slimDOM:p=!1,dataURLOptions:m,preserveWhiteSpace:f,onSerialize:g,onIframeLoad:v,iframeLoadTimeout:y,onStylesheetLoad:S,stylesheetLoadTimeout:b,keepIframeSrcFn:w=()=>!1}=t||{};return ke(e,{doc:e,mirror:n,blockClass:o,blockSelector:r,maskTextClass:s,maskTextSelector:i,skipChild:!1,inlineStylesheet:a,maskInputOptions:!0===d?{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===d?{password:!0}:d,maskTextFn:u,maskInputFn:h,slimDOMOptions:!0===p||"all"===p?{script:!0,comment:!0,headFavicon:!0,headWhitespace:!0,headMetaDescKeywords:"all"===p,headMetaSocial:!0,headMetaRobots:!0,headMetaHttpEquiv:!0,headMetaAuthorship:!0,headMetaVerification:!0}:!1===p?{}:p,dataURLOptions:m,inlineImages:l,recordCanvas:c,preserveWhiteSpace:f,onSerialize:g,onIframeLoad:v,iframeLoadTimeout:y,onStylesheetLoad:S,stylesheetLoadTimeout:b,keepIframeSrcFn:w,newlyAddedElement:!1})}(document,{mirror:Gt,blockClass:r,blockSelector:s,maskTextClass:l,maskTextSelector:c,inlineStylesheet:d,maskAllInputs:F,maskTextFn:f,slimDOM:A,dataURLOptions:S,recordCanvas:k,inlineImages:T,onSerialize:e=>{Pe(e,Gt)&&H.addIframe(e),je(e,Gt)&&z.trackLinkElement(e),Ue(e)&&$.addShadowRoot(e.shadowRoot,document)},onIframeLoad:(e,t)=>{H.attachIframe(e,t),$.observeAttachShadow(e)},onStylesheetLoad:(e,t)=>{z.attachLinkElement(e,t)},keepIframeSrcFn:D});if(!t)return console.warn("Failed to snapshot the document");Ht(zt({type:$e.FullSnapshot,data:{node:t,initialOffset:Re(window)}}),e),ct.forEach(e=>e.unlock()),document.adoptedStyleSheets&&document.adoptedStyleSheets.length>0&&z.adoptStyleSheets(document.adoptedStyleSheets,Gt.getId(document))};try{const e=[],t=e=>{var t;return lt(St)({mutationCb:j,mousemoveCb:(e,t)=>Ht(zt({type:$e.IncrementalSnapshot,data:{source:t,positions:e}})),mouseInteractionCb:e=>Ht(zt({type:$e.IncrementalSnapshot,data:Object.assign({source:Ve.MouseInteraction},e)})),scrollCb:U,viewportResizeCb:e=>Ht(zt({type:$e.IncrementalSnapshot,data:Object.assign({source:Ve.ViewportResize},e)})),inputCb:e=>Ht(zt({type:$e.IncrementalSnapshot,data:Object.assign({source:Ve.Input},e)})),mediaInteractionCb:e=>Ht(zt({type:$e.IncrementalSnapshot,data:Object.assign({source:Ve.MediaInteraction},e)})),styleSheetRuleCb:e=>Ht(zt({type:$e.IncrementalSnapshot,data:Object.assign({source:Ve.StyleSheetRule},e)})),styleDeclarationCb:e=>Ht(zt({type:$e.IncrementalSnapshot,data:Object.assign({source:Ve.StyleDeclaration},e)})),canvasMutationCb:B,fontCb:e=>Ht(zt({type:$e.IncrementalSnapshot,data:Object.assign({source:Ve.Font},e)})),selectionCb:e=>{Ht(zt({type:$e.IncrementalSnapshot,data:Object.assign({source:Ve.Selection},e)}))},customElementCb:e=>{Ht(zt({type:$e.IncrementalSnapshot,data:Object.assign({source:Ve.CustomElement},e)}))},blockClass:r,ignoreClass:i,ignoreSelector:a,maskTextClass:l,maskTextSelector:c,maskInputOptions:F,inlineStylesheet:d,sampling:y,recordDOM:w,recordCanvas:k,inlineImages:T,userTriggeredOnInput:M,collectFonts:E,doc:e,maskInputFn:m,maskTextFn:f,keepIframeSrcFn:D,blockSelector:s,slimDOMOptions:A,dataURLOptions:S,mirror:Gt,iframeManager:H,stylesheetManager:z,shadowDomManager:$,processedNodeManager:q,canvasManager:$t,ignoreCSSAttributes:R,plugins:(null===(t=null==O?void 0:O.filter(e=>e.observer))||void 0===t?void 0:t.map(e=>({observer:e.observer,options:e.options,callback:t=>Ht(zt({type:$e.Plugin,data:{plugin:e.name,payload:t}}))})))||[]},g)};H.addLoadListener(n=>{try{e.push(t(n.contentDocument))}catch(e){console.warn(e)}});const n=()=>{qt(),e.push(t(document)),Vt=!0};return"interactive"===document.readyState||"complete"===document.readyState?n():(e.push(Ie("DOMContentLoaded",()=>{Ht(zt({type:$e.DomContentLoaded,data:{}})),"DOMContentLoaded"===C&&n()})),e.push(Ie("load",()=>{Ht(zt({type:$e.Load,data:{}})),"load"===C&&n()},window))),()=>{e.forEach(e=>e()),q.destroy(),Vt=!1,at()}}catch(e){console.warn(e)}}Xt.addCustomEvent=(e,t)=>{if(!Vt)throw new Error("please add custom event after start recording");Ht(zt({type:$e.Custom,data:{tag:e,payload:t}}))},Xt.freezePage=()=>{ct.forEach(e=>e.freeze())},Xt.takeFullSnapshot=e=>{if(!Vt)throw new Error("please take full snapshot after start recording");qt(e)},Xt.mirror=Gt;class Kt{constructor(e,t,n){this.stopFn=null,this.events=[],this.onEventsReady=null,this.flushInterval=null,this.hasFullSnapshot=!1,this.sessionId=e,this.config=t,this.onEventsReady=n}start(){if(this.config.enabled)if(this.stopFn)console.warn("[RRWeb] Recording already started");else try{console.log("[RRWeb] Starting session recording:",this.sessionId),console.log("[RRWeb] SDK Version: 1.0.12"),this.stopFn=Xt({emit:e=>{this.hasFullSnapshot||console.log("[RRWeb] Event captured:",{type:e.type,timestamp:e.timestamp,hasData:!!e.data}),this.events.push(e),2===e.type?(this.hasFullSnapshot=!0,console.log("[RRWeb] ✅ FullSnapshot captured! Sending immediately..."),console.log("[RRWeb] FullSnapshot data keys:",Object.keys(e.data||{})),this.flush()):this.hasFullSnapshot&&this.events.length>=50&&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()},1e4),setTimeout(()=>{if(!this.hasFullSnapshot){console.warn("[RRWeb] ⚠️ No FullSnapshot captured after 5 seconds!"),console.warn("[RRWeb] Events captured so far:",this.events.length),console.warn("[RRWeb] Event types:",this.events.map(e=>e.type)),console.warn("[RRWeb] Forcing a full snapshot via takeFullSnapshot()...");try{this.stopFn&&"function"==typeof this.stopFn&&(console.warn("[RRWeb] Triggering manual checkout..."),this.events.length>0&&(console.warn("[RRWeb] Flushing existing events..."),this.hasFullSnapshot=!0,this.flush()))}catch(e){console.error("[RRWeb] Failed to force snapshot:",e)}}},5e3),console.log("[RRWeb] Recording started successfully")}catch(e){console.error("[RRWeb] Failed to start recording:",e)}else console.log("[RRWeb] Recording disabled in config")}stop(){this.stopFn&&(this.stopFn(),this.stopFn=null,console.log("[RRWeb] Recording stopped")),this.flushInterval&&(clearInterval(this.flushInterval),this.flushInterval=null),this.events.length>0&&(this.hasFullSnapshot||console.warn("[RRWeb] Flushing events without FullSnapshot - recording may not replay correctly"),this.flush())}flush(){if(0===this.events.length)return;const e=[...this.events];this.events=[];const t={};e.forEach(e=>{t[e.type]=(t[e.type]||0)+1}),console.log("[RRWeb] Flushing events:",t),this.onEventsReady&&this.onEventsReady(e)}getEventCount(){return this.events.length}isRecording(){return null!==this.stopFn}}class Yt{constructor(e){this.config=e,this.queue=[],this.flushInterval=null,this.maxQueueSize=50,this.flushIntervalMs=5e3,this.apiUrl=e.apiUrl||"https://api.devskin.com",this.startPeriodicFlush(),"undefined"!=typeof window&&(window.addEventListener("beforeunload",()=>{this.flush()}),window.addEventListener("visibilitychange",()=>{document.hidden&&this.flush(!0)}))}sendEvent(e){this.enqueue("event",e)}identifyUser(e){this.sendToBackend("/v1/analytics/identify",e)}startSession(e){this.sendToBackend("/v1/analytics/session",e)}sendError(e){this.enqueue("error",e)}sendNetworkRequest(e){this.enqueue("network",e)}sendPerformanceMetric(e){this.enqueue("performance",e)}sendRecordingEvents(e,n){return t(this,void 0,void 0,function*(){const t=n.reduce((e,t)=>(e[t.type]=(e[t.type]||0)+1,e),{});console.log(`[DevSkin SDK] Sending ${n.length} recording events:`,t),console.log("[DevSkin SDK] First 3 events:",n.slice(0,3).map(e=>({type:e.type,timestamp:e.timestamp})));const o=n.some(e=>2===e.type),r=o?3:1;let s=null;for(let t=1;t<=r;t++)try{return yield this.sendToBackend("/v1/rum/recordings",{session_id:e,events:n,timestamp:(new Date).toISOString()}),void console.log("[DevSkin SDK] ✅ Recording events sent successfully"+(t>1?` (attempt ${t})`:""))}catch(e){if(s=e,t<r){const e=1e3*t;console.warn(`[DevSkin SDK] ⚠️ Failed to send recording events (attempt ${t}/${r}), retrying in ${e}ms...`),yield new Promise(t=>setTimeout(t,e))}}console.error(`[DevSkin SDK] ❌ Failed to send recording events after ${r} attempts:`,s)})}sendHeatmapData(e){this.enqueue("heatmap",e)}flush(e=!1){if(0===this.queue.length)return;const t=[...this.queue];this.queue=[];const n={};t.forEach(e=>{n[e.type]||(n[e.type]=[]),n[e.type].push(e.data)}),Object.entries(n).forEach(([t,n])=>{const o=this.getEndpointForType(t);this.sendToBackend(o,{[t+"s"]:n},e)}),this.config.debug&&console.log(`[DevSkin] Flushed ${t.length} items to backend`)}enqueue(e,t){this.queue.push({type:e,data:t,timestamp:Date.now()}),this.queue.length>=this.maxQueueSize&&this.flush()}startPeriodicFlush(){this.flushInterval=setInterval(()=>{this.flush()},this.flushIntervalMs)}getEndpointForType(e){switch(e){case"event":default:return"/v1/analytics/events";case"error":return"/v1/analytics/errors";case"network":return"/v1/analytics/network";case"performance":return"/v1/analytics/performance";case"heatmap":return"/v1/analytics/heatmap"}}sendToBackend(e,n){return t(this,arguments,void 0,function*(e,t,n=!1){const o=`${this.apiUrl}${e}`,r=Object.assign(Object.assign({},t),{apiKey:this.config.apiKey,appId:this.config.appId,environment:this.config.environment,release:this.config.release});if(this.config.beforeSend){if(!this.config.beforeSend(r))return}if(n&&navigator.sendBeacon){const e=new Blob([JSON.stringify(r)],{type:"application/json"});return void navigator.sendBeacon(o,e)}try{const t=yield fetch(o,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.config.apiKey}`},body:JSON.stringify(r),keepalive:!0});if(!t.ok){const e=yield t.text();throw console.error("[DevSkin] HTTP Error:",t.status,e),new Error(`HTTP ${t.status}: ${t.statusText}`)}this.config.debug&&console.log("[DevSkin] Data sent successfully:",e)}catch(t){throw console.error("[DevSkin] Failed to send data to",e,":",t),t}})}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.deviceCollector=null,this.locationCollector=null,this.browserCollector=null,this.performanceCollector=null,this.errorCollector=null,this.networkCollector=null,this.heatmapCollector=null,this.rrwebRecorder=null}init(t){var r,s;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},t),this.config.debug&&console.log("[DevSkin] Initializing SDK with config:",this.config),this.transport=new Yt(this.config),this.anonymousId=this.getOrCreateAnonymousId(),this.deviceCollector=new e(this.config),this.locationCollector=new n(this.config),this.browserCollector=new o(this.config),this.startSession(),this.config.captureWebVitals&&(this.performanceCollector=new B(this.config,this.transport),this.performanceCollector.start()),this.config.captureErrors&&(this.errorCollector=new z(this.config,this.transport),this.errorCollector.start()),this.config.captureNetworkRequests&&(this.networkCollector=new H(this.config,this.transport),this.networkCollector.start()),(null===(r=this.config.heatmapOptions)||void 0===r?void 0:r.enabled)&&(this.heatmapCollector=new q(this.config,this.transport),this.heatmapCollector.start()),(null===(s=this.config.sessionRecording)||void 0===s?void 0:s.enabled)&&(this.rrwebRecorder=new Kt(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},e=>{var t;null===(t=this.transport)||void 0===t||t.sendRecordingEvents(this.sessionId,e)}),setTimeout(()=>{var e,t;null===(e=this.rrwebRecorder)||void 0===e||e.start(),(null===(t=this.config)||void 0===t?void 0:t.debug)&&console.log("[DevSkin] RRWeb recording started for session:",this.sessionId)},500)),this.trackPageView(),this.setupVisibilityTracking(),this.setupUnloadTracking(),this.initialized=!0,this.config.debug&&console.log("[DevSkin] SDK initialized successfully"))}track(e,t){var n,o;if(!this.initialized)return void console.warn("[DevSkin] SDK not initialized. Call init() first.");const r={event_name:e,event_type:"track",timestamp:(new Date).toISOString(),session_id:this.sessionId,user_id:this.userId||void 0,anonymous_id:this.anonymousId||void 0,properties:Object.assign(Object.assign({},t),this.getContextData()),page_url:window.location.href,page_title:document.title};null===(n=this.transport)||void 0===n||n.sendEvent(r),(null===(o=this.config)||void 0===o?void 0:o.debug)&&console.log("[DevSkin] Event tracked:",r)}trackPageView(e){this.track("page_view",Object.assign({path:window.location.pathname,search:window.location.search,hash:window.location.hash,referrer:document.referrer},e))}identify(e,t){var n,o;if(!this.initialized)return void console.warn("[DevSkin] SDK not initialized. Call init() first.");this.userId=e;const r={user_id:e,anonymous_id:this.anonymousId||void 0,traits:Object.assign(Object.assign({},t),this.getContextData()),session_id:this.sessionId,timestamp:(new Date).toISOString()};null===(n=this.transport)||void 0===n||n.identifyUser(r),(null===(o=this.config)||void 0===o?void 0:o.debug)&&console.log("[DevSkin] User identified:",r)}captureError(e,t){var n;this.initialized?null===(n=this.errorCollector)||void 0===n||n.captureError(e,Object.assign(Object.assign({},t),{session_id:this.sessionId,user_id:this.userId||void 0})):console.warn("[DevSkin] SDK not initialized. Call init() first.")}addBreadcrumb(e){var t;this.initialized&&(null===(t=this.errorCollector)||void 0===t||t.addBreadcrumb(e))}startRecording(){var e;null===(e=this.rrwebRecorder)||void 0===e||e.start()}stopRecording(){var e;null===(e=this.rrwebRecorder)||void 0===e||e.stop()}optOut(){localStorage.setItem("devskin_opt_out","true"),this.initialized=!1}optIn(){localStorage.removeItem("devskin_opt_out")}startSession(){var e;this.sessionId=this.generateId(),this.sessionStartTime=Date.now();const t=Object.assign({session_id:this.sessionId,user_id:this.userId||void 0,anonymous_id:this.anonymousId,started_at:(new Date).toISOString()},this.getContextData());null===(e=this.transport)||void 0===e||e.startSession(t)}getContextData(){const e={};return this.deviceCollector&&(e.device=this.deviceCollector.collect()),this.browserCollector&&(e.browser=this.browserCollector.collect()),this.locationCollector&&(e.location=this.locationCollector.collect()),e}getOrCreateAnonymousId(){let e=localStorage.getItem("devskin_anonymous_id");return e||(e=this.generateId(),localStorage.setItem("devskin_anonymous_id",e)),e}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(){window.addEventListener("beforeunload",()=>{var e,t;if(this.track("page_unload"),this.sessionId&&this.sessionStartTime){const t=new Date,n=Date.now()-this.sessionStartTime;null===(e=this.transport)||void 0===e||e.startSession(Object.assign({session_id:this.sessionId,user_id:this.userId||void 0,anonymous_id:this.anonymousId,ended_at:t.toISOString(),duration_ms:n},this.getContextData()))}null===(t=this.transport)||void 0===t||t.flush(!0)})}}});
|
|
30
|
+
function e(e,t,n,o){return new(n||(n=Promise))(function(t,r){function s(e){try{a(o.next(e))}catch(e){r(e)}}function i(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var o;e.done?t(e.value):(o=e.value,o instanceof n?o:new n(function(e){e(o)})).then(s,i)}a((o=o.apply(e,[])).next())})}for(var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n="undefined"==typeof Uint8Array?[]:new Uint8Array(256),o=0;o<64;o++)n[t.charCodeAt(o)]=o;var r=function(e){var n,o=new Uint8Array(e),r=o.length,s="";for(n=0;n<r;n+=3)s+=t[o[n]>>2],s+=t[(3&o[n])<<4|o[n+1]>>4],s+=t[(15&o[n+1])<<2|o[n+2]>>6],s+=t[63&o[n+2]];return r%3==2?s=s.substring(0,s.length-1)+"=":r%3==1&&(s=s.substring(0,s.length-2)+"=="),s};const s=new Map,i=new Map,a=self;a.onmessage=function(t){return e(this,0,void 0,function*(){if(!("OffscreenCanvas"in globalThis))return a.postMessage({id:t.data.id});{const{id:n,bitmap:o,width:l,height:c,dataURLOptions:d}=t.data,u=function(t,n,o){return e(this,0,void 0,function*(){const e=`${t}-${n}`;if("OffscreenCanvas"in globalThis){if(i.has(e))return i.get(e);const s=new OffscreenCanvas(t,n);s.getContext("2d");const a=yield s.convertToBlob(o),l=yield a.arrayBuffer(),c=r(l);return i.set(e,c),c}return""})}(l,c,d),h=new OffscreenCanvas(l,c);h.getContext("2d").drawImage(o,0,0),o.close();const p=yield h.convertToBlob(d),m=p.type,f=yield p.arrayBuffer(),g=r(f);if(!s.has(n)&&(yield u)===g)return s.set(n,g),a.postMessage({id:n});if(s.get(n)===g)return a.postMessage({id:n});a.postMessage({id:n,type:m,base64:g,width:l,height:c}),s.set(n,g)}})}}()},function(e){return Wt=Wt||function(e){var t=function(e){var t=e.toString().split("\n");t.pop(),t.shift();for(var n=t[0].search(/\S/),o=/(['"])__worker_loader_strict__(['"])/g,r=0,s=t.length;r<s;++r)t[r]=t[r].substring(n).replace(o,"$1use strict$2")+"\n";return t}(e),n=new Blob(t,{type:"application/javascript"});return URL.createObjectURL(n)}(_t),new Worker(Wt,e)});class jt{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(e){this.pendingCanvasMutations=new Map,this.rafStamps={latestId:0,invokeId:null},this.frozen=!1,this.locked=!1,this.processMutation=(e,t)=>{!(this.rafStamps.invokeId&&this.rafStamps.latestId!==this.rafStamps.invokeId)&&this.rafStamps.invokeId||(this.rafStamps.invokeId=this.rafStamps.latestId),this.pendingCanvasMutations.has(e)||this.pendingCanvasMutations.set(e,[]),this.pendingCanvasMutations.get(e).push(t)};const{sampling:t="all",win:n,blockClass:o,blockSelector:r,recordCanvas:s,dataURLOptions:i}=e;this.mutationCb=e.mutationCb,this.mirror=e.mirror,s&&"all"===t&&this.initCanvasMutationObserver(n,o,r),s&&"number"==typeof t&&this.initCanvasFPSObserver(t,n,o,r,{dataURLOptions:i})}initCanvasFPSObserver(e,t,n,o,r){const s=Ft(t,n,o,!0),i=new Map,a=new Pt;a.onmessage=e=>{const{id:t}=e.data;if(i.set(t,!1),!("base64"in e.data))return;const{base64:n,type:o,width:r,height:s}=e.data;this.mutationCb({id:t,type:Ke["2D"],commands:[{property:"clearRect",args:[0,0,r,s]},{property:"drawImage",args:[{rr_type:"ImageBitmap",args:[{rr_type:"Blob",data:[{rr_type:"ArrayBuffer",base64:n}],type:o}]},0,0]}]})};const l=1e3/e;let c,d=0;const u=e=>{d&&e-d<l||(d=e,(()=>{const e=[];return t.document.querySelectorAll("canvas").forEach(t=>{Fe(t,n,o,!0)||e.push(t)}),e})().forEach(e=>Mt(this,0,void 0,function*(){var t;const n=this.mirror.getId(e);if(i.get(n))return;if(0===e.width||0===e.height)return;if(i.set(n,!0),["webgl","webgl2"].includes(e.__context)){const n=e.getContext(e.__context);!1===(null===(t=null==n?void 0:n.getContextAttributes())||void 0===t?void 0:t.preserveDrawingBuffer)&&n.clear(n.COLOR_BUFFER_BIT)}const o=yield createImageBitmap(e);a.postMessage({id:n,bitmap:o,width:e.width,height:e.height,dataURLOptions:r.dataURLOptions},[o])}))),c=requestAnimationFrame(u)};c=requestAnimationFrame(u),this.resetObservers=()=>{s(),cancelAnimationFrame(c)}}initCanvasMutationObserver(e,t,n){this.startRAFTimestamping(),this.startPendingCanvasMutationFlusher();const o=Ft(e,t,n,!1),r=function(e,t,n,o){const r=[],s=Object.getOwnPropertyNames(t.CanvasRenderingContext2D.prototype);for(const i of s)try{if("function"!=typeof t.CanvasRenderingContext2D.prototype[i])continue;const s=Oe(t.CanvasRenderingContext2D.prototype,i,function(r){return function(...s){return Fe(this.canvas,n,o,!0)||setTimeout(()=>{const n=Lt(s,t,this);e(this.canvas,{type:Ke["2D"],property:i,args:n})},0),r.apply(this,s)}});r.push(s)}catch(n){const o=Te(t.CanvasRenderingContext2D.prototype,i,{set(t){e(this.canvas,{type:Ke["2D"],property:i,args:[t],setter:!0})}});r.push(o)}return()=>{r.forEach(e=>e())}}(this.processMutation.bind(this),e,t,n),s=function(e,t,n,o){const r=[];return r.push(...At(t.WebGLRenderingContext.prototype,Ke.WebGL,e,n,o,0,t)),void 0!==t.WebGL2RenderingContext&&r.push(...At(t.WebGL2RenderingContext.prototype,Ke.WebGL2,e,n,o,0,t)),()=>{r.forEach(e=>e())}}(this.processMutation.bind(this),e,t,n,this.mirror);this.resetObservers=()=>{o(),r(),s()}}startPendingCanvasMutationFlusher(){requestAnimationFrame(()=>this.flushPendingCanvasMutations())}startRAFTimestamping(){const e=t=>{this.rafStamps.latestId=t,requestAnimationFrame(e)};requestAnimationFrame(e)}flushPendingCanvasMutations(){this.pendingCanvasMutations.forEach((e,t)=>{const n=this.mirror.getId(t);this.flushPendingCanvasMutationFor(t,n)}),requestAnimationFrame(()=>this.flushPendingCanvasMutations())}flushPendingCanvasMutationFor(e,t){if(this.frozen||this.locked)return;const n=this.pendingCanvasMutations.get(e);if(!n||-1===t)return;const o=n.map(e=>{const t=function(e,t){var n={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(n[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(o=Object.getOwnPropertySymbols(e);r<o.length;r++)t.indexOf(o[r])<0&&Object.prototype.propertyIsEnumerable.call(e,o[r])&&(n[o[r]]=e[o[r]])}return n}(e,["type"]);return t}),{type:r}=n[0];this.mutationCb({id:t,type:r,commands:o}),this.pendingCanvasMutations.delete(e)}}class Ut{constructor(e){this.trackedLinkElements=new WeakSet,this.styleMirror=new Be,this.mutationCb=e.mutationCb,this.adoptedStyleSheetCb=e.adoptedStyleSheetCb}attachLinkElement(e,t){"_cssText"in t.attributes&&this.mutationCb({adds:[],removes:[],texts:[],attributes:[{id:t.id,attributes:t.attributes}]}),this.trackLinkElement(e)}trackLinkElement(e){this.trackedLinkElements.has(e)||(this.trackedLinkElements.add(e),this.trackStylesheetInLinkElement(e))}adoptStyleSheets(e,t){if(0===e.length)return;const n={id:t,styleIds:[]},o=[];for(const t of e){let e;this.styleMirror.has(t)?e=this.styleMirror.getId(t):(e=this.styleMirror.add(t),o.push({styleId:e,rules:Array.from(t.rules||CSSRule,(e,t)=>({rule:X(e),index:t}))})),n.styleIds.push(e)}o.length>0&&(n.styles=o),this.adoptedStyleSheetCb(n)}reset(){this.styleMirror.reset(),this.trackedLinkElements=new WeakSet}trackStylesheetInLinkElement(e){}}class Bt{constructor(){this.nodeMap=new WeakMap,this.loop=!0,this.periodicallyClear()}periodicallyClear(){requestAnimationFrame(()=>{this.clear(),this.loop&&this.periodicallyClear()})}inOtherBuffer(e,t){const n=this.nodeMap.get(e);return n&&Array.from(n).some(e=>e!==t)}add(e,t){this.nodeMap.set(e,(this.nodeMap.get(e)||new Set).add(t))}clear(){this.nodeMap=new WeakMap}destroy(){this.loop=!1}}function zt(e){return Object.assign(Object.assign({},e),{timestamp:De()})}let Ht,qt,$t,Vt=!1;const Gt=new K;function Xt(e={}){const{emit:t,checkoutEveryNms:n,checkoutEveryNth:o,blockClass:r="rr-block",blockSelector:s=null,ignoreClass:i="rr-ignore",ignoreSelector:a=null,maskTextClass:l="rr-mask",maskTextSelector:c=null,inlineStylesheet:d=!0,maskAllInputs:u,maskInputOptions:h,slimDOMOptions:p,maskInputFn:m,maskTextFn:f,hooks:g,packFn:v,sampling:y={},dataURLOptions:S={},mousemoveWait:b,recordDOM:w=!0,recordCanvas:k=!1,recordCrossOriginIframes:I=!1,recordAfter:C=("DOMContentLoaded"===e.recordAfter?e.recordAfter:"load"),userTriggeredOnInput:M=!1,collectFonts:E=!1,inlineImages:T=!1,plugins:O,keepIframeSrcFn:D=()=>!1,ignoreCSSAttributes:R=new Set([]),errorHandler:x}=e;it(x);const L=!I||window.parent===window;let N=!1;if(!L)try{window.parent.document&&(N=!1)}catch(e){N=!0}if(L&&!t)throw new Error("emit function is required");void 0!==b&&void 0===y.mousemove&&(y.mousemove=b),Gt.reset();const F=!0===u?{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!==h?h:{password:!0},A=!0===p||"all"===p?{script:!0,comment:!0,headFavicon:!0,headWhitespace:!0,headMetaSocial:!0,headMetaRobots:!0,headMetaHttpEquiv:!0,headMetaVerification:!0,headMetaAuthorship:"all"===p,headMetaDescKeywords:"all"===p}:p||{};let _;!function(e=window){"NodeList"in e&&!e.NodeList.prototype.forEach&&(e.NodeList.prototype.forEach=Array.prototype.forEach),"DOMTokenList"in e&&!e.DOMTokenList.prototype.forEach&&(e.DOMTokenList.prototype.forEach=Array.prototype.forEach),Node.prototype.contains||(Node.prototype.contains=(...e)=>{let t=e[0];if(!(0 in e))throw new TypeError("1 argument is required");do{if(this===t)return!0}while(t=t&&t.parentNode);return!1})}();let W=0;const P=e=>{for(const t of O||[])t.eventProcessor&&(e=t.eventProcessor(e));return v&&!N&&(e=v(e)),e};Ht=(e,r)=>{var s;if(!(null===(s=ct[0])||void 0===s?void 0:s.isFrozen())||e.type===$e.FullSnapshot||e.type===$e.IncrementalSnapshot&&e.data.source===Ve.Mutation||ct.forEach(e=>e.unfreeze()),L)null==t||t(P(e),r);else if(N){const t={type:"rrweb",event:P(e),origin:window.location.origin,isCheckout:r};window.parent.postMessage(t,"*")}if(e.type===$e.FullSnapshot)_=e,W=0;else if(e.type===$e.IncrementalSnapshot){if(e.data.source===Ve.Mutation&&e.data.isAttachIframe)return;W++;const t=o&&W>=o,r=n&&e.timestamp-_.timestamp>n;(t||r)&&qt(!0)}};const j=e=>{Ht(zt({type:$e.IncrementalSnapshot,data:Object.assign({source:Ve.Mutation},e)}))},U=e=>Ht(zt({type:$e.IncrementalSnapshot,data:Object.assign({source:Ve.Scroll},e)})),B=e=>Ht(zt({type:$e.IncrementalSnapshot,data:Object.assign({source:Ve.CanvasMutation},e)})),z=new Ut({mutationCb:j,adoptedStyleSheetCb:e=>Ht(zt({type:$e.IncrementalSnapshot,data:Object.assign({source:Ve.AdoptedStyleSheet},e)}))}),H=new It({mirror:Gt,mutationCb:j,stylesheetManager:z,recordCrossOriginIframes:I,wrappedEmit:Ht});for(const e of O||[])e.getMirror&&e.getMirror({nodeMirror:Gt,crossOriginIframeMirror:H.crossOriginIframeMirror,crossOriginIframeStyleMirror:H.crossOriginIframeStyleMirror});const q=new Bt;$t=new jt({recordCanvas:k,mutationCb:B,win:window,blockClass:r,blockSelector:s,mirror:Gt,sampling:y.canvas,dataURLOptions:S});const $=new Ct({mutationCb:j,scrollCb:U,bypassOptions:{blockClass:r,blockSelector:s,maskTextClass:l,maskTextSelector:c,inlineStylesheet:d,maskInputOptions:F,dataURLOptions:S,maskTextFn:f,maskInputFn:m,recordCanvas:k,inlineImages:T,sampling:y,slimDOMOptions:A,iframeManager:H,stylesheetManager:z,canvasManager:$t,keepIframeSrcFn:D,processedNodeManager:q},mirror:Gt});qt=(e=!1)=>{if(!w)return;Ht(zt({type:$e.Meta,data:{href:window.location.href,width:Le(),height:xe()}}),e),z.reset(),$.init(),ct.forEach(e=>e.lock());const t=function(e,t){const{mirror:n=new K,blockClass:o="rr-block",blockSelector:r=null,maskTextClass:s="rr-mask",maskTextSelector:i=null,inlineStylesheet:a=!0,inlineImages:l=!1,recordCanvas:c=!1,maskAllInputs:d=!1,maskTextFn:u,maskInputFn:h,slimDOM:p=!1,dataURLOptions:m,preserveWhiteSpace:f,onSerialize:g,onIframeLoad:v,iframeLoadTimeout:y,onStylesheetLoad:S,stylesheetLoadTimeout:b,keepIframeSrcFn:w=()=>!1}=t||{};return ke(e,{doc:e,mirror:n,blockClass:o,blockSelector:r,maskTextClass:s,maskTextSelector:i,skipChild:!1,inlineStylesheet:a,maskInputOptions:!0===d?{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===d?{password:!0}:d,maskTextFn:u,maskInputFn:h,slimDOMOptions:!0===p||"all"===p?{script:!0,comment:!0,headFavicon:!0,headWhitespace:!0,headMetaDescKeywords:"all"===p,headMetaSocial:!0,headMetaRobots:!0,headMetaHttpEquiv:!0,headMetaAuthorship:!0,headMetaVerification:!0}:!1===p?{}:p,dataURLOptions:m,inlineImages:l,recordCanvas:c,preserveWhiteSpace:f,onSerialize:g,onIframeLoad:v,iframeLoadTimeout:y,onStylesheetLoad:S,stylesheetLoadTimeout:b,keepIframeSrcFn:w,newlyAddedElement:!1})}(document,{mirror:Gt,blockClass:r,blockSelector:s,maskTextClass:l,maskTextSelector:c,inlineStylesheet:d,maskAllInputs:F,maskTextFn:f,slimDOM:A,dataURLOptions:S,recordCanvas:k,inlineImages:T,onSerialize:e=>{Pe(e,Gt)&&H.addIframe(e),je(e,Gt)&&z.trackLinkElement(e),Ue(e)&&$.addShadowRoot(e.shadowRoot,document)},onIframeLoad:(e,t)=>{H.attachIframe(e,t),$.observeAttachShadow(e)},onStylesheetLoad:(e,t)=>{z.attachLinkElement(e,t)},keepIframeSrcFn:D});if(!t)return console.warn("Failed to snapshot the document");Ht(zt({type:$e.FullSnapshot,data:{node:t,initialOffset:Re(window)}}),e),ct.forEach(e=>e.unlock()),document.adoptedStyleSheets&&document.adoptedStyleSheets.length>0&&z.adoptStyleSheets(document.adoptedStyleSheets,Gt.getId(document))};try{const e=[],t=e=>{var t;return lt(St)({mutationCb:j,mousemoveCb:(e,t)=>Ht(zt({type:$e.IncrementalSnapshot,data:{source:t,positions:e}})),mouseInteractionCb:e=>Ht(zt({type:$e.IncrementalSnapshot,data:Object.assign({source:Ve.MouseInteraction},e)})),scrollCb:U,viewportResizeCb:e=>Ht(zt({type:$e.IncrementalSnapshot,data:Object.assign({source:Ve.ViewportResize},e)})),inputCb:e=>Ht(zt({type:$e.IncrementalSnapshot,data:Object.assign({source:Ve.Input},e)})),mediaInteractionCb:e=>Ht(zt({type:$e.IncrementalSnapshot,data:Object.assign({source:Ve.MediaInteraction},e)})),styleSheetRuleCb:e=>Ht(zt({type:$e.IncrementalSnapshot,data:Object.assign({source:Ve.StyleSheetRule},e)})),styleDeclarationCb:e=>Ht(zt({type:$e.IncrementalSnapshot,data:Object.assign({source:Ve.StyleDeclaration},e)})),canvasMutationCb:B,fontCb:e=>Ht(zt({type:$e.IncrementalSnapshot,data:Object.assign({source:Ve.Font},e)})),selectionCb:e=>{Ht(zt({type:$e.IncrementalSnapshot,data:Object.assign({source:Ve.Selection},e)}))},customElementCb:e=>{Ht(zt({type:$e.IncrementalSnapshot,data:Object.assign({source:Ve.CustomElement},e)}))},blockClass:r,ignoreClass:i,ignoreSelector:a,maskTextClass:l,maskTextSelector:c,maskInputOptions:F,inlineStylesheet:d,sampling:y,recordDOM:w,recordCanvas:k,inlineImages:T,userTriggeredOnInput:M,collectFonts:E,doc:e,maskInputFn:m,maskTextFn:f,keepIframeSrcFn:D,blockSelector:s,slimDOMOptions:A,dataURLOptions:S,mirror:Gt,iframeManager:H,stylesheetManager:z,shadowDomManager:$,processedNodeManager:q,canvasManager:$t,ignoreCSSAttributes:R,plugins:(null===(t=null==O?void 0:O.filter(e=>e.observer))||void 0===t?void 0:t.map(e=>({observer:e.observer,options:e.options,callback:t=>Ht(zt({type:$e.Plugin,data:{plugin:e.name,payload:t}}))})))||[]},g)};H.addLoadListener(n=>{try{e.push(t(n.contentDocument))}catch(e){console.warn(e)}});const n=()=>{qt(),e.push(t(document)),Vt=!0};return"interactive"===document.readyState||"complete"===document.readyState?n():(e.push(Ie("DOMContentLoaded",()=>{Ht(zt({type:$e.DomContentLoaded,data:{}})),"DOMContentLoaded"===C&&n()})),e.push(Ie("load",()=>{Ht(zt({type:$e.Load,data:{}})),"load"===C&&n()},window))),()=>{e.forEach(e=>e()),q.destroy(),Vt=!1,at()}}catch(e){console.warn(e)}}Xt.addCustomEvent=(e,t)=>{if(!Vt)throw new Error("please add custom event after start recording");Ht(zt({type:$e.Custom,data:{tag:e,payload:t}}))},Xt.freezePage=()=>{ct.forEach(e=>e.freeze())},Xt.takeFullSnapshot=e=>{if(!Vt)throw new Error("please take full snapshot after start recording");qt(e)},Xt.mirror=Gt;class Kt{constructor(e,t,n){this.stopFn=null,this.events=[],this.onEventsReady=null,this.flushInterval=null,this.hasFullSnapshot=!1,this.sessionId=e,this.config=t,this.onEventsReady=n}start(){if(this.config.enabled)if(this.stopFn)console.warn("[RRWeb] Recording already started");else try{console.log("[RRWeb] Starting session recording:",this.sessionId),console.log("[RRWeb] SDK Version: 1.0.13"),this.stopFn=Xt({emit:e=>{this.hasFullSnapshot||console.log("[RRWeb] Event captured:",{type:e.type,timestamp:e.timestamp,hasData:!!e.data}),this.events.push(e),2===e.type?(this.hasFullSnapshot=!0,console.log("[RRWeb] ✅ FullSnapshot captured! Sending immediately..."),console.log("[RRWeb] FullSnapshot data keys:",Object.keys(e.data||{})),this.flush()):this.hasFullSnapshot&&this.events.length>=50&&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()},1e4),setTimeout(()=>{if(!this.hasFullSnapshot){console.warn("[RRWeb] ⚠️ No FullSnapshot captured after 2 seconds!"),console.warn("[RRWeb] Events captured so far:",this.events.length),console.warn("[RRWeb] Event types:",this.events.map(e=>e.type)),console.warn("[RRWeb] Forcing a full snapshot via record.takeFullSnapshot()...");try{Xt.takeFullSnapshot(),console.log("[RRWeb] ✅ Manual FullSnapshot triggered!")}catch(e){console.error("[RRWeb] Failed to force snapshot:",e),this.events.length>0&&(console.warn("[RRWeb] Flushing existing events WITHOUT FullSnapshot..."),this.hasFullSnapshot=!0,this.flush())}}},2e3),console.log("[RRWeb] Recording started successfully")}catch(e){console.error("[RRWeb] Failed to start recording:",e)}else console.log("[RRWeb] Recording disabled in config")}stop(){this.stopFn&&(this.stopFn(),this.stopFn=null,console.log("[RRWeb] Recording stopped")),this.flushInterval&&(clearInterval(this.flushInterval),this.flushInterval=null),this.events.length>0&&(this.hasFullSnapshot||console.warn("[RRWeb] Flushing events without FullSnapshot - recording may not replay correctly"),this.flush())}flush(){if(0===this.events.length)return;const e=[...this.events];this.events=[];const t={};e.forEach(e=>{t[e.type]=(t[e.type]||0)+1}),console.log("[RRWeb] Flushing events:",t),this.onEventsReady&&this.onEventsReady(e)}getEventCount(){return this.events.length}isRecording(){return null!==this.stopFn}}class Yt{constructor(e){this.config=e,this.queue=[],this.flushInterval=null,this.maxQueueSize=50,this.flushIntervalMs=5e3,this.apiUrl=e.apiUrl||"https://api.devskin.com",this.startPeriodicFlush(),"undefined"!=typeof window&&(window.addEventListener("beforeunload",()=>{this.flush()}),window.addEventListener("visibilitychange",()=>{document.hidden&&this.flush(!0)}))}sendEvent(e){this.enqueue("event",e)}identifyUser(e){this.sendToBackend("/v1/analytics/identify",e)}startSession(e){this.sendToBackend("/v1/analytics/session",e)}sendError(e){this.enqueue("error",e)}sendNetworkRequest(e){this.enqueue("network",e)}sendPerformanceMetric(e){this.enqueue("performance",e)}sendRecordingEvents(e,n){return t(this,void 0,void 0,function*(){const t=n.reduce((e,t)=>(e[t.type]=(e[t.type]||0)+1,e),{});console.log(`[DevSkin SDK] Sending ${n.length} recording events:`,t),console.log("[DevSkin SDK] First 3 events:",n.slice(0,3).map(e=>({type:e.type,timestamp:e.timestamp})));const o=n.some(e=>2===e.type),r=o?3:1;let s=null;for(let t=1;t<=r;t++)try{return yield this.sendToBackend("/v1/rum/recordings",{session_id:e,events:n,timestamp:(new Date).toISOString()}),void console.log("[DevSkin SDK] ✅ Recording events sent successfully"+(t>1?` (attempt ${t})`:""))}catch(e){if(s=e,t<r){const e=1e3*t;console.warn(`[DevSkin SDK] ⚠️ Failed to send recording events (attempt ${t}/${r}), retrying in ${e}ms...`),yield new Promise(t=>setTimeout(t,e))}}console.error(`[DevSkin SDK] ❌ Failed to send recording events after ${r} attempts:`,s)})}sendHeatmapData(e){this.enqueue("heatmap",e)}flush(e=!1){if(0===this.queue.length)return;const t=[...this.queue];this.queue=[];const n={};t.forEach(e=>{n[e.type]||(n[e.type]=[]),n[e.type].push(e.data)}),Object.entries(n).forEach(([t,n])=>{const o=this.getEndpointForType(t);this.sendToBackend(o,{[t+"s"]:n},e)}),this.config.debug&&console.log(`[DevSkin] Flushed ${t.length} items to backend`)}enqueue(e,t){this.queue.push({type:e,data:t,timestamp:Date.now()}),this.queue.length>=this.maxQueueSize&&this.flush()}startPeriodicFlush(){this.flushInterval=setInterval(()=>{this.flush()},this.flushIntervalMs)}getEndpointForType(e){switch(e){case"event":default:return"/v1/analytics/events";case"error":return"/v1/analytics/errors";case"network":return"/v1/analytics/network";case"performance":return"/v1/analytics/performance";case"heatmap":return"/v1/analytics/heatmap"}}sendToBackend(e,n){return t(this,arguments,void 0,function*(e,t,n=!1){const o=`${this.apiUrl}${e}`,r=Object.assign(Object.assign({},t),{apiKey:this.config.apiKey,appId:this.config.appId,environment:this.config.environment,release:this.config.release});if(this.config.beforeSend){if(!this.config.beforeSend(r))return}if(n&&navigator.sendBeacon){const e=new Blob([JSON.stringify(r)],{type:"application/json"});return void navigator.sendBeacon(o,e)}try{const t=yield fetch(o,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.config.apiKey}`},body:JSON.stringify(r),keepalive:!0});if(!t.ok){const e=yield t.text();throw console.error("[DevSkin] HTTP Error:",t.status,e),new Error(`HTTP ${t.status}: ${t.statusText}`)}this.config.debug&&console.log("[DevSkin] Data sent successfully:",e)}catch(t){throw console.error("[DevSkin] Failed to send data to",e,":",t),t}})}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.deviceCollector=null,this.locationCollector=null,this.browserCollector=null,this.performanceCollector=null,this.errorCollector=null,this.networkCollector=null,this.heatmapCollector=null,this.rrwebRecorder=null}init(t){var r,s;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},t),this.config.debug&&console.log("[DevSkin] Initializing SDK with config:",this.config),this.transport=new Yt(this.config),this.anonymousId=this.getOrCreateAnonymousId(),this.deviceCollector=new e(this.config),this.locationCollector=new n(this.config),this.browserCollector=new o(this.config),this.startSession(),this.config.captureWebVitals&&(this.performanceCollector=new B(this.config,this.transport),this.performanceCollector.start()),this.config.captureErrors&&(this.errorCollector=new z(this.config,this.transport),this.errorCollector.start()),this.config.captureNetworkRequests&&(this.networkCollector=new H(this.config,this.transport),this.networkCollector.start()),(null===(r=this.config.heatmapOptions)||void 0===r?void 0:r.enabled)&&(this.heatmapCollector=new q(this.config,this.transport),this.heatmapCollector.start()),(null===(s=this.config.sessionRecording)||void 0===s?void 0:s.enabled)&&(this.rrwebRecorder=new Kt(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},e=>{var t;null===(t=this.transport)||void 0===t||t.sendRecordingEvents(this.sessionId,e)}),setTimeout(()=>{var e,t;null===(e=this.rrwebRecorder)||void 0===e||e.start(),(null===(t=this.config)||void 0===t?void 0:t.debug)&&console.log("[DevSkin] RRWeb recording started for session:",this.sessionId)},500)),this.trackPageView(),this.setupVisibilityTracking(),this.setupUnloadTracking(),this.initialized=!0,this.config.debug&&console.log("[DevSkin] SDK initialized successfully"))}track(e,t){var n,o;if(!this.initialized)return void console.warn("[DevSkin] SDK not initialized. Call init() first.");const r={event_name:e,event_type:"track",timestamp:(new Date).toISOString(),session_id:this.sessionId,user_id:this.userId||void 0,anonymous_id:this.anonymousId||void 0,properties:Object.assign(Object.assign({},t),this.getContextData()),page_url:window.location.href,page_title:document.title};null===(n=this.transport)||void 0===n||n.sendEvent(r),(null===(o=this.config)||void 0===o?void 0:o.debug)&&console.log("[DevSkin] Event tracked:",r)}trackPageView(e){this.track("page_view",Object.assign({path:window.location.pathname,search:window.location.search,hash:window.location.hash,referrer:document.referrer},e))}identify(e,t){var n,o;if(!this.initialized)return void console.warn("[DevSkin] SDK not initialized. Call init() first.");this.userId=e;const r={user_id:e,anonymous_id:this.anonymousId||void 0,traits:Object.assign(Object.assign({},t),this.getContextData()),session_id:this.sessionId,timestamp:(new Date).toISOString()};null===(n=this.transport)||void 0===n||n.identifyUser(r),(null===(o=this.config)||void 0===o?void 0:o.debug)&&console.log("[DevSkin] User identified:",r)}captureError(e,t){var n;this.initialized?null===(n=this.errorCollector)||void 0===n||n.captureError(e,Object.assign(Object.assign({},t),{session_id:this.sessionId,user_id:this.userId||void 0})):console.warn("[DevSkin] SDK not initialized. Call init() first.")}addBreadcrumb(e){var t;this.initialized&&(null===(t=this.errorCollector)||void 0===t||t.addBreadcrumb(e))}startRecording(){var e;null===(e=this.rrwebRecorder)||void 0===e||e.start()}stopRecording(){var e;null===(e=this.rrwebRecorder)||void 0===e||e.stop()}optOut(){localStorage.setItem("devskin_opt_out","true"),this.initialized=!1}optIn(){localStorage.removeItem("devskin_opt_out")}startSession(){var e;this.sessionId=this.generateId(),this.sessionStartTime=Date.now();const t=Object.assign({session_id:this.sessionId,user_id:this.userId||void 0,anonymous_id:this.anonymousId,started_at:(new Date).toISOString()},this.getContextData());null===(e=this.transport)||void 0===e||e.startSession(t)}getContextData(){const e={};return this.deviceCollector&&(e.device=this.deviceCollector.collect()),this.browserCollector&&(e.browser=this.browserCollector.collect()),this.locationCollector&&(e.location=this.locationCollector.collect()),e}getOrCreateAnonymousId(){let e=localStorage.getItem("devskin_anonymous_id");return e||(e=this.generateId(),localStorage.setItem("devskin_anonymous_id",e)),e}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(){window.addEventListener("beforeunload",()=>{var e,t;if(this.track("page_unload"),this.sessionId&&this.sessionStartTime){const t=new Date,n=Date.now()-this.sessionStartTime;null===(e=this.transport)||void 0===e||e.startSession(Object.assign({session_id:this.sessionId,user_id:this.userId||void 0,anonymous_id:this.anonymousId,ended_at:t.toISOString(),duration_ms:n},this.getContextData()))}null===(t=this.transport)||void 0===t||t.flush(!0)})}}});
|
|
31
31
|
//# sourceMappingURL=devskin.umd.min.js.map
|