@arvoretech/bug-jar 0.3.2 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,293 +1,86 @@
1
- "use strict";var U=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var z=Object.prototype.hasOwnProperty;var I=(o,e)=>{for(var t in e)U(o,t,{get:e[t],enumerable:!0})},X=(o,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of F(e))!z.call(o,r)&&r!==t&&U(o,r,{get:()=>e[r],enumerable:!(n=P(e,r))||n.enumerable});return o};var N=o=>X(U({},"__esModule",{value:!0}),o);var te={};I(te,{BugJar:()=>v,default:()=>ee,exportAsZip:()=>M,generateSummary:()=>H,init:()=>$});module.exports=N(te);function m(){return`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`}function A(o,e=1e4){try{let t=new WeakSet,n=JSON.stringify(o,(r,s)=>{if(typeof s=="object"&&s!==null){if(t.has(s))return"[Circular]";t.add(s)}return s instanceof Error?{message:s.message,stack:s.stack,name:s.name}:typeof s=="function"?"[Function]":s instanceof HTMLElement?b(s):s});return n&&n.length>e?n.slice(0,e)+"...[truncated]":n||""}catch{return"[Unserializable]"}}function b(o){if(!o||!(o instanceof Element))return"unknown";let e=o.tagName.toLowerCase(),t=o.id?`#${o.id}`:"",n=o.className&&typeof o.className=="string"?`.${o.className.trim().split(/\s+/).join(".")}`:"",r=o.textContent?.trim().slice(0,30)||"",s=r?` "${r}"`:"";return`${e}${t}${n}${s}`}function h(o,e){if(!o||typeof o!="object")return o;if(Array.isArray(o))return o.map(n=>h(n,e));let t={};for(let[n,r]of Object.entries(o))e.some(a=>n.toLowerCase().includes(a.toLowerCase()))?t[n]="[REDACTED]":typeof r=="object"&&r!==null?t[n]=h(r,e):t[n]=r;return t}var f=class{constructor(e){this.buffer=[];this.maxSize=e}push(e){this.buffer.length>=this.maxSize&&this.buffer.shift(),this.buffer.push(e)}getAll(){return[...this.buffer]}clear(){this.buffer=[]}get length(){return this.buffer.length}};var w=class{constructor(e){this.originalFetch=null;this.originalXhrOpen=null;this.originalXhrSend=null;this.originalXhrSetRequestHeader=null;this.originalSendBeacon=null;this.config=e,this.buffer=new f(e.maxNetworkEntries)}start(){this.interceptFetch(),this.interceptXHR(),this.interceptBeacon()}stop(){this.originalFetch&&(window.fetch=this.originalFetch,this.originalFetch=null),this.originalXhrOpen&&this.originalXhrSend&&(XMLHttpRequest.prototype.open=this.originalXhrOpen,XMLHttpRequest.prototype.send=this.originalXhrSend,this.originalXhrOpen=null,this.originalXhrSend=null),this.originalXhrSetRequestHeader&&(XMLHttpRequest.prototype.setRequestHeader=this.originalXhrSetRequestHeader,this.originalXhrSetRequestHeader=null),this.originalSendBeacon&&(Navigator.prototype.sendBeacon=this.originalSendBeacon,this.originalSendBeacon=null)}getEntries(){return this.buffer.getAll()}clear(){this.buffer.clear()}interceptFetch(){this.originalFetch=window.fetch.bind(window);let e=this;window.fetch=async function(t,n){let r=performance.now(),s={id:m(),timestamp:Date.now(),method:(n?.method||"GET").toUpperCase(),url:typeof t=="string"?t:t instanceof URL?t.href:t.url,requestHeaders:e.extractHeaders(n?.headers),requestBody:e.safeParseBody(n?.body),status:null,statusText:"",responseHeaders:{},responseBody:null,responseSize:null,duration:null,type:"fetch",error:null,initiator:e.getInitiator()};try{let a=await e.originalFetch(t,n);s.status=a.status,s.statusText=a.statusText,s.responseHeaders=e.extractResponseHeaders(a.headers),s.duration=performance.now()-r;let c=a.clone();try{let i=await c.text();s.responseSize=i.length,s.responseBody=e.safeParseJson(i)}catch{s.responseBody="[Unable to read response]"}return s.requestBody=h(s.requestBody,e.config.sensitiveFields),s.responseBody=h(s.responseBody,e.config.sensitiveFields),e.buffer.push(s),a}catch(a){throw s.duration=performance.now()-r,s.error=a instanceof Error?a.message:String(a),e.buffer.push(s),a}}}interceptXHR(){this.originalXhrOpen=XMLHttpRequest.prototype.open,this.originalXhrSend=XMLHttpRequest.prototype.send,this.originalXhrSetRequestHeader=XMLHttpRequest.prototype.setRequestHeader;let e=this;XMLHttpRequest.prototype.open=function(t,n){return this.__bugjar_method=t,this.__bugjar_url=typeof n=="string"?n:n.href,this.__bugjar_headers={},e.originalXhrOpen.apply(this,arguments)},XMLHttpRequest.prototype.setRequestHeader=function(t,n){return this.__bugjar_headers&&(this.__bugjar_headers[t]=n),e.originalXhrSetRequestHeader.apply(this,arguments)},XMLHttpRequest.prototype.send=function(t){let n=performance.now(),r={id:m(),timestamp:Date.now(),method:(this.__bugjar_method||"GET").toUpperCase(),url:this.__bugjar_url||"",requestHeaders:this.__bugjar_headers||{},requestBody:e.safeParseBody(t),status:null,statusText:"",responseHeaders:{},responseBody:null,responseSize:null,duration:null,type:"xhr",error:null,initiator:e.getInitiator()};return this.addEventListener("load",function(){r.status=this.status,r.statusText=this.statusText,r.responseHeaders=e.parseXhrHeaders(this.getAllResponseHeaders()),r.duration=performance.now()-n,r.responseSize=this.responseText?.length||null,r.responseBody=e.safeParseJson(this.responseText),r.requestBody=h(r.requestBody,e.config.sensitiveFields),r.responseBody=h(r.responseBody,e.config.sensitiveFields),e.buffer.push(r)}),this.addEventListener("error",function(){r.duration=performance.now()-n,r.error="Network error",e.buffer.push(r)}),this.addEventListener("timeout",function(){r.duration=performance.now()-n,r.error="Request timeout",e.buffer.push(r)}),e.originalXhrSend.apply(this,arguments)}}interceptBeacon(){if(!navigator.sendBeacon)return;this.originalSendBeacon=navigator.sendBeacon.bind(navigator);let e=this;Navigator.prototype.sendBeacon=function(t,n){let r={id:m(),timestamp:Date.now(),method:"POST",url:typeof t=="string"?t:t.href,requestHeaders:{},requestBody:e.safeParseBody(n),status:null,statusText:"",responseHeaders:{},responseBody:null,responseSize:null,duration:null,type:"beacon",error:null,initiator:"sendBeacon"};return r.requestBody=h(r.requestBody,e.config.sensitiveFields),e.buffer.push(r),e.originalSendBeacon(t,n)}}extractHeaders(e){let t={};return e&&(e instanceof Headers?e.forEach((n,r)=>{t[r]=n}):Array.isArray(e)?e.forEach(([n,r])=>{t[n]=r}):Object.assign(t,e)),t}extractResponseHeaders(e){let t={};return e.forEach((n,r)=>{t[r]=n}),t}parseXhrHeaders(e){let t={};return e&&e.trim().split(/[\r\n]+/).forEach(n=>{let r=n.split(": "),s=r.shift();s&&(t[s]=r.join(": "))}),t}safeParseBody(e){if(!e)return null;if(typeof e=="string")return this.safeParseJson(e);if(e instanceof FormData){let t={};return e.forEach((n,r)=>{t[r]=n instanceof File?`[File: ${n.name}]`:n}),t}return e instanceof URLSearchParams?Object.fromEntries(e.entries()):e instanceof Blob?`[Blob: ${e.size} bytes]`:e instanceof ArrayBuffer?`[ArrayBuffer: ${e.byteLength} bytes]`:String(e)}safeParseJson(e){if(!e)return null;try{return JSON.parse(e)}catch{return e.length>5e3?e.slice(0,5e3)+"...[truncated]":e}}getInitiator(){try{let e=new Error().stack;if(!e)return null;let t=e.split(`
2
- `);for(let n of t)if(!n.includes("bug-jar")&&n.includes("at "))return n.trim().slice(0,200);return null}catch{return null}}};var E=class{constructor(e){this.originals={};this.levels=["log","warn","error","info","debug"];this.buffer=new f(e.maxConsoleEntries)}start(){for(let e of this.levels){this.originals[e]=console[e].bind(console);let t=this;console[e]=(...n)=>{t.capture(e,n),t.originals[e](...n)}}}stop(){for(let e of this.levels)this.originals[e]&&(console[e]=this.originals[e]);this.originals={}}getEntries(){return this.buffer.getAll()}clear(){this.buffer.clear()}capture(e,t){let n={timestamp:Date.now(),level:e,args:t.map(r=>typeof r=="string"||typeof r=="number"||typeof r=="boolean"?r:JSON.parse(A(r))),stack:e==="error"||e==="warn"?this.getStack():null};this.buffer.push(n)}getStack(){try{return new Error().stack?.split(`
1
+ "use strict";var X=Object.create;var v=Object.defineProperty;var K=Object.getOwnPropertyDescriptor;var G=Object.getOwnPropertyNames;var V=Object.getPrototypeOf,W=Object.prototype.hasOwnProperty;var Z=(s,e)=>{for(var t in e)v(s,t,{get:e[t],enumerable:!0})},D=(s,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of G(e))!W.call(s,n)&&n!==t&&v(s,n,{get:()=>e[n],enumerable:!(r=K(e,n))||r.enumerable});return s};var Y=(s,e,t)=>(t=s!=null?X(V(s)):{},D(e||!s||!s.__esModule?v(t,"default",{value:s,enumerable:!0}):t,s)),Q=s=>D(v({},"__esModule",{value:!0}),s);var ge={};Z(ge,{BugJar:()=>g,default:()=>fe,exportAsZip:()=>P,generateSummary:()=>H,init:()=>N});module.exports=Q(ge);function h(){return`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`}function $(s,e=1e4){try{let t=new WeakSet,r=JSON.stringify(s,(n,o)=>{if(typeof o=="object"&&o!==null){if(t.has(o))return"[Circular]";t.add(o)}return o instanceof Error?{message:o.message,stack:o.stack,name:o.name}:typeof o=="function"?"[Function]":o instanceof HTMLElement?f(o):o});return r&&r.length>e?r.slice(0,e)+"...[truncated]":r||""}catch{return"[Unserializable]"}}function f(s){if(!s||!(s instanceof Element))return"unknown";let e=s.tagName.toLowerCase(),t=s.id?`#${s.id}`:"",r=s.className&&typeof s.className=="string"?`.${s.className.trim().split(/\s+/).join(".")}`:"",n=s.textContent?.trim().slice(0,30)||"",o=n?` "${n}"`:"";return`${e}${t}${r}${o}`}function d(s,e){if(!s||typeof s!="object")return s;if(Array.isArray(s))return s.map(r=>d(r,e));let t={};for(let[r,n]of Object.entries(s))e.some(a=>r.toLowerCase().includes(a.toLowerCase()))?t[r]="[REDACTED]":typeof n=="object"&&n!==null?t[r]=d(n,e):t[r]=n;return t}var l=class{constructor(e){this.buffer=[];this.maxSize=e}push(e){this.buffer.length>=this.maxSize&&this.buffer.shift(),this.buffer.push(e)}getAll(){return[...this.buffer]}clear(){this.buffer=[]}get length(){return this.buffer.length}};var w=class{constructor(e){this.originalFetch=null;this.originalXhrOpen=null;this.originalXhrSend=null;this.originalXhrSetRequestHeader=null;this.originalSendBeacon=null;this.config=e,this.buffer=new l(e.maxNetworkEntries)}start(){this.interceptFetch(),this.interceptXHR(),this.interceptBeacon()}stop(){this.originalFetch&&(window.fetch=this.originalFetch,this.originalFetch=null),this.originalXhrOpen&&this.originalXhrSend&&(XMLHttpRequest.prototype.open=this.originalXhrOpen,XMLHttpRequest.prototype.send=this.originalXhrSend,this.originalXhrOpen=null,this.originalXhrSend=null),this.originalXhrSetRequestHeader&&(XMLHttpRequest.prototype.setRequestHeader=this.originalXhrSetRequestHeader,this.originalXhrSetRequestHeader=null),this.originalSendBeacon&&(Navigator.prototype.sendBeacon=this.originalSendBeacon,this.originalSendBeacon=null)}getEntries(){return this.buffer.getAll()}clear(){this.buffer.clear()}interceptFetch(){this.originalFetch=window.fetch.bind(window);let e=this;window.fetch=async function(t,r){let n=performance.now(),o={id:h(),timestamp:Date.now(),method:(r?.method||"GET").toUpperCase(),url:typeof t=="string"?t:t instanceof URL?t.href:t.url,requestHeaders:e.extractHeaders(r?.headers),requestBody:e.safeParseBody(r?.body),status:null,statusText:"",responseHeaders:{},responseBody:null,responseSize:null,duration:null,type:"fetch",error:null,initiator:e.getInitiator()};try{let a=await e.originalFetch(t,r);o.status=a.status,o.statusText=a.statusText,o.responseHeaders=e.extractResponseHeaders(a.headers),o.duration=performance.now()-n;let c=a.clone();try{let i=await c.text();o.responseSize=i.length,o.responseBody=e.safeParseJson(i)}catch{o.responseBody="[Unable to read response]"}return o.requestBody=d(o.requestBody,e.config.sensitiveFields),o.responseBody=d(o.responseBody,e.config.sensitiveFields),e.buffer.push(o),a}catch(a){throw o.duration=performance.now()-n,o.error=a instanceof Error?a.message:String(a),e.buffer.push(o),a}}}interceptXHR(){this.originalXhrOpen=XMLHttpRequest.prototype.open,this.originalXhrSend=XMLHttpRequest.prototype.send,this.originalXhrSetRequestHeader=XMLHttpRequest.prototype.setRequestHeader;let e=this;XMLHttpRequest.prototype.open=function(t,r){return this.__bugjar_method=t,this.__bugjar_url=typeof r=="string"?r:r.href,this.__bugjar_headers={},e.originalXhrOpen.apply(this,arguments)},XMLHttpRequest.prototype.setRequestHeader=function(t,r){return this.__bugjar_headers&&(this.__bugjar_headers[t]=r),e.originalXhrSetRequestHeader.apply(this,arguments)},XMLHttpRequest.prototype.send=function(t){let r=performance.now(),n={id:h(),timestamp:Date.now(),method:(this.__bugjar_method||"GET").toUpperCase(),url:this.__bugjar_url||"",requestHeaders:this.__bugjar_headers||{},requestBody:e.safeParseBody(t),status:null,statusText:"",responseHeaders:{},responseBody:null,responseSize:null,duration:null,type:"xhr",error:null,initiator:e.getInitiator()};return this.addEventListener("load",function(){n.status=this.status,n.statusText=this.statusText,n.responseHeaders=e.parseXhrHeaders(this.getAllResponseHeaders()),n.duration=performance.now()-r,n.responseSize=this.responseText?.length||null,n.responseBody=e.safeParseJson(this.responseText),n.requestBody=d(n.requestBody,e.config.sensitiveFields),n.responseBody=d(n.responseBody,e.config.sensitiveFields),e.buffer.push(n)}),this.addEventListener("error",function(){n.duration=performance.now()-r,n.error="Network error",e.buffer.push(n)}),this.addEventListener("timeout",function(){n.duration=performance.now()-r,n.error="Request timeout",e.buffer.push(n)}),e.originalXhrSend.apply(this,arguments)}}interceptBeacon(){if(!navigator.sendBeacon)return;this.originalSendBeacon=navigator.sendBeacon.bind(navigator);let e=this;Navigator.prototype.sendBeacon=function(t,r){let n={id:h(),timestamp:Date.now(),method:"POST",url:typeof t=="string"?t:t.href,requestHeaders:{},requestBody:e.safeParseBody(r),status:null,statusText:"",responseHeaders:{},responseBody:null,responseSize:null,duration:null,type:"beacon",error:null,initiator:"sendBeacon"};return n.requestBody=d(n.requestBody,e.config.sensitiveFields),e.buffer.push(n),e.originalSendBeacon(t,r)}}extractHeaders(e){let t={};return e&&(e instanceof Headers?e.forEach((r,n)=>{t[n]=r}):Array.isArray(e)?e.forEach(([r,n])=>{t[r]=n}):Object.assign(t,e)),t}extractResponseHeaders(e){let t={};return e.forEach((r,n)=>{t[n]=r}),t}parseXhrHeaders(e){let t={};return e&&e.trim().split(/[\r\n]+/).forEach(r=>{let n=r.split(": "),o=n.shift();o&&(t[o]=n.join(": "))}),t}safeParseBody(e){if(!e)return null;if(typeof e=="string")return this.safeParseJson(e);if(e instanceof FormData){let t={};return e.forEach((r,n)=>{t[n]=r instanceof File?`[File: ${r.name}]`:r}),t}return e instanceof URLSearchParams?Object.fromEntries(e.entries()):e instanceof Blob?`[Blob: ${e.size} bytes]`:e instanceof ArrayBuffer?`[ArrayBuffer: ${e.byteLength} bytes]`:String(e)}safeParseJson(e){if(!e)return null;try{return JSON.parse(e)}catch{return e.length>5e3?e.slice(0,5e3)+"...[truncated]":e}}getInitiator(){try{let e=new Error().stack;if(!e)return null;let t=e.split(`
2
+ `);for(let r of t)if(!r.includes("bug-jar")&&r.includes("at "))return r.trim().slice(0,200);return null}catch{return null}}};var b=class{constructor(e){this.originals={};this.levels=["log","warn","error","info","debug"];this.buffer=new l(e.maxConsoleEntries)}start(){for(let e of this.levels){this.originals[e]=console[e].bind(console);let t=this;console[e]=(...r)=>{t.capture(e,r),t.originals[e](...r)}}}stop(){for(let e of this.levels)this.originals[e]&&(console[e]=this.originals[e]);this.originals={}}getEntries(){return this.buffer.getAll()}clear(){this.buffer.clear()}capture(e,t){let r={timestamp:Date.now(),level:e,args:t.map(n=>typeof n=="string"||typeof n=="number"||typeof n=="boolean"?n:JSON.parse($(n))),stack:e==="error"||e==="warn"?this.getStack():null};this.buffer.push(r)}getStack(){try{return new Error().stack?.split(`
3
3
  `).slice(4).join(`
4
- `)||null}catch{return null}}};var x=class{constructor(e){this.errorHandler=null;this.rejectionHandler=null;this.resourceErrorHandler=null;this.buffer=new f(e.maxErrors)}start(){this.errorHandler=e=>{this.buffer.push({timestamp:Date.now(),message:e.message||"Unknown error",stack:e.error?.stack||null,filename:e.filename||null,lineno:e.lineno||null,colno:e.colno||null,type:"uncaught",context:this.getContext(e.error)})},this.rejectionHandler=e=>{let t=e.reason;this.buffer.push({timestamp:Date.now(),message:t instanceof Error?t.message:String(t),stack:t instanceof Error&&t.stack||null,filename:null,lineno:null,colno:null,type:"unhandledrejection",context:t instanceof Error?this.getContext(t):null})},this.resourceErrorHandler=e=>{let t=e.target;!t||!(t instanceof HTMLElement)||(t.tagName==="SCRIPT"||t.tagName==="LINK"||t.tagName==="IMG")&&this.buffer.push({timestamp:Date.now(),message:`Failed to load ${t.tagName.toLowerCase()}: ${t.src||t.href||"unknown"}`,stack:null,filename:t.src||t.href||null,lineno:null,colno:null,type:"resource",context:null})},window.addEventListener("error",this.errorHandler),window.addEventListener("unhandledrejection",this.rejectionHandler),window.addEventListener("error",this.resourceErrorHandler,!0)}stop(){this.errorHandler&&(window.removeEventListener("error",this.errorHandler),this.errorHandler=null),this.rejectionHandler&&(window.removeEventListener("unhandledrejection",this.rejectionHandler),this.rejectionHandler=null),this.resourceErrorHandler&&(window.removeEventListener("error",this.resourceErrorHandler,!0),this.resourceErrorHandler=null)}getEntries(){return this.buffer.getAll()}clear(){this.buffer.clear()}getContext(e){if(!e)return null;try{let t=e.stack;if(!t)return null;let n=t.match(/at\s+(.+?)\s+\(/);return n?n[1]:null}catch{return null}}};var S=class{constructor(e){this.listeners=[];this.buffer=new f(e.maxUserActions)}start(){this.addListener("click",r=>{let s=r.target;this.buffer.push({timestamp:Date.now(),type:"click",target:b(s),metadata:{x:r.clientX,y:r.clientY,button:r.button}})},!0),this.addListener("input",r=>{let s=r.target,a=s.type==="password"||s.type==="hidden"||s.name?.toLowerCase().includes("password")||s.name?.toLowerCase().includes("token")||s.name?.toLowerCase().includes("secret");this.buffer.push({timestamp:Date.now(),type:"input",target:b(s),value:a?"[REDACTED]":s.value?.slice(0,50)||"",metadata:{inputType:s.type,name:s.name}})},!0),this.addListener("scroll",this.throttle(()=>{this.buffer.push({timestamp:Date.now(),type:"scroll",target:"window",metadata:{scrollX:window.scrollX,scrollY:window.scrollY,scrollHeight:document.documentElement.scrollHeight}})},500)),this.addListener("resize",this.throttle(()=>{this.buffer.push({timestamp:Date.now(),type:"resize",target:"window",metadata:{width:window.innerWidth,height:window.innerHeight}})},500)),this.addListener("visibilitychange",()=>{this.buffer.push({timestamp:Date.now(),type:"visibility",target:"document",value:document.visibilityState})}),this.addListener("copy",r=>{this.buffer.push({timestamp:Date.now(),type:"copy",target:b(r.target)})}),this.addListener("paste",r=>{this.buffer.push({timestamp:Date.now(),type:"paste",target:b(r.target)})});let e=history.pushState.bind(history),t=history.replaceState.bind(history),n=this;history.pushState=function(...r){return n.buffer.push({timestamp:Date.now(),type:"navigation",target:String(r[2]||window.location.href),metadata:{method:"pushState"}}),e(...r)},history.replaceState=function(...r){return n.buffer.push({timestamp:Date.now(),type:"navigation",target:String(r[2]||window.location.href),metadata:{method:"replaceState"}}),t(...r)},this.addListener("popstate",()=>{this.buffer.push({timestamp:Date.now(),type:"navigation",target:window.location.href,metadata:{method:"popstate"}})})}stop(){for(let{event:e,handler:t,options:n}of this.listeners)(e==="visibilitychange"?document:window).removeEventListener(e,t,n);this.listeners=[]}getEntries(){return this.buffer.getAll()}clear(){this.buffer.clear()}addListener(e,t,n){(e==="visibilitychange"?document:window).addEventListener(e,t,n),this.listeners.push({event:e,handler:t,options:n})}throttle(e,t){let n=0;return()=>{let r=Date.now();r-n>=t&&(n=r,e())}}};var R=class{collect(){return{userAgent:navigator.userAgent,platform:navigator.platform,language:navigator.language,languages:[...navigator.languages],timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,timezoneOffset:new Date().getTimezoneOffset(),screenWidth:screen.width,screenHeight:screen.height,viewportWidth:window.innerWidth,viewportHeight:window.innerHeight,devicePixelRatio:window.devicePixelRatio,colorDepth:screen.colorDepth,cookiesEnabled:navigator.cookieEnabled,doNotTrack:navigator.doNotTrack,online:navigator.onLine,hardwareConcurrency:navigator.hardwareConcurrency||0,maxTouchPoints:navigator.maxTouchPoints||0,vendor:navigator.vendor,connection:this.getConnection(),memory:this.getMemory()}}getConnection(){let e=navigator.connection;return e?{effectiveType:e.effectiveType||"unknown",downlink:e.downlink||0,rtt:e.rtt||0,saveData:e.saveData||!1}:null}getMemory(){let e=performance.memory;return e?{jsHeapSizeLimit:e.jsHeapSizeLimit,totalJSHeapSize:e.totalJSHeapSize,usedJSHeapSize:e.usedJSHeapSize}:null}};var j=class{constructor(){this.lcp=null;this.fid=null;this.cls=null;this.observers=[]}start(){this.observeLCP(),this.observeFID(),this.observeCLS()}stop(){for(let e of this.observers)e.disconnect();this.observers=[]}collect(){let e=performance.getEntriesByType("navigation")[0],t=performance.getEntriesByType("paint"),n=performance.getEntriesByType("resource"),r=t.find(a=>a.name==="first-paint"),s=t.find(a=>a.name==="first-contentful-paint");return{navigationTiming:e?{redirectTime:e.redirectEnd-e.redirectStart,dnsTime:e.domainLookupEnd-e.domainLookupStart,tcpTime:e.connectEnd-e.connectStart,tlsTime:e.secureConnectionStart>0?e.connectEnd-e.secureConnectionStart:0,ttfb:e.responseStart-e.requestStart,downloadTime:e.responseEnd-e.responseStart,domParsing:e.domInteractive-e.responseEnd,domContentLoaded:e.domContentLoadedEventEnd-e.domContentLoadedEventStart,loadEvent:e.loadEventEnd-e.loadEventStart,totalTime:e.loadEventEnd-e.startTime}:{},resourceCount:n.length,totalTransferSize:n.reduce((a,c)=>a+(c.transferSize||0),0),domContentLoaded:e?e.domContentLoadedEventEnd-e.startTime:null,loadComplete:e?e.loadEventEnd-e.startTime:null,firstPaint:r?r.startTime:null,firstContentfulPaint:s?s.startTime:null,largestContentfulPaint:this.lcp,firstInputDelay:this.fid,cumulativeLayoutShift:this.cls,timeToInteractive:null}}observeLCP(){try{let e=new PerformanceObserver(t=>{let n=t.getEntries();n.length>0&&(this.lcp=n[n.length-1].startTime)});e.observe({type:"largest-contentful-paint",buffered:!0}),this.observers.push(e)}catch{}}observeFID(){try{let e=new PerformanceObserver(t=>{let n=t.getEntries();n.length>0&&(this.fid=n[0].processingStart-n[0].startTime)});e.observe({type:"first-input",buffered:!0}),this.observers.push(e)}catch{}}observeCLS(){try{let e=0,t=new PerformanceObserver(n=>{for(let r of n.getEntries())r.hadRecentInput||(e+=r.value);this.cls=e});t.observe({type:"layout-shift",buffered:!0}),this.observers.push(t)}catch{}}};var L=class{constructor(e){this.config=e}collect(){return{localStorage:this.config.captureLocalStorage?this.collectStorage(localStorage):{},sessionStorage:this.config.captureSessionStorage?this.collectStorage(sessionStorage):{},cookies:this.config.captureCookies?this.collectCookies():[]}}collectStorage(e){let t={};try{for(let n=0;n<e.length;n++){let r=e.key(n);if(!r)continue;if(this.config.sensitiveFields.some(a=>r.toLowerCase().includes(a.toLowerCase())))t[r]="[REDACTED]";else{let a=e.getItem(r)||"";t[r]=a.length>500?a.slice(0,500)+"...[truncated]":a}}}catch{}return t}collectCookies(){try{return document.cookie.split(";").map(e=>e.trim().split("=")[0]).filter(Boolean)}catch{return[]}}};var C=class{async capture(){try{let e=document.createElement("canvas"),t=e.getContext("2d");if(!t)return null;let n=window.innerWidth,r=window.innerHeight,s=Math.min(window.devicePixelRatio,2);e.width=n*s,e.height=r*s,t.scale(s,s);let a=this.domToSvg(n,r);return a?new Promise(c=>{let i=new Image;i.onload=()=>{t.drawImage(i,0,0);try{let u=e.toDataURL("image/png",.8);c(u)}catch{c(null)}},i.onerror=()=>c(null),i.src=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(a)}`,setTimeout(()=>c(null),3e3)}):null}catch{return null}}domToSvg(e,t){try{let n=document.documentElement.cloneNode(!0);n.querySelectorAll("script").forEach(a=>a.remove());let s=new XMLSerializer().serializeToString(n);return`<svg xmlns="http://www.w3.org/2000/svg" width="${e}" height="${t}">
4
+ `)||null}catch{return null}}};var S=class{constructor(e){this.errorHandler=null;this.rejectionHandler=null;this.resourceErrorHandler=null;this.buffer=new l(e.maxErrors)}start(){this.errorHandler=e=>{this.buffer.push({timestamp:Date.now(),message:e.message||"Unknown error",stack:e.error?.stack||null,filename:e.filename||null,lineno:e.lineno||null,colno:e.colno||null,type:"uncaught",context:this.getContext(e.error)})},this.rejectionHandler=e=>{let t=e.reason;this.buffer.push({timestamp:Date.now(),message:t instanceof Error?t.message:String(t),stack:t instanceof Error&&t.stack||null,filename:null,lineno:null,colno:null,type:"unhandledrejection",context:t instanceof Error?this.getContext(t):null})},this.resourceErrorHandler=e=>{let t=e.target;!t||!(t instanceof HTMLElement)||(t.tagName==="SCRIPT"||t.tagName==="LINK"||t.tagName==="IMG")&&this.buffer.push({timestamp:Date.now(),message:`Failed to load ${t.tagName.toLowerCase()}: ${t.src||t.href||"unknown"}`,stack:null,filename:t.src||t.href||null,lineno:null,colno:null,type:"resource",context:null})},window.addEventListener("error",this.errorHandler),window.addEventListener("unhandledrejection",this.rejectionHandler),window.addEventListener("error",this.resourceErrorHandler,!0)}stop(){this.errorHandler&&(window.removeEventListener("error",this.errorHandler),this.errorHandler=null),this.rejectionHandler&&(window.removeEventListener("unhandledrejection",this.rejectionHandler),this.rejectionHandler=null),this.resourceErrorHandler&&(window.removeEventListener("error",this.resourceErrorHandler,!0),this.resourceErrorHandler=null)}getEntries(){return this.buffer.getAll()}clear(){this.buffer.clear()}getContext(e){if(!e)return null;try{let t=e.stack;if(!t)return null;let r=t.match(/at\s+(.+?)\s+\(/);return r?r[1]:null}catch{return null}}};var E=class{constructor(e){this.listeners=[];this.buffer=new l(e.maxUserActions)}start(){this.addListener("click",n=>{let o=n.target;this.buffer.push({timestamp:Date.now(),type:"click",target:f(o),metadata:{x:n.clientX,y:n.clientY,button:n.button}})},!0),this.addListener("input",n=>{let o=n.target,a=o.type==="password"||o.type==="hidden"||o.name?.toLowerCase().includes("password")||o.name?.toLowerCase().includes("token")||o.name?.toLowerCase().includes("secret");this.buffer.push({timestamp:Date.now(),type:"input",target:f(o),value:a?"[REDACTED]":o.value?.slice(0,50)||"",metadata:{inputType:o.type,name:o.name}})},!0),this.addListener("scroll",this.throttle(()=>{this.buffer.push({timestamp:Date.now(),type:"scroll",target:"window",metadata:{scrollX:window.scrollX,scrollY:window.scrollY,scrollHeight:document.documentElement.scrollHeight}})},500)),this.addListener("resize",this.throttle(()=>{this.buffer.push({timestamp:Date.now(),type:"resize",target:"window",metadata:{width:window.innerWidth,height:window.innerHeight}})},500)),this.addListener("visibilitychange",()=>{this.buffer.push({timestamp:Date.now(),type:"visibility",target:"document",value:document.visibilityState})}),this.addListener("copy",n=>{this.buffer.push({timestamp:Date.now(),type:"copy",target:f(n.target)})}),this.addListener("paste",n=>{this.buffer.push({timestamp:Date.now(),type:"paste",target:f(n.target)})});let e=history.pushState.bind(history),t=history.replaceState.bind(history),r=this;history.pushState=function(...n){return r.buffer.push({timestamp:Date.now(),type:"navigation",target:String(n[2]||window.location.href),metadata:{method:"pushState"}}),e(...n)},history.replaceState=function(...n){return r.buffer.push({timestamp:Date.now(),type:"navigation",target:String(n[2]||window.location.href),metadata:{method:"replaceState"}}),t(...n)},this.addListener("popstate",()=>{this.buffer.push({timestamp:Date.now(),type:"navigation",target:window.location.href,metadata:{method:"popstate"}})})}stop(){for(let{event:e,handler:t,options:r}of this.listeners)(e==="visibilitychange"?document:window).removeEventListener(e,t,r);this.listeners=[]}getEntries(){return this.buffer.getAll()}clear(){this.buffer.clear()}addListener(e,t,r){(e==="visibilitychange"?document:window).addEventListener(e,t,r),this.listeners.push({event:e,handler:t,options:r})}throttle(e,t){let r=0;return()=>{let n=Date.now();n-r>=t&&(r=n,e())}}};var k=class{collect(){return{userAgent:navigator.userAgent,platform:navigator.platform,language:navigator.language,languages:[...navigator.languages],timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,timezoneOffset:new Date().getTimezoneOffset(),screenWidth:screen.width,screenHeight:screen.height,viewportWidth:window.innerWidth,viewportHeight:window.innerHeight,devicePixelRatio:window.devicePixelRatio,colorDepth:screen.colorDepth,cookiesEnabled:navigator.cookieEnabled,doNotTrack:navigator.doNotTrack,online:navigator.onLine,hardwareConcurrency:navigator.hardwareConcurrency||0,maxTouchPoints:navigator.maxTouchPoints||0,vendor:navigator.vendor,connection:this.getConnection(),memory:this.getMemory()}}getConnection(){let e=navigator.connection;return e?{effectiveType:e.effectiveType||"unknown",downlink:e.downlink||0,rtt:e.rtt||0,saveData:e.saveData||!1}:null}getMemory(){let e=performance.memory;return e?{jsHeapSizeLimit:e.jsHeapSizeLimit,totalJSHeapSize:e.totalJSHeapSize,usedJSHeapSize:e.usedJSHeapSize}:null}};var C=class{constructor(){this.lcp=null;this.fid=null;this.cls=null;this.observers=[]}start(){this.observeLCP(),this.observeFID(),this.observeCLS()}stop(){for(let e of this.observers)e.disconnect();this.observers=[]}collect(){let e=performance.getEntriesByType("navigation")[0],t=performance.getEntriesByType("paint"),r=performance.getEntriesByType("resource"),n=t.find(a=>a.name==="first-paint"),o=t.find(a=>a.name==="first-contentful-paint");return{navigationTiming:e?{redirectTime:e.redirectEnd-e.redirectStart,dnsTime:e.domainLookupEnd-e.domainLookupStart,tcpTime:e.connectEnd-e.connectStart,tlsTime:e.secureConnectionStart>0?e.connectEnd-e.secureConnectionStart:0,ttfb:e.responseStart-e.requestStart,downloadTime:e.responseEnd-e.responseStart,domParsing:e.domInteractive-e.responseEnd,domContentLoaded:e.domContentLoadedEventEnd-e.domContentLoadedEventStart,loadEvent:e.loadEventEnd-e.loadEventStart,totalTime:e.loadEventEnd-e.startTime}:{},resourceCount:r.length,totalTransferSize:r.reduce((a,c)=>a+(c.transferSize||0),0),domContentLoaded:e?e.domContentLoadedEventEnd-e.startTime:null,loadComplete:e?e.loadEventEnd-e.startTime:null,firstPaint:n?n.startTime:null,firstContentfulPaint:o?o.startTime:null,largestContentfulPaint:this.lcp,firstInputDelay:this.fid,cumulativeLayoutShift:this.cls,timeToInteractive:null}}observeLCP(){try{let e=new PerformanceObserver(t=>{let r=t.getEntries();r.length>0&&(this.lcp=r[r.length-1].startTime)});e.observe({type:"largest-contentful-paint",buffered:!0}),this.observers.push(e)}catch{}}observeFID(){try{let e=new PerformanceObserver(t=>{let r=t.getEntries();r.length>0&&(this.fid=r[0].processingStart-r[0].startTime)});e.observe({type:"first-input",buffered:!0}),this.observers.push(e)}catch{}}observeCLS(){try{let e=0,t=new PerformanceObserver(r=>{for(let n of r.getEntries())n.hadRecentInput||(e+=n.value);this.cls=e});t.observe({type:"layout-shift",buffered:!0}),this.observers.push(t)}catch{}}};var x=class{constructor(e){this.config=e}collect(){return{localStorage:this.config.captureLocalStorage?this.collectStorage(localStorage):{},sessionStorage:this.config.captureSessionStorage?this.collectStorage(sessionStorage):{},cookies:this.config.captureCookies?this.collectCookies():[]}}collectStorage(e){let t={};try{for(let r=0;r<e.length;r++){let n=e.key(r);if(!n)continue;if(this.config.sensitiveFields.some(a=>n.toLowerCase().includes(a.toLowerCase())))t[n]="[REDACTED]";else{let a=e.getItem(n)||"";t[n]=a.length>500?a.slice(0,500)+"...[truncated]":a}}}catch{}return t}collectCookies(){try{return document.cookie.split(";").map(e=>e.trim().split("=")[0]).filter(Boolean)}catch{return[]}}};var R=class{async capture(){try{let e=document.createElement("canvas"),t=e.getContext("2d");if(!t)return null;let r=window.innerWidth,n=window.innerHeight,o=Math.min(window.devicePixelRatio,2);e.width=r*o,e.height=n*o,t.scale(o,o);let a=this.domToSvg(r,n);return a?new Promise(c=>{let i=new Image;i.onload=()=>{t.drawImage(i,0,0);try{let u=e.toDataURL("image/png",.8);c(u)}catch{c(null)}},i.onerror=()=>c(null),i.src=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(a)}`,setTimeout(()=>c(null),3e3)}):null}catch{return null}}domToSvg(e,t){try{let r=document.documentElement.cloneNode(!0);r.querySelectorAll("script").forEach(a=>a.remove());let o=new XMLSerializer().serializeToString(r);return`<svg xmlns="http://www.w3.org/2000/svg" width="${e}" height="${t}">
5
5
  <foreignObject width="100%" height="100%">
6
- ${s}
6
+ ${o}
7
7
  </foreignObject>
8
- </svg>`}catch{return null}}captureHtml(){try{let e=document.documentElement.cloneNode(!0);return e.querySelectorAll("script").forEach(r=>r.remove()),e.querySelectorAll('input[type="password"], input[name*="token"], input[name*="secret"]').forEach(r=>r.value="[REDACTED]"),e.outerHTML.slice(0,5e5)}catch{return null}}};var k=class{collect(){let e={},t=!1,n=window.posthog;if(n?.getFeatureFlag)try{let c=n.getAllFlags?.()||n.getFeatureFlags?.()||{};e.posthog=c,t=!0}catch{}let r=window.ldclient;if(r?.allFlags)try{e.launchdarkly=r.allFlags(),t=!0}catch{}let s=window.statsig;if(s?.getExperiment||s?.checkGate)try{e.statsig={detected:!0},t=!0}catch{}let a=window.unleash;if(a?.getAllToggles)try{e.unleash=a.getAllToggles(),t=!0}catch{}return t?e:null}};var T=class{constructor(){this.mediaRecorder=null;this.chunks=[];this.stream=null;this.recording=!1}get isRecording(){return this.recording}async start(){if(!this.recording)try{this.stream=await navigator.mediaDevices.getDisplayMedia({video:{frameRate:15},audio:!1,preferCurrentTab:!0}),this.chunks=[],this.mediaRecorder=new MediaRecorder(this.stream,{mimeType:this.getSupportedMimeType(),videoBitsPerSecond:1e6}),this.mediaRecorder.ondataavailable=e=>{e.data.size>0&&this.chunks.push(e.data)},this.mediaRecorder.onstop=()=>{this.recording=!1,this.stopTracks()},this.stream.getVideoTracks()[0].onended=()=>{this.stop()},this.mediaRecorder.start(1e3),this.recording=!0}catch{this.recording=!1,this.stream=null,this.mediaRecorder=null}}stop(){return new Promise(e=>{if(!this.mediaRecorder||!this.recording){e(null);return}this.mediaRecorder.onstop=()=>{this.recording=!1,this.stopTracks();let t=new Blob(this.chunks,{type:this.getSupportedMimeType()});this.chunks=[],e(t)},this.mediaRecorder.stop()})}stopTracks(){this.stream&&(this.stream.getTracks().forEach(e=>e.stop()),this.stream=null)}getSupportedMimeType(){let e=["video/webm;codecs=vp9","video/webm;codecs=vp8","video/webm","video/mp4"];for(let t of e)if(MediaRecorder.isTypeSupported(t))return t;return"video/webm"}};var B=class{constructor(e,t,n){this.container=null;this.config=e,this.onReport=t,this.screenRecorder=n}mount(){if(this.container)return;let e=typeof window<"u"&&window.innerWidth<=768;if(this.config.hideOnMobile&&e)return;this.container=document.createElement("div"),this.container.id="bug-jar-widget";let t=e&&this.config.uiCompactOnMobile;this.container.innerHTML=this.getWidgetHTML(t),this.container.dataset.compact=String(t),document.body.appendChild(this.container),this.injectStyles(t),this.bindEvents(),this.makeDraggable()}unmount(){this.container&&(this.container.remove(),this.container=null);let e=document.getElementById("bug-jar-styles");e&&e.remove()}getWidgetHTML(e=!1){return`
9
- <button class="bug-jar-trigger ${`bug-jar--${this.config.uiPosition}`}${e?" bug-jar-trigger--compact":""}" aria-label="${this.config.uiLabel}">
10
- <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
11
- <path d="M8 2l1.88 1.88M14.12 3.88L16 2M9 7.13v-1a3.003 3.003 0 116 0v1"/>
12
- <path d="M12 20c-3.3 0-6-2.7-6-6v-3a6 6 0 0112 0v3c0 3.3-2.7 6-6 6z"/>
13
- <path d="M12 20v2M6 13H2M22 13h-4M6 17l-2 2M18 17l2 2M6 9l-2-2M18 9l2-2"/>
14
- </svg>
15
- ${e?"":`<span>${this.config.uiLabel}</span>`}
16
- </button>
17
- <div class="bug-jar-modal" hidden>
18
- <div class="bug-jar-modal-backdrop"></div>
19
- <div class="bug-jar-modal-content">
20
- <div class="bug-jar-modal-header">
21
- <h3>Reportar Bug</h3>
22
- <button class="bug-jar-close" aria-label="Fechar">&times;</button>
23
- </div>
24
- <div class="bug-jar-modal-body">
25
- <label for="bug-jar-description">O que aconteceu?</label>
26
- <textarea id="bug-jar-description" placeholder="Descreva o que voc\xEA estava fazendo e o que deu errado..." rows="4"></textarea>
27
- <p class="bug-jar-hint">Todas as informa\xE7\xF5es t\xE9cnicas ser\xE3o capturadas automaticamente.</p>
28
- <div class="bug-jar-recording-section">
29
- <button class="bug-jar-record-btn">
30
- <span class="bug-jar-record-icon"></span>
31
- <span class="bug-jar-record-label">Gravar Tela</span>
32
- </button>
33
- <span class="bug-jar-recording-status" hidden>Gravando...</span>
34
- </div>
35
- </div>
36
- <div class="bug-jar-modal-footer">
37
- <button class="bug-jar-cancel">Cancelar</button>
38
- <button class="bug-jar-submit">Enviar Relat\xF3rio</button>
39
- </div>
40
- <div class="bug-jar-status" hidden></div>
41
- </div>
8
+ </svg>`}catch{return null}}captureHtml(){try{let e=document.documentElement.cloneNode(!0);return e.querySelectorAll("script").forEach(n=>n.remove()),e.querySelectorAll('input[type="password"], input[name*="token"], input[name*="secret"]').forEach(n=>n.value="[REDACTED]"),e.outerHTML.slice(0,5e5)}catch{return null}}};var U=class{collect(){let e={},t=!1,r=window.posthog;if(r?.getFeatureFlag)try{let c=r.getAllFlags?.()||r.getFeatureFlags?.()||{};e.posthog=c,t=!0}catch{}let n=window.ldclient;if(n?.allFlags)try{e.launchdarkly=n.allFlags(),t=!0}catch{}let o=window.statsig;if(o?.getExperiment||o?.checkGate)try{e.statsig={detected:!0},t=!0}catch{}let a=window.unleash;if(a?.getAllToggles)try{e.unleash=a.getAllToggles(),t=!0}catch{}return t?e:null}};var T=class{constructor(){this.mediaRecorder=null;this.chunks=[];this.stream=null;this.recording=!1;this.onChunk=null}get isRecording(){return this.recording}setChunkHandler(e){this.onChunk=e}async start(){if(!this.recording)try{this.stream=await navigator.mediaDevices.getDisplayMedia({video:{frameRate:15},audio:!1,preferCurrentTab:!0}),this.chunks=[],this.mediaRecorder=new MediaRecorder(this.stream,{mimeType:this.getSupportedMimeType(),videoBitsPerSecond:1e6}),this.mediaRecorder.ondataavailable=e=>{e.data.size>0&&(this.chunks.push(e.data),this.onChunk&&e.data.arrayBuffer().then(t=>this.onChunk?.(new Uint8Array(t),!1)))},this.mediaRecorder.onstop=()=>{this.recording=!1,this.stopTracks()},this.stream.getVideoTracks()[0].onended=()=>{this.stop()},this.mediaRecorder.start(1e3),this.recording=!0}catch{this.recording=!1,this.stream=null,this.mediaRecorder=null}}stop(){return new Promise(e=>{if(!this.mediaRecorder||!this.recording){e(null);return}this.mediaRecorder.onstop=()=>{this.recording=!1,this.stopTracks();let t=new Blob(this.chunks,{type:this.getSupportedMimeType()});this.chunks=[],e(t)},this.mediaRecorder.stop()})}stopTracks(){this.stream&&(this.stream.getTracks().forEach(e=>e.stop()),this.stream=null)}getSupportedMimeType(){let e=["video/webm;codecs=vp9","video/webm;codecs=vp8","video/webm","video/mp4"];for(let t of e)if(MediaRecorder.isTypeSupported(t))return t;return"video/webm"}};var B=class{constructor(){this.container=null}mount(){this.container||(this.container=document.createElement("div"),this.container.id="bug-jar-session-border",this.container.setAttribute("aria-hidden","true"),this.container.innerHTML=`
9
+ <div class="bug-jar-session-border-glow"></div>
10
+ <div class="bug-jar-session-pill">
11
+ <span class="bug-jar-session-pill-dot"></span>
12
+ <span>Sess\xE3o de depura\xE7\xE3o ativa</span>
42
13
  </div>
43
- `}bindEvents(){if(!this.container)return;let e=this.container.querySelector(".bug-jar-trigger"),t=this.container.querySelector(".bug-jar-modal"),n=this.container.querySelector(".bug-jar-modal-backdrop"),r=this.container.querySelector(".bug-jar-close"),s=this.container.querySelector(".bug-jar-cancel"),a=this.container.querySelector(".bug-jar-submit"),c=this.container.querySelector("#bug-jar-description"),i=this.container.querySelector(".bug-jar-status"),u=this.container.querySelector(".bug-jar-record-btn"),p=this.container.querySelector(".bug-jar-recording-status"),l=()=>{this.container?.dataset.compact==="true"&&this.container.querySelector(".bug-jar-trigger")?.classList.add("bug-jar-trigger--expanded"),t&&(t.hidden=!1),c?.focus(),this.updateRecordingUI(u,p)},d=()=>{t&&(t.hidden=!0),c&&(c.value=""),i&&(i.hidden=!0),this.container?.dataset.compact==="true"&&this.container.querySelector(".bug-jar-trigger")?.classList.remove("bug-jar-trigger--expanded")};e.addEventListener("click",l),n&&n.addEventListener("click",d),r&&r.addEventListener("click",d),s&&s.addEventListener("click",d),u?.addEventListener("click",async()=>{this.screenRecorder.isRecording||(d(),await this.screenRecorder.start(),this.updateTriggerForRecording(e))}),a?.addEventListener("click",async()=>{let g=c?.value.trim();if(!(!g||!c||!a||!i)){c.classList.remove("bug-jar-error"),a.setAttribute("disabled","true"),a.textContent="Capturando...",i.hidden=!0;try{await this.onReport(g),i.textContent="\u2713 Relat\xF3rio baixado como .zip!",i.className="bug-jar-status bug-jar-status--success",i.hidden=!1,this.resetTrigger(e),setTimeout(d,2e3)}catch(y){i.textContent=`Erro: ${y instanceof Error?y.message:"Falha ao gerar relat\xF3rio"}`,i.className="bug-jar-status bug-jar-status--error",i.hidden=!1}finally{a.removeAttribute("disabled"),a.textContent="Enviar Relat\xF3rio"}}}),c?.addEventListener("input",()=>{c?.classList.remove("bug-jar-error")})}updateRecordingUI(e,t){if(!(!e||!t))if(this.screenRecorder.isRecording){e.classList.add("bug-jar-record-btn--active"),t.hidden=!1;let n=e.querySelector(".bug-jar-record-label");n&&(n.textContent="Gravando...")}else{e.classList.remove("bug-jar-record-btn--active"),t.hidden=!0;let n=e.querySelector(".bug-jar-record-label");n&&(n.textContent="Gravar Tela")}}updateTriggerForRecording(e){e.classList.add("bug-jar-trigger--recording");let t=e.querySelector("span");t&&(t.textContent="\u23FA Gravando...")}resetTrigger(e){e.classList.remove("bug-jar-trigger--recording");let t=e.querySelector("span");t&&(t.textContent=this.config.uiLabel)}makeDraggable(){if(!this.container)return;let e=this.container.querySelector(".bug-jar-trigger");if(!e)return;let t=!1,n=0,r=0,s=0,a=0,c=!1,i=l=>{let d="touches"in l?l.touches[0]:l;n=d.clientX,r=d.clientY;let g=e.getBoundingClientRect();s=g.left,a=g.top,c=!1,t=!0,e.classList.add("bug-jar-trigger--dragging"),document.addEventListener("mousemove",u),document.addEventListener("mouseup",p),document.addEventListener("touchmove",u,{passive:!1}),document.addEventListener("touchend",p)},u=l=>{if(!t)return;l.preventDefault();let d="touches"in l?l.touches[0]:l,g=d.clientX-n,y=d.clientY-r;(Math.abs(g)>5||Math.abs(y)>5)&&(c=!0);let q=s+g,D=a+y;e.style.position="fixed",e.style.left=`${q}px`,e.style.top=`${D}px`,e.style.right="auto",e.style.bottom="auto",e.classList.remove("bug-jar--bottom-right","bug-jar--bottom-left","bug-jar--top-right","bug-jar--top-left")},p=()=>{t=!1,e.classList.remove("bug-jar-trigger--dragging"),document.removeEventListener("mousemove",u),document.removeEventListener("mouseup",p),document.removeEventListener("touchmove",u),document.removeEventListener("touchend",p),c&&(e.style.cursor="")};e.addEventListener("mousedown",i),e.addEventListener("touchstart",i,{passive:!0})}injectStyles(e=!1){if(document.getElementById("bug-jar-styles"))return;let t=document.createElement("style");t.id="bug-jar-styles",t.textContent=`
44
- #bug-jar-widget {
45
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
46
- font-size: 14px;
47
- line-height: 1.5;
48
- color: #1a1a1a;
49
- }
50
-
51
- .bug-jar-trigger {
52
- position: fixed;
53
- z-index: 99999;
54
- display: flex;
55
- align-items: center;
56
- gap: 6px;
57
- padding: 10px 16px;
58
- border: none;
59
- border-radius: 24px;
60
- background: #1a1a1a;
61
- color: #fff;
62
- font-size: 13px;
63
- font-weight: 500;
64
- cursor: pointer;
65
- box-shadow: 0 4px 12px rgba(0,0,0,0.15);
66
- transition: transform 0.15s, box-shadow 0.15s, background 0.3s;
67
- user-select: none;
68
- touch-action: none;
69
- }
70
-
71
- .bug-jar-trigger:hover {
72
- transform: scale(1.05);
73
- box-shadow: 0 6px 20px rgba(0,0,0,0.2);
74
- }
75
-
76
- .bug-jar-trigger--compact {
77
- padding: 12px;
78
- border-radius: 50%;
79
- width: 44px;
80
- height: 44px;
81
- justify-content: center;
82
- }
83
-
84
- .bug-jar-trigger--compact span {
85
- display: none;
86
- }
87
-
88
- .bug-jar-trigger--expanded {
89
- padding: 10px 16px;
90
- width: auto;
91
- height: auto;
92
- border-radius: 24px;
93
- }
94
-
95
- .bug-jar-trigger--dragging {
96
- cursor: grabbing;
97
- transform: scale(1.1);
98
- box-shadow: 0 8px 25px rgba(0,0,0,0.3);
99
- }
100
-
101
- .bug-jar-trigger--recording {
102
- background: #dc2626;
103
- animation: bug-jar-pulse 1.5s infinite;
104
- }
105
-
106
- @keyframes bug-jar-pulse {
107
- 0%, 100% { opacity: 1; }
108
- 50% { opacity: 0.7; }
109
- }
110
-
111
- .bug-jar--bottom-right { bottom: 20px; right: 20px; }
112
- .bug-jar--bottom-left { bottom: 20px; left: 20px; }
113
- .bug-jar--top-right { top: 20px; right: 20px; }
114
- .bug-jar--top-left { top: 20px; left: 20px; }
115
-
116
- .bug-jar-modal {
14
+ `,this.injectStyles(),document.body.appendChild(this.container))}unmount(){this.container?.remove(),this.container=null,document.getElementById("bug-jar-session-border-styles")?.remove()}injectStyles(){if(document.getElementById("bug-jar-session-border-styles"))return;let e=document.createElement("style");e.id="bug-jar-session-border-styles",e.textContent=`
15
+ #bug-jar-session-border {
117
16
  position: fixed;
118
17
  inset: 0;
119
- z-index: 100000;
120
- display: flex;
121
- align-items: center;
122
- justify-content: center;
18
+ z-index: 2147483646;
19
+ pointer-events: none;
123
20
  }
124
-
125
- .bug-jar-modal[hidden] { display: none; }
126
-
127
- .bug-jar-modal-backdrop {
21
+ .bug-jar-session-border-glow {
128
22
  position: absolute;
129
23
  inset: 0;
130
- background: rgba(0,0,0,0.5);
131
- backdrop-filter: blur(2px);
132
- }
133
-
134
- .bug-jar-modal-content {
135
- position: relative;
136
- width: 90%;
137
- max-width: 480px;
138
- background: #fff;
139
- border-radius: 12px;
140
- box-shadow: 0 20px 60px rgba(0,0,0,0.3);
141
- overflow: hidden;
142
- }
143
-
144
- .bug-jar-modal-header {
145
- display: flex;
146
- align-items: center;
147
- justify-content: space-between;
148
- padding: 16px 20px;
149
- border-bottom: 1px solid #eee;
150
- }
151
-
152
- .bug-jar-modal-header h3 {
153
- margin: 0;
154
- font-size: 16px;
155
- font-weight: 600;
156
- }
157
-
158
- .bug-jar-close {
159
- background: none;
160
- border: none;
161
- font-size: 24px;
162
- cursor: pointer;
163
- color: #666;
164
- padding: 0 4px;
165
- }
166
-
167
- .bug-jar-modal-body {
168
- padding: 20px;
169
- }
170
-
171
- .bug-jar-modal-body label {
172
- display: block;
173
- font-weight: 500;
174
- margin-bottom: 8px;
175
- }
176
-
177
- #bug-jar-description {
178
- width: 100%;
179
- padding: 12px;
180
- border: 1px solid #ddd;
181
- border-radius: 8px;
182
- font-size: 14px;
183
- font-family: inherit;
184
- resize: vertical;
185
- min-height: 100px;
186
- box-sizing: border-box;
187
- }
188
-
189
- #bug-jar-description:focus {
190
- outline: none;
191
- border-color: #1a1a1a;
192
- box-shadow: 0 0 0 2px rgba(26,26,26,0.1);
193
- }
194
-
195
- #bug-jar-description.bug-jar-error {
196
- border-color: #e53e3e;
197
- }
198
-
199
- .bug-jar-hint {
200
- margin: 8px 0 0;
201
- font-size: 12px;
202
- color: #888;
203
- }
204
-
205
- .bug-jar-recording-section {
206
- margin-top: 16px;
207
- display: flex;
208
- align-items: center;
209
- gap: 12px;
210
- }
211
-
212
- .bug-jar-record-btn {
24
+ border-radius: 14px;
25
+ padding: 4px;
26
+ background: linear-gradient(
27
+ 120deg,
28
+ #66DCCE,
29
+ #39AF9F,
30
+ #40CAB6,
31
+ #309385,
32
+ #66DCCE
33
+ );
34
+ background-size: 300% 300%;
35
+ animation: bug-jar-border-flow 6s ease infinite;
36
+ -webkit-mask:
37
+ linear-gradient(#fff 0 0) content-box,
38
+ linear-gradient(#fff 0 0);
39
+ -webkit-mask-composite: xor;
40
+ mask:
41
+ linear-gradient(#fff 0 0) content-box,
42
+ linear-gradient(#fff 0 0);
43
+ mask-composite: exclude;
44
+ }
45
+ .bug-jar-session-pill {
46
+ position: absolute;
47
+ bottom: 16px;
48
+ left: 50%;
49
+ transform: translateX(-50%);
213
50
  display: flex;
214
51
  align-items: center;
215
- gap: 6px;
216
- padding: 8px 14px;
217
- border: 1px solid #ddd;
218
- border-radius: 6px;
219
- background: #fff;
220
- cursor: pointer;
221
- font-size: 13px;
222
- transition: all 0.2s;
223
- }
224
-
225
- .bug-jar-record-btn:hover {
226
- border-color: #dc2626;
227
- color: #dc2626;
228
- }
229
-
230
- .bug-jar-record-btn--active {
231
- border-color: #dc2626;
232
- background: #fef2f2;
233
- color: #dc2626;
234
- pointer-events: none;
235
- }
236
-
237
- .bug-jar-record-icon {
238
- width: 10px;
239
- height: 10px;
240
- border-radius: 50%;
241
- background: #dc2626;
242
- }
243
-
244
- .bug-jar-recording-status {
245
- font-size: 12px;
246
- color: #dc2626;
247
- font-weight: 500;
248
- animation: bug-jar-pulse 1.5s infinite;
249
- }
250
-
251
- .bug-jar-modal-footer {
252
- display: flex;
253
- justify-content: flex-end;
254
52
  gap: 8px;
255
- padding: 16px 20px;
256
- border-top: 1px solid #eee;
257
- }
258
-
259
- .bug-jar-cancel {
260
- padding: 8px 16px;
261
- border: 1px solid #ddd;
262
- border-radius: 6px;
263
- background: #fff;
264
- cursor: pointer;
265
- font-size: 13px;
266
- }
267
-
268
- .bug-jar-submit {
269
- padding: 8px 16px;
270
- border: none;
271
- border-radius: 6px;
272
- background: #1a1a1a;
273
- color: #fff;
274
- cursor: pointer;
275
- font-size: 13px;
53
+ padding: 6px 14px;
54
+ border-radius: 999px;
55
+ background: rgba(15, 27, 21, 0.85);
56
+ color: #E6FAF7;
57
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
58
+ font-size: 12px;
276
59
  font-weight: 500;
60
+ box-shadow: 0 4px 16px rgba(0,0,0,0.25);
61
+ backdrop-filter: blur(6px);
277
62
  }
278
-
279
- .bug-jar-submit:disabled {
280
- opacity: 0.6;
281
- cursor: not-allowed;
282
- }
283
-
284
- .bug-jar-status {
285
- padding: 12px 20px;
286
- font-size: 13px;
287
- text-align: center;
288
- }
289
-
290
- .bug-jar-status--success { color: #16a34a; background: #f0fdf4; }
291
- .bug-jar-status--error { color: #dc2626; background: #fef2f2; }
292
- `,document.head.appendChild(t)}};function H(o){let e=[];e.push(`Bug Report: ${o.id}`),e.push(`URL: ${o.url}`),e.push(`Time: ${new Date(o.timestamp).toISOString()}`),e.push(`User Description: "${o.userDescription}"`),e.push(""),e.push("## Environment"),e.push(`Browser: ${O(o.environment.userAgent)}`),e.push(`Viewport: ${o.environment.viewportWidth}x${o.environment.viewportHeight}`),e.push(`Connection: ${o.environment.connection?.effectiveType||"unknown"}`),e.push(`Online: ${o.environment.online}`),e.push(""),e.push("## Network Activity");let t=o.network.length,n=o.network.filter(i=>i.error||i.status&&i.status>=400),r=o.network.filter(i=>i.duration&&i.duration>3e3);if(e.push(`Total requests: ${t}`),n.length>0){e.push(`Failed requests (${n.length}):`);for(let i of n)e.push(` - ${i.method} ${i.url} \u2192 ${i.error||`HTTP ${i.status}`}`)}if(r.length>0){e.push(`Slow requests >3s (${r.length}):`);for(let i of r)e.push(` - ${i.method} ${i.url} (${Math.round(i.duration)}ms)`)}if(e.push(""),e.push("## Errors"),o.errors.length===0)e.push("No errors captured.");else{e.push(`Total errors: ${o.errors.length}`);for(let i of o.errors)e.push(` - [${i.type}] ${i.message}`),i.filename&&e.push(` at ${i.filename}:${i.lineno}:${i.colno}`)}e.push(""),e.push("## Console");let s={log:0,warn:0,error:0,info:0,debug:0};for(let i of o.console)s[i.level]++;e.push(`Logs: ${s.log}, Warnings: ${s.warn}, Errors: ${s.error}, Info: ${s.info}, Debug: ${s.debug}`);let a=o.console.filter(i=>i.level==="error");if(a.length>0){e.push("Console errors:");for(let i of a)e.push(` - ${i.args.map(u=>typeof u=="string"?u:JSON.stringify(u)).join(" ")}`)}e.push(""),e.push("## User Actions"),e.push(`Total actions: ${o.userActions.length}`);let c={};for(let i of o.userActions)c[i.type]=(c[i.type]||0)+1;for(let[i,u]of Object.entries(c))e.push(` - ${i}: ${u}`);if(o.userActions.length>0){let i=o.userActions[0].timestamp,p=((o.userActions[o.userActions.length-1].timestamp-i)/1e3).toFixed(1);e.push(`Session duration: ${p}s`)}if(e.push(""),o.performance){e.push("## Performance");let i=o.performance;i.largestContentfulPaint&&e.push(`LCP: ${Math.round(i.largestContentfulPaint)}ms`),i.firstInputDelay&&e.push(`FID: ${Math.round(i.firstInputDelay)}ms`),i.cumulativeLayoutShift!==null&&e.push(`CLS: ${i.cumulativeLayoutShift?.toFixed(3)}`),i.loadComplete&&e.push(`Page Load: ${Math.round(i.loadComplete)}ms`),e.push(`Resources: ${i.resourceCount} (${J(i.totalTransferSize)})`)}return e.join(`
293
- `)}function O(o){return o.includes("Chrome/")?`Chrome ${o.match(/Chrome\/(\d+)/)?.[1]||""}`:o.includes("Firefox/")?`Firefox ${o.match(/Firefox\/(\d+)/)?.[1]||""}`:o.includes("Safari/")&&!o.includes("Chrome")?`Safari ${o.match(/Version\/(\d+)/)?.[1]||""}`:o.slice(0,50)}function J(o){return o<1024?`${o}B`:o<1024*1024?`${(o/1024).toFixed(1)}KB`:`${(o/(1024*1024)).toFixed(1)}MB`}async function M(o,e){let t=[],n=JSON.stringify(o,null,2);t.push({name:"report.json",content:new TextEncoder().encode(n)});let r=H(o);if(t.push({name:"summary.md",content:new TextEncoder().encode(r)}),o.screenshot){let s=_(o.screenshot);s&&t.push({name:"screenshot.png",content:s})}if(e){let s=new Uint8Array(await e.arrayBuffer());t.push({name:"recording.webm",content:s})}return W(t)}function _(o){try{let e=o.split(",")[1];if(!e)return null;let t=atob(e),n=new Uint8Array(t.length);for(let r=0;r<t.length;r++)n[r]=t.charCodeAt(r);return n}catch{return null}}function W(o){let e=[],t=[],n=0;for(let i of o){let u=new TextEncoder().encode(i.name),p=Z(i.content),l=G(u,i.content.length,p);e.push(l),e.push(u),e.push(i.content);let d=V(u,i.content.length,p,n);t.push(d),t.push(u),n+=l.length+u.length+i.content.length}let r=n,s=0;for(let i of t)s+=i.length;let a=Y(o.length,s,r),c=[...e,...t,a].map(i=>i.buffer);return new Blob(c,{type:"application/zip"})}function G(o,e,t){let n=new Uint8Array(30),r=new DataView(n.buffer);return r.setUint32(0,67324752,!0),r.setUint16(4,20,!0),r.setUint16(6,0,!0),r.setUint16(8,0,!0),r.setUint16(10,0,!0),r.setUint16(12,0,!0),r.setUint32(14,t,!0),r.setUint32(18,e,!0),r.setUint32(22,e,!0),r.setUint16(26,o.length,!0),r.setUint16(28,0,!0),n}function V(o,e,t,n){let r=new Uint8Array(46),s=new DataView(r.buffer);return s.setUint32(0,33639248,!0),s.setUint16(4,20,!0),s.setUint16(6,20,!0),s.setUint16(8,0,!0),s.setUint16(10,0,!0),s.setUint16(12,0,!0),s.setUint16(14,0,!0),s.setUint32(16,t,!0),s.setUint32(20,e,!0),s.setUint32(24,e,!0),s.setUint16(28,o.length,!0),s.setUint16(30,0,!0),s.setUint16(32,0,!0),s.setUint16(34,0,!0),s.setUint16(36,0,!0),s.setUint32(38,0,!0),s.setUint32(42,n,!0),r}function Y(o,e,t){let n=new Uint8Array(22),r=new DataView(n.buffer);return r.setUint32(0,101010256,!0),r.setUint16(4,0,!0),r.setUint16(6,0,!0),r.setUint16(8,o,!0),r.setUint16(10,o,!0),r.setUint32(12,e,!0),r.setUint32(16,t,!0),r.setUint16(20,0,!0),n}function Z(o){let e=4294967295;for(let t=0;t<o.length;t++){e^=o[t];for(let n=0;n<8;n++)e=e>>>1^(e&1?3988292384:0)}return(e^4294967295)>>>0}var K="0.2.0",Q={maxNetworkEntries:100,maxConsoleEntries:200,maxUserActions:150,maxErrors:50,captureScreenshot:!0,captureHtmlSnapshot:!0,captureCookies:!0,captureLocalStorage:!0,captureSessionStorage:!0,capturePerformance:!0,captureWebVitals:!0,captureMemory:!0,captureConnectivity:!0,sensitiveFields:["password","token","secret","authorization","cookie","session","credit_card","cvv","ssn","cpf"],endpoint:void 0,onCapture:void 0,ui:!0,uiPosition:"bottom-right",uiLabel:"Reportar Bug"},v=class{constructor(e={}){this.ui=null;this.started=!1;this.config={...Q,...e},this.network=new w(this.config),this.console=new E(this.config),this.errors=new x(this.config),this.userActions=new S(this.config),this.environment=new R,this.performance=new j,this.storage=new L(this.config),this.screenshot=new C,this.featureFlags=new k,this.screenRecorder=new T}start(){this.started||(this.started=!0,this.network.start(),this.console.start(),this.errors.start(),this.userActions.start(),this.config.captureWebVitals&&this.performance.start(),this.config.ui&&(this.ui=new B(this.config,e=>this.captureAndExport(e),this.screenRecorder),document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>this.ui?.mount()):this.ui.mount()))}stop(){this.started&&(this.started=!1,this.network.stop(),this.console.stop(),this.errors.stop(),this.userActions.stop(),this.performance.stop(),this.ui?.unmount())}async startRecording(){await this.screenRecorder.start()}get isRecording(){return this.screenRecorder.isRecording}async capture(e=""){let t={id:m(),timestamp:Date.now(),url:window.location.href,title:document.title,userDescription:e,environment:this.environment.collect(),network:this.network.getEntries(),console:this.console.getEntries(),errors:this.errors.getEntries(),userActions:this.userActions.getEntries(),performance:this.config.capturePerformance?this.performance.collect():null,storage:this.storage.collect(),screenshot:this.config.captureScreenshot?await this.screenshot.capture():null,htmlSnapshot:this.config.captureHtmlSnapshot?this.screenshot.captureHtml():null,featureFlags:this.featureFlags.collect(),metadata:{},version:K};return this.config.onCapture&&this.config.onCapture(t),t}async captureAndExport(e=""){let t=await this.screenRecorder.stop(),n=await this.capture(e);if(this.config.endpoint)if(t){let r=new FormData;r.append("report",JSON.stringify(n)),r.append("video",t,"recording.webm"),await fetch(this.config.endpoint,{method:"POST",body:r})}else await fetch(this.config.endpoint,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});else{let r=await M(n,t),s=URL.createObjectURL(r),a=document.createElement("a");a.href=s,a.download=`bug-report-${n.id}.zip`,a.click(),URL.revokeObjectURL(s)}return n}getReport(){return this.capture()}};function $(o={}){let e=new v(o);return e.start(),e}typeof window<"u"&&(window.BugJar={BugJar:v,init:$});var ee=v;0&&(module.exports={BugJar,exportAsZip,generateSummary,init});
63
+ .bug-jar-session-pill-dot {
64
+ width: 8px;
65
+ height: 8px;
66
+ border-radius: 50%;
67
+ background: #40CAB6;
68
+ animation: bug-jar-border-pulse 1.6s ease-in-out infinite;
69
+ }
70
+ @keyframes bug-jar-border-flow {
71
+ 0% { background-position: 0% 50%; }
72
+ 50% { background-position: 100% 50%; }
73
+ 100% { background-position: 0% 50%; }
74
+ }
75
+ @keyframes bug-jar-border-pulse {
76
+ 0%, 100% { opacity: 1; transform: scale(1); }
77
+ 50% { opacity: 0.5; transform: scale(0.85); }
78
+ }
79
+ @media (prefers-reduced-motion: reduce) {
80
+ .bug-jar-session-border-glow { animation: none; }
81
+ .bug-jar-session-pill-dot { animation: none; }
82
+ }
83
+ `,document.head.appendChild(e)}};function I(){if(typeof window>"u")return null;try{return new URLSearchParams(window.location.search).get("debug")}catch{return null}}async function F(s,e){let t=`${s.replace(/\/$/,"")}/${encodeURIComponent(e)}`,r=await fetch(t,{method:"GET",credentials:"include"});if(!r.ok)throw new Error(`Failed to load debug session (${r.status})`);return await r.json()}function j(s){let e=s.replace(/\/$/,"");return async t=>{let r=`${e}/${encodeURIComponent(t.token)}/chunk-url`,n=await fetch(r,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({pageId:t.pageId,stream:t.stream,seq:t.seq})});if(!n.ok)throw new Error(`Failed to get chunk URL (${n.status})`);return await n.json()}}async function q(s,e,t,r){let o=`${s.replace(/\/$/,"")}/${encodeURIComponent(e)}/meta`;await fetch(o,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",keepalive:!0,body:JSON.stringify({pageId:t,meta:r})})}async function ee(){let s=await import("libsodium-wrappers"),e=s.default??s;return await e.ready,e}function te(s){let e=atob(s),t=new Uint8Array(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}var ne=[66,74,83,49],A=class{constructor(){this.sodium=null;this.state=null;this.headerEnvelope=null}async init(e){let t=await ee();this.sodium=t;let r=te(e),n=t.crypto_secretstream_xchacha20poly1305_keygen(),o=t.crypto_box_seal(n,r),{state:a,header:c}=t.crypto_secretstream_xchacha20poly1305_init_push(n);this.state=a;let i=new Uint8Array(ne),u=new Uint8Array([1]),p=new Uint8Array(4);new DataView(p.buffer).setUint32(0,o.length,!0);let m=re([i,u,p,o,c]);return this.headerEnvelope=m,m}get header(){if(!this.headerEnvelope)throw new Error("StreamEncryptor not initialized");return this.headerEnvelope}encryptChunk(e,t=!1){if(!this.sodium||!this.state)throw new Error("StreamEncryptor not initialized");let r=t?this.sodium.crypto_secretstream_xchacha20poly1305_TAG_FINAL:this.sodium.crypto_secretstream_xchacha20poly1305_TAG_MESSAGE;return this.sodium.crypto_secretstream_xchacha20poly1305_push(this.state,e,null,r)}};function re(s){let e=s.reduce((n,o)=>n+o.length,0),t=new Uint8Array(e),r=0;for(let n of s)t.set(n,r),r+=n.length;return t}var y=class{constructor(e,t,r,n,o){this.token=e;this.pageId=t;this.stream=r;this.publicKey=n;this.fetchChunkUrl=o;this.encryptor=new A;this.seq=0;this.initialized=!1;this.queue=Promise.resolve()}async ensureInit(){if(this.initialized)return;this.initialized=!0;let e=await this.encryptor.init(this.publicKey);await this.putChunk(e)}pushChunk(e,t=!1){this.queue=this.queue.then(async()=>{await this.ensureInit();let r=this.encryptor.encryptChunk(e,t);await this.putChunk(r)})}async flush(){await this.queue}async putChunk(e){let{uploadUrl:t}=await this.fetchChunkUrl({token:this.token,pageId:this.pageId,stream:this.stream,seq:this.seq});this.seq+=1,await fetch(t,{method:"PUT",headers:{"Content-Type":"application/octet-stream"},body:e})}};var L="bug-jar-session";function M(){if(typeof window>"u")return;let e=window.location.hostname.split(".");return e.length<2?void 0:`.${e.slice(-2).join(".")}`}function _(){if(typeof document>"u")return null;let s=document.cookie.split("; ").find(t=>t.startsWith(`${L}=`));if(!s)return null;let e=s.slice(L.length+1);return e?decodeURIComponent(e):null}function O(s,e){if(typeof document>"u")return;let t=M(),r=new Date(e).toUTCString(),n=window.location.protocol==="https:"?"; Secure":"",o=t?`; Domain=${t}`:"";document.cookie=`${L}=${encodeURIComponent(s)}; Path=/; Expires=${r}; SameSite=Lax${o}${n}`}function z(){if(typeof document>"u")return;let s=M(),e=s?`; Domain=${s}`:"";document.cookie=`${L}=; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT; SameSite=Lax${e}`}function H(s){let e=[];e.push(`Bug Report: ${s.id}`),e.push(`URL: ${s.url}`),e.push(`Time: ${new Date(s.timestamp).toISOString()}`),e.push(`User Description: "${s.userDescription}"`),e.push(""),e.push("## Environment"),e.push(`Browser: ${se(s.environment.userAgent)}`),e.push(`Viewport: ${s.environment.viewportWidth}x${s.environment.viewportHeight}`),e.push(`Connection: ${s.environment.connection?.effectiveType||"unknown"}`),e.push(`Online: ${s.environment.online}`),e.push(""),e.push("## Network Activity");let t=s.network.length,r=s.network.filter(i=>i.error||i.status&&i.status>=400),n=s.network.filter(i=>i.duration&&i.duration>3e3);if(e.push(`Total requests: ${t}`),r.length>0){e.push(`Failed requests (${r.length}):`);for(let i of r)e.push(` - ${i.method} ${i.url} \u2192 ${i.error||`HTTP ${i.status}`}`)}if(n.length>0){e.push(`Slow requests >3s (${n.length}):`);for(let i of n)e.push(` - ${i.method} ${i.url} (${Math.round(i.duration)}ms)`)}if(e.push(""),e.push("## Errors"),s.errors.length===0)e.push("No errors captured.");else{e.push(`Total errors: ${s.errors.length}`);for(let i of s.errors)e.push(` - [${i.type}] ${i.message}`),i.filename&&e.push(` at ${i.filename}:${i.lineno}:${i.colno}`)}e.push(""),e.push("## Console");let o={log:0,warn:0,error:0,info:0,debug:0};for(let i of s.console)o[i.level]++;e.push(`Logs: ${o.log}, Warnings: ${o.warn}, Errors: ${o.error}, Info: ${o.info}, Debug: ${o.debug}`);let a=s.console.filter(i=>i.level==="error");if(a.length>0){e.push("Console errors:");for(let i of a)e.push(` - ${i.args.map(u=>typeof u=="string"?u:JSON.stringify(u)).join(" ")}`)}e.push(""),e.push("## User Actions"),e.push(`Total actions: ${s.userActions.length}`);let c={};for(let i of s.userActions)c[i.type]=(c[i.type]||0)+1;for(let[i,u]of Object.entries(c))e.push(` - ${i}: ${u}`);if(s.userActions.length>0){let i=s.userActions[0].timestamp,p=((s.userActions[s.userActions.length-1].timestamp-i)/1e3).toFixed(1);e.push(`Session duration: ${p}s`)}if(e.push(""),s.performance){e.push("## Performance");let i=s.performance;i.largestContentfulPaint&&e.push(`LCP: ${Math.round(i.largestContentfulPaint)}ms`),i.firstInputDelay&&e.push(`FID: ${Math.round(i.firstInputDelay)}ms`),i.cumulativeLayoutShift!==null&&e.push(`CLS: ${i.cumulativeLayoutShift?.toFixed(3)}`),i.loadComplete&&e.push(`Page Load: ${Math.round(i.loadComplete)}ms`),e.push(`Resources: ${i.resourceCount} (${oe(i.totalTransferSize)})`)}return e.join(`
84
+ `)}function se(s){return s.includes("Chrome/")?`Chrome ${s.match(/Chrome\/(\d+)/)?.[1]||""}`:s.includes("Firefox/")?`Firefox ${s.match(/Firefox\/(\d+)/)?.[1]||""}`:s.includes("Safari/")&&!s.includes("Chrome")?`Safari ${s.match(/Version\/(\d+)/)?.[1]||""}`:s.slice(0,50)}function oe(s){return s<1024?`${s}B`:s<1024*1024?`${(s/1024).toFixed(1)}KB`:`${(s/(1024*1024)).toFixed(1)}MB`}async function P(s,e){let t=[],r=JSON.stringify(s,null,2);t.push({name:"report.json",content:new TextEncoder().encode(r)});let n=H(s);if(t.push({name:"summary.md",content:new TextEncoder().encode(n)}),s.screenshot){let o=ie(s.screenshot);o&&t.push({name:"screenshot.png",content:o})}if(e){let o=new Uint8Array(await e.arrayBuffer());t.push({name:"recording.webm",content:o})}return ae(t)}function ie(s){try{let e=s.split(",")[1];if(!e)return null;let t=atob(e),r=new Uint8Array(t.length);for(let n=0;n<t.length;n++)r[n]=t.charCodeAt(n);return r}catch{return null}}function ae(s){let e=[],t=[],r=0;for(let i of s){let u=new TextEncoder().encode(i.name),p=de(i.content),m=ce(u,i.content.length,p);e.push(m),e.push(u),e.push(i.content);let J=ue(u,i.content.length,p,r);t.push(J),t.push(u),r+=m.length+u.length+i.content.length}let n=r,o=0;for(let i of t)o+=i.length;let a=le(s.length,o,n),c=[...e,...t,a].map(i=>i.buffer);return new Blob(c,{type:"application/zip"})}function ce(s,e,t){let r=new Uint8Array(30),n=new DataView(r.buffer);return n.setUint32(0,67324752,!0),n.setUint16(4,20,!0),n.setUint16(6,0,!0),n.setUint16(8,0,!0),n.setUint16(10,0,!0),n.setUint16(12,0,!0),n.setUint32(14,t,!0),n.setUint32(18,e,!0),n.setUint32(22,e,!0),n.setUint16(26,s.length,!0),n.setUint16(28,0,!0),r}function ue(s,e,t,r){let n=new Uint8Array(46),o=new DataView(n.buffer);return o.setUint32(0,33639248,!0),o.setUint16(4,20,!0),o.setUint16(6,20,!0),o.setUint16(8,0,!0),o.setUint16(10,0,!0),o.setUint16(12,0,!0),o.setUint16(14,0,!0),o.setUint32(16,t,!0),o.setUint32(20,e,!0),o.setUint32(24,e,!0),o.setUint16(28,s.length,!0),o.setUint16(30,0,!0),o.setUint16(32,0,!0),o.setUint16(34,0,!0),o.setUint16(36,0,!0),o.setUint32(38,0,!0),o.setUint32(42,r,!0),n}function le(s,e,t){let r=new Uint8Array(22),n=new DataView(r.buffer);return n.setUint32(0,101010256,!0),n.setUint16(4,0,!0),n.setUint16(6,0,!0),n.setUint16(8,s,!0),n.setUint16(10,s,!0),n.setUint32(12,e,!0),n.setUint32(16,t,!0),n.setUint16(20,0,!0),r}function de(s){let e=4294967295;for(let t=0;t<s.length;t++){e^=s[t];for(let r=0;r<8;r++)e=e>>>1^(e&1?3988292384:0)}return(e^4294967295)>>>0}var pe="0.6.0",he={maxNetworkEntries:100,maxConsoleEntries:200,maxUserActions:150,maxErrors:50,captureScreenshot:!0,captureHtmlSnapshot:!0,captureCookies:!0,captureLocalStorage:!0,captureSessionStorage:!0,capturePerformance:!0,captureWebVitals:!0,captureMemory:!0,captureConnectivity:!0,sensitiveFields:["password","token","secret","authorization","cookie","session","credit_card","cvv","ssn","cpf"],endpoint:void 0,onCapture:void 0,debugToken:void 0,debugSessionEndpoint:void 0},g=class{constructor(e={}){this.sessionBorder=null;this.debugSession=null;this.dataUploader=null;this.videoUploader=null;this.pageId=h();this.dataInterval=null;this.finalized=!1;this.started=!1;this.config={...he,...e},this.network=new w(this.config),this.console=new b(this.config),this.errors=new S(this.config),this.userActions=new E(this.config),this.environment=new k,this.performance=new C,this.storage=new x(this.config),this.screenshot=new R,this.featureFlags=new U,this.screenRecorder=new T}start(){if(this.started)return;this.started=!0,this.network.start(),this.console.start(),this.errors.start(),this.userActions.start(),this.config.captureWebVitals&&this.performance.start();let e=this.config.debugToken??I()??_();e&&this.startDebugSession(e)}stop(){this.started&&(this.started=!1,this.network.stop(),this.console.stop(),this.errors.stop(),this.userActions.stop(),this.performance.stop(),this.sessionBorder?.unmount())}async startRecording(){await this.screenRecorder.start()}get isRecording(){return this.screenRecorder.isRecording}async capture(e=""){let t={id:h(),timestamp:Date.now(),url:window.location.href,title:document.title,userDescription:e,environment:this.environment.collect(),network:this.network.getEntries(),console:this.console.getEntries(),errors:this.errors.getEntries(),userActions:this.userActions.getEntries(),performance:this.config.capturePerformance?this.performance.collect():null,storage:this.storage.collect(),screenshot:this.config.captureScreenshot?await this.screenshot.capture():null,htmlSnapshot:this.config.captureHtmlSnapshot?this.screenshot.captureHtml():null,featureFlags:this.featureFlags.collect(),metadata:{},version:pe};return this.config.onCapture&&this.config.onCapture(t),t}async captureAndExport(e=""){let t=await this.screenRecorder.stop(),r=await this.capture(e);if(this.config.endpoint)if(t){let n=new FormData;n.append("report",JSON.stringify(r)),n.append("video",t,"recording.webm"),await fetch(this.config.endpoint,{method:"POST",body:n})}else await fetch(this.config.endpoint,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});else{let n=await P(r,t),o=URL.createObjectURL(n),a=document.createElement("a");a.href=o,a.download=`bug-report-${r.id}.zip`,a.click(),URL.revokeObjectURL(o)}return r}getReport(){return this.capture()}async startDebugSession(e){if(!this.config.debugSessionEndpoint)return;let t=this.config.debugSessionEndpoint,r=()=>{this.sessionBorder=new B,this.sessionBorder.mount()};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",r):r();try{this.debugSession=await F(t,e),O(this.debugSession.token,this.debugSession.expiresAt);let n=j(t);this.dataUploader=new y(this.debugSession.token,this.pageId,"data",this.debugSession.publicKey,n),this.videoUploader=new y(this.debugSession.token,this.pageId,"video",this.debugSession.publicKey,n),q(t,this.debugSession.token,this.pageId,{url:window.location.href,title:document.title,startedAt:Date.now(),environment:this.environment.collect()}),this.screenRecorder.setChunkHandler(o=>{this.videoUploader?.pushChunk(o)}),await this.screenRecorder.start(),this.startDataStreaming(),this.registerFlushHandlers()}catch{this.sessionBorder?.unmount()}}startDataStreaming(){let e=t=>{if(!this.dataUploader)return;let r={pageId:this.pageId,timestamp:Date.now(),url:window.location.href,network:this.network.getEntries(),console:this.console.getEntries(),errors:this.errors.getEntries(),userActions:this.userActions.getEntries(),storage:this.storage.collect(),featureFlags:this.featureFlags.collect()},n=new TextEncoder().encode(JSON.stringify(r)+`
85
+ `);this.dataUploader.pushChunk(n,t)};this.dataInterval=setInterval(()=>e(!1),5e3)}registerFlushHandlers(){let e=()=>{this.finalizePage()};window.addEventListener("pagehide",e),document.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&e()})}async finalizePage(){if(this.finalized||!this.debugSession)return;this.finalized=!0,this.dataInterval&&(clearInterval(this.dataInterval),this.dataInterval=null);let e={pageId:this.pageId,timestamp:Date.now(),url:window.location.href,network:this.network.getEntries(),console:this.console.getEntries(),errors:this.errors.getEntries(),userActions:this.userActions.getEntries(),storage:this.storage.collect(),featureFlags:this.featureFlags.collect(),screenshot:this.config.captureScreenshot?await this.screenshot.capture():null},t=new TextEncoder().encode(JSON.stringify(e)+`
86
+ `);this.dataUploader?.pushChunk(t,!0),await this.screenRecorder.stop(),await Promise.allSettled([this.dataUploader?.flush()??Promise.resolve(),this.videoUploader?.flush()??Promise.resolve()])}endDebugSession(){z(),this.sessionBorder?.unmount(),this.finalizePage()}};function N(s={}){let e=new g(s);return e.start(),e}typeof window<"u"&&(window.BugJar={BugJar:g,init:N});var fe=g;0&&(module.exports={BugJar,exportAsZip,generateSummary,init});