@arvoretech/bug-jar 0.2.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.
@@ -0,0 +1,266 @@
1
+ "use strict";var BugJar=(()=>{var H=Object.defineProperty;var q=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var P=Object.prototype.hasOwnProperty;var F=(o,e)=>{for(var t in e)H(o,t,{get:e[t],enumerable:!0})},z=(o,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of D(e))!P.call(o,r)&&r!==t&&H(o,r,{get:()=>e[r],enumerable:!(n=q(e,r))||n.enumerable});return o};var I=o=>z(H({},"__esModule",{value:!0}),o);var Q={};F(Q,{BugJar:()=>m,default:()=>K,exportAsZip:()=>B,generateSummary:()=>T,init:()=>$});function g(){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?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 y=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:g(),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:g(),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:g(),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(A(r))),stack:e==="error"||e==="warn"?this.getStack():null};this.buffer.push(n)}getStack(){try{return new Error().stack?.split(`
3
+ `).slice(4).join(`
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 E=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 x=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 S=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 R=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 j=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
+ <foreignObject width="100%" height="100%">
6
+ ${s}
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 L=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 C=class{constructor(e,t,n){this.container=null;this.config=e,this.onReport=t,this.screenRecorder=n}mount(){this.container||(this.container=document.createElement("div"),this.container.id="bug-jar-widget",this.container.innerHTML=this.getWidgetHTML(),document.body.appendChild(this.container),this.injectStyles(),this.bindEvents())}unmount(){this.container&&(this.container.remove(),this.container=null);let e=document.getElementById("bug-jar-styles");e&&e.remove()}getWidgetHTML(){return`
9
+ <button class="bug-jar-trigger ${`bug-jar--${this.config.uiPosition}`}" 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
+ <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>
42
+ </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"),f=this.container.querySelector(".bug-jar-recording-status"),b=()=>{t.hidden=!1,c.focus(),this.updateRecordingUI(u,f)},p=()=>{t.hidden=!0,c.value="",i.hidden=!0};e.addEventListener("click",b),n.addEventListener("click",p),r.addEventListener("click",p),s.addEventListener("click",p),u.addEventListener("click",async()=>{this.screenRecorder.isRecording||(p(),await this.screenRecorder.start(),this.updateTriggerForRecording(e))}),a.addEventListener("click",async()=>{let U=c.value.trim();if(!U){c.classList.add("bug-jar-error");return}c.classList.remove("bug-jar-error"),a.setAttribute("disabled","true"),a.textContent="Capturando...",i.hidden=!0;try{await this.onReport(U),i.textContent="\u2713 Relat\xF3rio baixado como .zip!",i.className="bug-jar-status bug-jar-status--success",i.hidden=!1,this.resetTrigger(e),setTimeout(p,2e3)}catch(M){i.textContent=`Erro: ${M instanceof Error?M.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(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)}injectStyles(){if(document.getElementById("bug-jar-styles"))return;let e=document.createElement("style");e.id="bug-jar-styles",e.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
+ }
68
+
69
+ .bug-jar-trigger:hover {
70
+ transform: scale(1.05);
71
+ box-shadow: 0 6px 20px rgba(0,0,0,0.2);
72
+ }
73
+
74
+ .bug-jar-trigger--recording {
75
+ background: #dc2626;
76
+ animation: bug-jar-pulse 1.5s infinite;
77
+ }
78
+
79
+ @keyframes bug-jar-pulse {
80
+ 0%, 100% { opacity: 1; }
81
+ 50% { opacity: 0.7; }
82
+ }
83
+
84
+ .bug-jar--bottom-right { bottom: 20px; right: 20px; }
85
+ .bug-jar--bottom-left { bottom: 20px; left: 20px; }
86
+ .bug-jar--top-right { top: 20px; right: 20px; }
87
+ .bug-jar--top-left { top: 20px; left: 20px; }
88
+
89
+ .bug-jar-modal {
90
+ position: fixed;
91
+ inset: 0;
92
+ z-index: 100000;
93
+ display: flex;
94
+ align-items: center;
95
+ justify-content: center;
96
+ }
97
+
98
+ .bug-jar-modal[hidden] { display: none; }
99
+
100
+ .bug-jar-modal-backdrop {
101
+ position: absolute;
102
+ inset: 0;
103
+ background: rgba(0,0,0,0.5);
104
+ backdrop-filter: blur(2px);
105
+ }
106
+
107
+ .bug-jar-modal-content {
108
+ position: relative;
109
+ width: 90%;
110
+ max-width: 480px;
111
+ background: #fff;
112
+ border-radius: 12px;
113
+ box-shadow: 0 20px 60px rgba(0,0,0,0.3);
114
+ overflow: hidden;
115
+ }
116
+
117
+ .bug-jar-modal-header {
118
+ display: flex;
119
+ align-items: center;
120
+ justify-content: space-between;
121
+ padding: 16px 20px;
122
+ border-bottom: 1px solid #eee;
123
+ }
124
+
125
+ .bug-jar-modal-header h3 {
126
+ margin: 0;
127
+ font-size: 16px;
128
+ font-weight: 600;
129
+ }
130
+
131
+ .bug-jar-close {
132
+ background: none;
133
+ border: none;
134
+ font-size: 24px;
135
+ cursor: pointer;
136
+ color: #666;
137
+ padding: 0 4px;
138
+ }
139
+
140
+ .bug-jar-modal-body {
141
+ padding: 20px;
142
+ }
143
+
144
+ .bug-jar-modal-body label {
145
+ display: block;
146
+ font-weight: 500;
147
+ margin-bottom: 8px;
148
+ }
149
+
150
+ #bug-jar-description {
151
+ width: 100%;
152
+ padding: 12px;
153
+ border: 1px solid #ddd;
154
+ border-radius: 8px;
155
+ font-size: 14px;
156
+ font-family: inherit;
157
+ resize: vertical;
158
+ min-height: 100px;
159
+ box-sizing: border-box;
160
+ }
161
+
162
+ #bug-jar-description:focus {
163
+ outline: none;
164
+ border-color: #1a1a1a;
165
+ box-shadow: 0 0 0 2px rgba(26,26,26,0.1);
166
+ }
167
+
168
+ #bug-jar-description.bug-jar-error {
169
+ border-color: #e53e3e;
170
+ }
171
+
172
+ .bug-jar-hint {
173
+ margin: 8px 0 0;
174
+ font-size: 12px;
175
+ color: #888;
176
+ }
177
+
178
+ .bug-jar-recording-section {
179
+ margin-top: 16px;
180
+ display: flex;
181
+ align-items: center;
182
+ gap: 12px;
183
+ }
184
+
185
+ .bug-jar-record-btn {
186
+ display: flex;
187
+ align-items: center;
188
+ gap: 6px;
189
+ padding: 8px 14px;
190
+ border: 1px solid #ddd;
191
+ border-radius: 6px;
192
+ background: #fff;
193
+ cursor: pointer;
194
+ font-size: 13px;
195
+ transition: all 0.2s;
196
+ }
197
+
198
+ .bug-jar-record-btn:hover {
199
+ border-color: #dc2626;
200
+ color: #dc2626;
201
+ }
202
+
203
+ .bug-jar-record-btn--active {
204
+ border-color: #dc2626;
205
+ background: #fef2f2;
206
+ color: #dc2626;
207
+ pointer-events: none;
208
+ }
209
+
210
+ .bug-jar-record-icon {
211
+ width: 10px;
212
+ height: 10px;
213
+ border-radius: 50%;
214
+ background: #dc2626;
215
+ }
216
+
217
+ .bug-jar-recording-status {
218
+ font-size: 12px;
219
+ color: #dc2626;
220
+ font-weight: 500;
221
+ animation: bug-jar-pulse 1.5s infinite;
222
+ }
223
+
224
+ .bug-jar-modal-footer {
225
+ display: flex;
226
+ justify-content: flex-end;
227
+ gap: 8px;
228
+ padding: 16px 20px;
229
+ border-top: 1px solid #eee;
230
+ }
231
+
232
+ .bug-jar-cancel {
233
+ padding: 8px 16px;
234
+ border: 1px solid #ddd;
235
+ border-radius: 6px;
236
+ background: #fff;
237
+ cursor: pointer;
238
+ font-size: 13px;
239
+ }
240
+
241
+ .bug-jar-submit {
242
+ padding: 8px 16px;
243
+ border: none;
244
+ border-radius: 6px;
245
+ background: #1a1a1a;
246
+ color: #fff;
247
+ cursor: pointer;
248
+ font-size: 13px;
249
+ font-weight: 500;
250
+ }
251
+
252
+ .bug-jar-submit:disabled {
253
+ opacity: 0.6;
254
+ cursor: not-allowed;
255
+ }
256
+
257
+ .bug-jar-status {
258
+ padding: 12px 20px;
259
+ font-size: 13px;
260
+ text-align: center;
261
+ }
262
+
263
+ .bug-jar-status--success { color: #16a34a; background: #f0fdf4; }
264
+ .bug-jar-status--error { color: #dc2626; background: #fef2f2; }
265
+ `,document.head.appendChild(e)}};function T(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: ${N(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,f=((o.userActions[o.userActions.length-1].timestamp-i)/1e3).toFixed(1);e.push(`Session duration: ${f}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(`
266
+ `)}function N(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 B(o,e){let t=[],n=JSON.stringify(o,null,2);t.push({name:"report.json",content:new TextEncoder().encode(n)});let r=T(o);if(t.push({name:"summary.md",content:new TextEncoder().encode(r)}),o.screenshot){let s=X(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 O(t)}function X(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 O(o){let e=[],t=[],n=0;for(let i of o){let u=new TextEncoder().encode(i.name),f=V(i.content),b=_(u,i.content.length,f);e.push(b),e.push(u),e.push(i.content);let p=W(u,i.content.length,f,n);t.push(p),t.push(u),n+=b.length+u.length+i.content.length}let r=n,s=0;for(let i of t)s+=i.length;let a=G(o.length,s,r),c=[...e,...t,a].map(i=>i.buffer);return new Blob(c,{type:"application/zip"})}function _(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 W(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 G(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 V(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 Z="0.2.0",Y={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"},m=class{constructor(e={}){this.ui=null;this.started=!1;this.config={...Y,...e},this.network=new y(this.config),this.console=new v(this.config),this.errors=new w(this.config),this.userActions=new E(this.config),this.environment=new x,this.performance=new S,this.storage=new R(this.config),this.screenshot=new j,this.featureFlags=new k,this.screenRecorder=new L}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 C(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:g(),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:Z};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 B(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 m(o);return e.start(),e}typeof window<"u"&&(window.BugJar={BugJar:m,init:$});var K=m;return I(Q);})();
package/dist/index.js ADDED
@@ -0,0 +1,266 @@
1
+ "use strict";var H=Object.defineProperty;var q=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var P=Object.prototype.hasOwnProperty;var F=(o,e)=>{for(var t in e)H(o,t,{get:e[t],enumerable:!0})},z=(o,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of D(e))!P.call(o,r)&&r!==t&&H(o,r,{get:()=>e[r],enumerable:!(n=q(e,r))||n.enumerable});return o};var I=o=>z(H({},"__esModule",{value:!0}),o);var Q={};F(Q,{BugJar:()=>m,default:()=>K,exportAsZip:()=>B,generateSummary:()=>T,init:()=>$});module.exports=I(Q);function g(){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?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 y=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:g(),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:g(),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:g(),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(A(r))),stack:e==="error"||e==="warn"?this.getStack():null};this.buffer.push(n)}getStack(){try{return new Error().stack?.split(`
3
+ `).slice(4).join(`
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 E=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 x=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 S=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 R=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 j=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
+ <foreignObject width="100%" height="100%">
6
+ ${s}
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 L=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 C=class{constructor(e,t,n){this.container=null;this.config=e,this.onReport=t,this.screenRecorder=n}mount(){this.container||(this.container=document.createElement("div"),this.container.id="bug-jar-widget",this.container.innerHTML=this.getWidgetHTML(),document.body.appendChild(this.container),this.injectStyles(),this.bindEvents())}unmount(){this.container&&(this.container.remove(),this.container=null);let e=document.getElementById("bug-jar-styles");e&&e.remove()}getWidgetHTML(){return`
9
+ <button class="bug-jar-trigger ${`bug-jar--${this.config.uiPosition}`}" 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
+ <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>
42
+ </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"),f=this.container.querySelector(".bug-jar-recording-status"),b=()=>{t.hidden=!1,c.focus(),this.updateRecordingUI(u,f)},p=()=>{t.hidden=!0,c.value="",i.hidden=!0};e.addEventListener("click",b),n.addEventListener("click",p),r.addEventListener("click",p),s.addEventListener("click",p),u.addEventListener("click",async()=>{this.screenRecorder.isRecording||(p(),await this.screenRecorder.start(),this.updateTriggerForRecording(e))}),a.addEventListener("click",async()=>{let U=c.value.trim();if(!U){c.classList.add("bug-jar-error");return}c.classList.remove("bug-jar-error"),a.setAttribute("disabled","true"),a.textContent="Capturando...",i.hidden=!0;try{await this.onReport(U),i.textContent="\u2713 Relat\xF3rio baixado como .zip!",i.className="bug-jar-status bug-jar-status--success",i.hidden=!1,this.resetTrigger(e),setTimeout(p,2e3)}catch(M){i.textContent=`Erro: ${M instanceof Error?M.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(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)}injectStyles(){if(document.getElementById("bug-jar-styles"))return;let e=document.createElement("style");e.id="bug-jar-styles",e.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
+ }
68
+
69
+ .bug-jar-trigger:hover {
70
+ transform: scale(1.05);
71
+ box-shadow: 0 6px 20px rgba(0,0,0,0.2);
72
+ }
73
+
74
+ .bug-jar-trigger--recording {
75
+ background: #dc2626;
76
+ animation: bug-jar-pulse 1.5s infinite;
77
+ }
78
+
79
+ @keyframes bug-jar-pulse {
80
+ 0%, 100% { opacity: 1; }
81
+ 50% { opacity: 0.7; }
82
+ }
83
+
84
+ .bug-jar--bottom-right { bottom: 20px; right: 20px; }
85
+ .bug-jar--bottom-left { bottom: 20px; left: 20px; }
86
+ .bug-jar--top-right { top: 20px; right: 20px; }
87
+ .bug-jar--top-left { top: 20px; left: 20px; }
88
+
89
+ .bug-jar-modal {
90
+ position: fixed;
91
+ inset: 0;
92
+ z-index: 100000;
93
+ display: flex;
94
+ align-items: center;
95
+ justify-content: center;
96
+ }
97
+
98
+ .bug-jar-modal[hidden] { display: none; }
99
+
100
+ .bug-jar-modal-backdrop {
101
+ position: absolute;
102
+ inset: 0;
103
+ background: rgba(0,0,0,0.5);
104
+ backdrop-filter: blur(2px);
105
+ }
106
+
107
+ .bug-jar-modal-content {
108
+ position: relative;
109
+ width: 90%;
110
+ max-width: 480px;
111
+ background: #fff;
112
+ border-radius: 12px;
113
+ box-shadow: 0 20px 60px rgba(0,0,0,0.3);
114
+ overflow: hidden;
115
+ }
116
+
117
+ .bug-jar-modal-header {
118
+ display: flex;
119
+ align-items: center;
120
+ justify-content: space-between;
121
+ padding: 16px 20px;
122
+ border-bottom: 1px solid #eee;
123
+ }
124
+
125
+ .bug-jar-modal-header h3 {
126
+ margin: 0;
127
+ font-size: 16px;
128
+ font-weight: 600;
129
+ }
130
+
131
+ .bug-jar-close {
132
+ background: none;
133
+ border: none;
134
+ font-size: 24px;
135
+ cursor: pointer;
136
+ color: #666;
137
+ padding: 0 4px;
138
+ }
139
+
140
+ .bug-jar-modal-body {
141
+ padding: 20px;
142
+ }
143
+
144
+ .bug-jar-modal-body label {
145
+ display: block;
146
+ font-weight: 500;
147
+ margin-bottom: 8px;
148
+ }
149
+
150
+ #bug-jar-description {
151
+ width: 100%;
152
+ padding: 12px;
153
+ border: 1px solid #ddd;
154
+ border-radius: 8px;
155
+ font-size: 14px;
156
+ font-family: inherit;
157
+ resize: vertical;
158
+ min-height: 100px;
159
+ box-sizing: border-box;
160
+ }
161
+
162
+ #bug-jar-description:focus {
163
+ outline: none;
164
+ border-color: #1a1a1a;
165
+ box-shadow: 0 0 0 2px rgba(26,26,26,0.1);
166
+ }
167
+
168
+ #bug-jar-description.bug-jar-error {
169
+ border-color: #e53e3e;
170
+ }
171
+
172
+ .bug-jar-hint {
173
+ margin: 8px 0 0;
174
+ font-size: 12px;
175
+ color: #888;
176
+ }
177
+
178
+ .bug-jar-recording-section {
179
+ margin-top: 16px;
180
+ display: flex;
181
+ align-items: center;
182
+ gap: 12px;
183
+ }
184
+
185
+ .bug-jar-record-btn {
186
+ display: flex;
187
+ align-items: center;
188
+ gap: 6px;
189
+ padding: 8px 14px;
190
+ border: 1px solid #ddd;
191
+ border-radius: 6px;
192
+ background: #fff;
193
+ cursor: pointer;
194
+ font-size: 13px;
195
+ transition: all 0.2s;
196
+ }
197
+
198
+ .bug-jar-record-btn:hover {
199
+ border-color: #dc2626;
200
+ color: #dc2626;
201
+ }
202
+
203
+ .bug-jar-record-btn--active {
204
+ border-color: #dc2626;
205
+ background: #fef2f2;
206
+ color: #dc2626;
207
+ pointer-events: none;
208
+ }
209
+
210
+ .bug-jar-record-icon {
211
+ width: 10px;
212
+ height: 10px;
213
+ border-radius: 50%;
214
+ background: #dc2626;
215
+ }
216
+
217
+ .bug-jar-recording-status {
218
+ font-size: 12px;
219
+ color: #dc2626;
220
+ font-weight: 500;
221
+ animation: bug-jar-pulse 1.5s infinite;
222
+ }
223
+
224
+ .bug-jar-modal-footer {
225
+ display: flex;
226
+ justify-content: flex-end;
227
+ gap: 8px;
228
+ padding: 16px 20px;
229
+ border-top: 1px solid #eee;
230
+ }
231
+
232
+ .bug-jar-cancel {
233
+ padding: 8px 16px;
234
+ border: 1px solid #ddd;
235
+ border-radius: 6px;
236
+ background: #fff;
237
+ cursor: pointer;
238
+ font-size: 13px;
239
+ }
240
+
241
+ .bug-jar-submit {
242
+ padding: 8px 16px;
243
+ border: none;
244
+ border-radius: 6px;
245
+ background: #1a1a1a;
246
+ color: #fff;
247
+ cursor: pointer;
248
+ font-size: 13px;
249
+ font-weight: 500;
250
+ }
251
+
252
+ .bug-jar-submit:disabled {
253
+ opacity: 0.6;
254
+ cursor: not-allowed;
255
+ }
256
+
257
+ .bug-jar-status {
258
+ padding: 12px 20px;
259
+ font-size: 13px;
260
+ text-align: center;
261
+ }
262
+
263
+ .bug-jar-status--success { color: #16a34a; background: #f0fdf4; }
264
+ .bug-jar-status--error { color: #dc2626; background: #fef2f2; }
265
+ `,document.head.appendChild(e)}};function T(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: ${N(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,f=((o.userActions[o.userActions.length-1].timestamp-i)/1e3).toFixed(1);e.push(`Session duration: ${f}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(`
266
+ `)}function N(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 B(o,e){let t=[],n=JSON.stringify(o,null,2);t.push({name:"report.json",content:new TextEncoder().encode(n)});let r=T(o);if(t.push({name:"summary.md",content:new TextEncoder().encode(r)}),o.screenshot){let s=X(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 O(t)}function X(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 O(o){let e=[],t=[],n=0;for(let i of o){let u=new TextEncoder().encode(i.name),f=V(i.content),b=_(u,i.content.length,f);e.push(b),e.push(u),e.push(i.content);let p=W(u,i.content.length,f,n);t.push(p),t.push(u),n+=b.length+u.length+i.content.length}let r=n,s=0;for(let i of t)s+=i.length;let a=G(o.length,s,r),c=[...e,...t,a].map(i=>i.buffer);return new Blob(c,{type:"application/zip"})}function _(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 W(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 G(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 V(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 Z="0.2.0",Y={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"},m=class{constructor(e={}){this.ui=null;this.started=!1;this.config={...Y,...e},this.network=new y(this.config),this.console=new v(this.config),this.errors=new w(this.config),this.userActions=new E(this.config),this.environment=new x,this.performance=new S,this.storage=new R(this.config),this.screenshot=new j,this.featureFlags=new k,this.screenRecorder=new L}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 C(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:g(),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:Z};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 B(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 m(o);return e.start(),e}typeof window<"u"&&(window.BugJar={BugJar:m,init:$});var K=m;0&&(module.exports={BugJar,exportAsZip,generateSummary,init});