@arvoretech/bug-jar 0.3.1 → 0.4.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,301 +1,60 @@
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 I=Object.create;var y=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var X=Object.getOwnPropertyNames;var _=Object.getPrototypeOf,O=Object.prototype.hasOwnProperty;var z=(o,e)=>{for(var t in e)y(o,t,{get:e[t],enumerable:!0})},A=(o,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of X(e))!O.call(o,r)&&r!==t&&y(o,r,{get:()=>e[r],enumerable:!(n=N(e,r))||n.enumerable});return o};var J=(o,e,t)=>(t=o!=null?I(_(o)):{},A(e||!o||!o.__esModule?y(t,"default",{value:o,enumerable:!0}):t,o)),V=o=>A(y({},"__esModule",{value:!0}),o);var ie={};z(ie,{BugJar:()=>m,default:()=>se,exportAsZip:()=>g,generateSummary:()=>L,init:()=>M});module.exports=V(ie);function f(){return`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`}function D(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?h(s):s});return n&&n.length>e?n.slice(0,e)+"...[truncated]":n||""}catch{return"[Unserializable]"}}function h(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 d(o,e){if(!o||typeof o!="object")return o;if(Array.isArray(o))return o.map(n=>d(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]=d(r,e):t[n]=r;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 b=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,n){let r=performance.now(),s={id:f(),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=d(s.requestBody,e.config.sensitiveFields),s.responseBody=d(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:f(),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=d(r.requestBody,e.config.sensitiveFields),r.responseBody=d(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:f(),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=d(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 v=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]=(...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(D(r))),stack:e==="error"||e==="warn"?this.getStack():null};this.buffer.push(n)}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 k=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 w=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 n=t.match(/at\s+(.+?)\s+\(/);return n?n[1]:null}catch{return null}}};var S=class{constructor(e){this.listeners=[];this.buffer=new l(e.maxUserActions)}start(){this.addListener("click",r=>{let s=r.target;this.buffer.push({timestamp:Date.now(),type:"click",target:h(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:h(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:h(r.target)})}),this.addListener("paste",r=>{this.buffer.push({timestamp:Date.now(),type:"paste",target:h(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 E=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 B=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 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 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 R=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}">
5
5
  <foreignObject width="100%" height="100%">
6
6
  ${s}
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 C=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){let n=`bug-jar--${this.config.uiPosition}`,r=e?" bug-jar-trigger--compact":"";return e?`
9
- <button class="bug-jar-trigger ${n}${r}" 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
- </button>
16
- `:`
17
- <button class="bug-jar-trigger ${n}" aria-label="${this.config.uiLabel}">
18
- <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
19
- <path d="M8 2l1.88 1.88M14.12 3.88L16 2M9 7.13v-1a3.003 3.003 0 116 0v1"/>
20
- <path d="M12 20c-3.3 0-6-2.7-6-6v-3a6 6 0 0112 0v3c0 3.3-2.7 6-6 6z"/>
21
- <path d="M12 20v2M6 13H2M22 13h-4M6 17l-2 2M18 17l2 2M6 9l-2-2M18 9l2-2"/>
22
- </svg>
23
- <span>${this.config.uiLabel}</span>
24
- </button>
25
- <div class="bug-jar-modal" hidden>
26
- <div class="bug-jar-modal-backdrop"></div>
27
- <div class="bug-jar-modal-content">
28
- <div class="bug-jar-modal-header">
29
- <h3>Reportar Bug</h3>
30
- <button class="bug-jar-close" aria-label="Fechar">&times;</button>
31
- </div>
32
- <div class="bug-jar-modal-body">
33
- <label for="bug-jar-description">O que aconteceu?</label>
34
- <textarea id="bug-jar-description" placeholder="Descreva o que voc\xEA estava fazendo e o que deu errado..." rows="4"></textarea>
35
- <p class="bug-jar-hint">Todas as informa\xE7\xF5es t\xE9cnicas ser\xE3o capturadas automaticamente.</p>
36
- <div class="bug-jar-recording-section">
37
- <button class="bug-jar-record-btn">
38
- <span class="bug-jar-record-icon"></span>
39
- <span class="bug-jar-record-label">Gravar Tela</span>
40
- </button>
41
- <span class="bug-jar-recording-status" hidden>Gravando...</span>
42
- </div>
43
- </div>
44
- <div class="bug-jar-modal-footer">
45
- <button class="bug-jar-cancel">Cancelar</button>
46
- <button class="bug-jar-submit">Enviar Relat\xF3rio</button>
47
- </div>
48
- <div class="bug-jar-status" hidden></div>
49
- </div>
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 C=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 k=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 T=class{constructor(e){this.container=null;this.onFinish=e}mount(){this.container||(this.container=document.createElement("div"),this.container.id="bug-jar-debug-banner",this.container.innerHTML=`
9
+ <div class="bug-jar-debug-banner-inner">
10
+ <span class="bug-jar-debug-dot"></span>
11
+ <span class="bug-jar-debug-text">Sess\xE3o de depura\xE7\xE3o ativa \u2014 gravando</span>
12
+ <button class="bug-jar-debug-finish">Finalizar e enviar</button>
50
13
  </div>
51
- `}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=`
52
- #bug-jar-widget {
14
+ `,this.injectStyles(),document.body.appendChild(this.container),this.bindEvents())}unmount(){this.container?.remove(),this.container=null,document.getElementById("bug-jar-debug-banner-styles")?.remove()}setState(e,t){if(!this.container)return;let n=this.container.querySelector(".bug-jar-debug-text"),r=this.container.querySelector(".bug-jar-debug-finish"),s=this.container.querySelector(".bug-jar-debug-dot"),a={recording:"Sess\xE3o de depura\xE7\xE3o ativa \u2014 gravando",encrypting:"Criptografando o relat\xF3rio...",uploading:"Enviando o relat\xF3rio...",done:"Relat\xF3rio enviado com sucesso. Pode fechar a aba.",error:t??"Falha ao enviar o relat\xF3rio."};n&&(n.textContent=a[e]),r&&(r.disabled=e!=="recording"&&e!=="error"),s&&(s.dataset.state=e),e==="error"&&r&&(r.textContent="Tentar novamente"),e==="recording"&&r&&(r.textContent="Finalizar e enviar")}bindEvents(){this.container?.querySelector(".bug-jar-debug-finish")?.addEventListener("click",()=>{this.onFinish()})}injectStyles(){if(document.getElementById("bug-jar-debug-banner-styles"))return;let e=document.createElement("style");e.id="bug-jar-debug-banner-styles",e.textContent=`
15
+ #bug-jar-debug-banner {
16
+ position: fixed;
17
+ top: 0;
18
+ left: 0;
19
+ right: 0;
20
+ z-index: 2147483647;
53
21
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
54
- font-size: 14px;
55
- line-height: 1.5;
56
- color: #1a1a1a;
57
22
  }
58
-
59
- .bug-jar-trigger {
60
- position: fixed;
61
- z-index: 99999;
23
+ .bug-jar-debug-banner-inner {
62
24
  display: flex;
63
25
  align-items: center;
64
- gap: 6px;
65
- padding: 10px 16px;
66
- border: none;
67
- border-radius: 24px;
26
+ gap: 12px;
27
+ padding: 8px 16px;
68
28
  background: #1a1a1a;
69
29
  color: #fff;
70
30
  font-size: 13px;
71
- font-weight: 500;
72
- cursor: pointer;
73
- box-shadow: 0 4px 12px rgba(0,0,0,0.15);
74
- transition: transform 0.15s, box-shadow 0.15s, background 0.3s;
75
- user-select: none;
76
- touch-action: none;
77
- }
78
-
79
- .bug-jar-trigger:hover {
80
- transform: scale(1.05);
81
- box-shadow: 0 6px 20px rgba(0,0,0,0.2);
82
- }
83
-
84
- .bug-jar-trigger--compact {
85
- padding: 12px;
86
- border-radius: 50%;
87
- width: 44px;
88
- height: 44px;
89
- justify-content: center;
90
- }
91
-
92
- .bug-jar-trigger--compact span {
93
- display: none;
94
- }
95
-
96
- .bug-jar-trigger--expanded {
97
- padding: 10px 16px;
98
- width: auto;
99
- height: auto;
100
- border-radius: 24px;
101
- }
102
-
103
- .bug-jar-trigger--dragging {
104
- cursor: grabbing;
105
- transform: scale(1.1);
106
- box-shadow: 0 8px 25px rgba(0,0,0,0.3);
107
- }
108
-
109
- .bug-jar-trigger--recording {
110
- background: #dc2626;
111
- animation: bug-jar-pulse 1.5s infinite;
112
- }
113
-
114
- @keyframes bug-jar-pulse {
115
- 0%, 100% { opacity: 1; }
116
- 50% { opacity: 0.7; }
117
- }
118
-
119
- .bug-jar--bottom-right { bottom: 20px; right: 20px; }
120
- .bug-jar--bottom-left { bottom: 20px; left: 20px; }
121
- .bug-jar--top-right { top: 20px; right: 20px; }
122
- .bug-jar--top-left { top: 20px; left: 20px; }
123
-
124
- .bug-jar-modal {
125
- position: fixed;
126
- inset: 0;
127
- z-index: 100000;
128
- display: flex;
129
- align-items: center;
130
- justify-content: center;
131
- }
132
-
133
- .bug-jar-modal[hidden] { display: none; }
134
-
135
- .bug-jar-modal-backdrop {
136
- position: absolute;
137
- inset: 0;
138
- background: rgba(0,0,0,0.5);
139
- backdrop-filter: blur(2px);
140
- }
141
-
142
- .bug-jar-modal-content {
143
- position: relative;
144
- width: 90%;
145
- max-width: 480px;
146
- background: #fff;
147
- border-radius: 12px;
148
- box-shadow: 0 20px 60px rgba(0,0,0,0.3);
149
- overflow: hidden;
150
- }
151
-
152
- .bug-jar-modal-header {
153
- display: flex;
154
- align-items: center;
155
- justify-content: space-between;
156
- padding: 16px 20px;
157
- border-bottom: 1px solid #eee;
158
- }
159
-
160
- .bug-jar-modal-header h3 {
161
- margin: 0;
162
- font-size: 16px;
163
- font-weight: 600;
164
- }
165
-
166
- .bug-jar-close {
167
- background: none;
168
- border: none;
169
- font-size: 24px;
170
- cursor: pointer;
171
- color: #666;
172
- padding: 0 4px;
173
- }
174
-
175
- .bug-jar-modal-body {
176
- padding: 20px;
177
- }
178
-
179
- .bug-jar-modal-body label {
180
- display: block;
181
- font-weight: 500;
182
- margin-bottom: 8px;
183
- }
184
-
185
- #bug-jar-description {
186
- width: 100%;
187
- padding: 12px;
188
- border: 1px solid #ddd;
189
- border-radius: 8px;
190
- font-size: 14px;
191
- font-family: inherit;
192
- resize: vertical;
193
- min-height: 100px;
194
- box-sizing: border-box;
195
- }
196
-
197
- #bug-jar-description:focus {
198
- outline: none;
199
- border-color: #1a1a1a;
200
- box-shadow: 0 0 0 2px rgba(26,26,26,0.1);
201
- }
202
-
203
- #bug-jar-description.bug-jar-error {
204
- border-color: #e53e3e;
205
- }
206
-
207
- .bug-jar-hint {
208
- margin: 8px 0 0;
209
- font-size: 12px;
210
- color: #888;
211
- }
212
-
213
- .bug-jar-recording-section {
214
- margin-top: 16px;
215
- display: flex;
216
- align-items: center;
217
- gap: 12px;
218
- }
219
-
220
- .bug-jar-record-btn {
221
- display: flex;
222
- align-items: center;
223
- gap: 6px;
224
- padding: 8px 14px;
225
- border: 1px solid #ddd;
226
- border-radius: 6px;
227
- background: #fff;
228
- cursor: pointer;
229
- font-size: 13px;
230
- transition: all 0.2s;
31
+ box-shadow: 0 2px 8px rgba(0,0,0,0.25);
231
32
  }
232
-
233
- .bug-jar-record-btn:hover {
234
- border-color: #dc2626;
235
- color: #dc2626;
236
- }
237
-
238
- .bug-jar-record-btn--active {
239
- border-color: #dc2626;
240
- background: #fef2f2;
241
- color: #dc2626;
242
- pointer-events: none;
243
- }
244
-
245
- .bug-jar-record-icon {
33
+ .bug-jar-debug-dot {
246
34
  width: 10px;
247
35
  height: 10px;
248
36
  border-radius: 50%;
249
37
  background: #dc2626;
250
- }
251
-
252
- .bug-jar-recording-status {
253
- font-size: 12px;
254
- color: #dc2626;
255
- font-weight: 500;
256
- animation: bug-jar-pulse 1.5s infinite;
257
- }
258
-
259
- .bug-jar-modal-footer {
260
- display: flex;
261
- justify-content: flex-end;
262
- gap: 8px;
263
- padding: 16px 20px;
264
- border-top: 1px solid #eee;
265
- }
266
-
267
- .bug-jar-cancel {
268
- padding: 8px 16px;
269
- border: 1px solid #ddd;
38
+ animation: bug-jar-debug-pulse 1.5s infinite;
39
+ flex-shrink: 0;
40
+ }
41
+ .bug-jar-debug-dot[data-state="done"] { background: #16a34a; animation: none; }
42
+ .bug-jar-debug-dot[data-state="error"] { background: #f59e0b; animation: none; }
43
+ .bug-jar-debug-text { flex: 1; }
44
+ .bug-jar-debug-finish {
45
+ padding: 6px 14px;
46
+ border: none;
270
47
  border-radius: 6px;
271
48
  background: #fff;
272
- cursor: pointer;
49
+ color: #1a1a1a;
273
50
  font-size: 13px;
274
- }
275
-
276
- .bug-jar-submit {
277
- padding: 8px 16px;
278
- border: none;
279
- border-radius: 6px;
280
- background: #1a1a1a;
281
- color: #fff;
51
+ font-weight: 600;
282
52
  cursor: pointer;
283
- font-size: 13px;
284
- font-weight: 500;
285
- }
286
-
287
- .bug-jar-submit:disabled {
288
- opacity: 0.6;
289
- cursor: not-allowed;
290
53
  }
291
-
292
- .bug-jar-status {
293
- padding: 12px 20px;
294
- font-size: 13px;
295
- text-align: center;
54
+ .bug-jar-debug-finish:disabled { opacity: 0.6; cursor: not-allowed; }
55
+ @keyframes bug-jar-debug-pulse {
56
+ 0%, 100% { opacity: 1; }
57
+ 50% { opacity: 0.4; }
296
58
  }
297
-
298
- .bug-jar-status--success { color: #16a34a; background: #f0fdf4; }
299
- .bug-jar-status--error { color: #dc2626; background: #fef2f2; }
300
- `,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(`
301
- `)}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 k,this.featureFlags=new C,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});
59
+ `,document.head.appendChild(e)}};function L(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: ${W(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} (${K(i.totalTransferSize)})`)}return e.join(`
60
+ `)}function W(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 K(o){return o<1024?`${o}B`:o<1024*1024?`${(o/1024).toFixed(1)}KB`:`${(o/(1024*1024)).toFixed(1)}MB`}async function g(o,e){let t=[],n=JSON.stringify(o,null,2);t.push({name:"report.json",content:new TextEncoder().encode(n)});let r=L(o);if(t.push({name:"summary.md",content:new TextEncoder().encode(r)}),o.screenshot){let s=G(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 Y(t)}function G(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 Y(o){let e=[],t=[],n=0;for(let i of o){let u=new TextEncoder().encode(i.name),p=te(i.content),H=Z(u,i.content.length,p);e.push(H),e.push(u),e.push(i.content);let q=Q(u,i.content.length,p,n);t.push(q),t.push(u),n+=H.length+u.length+i.content.length}let r=n,s=0;for(let i of t)s+=i.length;let a=ee(o.length,s,r),c=[...e,...t,a].map(i=>i.buffer);return new Blob(c,{type:"application/zip"})}function Z(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 Q(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 ee(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 te(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 U=[66,74,69,49];function re(o){let e=atob(o),t=new Uint8Array(e.length);for(let n=0;n<e.length;n++)t[n]=e.charCodeAt(n);return t}async function P(o,e){let t=await import("libsodium-wrappers"),n=t.default??t;await n.ready;let r=re(e),s=n.randombytes_buf(n.crypto_secretbox_KEYBYTES),a=n.randombytes_buf(n.crypto_secretbox_NONCEBYTES),c=n.crypto_secretbox_easy(o,a,s),i=n.crypto_box_seal(s,r),u=new Uint8Array(U.length+1);u.set(U,0),u[U.length]=1;let p=new Uint8Array(4);return new DataView(p.buffer).setUint32(0,i.length,!0),new Blob([u.buffer,a.buffer,p.buffer,i.buffer,c.buffer],{type:"application/octet-stream"})}function $(){if(typeof window>"u")return null;try{return new URLSearchParams(window.location.search).get("debug")}catch{return null}}async function j(o,e){let t=`${o.replace(/\/$/,"")}/${encodeURIComponent(e)}`,n=await fetch(t,{method:"GET",credentials:"include"});if(!n.ok)throw new Error(`Failed to load debug session (${n.status})`);return await n.json()}async function F(o,e,t){let n=await g(e,t),r=new Uint8Array(await n.arrayBuffer()),s=await P(r,o.publicKey),a=await fetch(o.presignedPut,{method:"PUT",headers:{"Content-Type":"application/octet-stream"},body:s});if(!a.ok)throw new Error(`Failed to upload report (${a.status})`)}var ne="0.4.0",oe={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},m=class{constructor(e={}){this.debugBanner=null;this.debugSession=null;this.started=!1;this.config={...oe,...e},this.network=new b(this.config),this.console=new v(this.config),this.errors=new w(this.config),this.userActions=new S(this.config),this.environment=new E,this.performance=new B,this.storage=new x(this.config),this.screenshot=new R,this.featureFlags=new C,this.screenRecorder=new k}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??$();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.debugBanner?.unmount())}async startRecording(){await this.screenRecorder.start()}get isRecording(){return this.screenRecorder.isRecording}async capture(e=""){let t={id:f(),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:ne};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 g(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()}async startDebugSession(e){if(!this.config.debugSessionEndpoint)return;let t=()=>{this.debugBanner=new T(()=>this.finishDebugSession()),this.debugBanner.mount()};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",t):t();try{this.debugSession=await j(this.config.debugSessionEndpoint,e),await this.screenRecorder.start()}catch(n){this.debugBanner?.setState("error",n instanceof Error?n.message:"Falha ao iniciar a sess\xE3o.")}}async finishDebugSession(){if(this.debugSession)try{let e=await this.screenRecorder.stop();this.debugBanner?.setState("encrypting");let t=await this.capture("Debug session capture");this.debugBanner?.setState("uploading"),await F(this.debugSession,t,e),this.debugBanner?.setState("done")}catch(e){this.debugBanner?.setState("error",e instanceof Error?e.message:"Falha ao enviar o relat\xF3rio.")}}};function M(o={}){let e=new m(o);return e.start(),e}typeof window<"u"&&(window.BugJar={BugJar:m,init:M});var se=m;0&&(module.exports={BugJar,exportAsZip,generateSummary,init});