@bugjar/reporter 0.1.4 → 0.1.6

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/README.md CHANGED
@@ -31,7 +31,6 @@ until they confirm.
31
31
  ```js
32
32
  BugJar.init({
33
33
  projectKey: 'pk_...', // required
34
- apiUrl: '/api/v1', // default; override for self-hosted
35
34
 
36
35
  ui: {
37
36
  primaryColor: '#ea580c', // hex, default is BugJar copper
@@ -18617,7 +18617,6 @@ function x_(t) {
18617
18617
  M_,
18618
18618
  {
18619
18619
  color: t.primaryColor,
18620
- url: t.preview?.reportUrl ?? null,
18621
18620
  onDismiss: t.onCancel
18622
18621
  }
18623
18622
  ),
@@ -18833,8 +18832,7 @@ function __({ color: t }) {
18833
18832
  }
18834
18833
  function M_({
18835
18834
  color: t,
18836
- url: e,
18837
- onDismiss: n
18835
+ onDismiss: e
18838
18836
  }) {
18839
18837
  return /* @__PURE__ */ w.jsxs(
18840
18838
  "div",
@@ -18851,8 +18849,8 @@ function M_({
18851
18849
  },
18852
18850
  children: [
18853
18851
  /* @__PURE__ */ w.jsx("div", { style: { fontWeight: 600, marginBottom: 6 }, children: "Report sent — thank you!" }),
18854
- e && /* @__PURE__ */ w.jsx("a", { href: e, target: "_blank", rel: "noreferrer", style: { color: t }, children: "View in dashboard " }),
18855
- /* @__PURE__ */ w.jsx("div", { style: { marginTop: 12, textAlign: "right" }, children: /* @__PURE__ */ w.jsx(mc, { onClick: n, children: "Close" }) })
18852
+ /* @__PURE__ */ w.jsx("div", { style: { color: "#475569", fontSize: 12, lineHeight: 1.5 }, children: "The team has been notified and will follow up by email if they need more from you." }),
18853
+ /* @__PURE__ */ w.jsx("div", { style: { marginTop: 12, textAlign: "right" }, children: /* @__PURE__ */ w.jsx(mc, { onClick: e, children: "Close" }) })
18856
18854
  ]
18857
18855
  }
18858
18856
  );
@@ -19132,7 +19130,7 @@ class $_ {
19132
19130
  n
19133
19131
  );
19134
19132
  const r = U_(this.config.captureTokenParam);
19135
- return r && this.applyCaptureToken(r), this.render(), this.attemptRecovery(), this.publicApi();
19133
+ return r && (B_(this.config.captureTokenParam), this.applyCaptureToken(r)), this.render(), this.attemptRecovery(), this.publicApi();
19136
19134
  }
19137
19135
  /** Reload-recovery path. Called once during init(). If a fresh
19138
19136
  * active-session flag exists, hydrate state and restart a recorder
@@ -19456,7 +19454,7 @@ class $_ {
19456
19454
  }
19457
19455
  async sendReport(e) {
19458
19456
  if (!(!this.capturedReport || !this.config)) {
19459
- this.capturedReport.description = e.description, this.capturedReport.annotations = e.annotations, this.view = "uploading", this.render();
19457
+ this.capturedReport.description = e.description, this.capturedReport.annotations = e.annotations, this.teardownMarkupLayer(), this.view = "uploading", this.render();
19460
19458
  try {
19461
19459
  const { reportId: n, dashboardUrl: r } = await I_({
19462
19460
  apiUrl: this.config.apiUrl,
@@ -19466,7 +19464,7 @@ class $_ {
19466
19464
  report: this.capturedReport,
19467
19465
  attachments: e.attachments
19468
19466
  });
19469
- this.preview && (this.preview.reportUrl = r), this.view = "success", this.teardownMarkupLayer(), this.config.onReportSubmitted?.(n), this.render();
19467
+ this.preview && (this.preview.reportUrl = r), this.view = "success", this.config.onReportSubmitted?.(n), this.render();
19470
19468
  } catch (n) {
19471
19469
  this.error = n instanceof Error ? n.message : String(n), this.failedAttachments = e.attachments, this.view = "failed", this.config.onError?.(n instanceof Error ? n : new Error(String(n))), this.render();
19472
19470
  }
@@ -19514,13 +19512,24 @@ function U_(t) {
19514
19512
  return null;
19515
19513
  }
19516
19514
  }
19517
- const B_ = new $_(), Ta = B_, W_ = {
19515
+ function B_(t) {
19516
+ if (!(typeof window > "u") && !(!window.history || typeof window.history.replaceState != "function"))
19517
+ try {
19518
+ const e = new URL(window.location.href);
19519
+ if (!e.searchParams.has(t)) return;
19520
+ e.searchParams.delete(t);
19521
+ const n = e.searchParams.toString(), r = e.pathname + (n ? `?${n}` : "") + e.hash;
19522
+ window.history.replaceState({}, "", r);
19523
+ } catch {
19524
+ }
19525
+ }
19526
+ const W_ = new $_(), Ta = W_, V_ = {
19518
19527
  init: (t) => Ta.init(t),
19519
19528
  open: () => Ta.open(),
19520
19529
  close: () => Ta.close()
19521
19530
  };
19522
- typeof window < "u" && (window.BugJar = W_);
19531
+ typeof window < "u" && (window.BugJar = V_);
19523
19532
  export {
19524
- W_ as BugJar,
19525
- B_ as _client
19533
+ V_ as BugJar,
19534
+ W_ as _client
19526
19535
  };
package/dist/index.cjs CHANGED
@@ -114,7 +114,7 @@ PERFORMANCE OF THIS SOFTWARE.
114
114
  ...
115
115
  }
116
116
  `);t(7,g=new ny(o,{speed:u,root:y,unpackFn:wy,...e})),g.on("resize",S=>{D(g.wrapper,S)}),b=Sy(()=>{Do()?setTimeout(()=>{v=i,x=s,t(13,i=p.offsetWidth),t(14,s=p.offsetHeight-(h?Wo:0)),D(g.wrapper,{width:g.iframe.offsetWidth,height:g.iframe.offsetHeight})},0):(t(13,i=v),t(14,s=x),D(g.wrapper,{width:g.iframe.offsetWidth,height:g.iframe.offsetHeight}))})}),ya(()=>{b&&b()});function pe(S){je[S?"unshift":"push"](()=>{y=S,t(9,y)})}function be(S){je[S?"unshift":"push"](()=>{k=S,t(10,k)})}const A=()=>W();function C(S){je[S?"unshift":"push"](()=>{p=S,t(8,p)})}return r.$$set=S=>{t(39,e=xn(xn({},e),An(S))),"width"in S&&t(13,i=S.width),"height"in S&&t(14,s=S.height),"maxScale"in S&&t(15,n=S.maxScale),"events"in S&&t(16,o=S.events),"skipInactive"in S&&t(0,a=S.skipInactive),"autoPlay"in S&&t(1,l=S.autoPlay),"speedOption"in S&&t(2,c=S.speedOption),"speed"in S&&t(17,u=S.speed),"showController"in S&&t(3,h=S.showController),"tags"in S&&t(4,f=S.tags),"inactiveColor"in S&&t(5,d=S.inactiveColor)},r.$$.update=()=>{r.$$.dirty[0]&24576&&t(11,N=_o({width:`${i}px`,height:`${s}px`})),r.$$.dirty[0]&24584&&t(12,F=_o({width:`${i}px`,height:`${s+(h?Wo:0)}px`}))},e=An(e),[a,l,c,h,f,d,W,g,p,y,k,N,F,i,s,n,o,u,w,J,de,ce,ee,B,ae,L,V,le,ne,re,q,pe,be,A,C]}let Oy=class extends Os{constructor(e){super(),Ts(this,e,Ty,Dy,_s,{width:13,height:14,maxScale:15,events:16,skipInactive:0,autoPlay:1,speedOption:2,speed:17,showController:3,tags:4,inactiveColor:5,getMirror:18,triggerResize:19,toggleFullscreen:6,addEventListener:20,addEvent:21,getMetaData:22,getReplayer:23,toggle:24,setSpeed:25,toggleSkipInactive:26,play:27,pause:28,goto:29,playRange:30},null,[-1,-1])}get getMirror(){return this.$$.ctx[18]}get triggerResize(){return this.$$.ctx[19]}get toggleFullscreen(){return this.$$.ctx[6]}get addEventListener(){return this.$$.ctx[20]}get addEvent(){return this.$$.ctx[21]}get getMetaData(){return this.$$.ctx[22]}get getReplayer(){return this.$$.ctx[23]}get toggle(){return this.$$.ctx[24]}get setSpeed(){return this.$$.ctx[25]}get toggleSkipInactive(){return this.$$.ctx[26]}get play(){return this.$$.ctx[27]}get pause(){return this.$$.ctx[28]}get goto(){return this.$$.ctx[29]}get playRange(){return this.$$.ctx[30]}};class Py extends Oy{constructor(e){super({target:e.target,props:e.data||e.props})}}const Ly=["image/png","image/jpeg","image/webp","image/gif","application/pdf","text/plain","application/json"],$y=2*1024*1024,Cs=5;function jy(r){const[e,t]=oe.useState(""),[i,s]=oe.useState([]),[n,o]=oe.useState(!1),[a,l]=oe.useState("console"),c=e.trim().length>0;return m.jsxs(Yy,{children:[m.jsxs("div",{style:Zy,children:[m.jsx("h2",{style:{margin:0,fontSize:18,fontWeight:700},children:"Review & send"}),m.jsx("span",{style:{fontSize:12,color:"#6b7280"},children:"You're seeing exactly what we'll upload."})]}),m.jsx(By,{hasReplay:r.hasReplay&&r.replayEvents.length>0,events:r.replayEvents,audioBlobUrl:r.audioBlobUrl,screenshotUrl:r.screenshotUrl,durationMs:r.durationMs,capturedViewport:r.capturedViewport,consoleCount:r.consoleLogs.length,networkCount:r.networkEvents.length,redactionSummary:r.redactionSummary}),m.jsxs("div",{style:{marginTop:18},children:[m.jsxs("label",{style:Yo,children:["What happened? ",m.jsx("span",{style:{color:"#ef4444"},children:"*"})]}),m.jsx("textarea",{value:e,onChange:u=>t(u.target.value),rows:4,placeholder:"Describe the bug — what you expected, what happened instead…",style:Xy})]}),m.jsxs("div",{style:{marginTop:14},children:[m.jsxs("label",{style:Yo,children:["Attachments"," ",m.jsxs("span",{style:{color:"#9ca3af",fontWeight:400},children:["(max ",Cs,", 2 MB each)"]})]}),m.jsx("input",{type:"file",multiple:!0,accept:".png,.jpg,.jpeg,.webp,.gif,.pdf,.txt,.log,.json",onChange:u=>Fy(u.target.files,i,s),style:{fontSize:12}}),i.length>0&&m.jsx("ul",{style:{margin:"8px 0 0 0",paddingLeft:16,fontSize:12,color:"#4b5563"},children:i.map((u,h)=>m.jsxs("li",{children:[u.name," (",Math.round(u.size/1024)," KB)"]},h))})]}),m.jsxs("div",{style:{marginTop:18},children:[m.jsxs("button",{type:"button",onClick:()=>o(u=>!u),style:Jy,children:[m.jsx("span",{children:n?"▾":"▸"}),m.jsx("span",{style:{fontWeight:600},children:"Inspect what's being sent"}),m.jsxs("span",{style:{color:"#9ca3af",fontWeight:400},children:["· ",r.consoleLogs.length," logs · ",r.networkEvents.length," requests ·"," ",r.redactionSummary.totalMatches," redactions"]})]}),n&&m.jsxs("div",{style:Ky,children:[m.jsxs("div",{style:qy,children:[m.jsxs(br,{active:a==="console",onClick:()=>l("console"),children:["Console (",r.consoleLogs.length,")"]}),m.jsxs(br,{active:a==="network",onClick:()=>l("network"),children:["Network (",r.networkEvents.length,")"]}),m.jsxs(br,{active:a==="redactions",onClick:()=>l("redactions"),children:["Redactions (",r.redactionSummary.totalMatches,")"]}),m.jsx(br,{active:a==="metadata",onClick:()=>l("metadata"),children:"Metadata"})]}),m.jsxs("div",{style:{padding:"12px 14px",maxHeight:240,overflow:"auto"},children:[a==="console"&&m.jsx(Uy,{logs:r.consoleLogs}),a==="network"&&m.jsx(zy,{events:r.networkEvents}),a==="redactions"&&m.jsx(Wy,{summary:r.redactionSummary}),a==="metadata"&&m.jsx(Vy,{pageUrl:r.pageUrl,userAgent:r.userAgent,durationMs:r.durationMs,viewport:r.capturedViewport,hasReplay:r.hasReplay,hasAudio:!!r.audioBlobUrl,attachments:i})]})]})]}),m.jsxs("div",{style:ew,children:[m.jsxs("div",{style:{display:"flex",gap:8},children:[m.jsx(Go,{onClick:r.onCancel,children:"Cancel"}),m.jsx(Go,{onClick:r.onBackToMarkup,children:"← Back to edit"})]}),m.jsx(Hy,{color:r.color,onClick:()=>r.onSend({description:e,annotations:[],attachments:i}),disabled:!c,title:c?void 0:"Description is required",children:"Send report"})]})]})}function Fy(r,e,t){if(!r)return;const i=[...e];for(const s of Array.from(r))if(Ly.includes(s.type)&&!(s.size>$y)&&(i.push(s),i.length>=Cs))break;t(i.slice(0,Cs))}function By(r){const[e,t]=oe.useState(r.hasReplay?"replay":"screenshot");return m.jsxs("div",{style:{background:"#0E1117",borderRadius:10,padding:14,border:"1px solid #1f2937"},children:[m.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:10},children:[r.hasReplay?m.jsxs("div",{style:{display:"flex",gap:4},children:[m.jsxs(Vo,{active:e==="replay",onClick:()=>t("replay"),children:["Replay · ",ln(r.durationMs),r.audioBlobUrl?" · audio":""]}),m.jsx(Vo,{active:e==="screenshot",onClick:()=>t("screenshot"),children:"Screenshot"})]}):m.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[m.jsx("span",{style:{display:"inline-block",width:8,height:8,borderRadius:"50%",background:"#9ca3af"}}),m.jsx("span",{style:{color:"#e5e7eb",fontSize:12,fontWeight:600},children:"Screenshot only"})]}),m.jsxs("div",{style:{color:"#9ca3af",fontSize:11,display:"flex",gap:12},children:[m.jsxs("span",{children:[r.consoleCount," logs"]}),m.jsx("span",{children:"·"}),m.jsxs("span",{children:[r.networkCount," requests"]}),m.jsx("span",{children:"·"}),m.jsxs("span",{style:{color:"#34d399"},children:[r.redactionSummary.totalMatches," redactions"]})]})]}),e==="replay"&&r.hasReplay?m.jsx(Gy,{events:r.events,audioBlobUrl:r.audioBlobUrl,capturedViewport:r.capturedViewport}):m.jsx("div",{style:{maxHeight:"60vh",overflow:"auto",background:"#000",borderRadius:6},children:m.jsx("img",{src:r.screenshotUrl,alt:"annotated page",style:{width:"100%",display:"block"}})})]})}function Uy({logs:r}){return r.length===0?m.jsx(an,{children:"Nothing was logged during the recording."}):m.jsx("pre",{style:Qy,children:r.map(e=>`[${ln(e.timestamp)}] [${e.level}] ${e.message}`).join(`
117
- `)})}function zy({events:r}){return r.length===0?m.jsx(an,{children:"No network requests captured."}):m.jsxs("table",{style:{width:"100%",fontSize:11,borderCollapse:"collapse"},children:[m.jsx("thead",{children:m.jsxs("tr",{style:{color:"#6b7280",textAlign:"left"},children:[m.jsx("th",{style:vr,children:"method"}),m.jsx("th",{style:vr,children:"status"}),m.jsx("th",{style:vr,children:"url"}),m.jsx("th",{style:{...vr,textAlign:"right"},children:"ms"})]})}),m.jsx("tbody",{children:r.map((e,t)=>m.jsxs("tr",{style:{color:e.ok?"#1f2937":"#b91c1c",borderTop:"1px solid #f3f4f6"},children:[m.jsx("td",{style:Sr,children:e.method}),m.jsx("td",{style:Sr,children:e.status??"—"}),m.jsx("td",{style:{...Sr,fontFamily:"monospace",wordBreak:"break-all"},children:e.url}),m.jsx("td",{style:{...Sr,textAlign:"right"},children:e.durationMs!=null?Math.round(e.durationMs):"—"})]},t))})]})}function Wy({summary:r}){const e=Object.entries(r.counts).filter(([,t])=>t>0);return e.length===0?m.jsx(an,{children:"No regex matches. Form input values are still automatically masked by rrweb."}):m.jsxs("div",{children:[m.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6,marginBottom:10},children:e.map(([t,i])=>m.jsxs("span",{style:{background:"#dcfce7",color:"#065f46",padding:"3px 9px",borderRadius:999,fontSize:11,fontWeight:600},children:[i," × ",t.replace(/_/g," ")]},t))}),m.jsxs("p",{style:{margin:0,fontSize:11,color:"#6b7280",lineHeight:1.55},children:["Pattern matches were replaced with"," ",m.jsx("code",{style:{background:"#f3f4f6",padding:"1px 4px",borderRadius:3},children:"[REDACTED:<category>]"})," ","before this preview rendered. The original values are not in the upload payload."]})]})}function Vy(r){const e=[["Page URL",r.pageUrl],["User agent",r.userAgent],["Viewport",`${r.viewport.width} × ${r.viewport.height}`],["Recording",r.hasReplay?`${ln(r.durationMs)} (replay)`:"screenshot only"],["Audio",r.hasAudio?"attached":"none"],["Attachments",r.attachments.length===0?"none":r.attachments.map(t=>`${t.name} (${Math.round(t.size/1024)} KB)`).join(", ")]];return m.jsx("table",{style:{width:"100%",fontSize:12,borderCollapse:"collapse"},children:m.jsx("tbody",{children:e.map(([t,i])=>m.jsxs("tr",{style:{borderTop:"1px solid #f3f4f6"},children:[m.jsx("td",{style:{padding:"7px 8px",color:"#6b7280",fontWeight:500,width:130,verticalAlign:"top"},children:t}),m.jsx("td",{style:{padding:"7px 8px",color:"#1f2937",fontFamily:"monospace",wordBreak:"break-all"},children:i})]},t))})})}function an({children:r}){return m.jsx("div",{style:{fontSize:12,color:"#9ca3af",fontStyle:"italic",padding:"20px 0",textAlign:"center"},children:r})}function br({active:r,onClick:e,children:t}){return m.jsx("button",{type:"button",onClick:e,style:{padding:"8px 12px",background:r?"white":"transparent",border:"none",borderBottom:r?"2px solid #ea580c":"2px solid transparent",fontSize:12,fontWeight:r?600:500,color:r?"#1f2937":"#6b7280",cursor:"pointer"},children:t})}function Vo({active:r,onClick:e,children:t}){return m.jsx("button",{type:"button",onClick:e,style:{padding:"5px 10px",background:r?"#1f2937":"transparent",border:"1px solid",borderColor:r?"#374151":"transparent",borderRadius:6,fontSize:12,fontWeight:600,color:r?"#e5e7eb":"#6b7280",cursor:"pointer",fontFamily:"inherit"},children:t})}function Gy(r){const e=oe.useRef(null),t=oe.useRef(null);return oe.useEffect(()=>{const i=e.current;if(!i||r.events.length===0)return;i.replaceChildren();const s=Math.min(720,i.clientWidth||720),n=r.capturedViewport.height/Math.max(1,r.capturedViewport.width),o=s,a=Math.max(280,Math.min(420,Math.round(o*n))),l=new Py({target:i,props:{events:r.events,width:o,height:a,autoPlay:!1,skipInactive:!1,showController:!0}}),c=h=>{const f=h?.payload??0,d=t.current;if(d?.duration&&!Number.isNaN(d.duration)){const g=f/1e3;Math.abs(d.currentTime-g)>.15&&(d.currentTime=Math.min(g,d.duration))}},u=h=>{const f=h?.payload,d=t.current;d&&(f==="playing"?d.play().catch(()=>{}):(f==="paused"||f==="ended"||f==="live")&&d.pause())};return l.addEventListener("ui-update-current-time",c),l.addEventListener("ui-update-player-state",u),()=>{try{l.$destroy?.()}catch{}i.replaceChildren()}},[r.events,r.capturedViewport.width,r.capturedViewport.height]),m.jsxs("div",{children:[m.jsx("div",{ref:e,style:{minHeight:280,maxWidth:"100%",background:"#000",borderRadius:6,overflow:"hidden",position:"relative",margin:"0 auto"}}),r.audioBlobUrl&&m.jsx("audio",{ref:t,src:r.audioBlobUrl,preload:"auto",style:{display:"none"}})]})}function Yy({children:r}){return m.jsx("div",{style:{position:"fixed",inset:0,background:"rgba(17, 24, 39, 0.55)",display:"flex",alignItems:"center",justifyContent:"center",padding:20,zIndex:2147483647},children:m.jsx("div",{style:{background:"white",borderRadius:14,padding:22,width:820,maxWidth:"100%",maxHeight:"92vh",overflow:"auto",fontFamily:"system-ui, -apple-system, sans-serif",color:"#111827",boxShadow:"0 20px 60px rgba(0,0,0,0.3)"},children:r})})}function Hy({color:r,onClick:e,children:t,disabled:i,title:s}){return m.jsx("button",{onClick:e,disabled:i,title:s,style:{background:i?"#cbd5e1":r,color:"white",border:"none",borderRadius:6,padding:"10px 18px",fontWeight:600,fontSize:13,cursor:i?"not-allowed":"pointer"},children:t})}function Go({onClick:r,children:e}){return m.jsx("button",{onClick:r,style:{background:"white",color:"#111827",border:"1px solid #d1d5db",borderRadius:6,padding:"10px 18px",fontWeight:500,fontSize:13,cursor:"pointer"},children:e})}const Zy={display:"flex",alignItems:"baseline",justifyContent:"space-between",marginBottom:14},Yo={display:"block",fontSize:12,fontWeight:600,marginBottom:6,color:"#374151"},Xy={width:"100%",boxSizing:"border-box",padding:10,borderRadius:6,border:"1px solid #d1d5db",fontFamily:"inherit",fontSize:13,resize:"vertical"},Jy={width:"100%",display:"flex",alignItems:"center",gap:8,background:"#f9fafb",border:"1px solid #e5e7eb",borderRadius:8,padding:"10px 14px",fontSize:13,color:"#1f2937",cursor:"pointer",textAlign:"left"},Ky={marginTop:8,border:"1px solid #e5e7eb",borderRadius:8,background:"#fafafa",overflow:"hidden"},qy={display:"flex",gap:4,background:"#f3f4f6",borderBottom:"1px solid #e5e7eb",padding:"0 8px"},Qy={margin:0,fontFamily:"ui-monospace, monospace",fontSize:11,lineHeight:1.5,color:"#1f2937",whiteSpace:"pre-wrap",wordBreak:"break-all"},vr={padding:"6px 8px",fontSize:10,fontWeight:600,textTransform:"uppercase",letterSpacing:.5,borderBottom:"1px solid #e5e7eb"},Sr={padding:"6px 8px",verticalAlign:"top"},ew={position:"sticky",bottom:-22,marginTop:22,marginLeft:-22,marginRight:-22,marginBottom:-22,padding:"14px 22px 22px 22px",display:"flex",gap:8,justifyContent:"space-between",background:"rgba(255,255,255,0.96)",backdropFilter:"blur(6px)",borderTop:"1px solid #e5e7eb",zIndex:1};function ln(r){const e=Math.floor(r/1e3),t=Math.floor(e/60),i=e%60;return`${t}:${String(i).padStart(2,"0")}`}const tw={"bottom-right":{right:20,bottom:20},"bottom-left":{left:20,bottom:20},"top-right":{right:20,top:20},"top-left":{left:20,top:20}};function rw(r){return m.jsxs("div",{"data-bugjar-block":"true",style:{position:"fixed",zIndex:2147483e3,...tw[r.position]},children:[r.view==="idle"&&r.triggerVisible&&m.jsx(sw,{color:r.primaryColor,label:r.triggerLabel,onClick:r.onOpenActive}),r.view==="active"&&m.jsx(xh,{primaryColor:r.primaryColor,isRecording:r.isRecording,hasRecording:r.hasRecording,elapsedMs:r.elapsedMs,maxDurationSec:r.maxDurationSec,onSelectTool:r.onSelectTool,onSelectColor:r.onSelectColor,onUndo:r.onUndoMarkup,onStartRecording:()=>{r.onStartRecording()},onStopRecording:()=>{r.onStopRecording()},onToggleMicMute:r.onToggleMicMute,onDone:()=>{r.onFinalize()},onCancel:r.onCancel}),r.view==="preview"&&r.preview&&m.jsx(jy,{color:r.primaryColor,hasReplay:r.preview.hasReplay,durationMs:r.preview.durationMs,replayEvents:r.preview.replayEvents,audioBlobUrl:r.preview.audioBlobUrl,screenshotUrl:r.preview.screenshotUrl,consoleLogs:r.preview.consoleLogs,networkEvents:r.preview.networkEvents,redactionSummary:r.preview.redactionSummary,capturedViewport:r.preview.capturedViewport,pageUrl:r.preview.pageUrl,userAgent:r.preview.userAgent,onCancel:r.onCancel,onBackToMarkup:r.onBackToMarkup,onSend:r.onSendReport}),r.view==="uploading"&&m.jsx(lw,{color:r.primaryColor}),r.view==="success"&&m.jsx(cw,{color:r.primaryColor,url:r.preview?.reportUrl??null,onDismiss:r.onCancel}),r.view==="failed"&&m.jsx(uw,{error:r.error??"Upload failed",onDismiss:r.onCancel,onDownload:()=>{r.onDownloadFailed()}}),r.resumingToast&&m.jsx(iw,{color:r.primaryColor,remainingMs:r.resumingToast.remainingMs})]})}function iw({color:r,remainingMs:e}){const t=Math.max(1,Math.ceil(e/1e3));return m.jsxs("div",{style:{position:"fixed",left:"50%",top:24,transform:"translateX(-50%)",background:"#111827",color:"white",padding:"10px 14px",borderRadius:10,fontFamily:"system-ui, -apple-system, sans-serif",fontSize:13,boxShadow:"0 10px 30px rgba(0,0,0,0.35)",display:"flex",alignItems:"center",gap:10,zIndex:2147483002,userSelect:"none",maxWidth:"calc(100vw - 32px)"},children:[m.jsx("span",{style:{width:8,height:8,borderRadius:"50%",background:r,animation:"bugjar-pulse 1.2s infinite",flexShrink:0}}),m.jsx("style",{children:"@keyframes bugjar-pulse { 0%,100%{opacity:1} 50%{opacity:0.35} }"}),m.jsxs("span",{children:["Continuing recording — ",t,"s left"]})]})}function sw({color:r,label:e,onClick:t}){const i=nw(r,.12),s=ow(r,.33);return m.jsxs(m.Fragment,{children:[m.jsx("style",{children:`
117
+ `)})}function zy({events:r}){return r.length===0?m.jsx(an,{children:"No network requests captured."}):m.jsxs("table",{style:{width:"100%",fontSize:11,borderCollapse:"collapse"},children:[m.jsx("thead",{children:m.jsxs("tr",{style:{color:"#6b7280",textAlign:"left"},children:[m.jsx("th",{style:vr,children:"method"}),m.jsx("th",{style:vr,children:"status"}),m.jsx("th",{style:vr,children:"url"}),m.jsx("th",{style:{...vr,textAlign:"right"},children:"ms"})]})}),m.jsx("tbody",{children:r.map((e,t)=>m.jsxs("tr",{style:{color:e.ok?"#1f2937":"#b91c1c",borderTop:"1px solid #f3f4f6"},children:[m.jsx("td",{style:Sr,children:e.method}),m.jsx("td",{style:Sr,children:e.status??"—"}),m.jsx("td",{style:{...Sr,fontFamily:"monospace",wordBreak:"break-all"},children:e.url}),m.jsx("td",{style:{...Sr,textAlign:"right"},children:e.durationMs!=null?Math.round(e.durationMs):"—"})]},t))})]})}function Wy({summary:r}){const e=Object.entries(r.counts).filter(([,t])=>t>0);return e.length===0?m.jsx(an,{children:"No regex matches. Form input values are still automatically masked by rrweb."}):m.jsxs("div",{children:[m.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6,marginBottom:10},children:e.map(([t,i])=>m.jsxs("span",{style:{background:"#dcfce7",color:"#065f46",padding:"3px 9px",borderRadius:999,fontSize:11,fontWeight:600},children:[i," × ",t.replace(/_/g," ")]},t))}),m.jsxs("p",{style:{margin:0,fontSize:11,color:"#6b7280",lineHeight:1.55},children:["Pattern matches were replaced with"," ",m.jsx("code",{style:{background:"#f3f4f6",padding:"1px 4px",borderRadius:3},children:"[REDACTED:<category>]"})," ","before this preview rendered. The original values are not in the upload payload."]})]})}function Vy(r){const e=[["Page URL",r.pageUrl],["User agent",r.userAgent],["Viewport",`${r.viewport.width} × ${r.viewport.height}`],["Recording",r.hasReplay?`${ln(r.durationMs)} (replay)`:"screenshot only"],["Audio",r.hasAudio?"attached":"none"],["Attachments",r.attachments.length===0?"none":r.attachments.map(t=>`${t.name} (${Math.round(t.size/1024)} KB)`).join(", ")]];return m.jsx("table",{style:{width:"100%",fontSize:12,borderCollapse:"collapse"},children:m.jsx("tbody",{children:e.map(([t,i])=>m.jsxs("tr",{style:{borderTop:"1px solid #f3f4f6"},children:[m.jsx("td",{style:{padding:"7px 8px",color:"#6b7280",fontWeight:500,width:130,verticalAlign:"top"},children:t}),m.jsx("td",{style:{padding:"7px 8px",color:"#1f2937",fontFamily:"monospace",wordBreak:"break-all"},children:i})]},t))})})}function an({children:r}){return m.jsx("div",{style:{fontSize:12,color:"#9ca3af",fontStyle:"italic",padding:"20px 0",textAlign:"center"},children:r})}function br({active:r,onClick:e,children:t}){return m.jsx("button",{type:"button",onClick:e,style:{padding:"8px 12px",background:r?"white":"transparent",border:"none",borderBottom:r?"2px solid #ea580c":"2px solid transparent",fontSize:12,fontWeight:r?600:500,color:r?"#1f2937":"#6b7280",cursor:"pointer"},children:t})}function Vo({active:r,onClick:e,children:t}){return m.jsx("button",{type:"button",onClick:e,style:{padding:"5px 10px",background:r?"#1f2937":"transparent",border:"1px solid",borderColor:r?"#374151":"transparent",borderRadius:6,fontSize:12,fontWeight:600,color:r?"#e5e7eb":"#6b7280",cursor:"pointer",fontFamily:"inherit"},children:t})}function Gy(r){const e=oe.useRef(null),t=oe.useRef(null);return oe.useEffect(()=>{const i=e.current;if(!i||r.events.length===0)return;i.replaceChildren();const s=Math.min(720,i.clientWidth||720),n=r.capturedViewport.height/Math.max(1,r.capturedViewport.width),o=s,a=Math.max(280,Math.min(420,Math.round(o*n))),l=new Py({target:i,props:{events:r.events,width:o,height:a,autoPlay:!1,skipInactive:!1,showController:!0}}),c=h=>{const f=h?.payload??0,d=t.current;if(d?.duration&&!Number.isNaN(d.duration)){const g=f/1e3;Math.abs(d.currentTime-g)>.15&&(d.currentTime=Math.min(g,d.duration))}},u=h=>{const f=h?.payload,d=t.current;d&&(f==="playing"?d.play().catch(()=>{}):(f==="paused"||f==="ended"||f==="live")&&d.pause())};return l.addEventListener("ui-update-current-time",c),l.addEventListener("ui-update-player-state",u),()=>{try{l.$destroy?.()}catch{}i.replaceChildren()}},[r.events,r.capturedViewport.width,r.capturedViewport.height]),m.jsxs("div",{children:[m.jsx("div",{ref:e,style:{minHeight:280,maxWidth:"100%",background:"#000",borderRadius:6,overflow:"hidden",position:"relative",margin:"0 auto"}}),r.audioBlobUrl&&m.jsx("audio",{ref:t,src:r.audioBlobUrl,preload:"auto",style:{display:"none"}})]})}function Yy({children:r}){return m.jsx("div",{style:{position:"fixed",inset:0,background:"rgba(17, 24, 39, 0.55)",display:"flex",alignItems:"center",justifyContent:"center",padding:20,zIndex:2147483647},children:m.jsx("div",{style:{background:"white",borderRadius:14,padding:22,width:820,maxWidth:"100%",maxHeight:"92vh",overflow:"auto",fontFamily:"system-ui, -apple-system, sans-serif",color:"#111827",boxShadow:"0 20px 60px rgba(0,0,0,0.3)"},children:r})})}function Hy({color:r,onClick:e,children:t,disabled:i,title:s}){return m.jsx("button",{onClick:e,disabled:i,title:s,style:{background:i?"#cbd5e1":r,color:"white",border:"none",borderRadius:6,padding:"10px 18px",fontWeight:600,fontSize:13,cursor:i?"not-allowed":"pointer"},children:t})}function Go({onClick:r,children:e}){return m.jsx("button",{onClick:r,style:{background:"white",color:"#111827",border:"1px solid #d1d5db",borderRadius:6,padding:"10px 18px",fontWeight:500,fontSize:13,cursor:"pointer"},children:e})}const Zy={display:"flex",alignItems:"baseline",justifyContent:"space-between",marginBottom:14},Yo={display:"block",fontSize:12,fontWeight:600,marginBottom:6,color:"#374151"},Xy={width:"100%",boxSizing:"border-box",padding:10,borderRadius:6,border:"1px solid #d1d5db",fontFamily:"inherit",fontSize:13,resize:"vertical"},Jy={width:"100%",display:"flex",alignItems:"center",gap:8,background:"#f9fafb",border:"1px solid #e5e7eb",borderRadius:8,padding:"10px 14px",fontSize:13,color:"#1f2937",cursor:"pointer",textAlign:"left"},Ky={marginTop:8,border:"1px solid #e5e7eb",borderRadius:8,background:"#fafafa",overflow:"hidden"},qy={display:"flex",gap:4,background:"#f3f4f6",borderBottom:"1px solid #e5e7eb",padding:"0 8px"},Qy={margin:0,fontFamily:"ui-monospace, monospace",fontSize:11,lineHeight:1.5,color:"#1f2937",whiteSpace:"pre-wrap",wordBreak:"break-all"},vr={padding:"6px 8px",fontSize:10,fontWeight:600,textTransform:"uppercase",letterSpacing:.5,borderBottom:"1px solid #e5e7eb"},Sr={padding:"6px 8px",verticalAlign:"top"},ew={position:"sticky",bottom:-22,marginTop:22,marginLeft:-22,marginRight:-22,marginBottom:-22,padding:"14px 22px 22px 22px",display:"flex",gap:8,justifyContent:"space-between",background:"rgba(255,255,255,0.96)",backdropFilter:"blur(6px)",borderTop:"1px solid #e5e7eb",zIndex:1};function ln(r){const e=Math.floor(r/1e3),t=Math.floor(e/60),i=e%60;return`${t}:${String(i).padStart(2,"0")}`}const tw={"bottom-right":{right:20,bottom:20},"bottom-left":{left:20,bottom:20},"top-right":{right:20,top:20},"top-left":{left:20,top:20}};function rw(r){return m.jsxs("div",{"data-bugjar-block":"true",style:{position:"fixed",zIndex:2147483e3,...tw[r.position]},children:[r.view==="idle"&&r.triggerVisible&&m.jsx(sw,{color:r.primaryColor,label:r.triggerLabel,onClick:r.onOpenActive}),r.view==="active"&&m.jsx(xh,{primaryColor:r.primaryColor,isRecording:r.isRecording,hasRecording:r.hasRecording,elapsedMs:r.elapsedMs,maxDurationSec:r.maxDurationSec,onSelectTool:r.onSelectTool,onSelectColor:r.onSelectColor,onUndo:r.onUndoMarkup,onStartRecording:()=>{r.onStartRecording()},onStopRecording:()=>{r.onStopRecording()},onToggleMicMute:r.onToggleMicMute,onDone:()=>{r.onFinalize()},onCancel:r.onCancel}),r.view==="preview"&&r.preview&&m.jsx(jy,{color:r.primaryColor,hasReplay:r.preview.hasReplay,durationMs:r.preview.durationMs,replayEvents:r.preview.replayEvents,audioBlobUrl:r.preview.audioBlobUrl,screenshotUrl:r.preview.screenshotUrl,consoleLogs:r.preview.consoleLogs,networkEvents:r.preview.networkEvents,redactionSummary:r.preview.redactionSummary,capturedViewport:r.preview.capturedViewport,pageUrl:r.preview.pageUrl,userAgent:r.preview.userAgent,onCancel:r.onCancel,onBackToMarkup:r.onBackToMarkup,onSend:r.onSendReport}),r.view==="uploading"&&m.jsx(lw,{color:r.primaryColor}),r.view==="success"&&m.jsx(cw,{color:r.primaryColor,onDismiss:r.onCancel}),r.view==="failed"&&m.jsx(uw,{error:r.error??"Upload failed",onDismiss:r.onCancel,onDownload:()=>{r.onDownloadFailed()}}),r.resumingToast&&m.jsx(iw,{color:r.primaryColor,remainingMs:r.resumingToast.remainingMs})]})}function iw({color:r,remainingMs:e}){const t=Math.max(1,Math.ceil(e/1e3));return m.jsxs("div",{style:{position:"fixed",left:"50%",top:24,transform:"translateX(-50%)",background:"#111827",color:"white",padding:"10px 14px",borderRadius:10,fontFamily:"system-ui, -apple-system, sans-serif",fontSize:13,boxShadow:"0 10px 30px rgba(0,0,0,0.35)",display:"flex",alignItems:"center",gap:10,zIndex:2147483002,userSelect:"none",maxWidth:"calc(100vw - 32px)"},children:[m.jsx("span",{style:{width:8,height:8,borderRadius:"50%",background:r,animation:"bugjar-pulse 1.2s infinite",flexShrink:0}}),m.jsx("style",{children:"@keyframes bugjar-pulse { 0%,100%{opacity:1} 50%{opacity:0.35} }"}),m.jsxs("span",{children:["Continuing recording — ",t,"s left"]})]})}function sw({color:r,label:e,onClick:t}){const i=nw(r,.12),s=ow(r,.33);return m.jsxs(m.Fragment,{children:[m.jsx("style",{children:`
118
118
  [data-bugjar-block] .bugjar-trigger {
119
119
  background: ${r};
120
120
  color: #fff;
@@ -173,4 +173,4 @@ PERFORMANCE OF THIS SOFTWARE.
173
173
  margin-top: 8px;
174
174
  border-radius: 2px;
175
175
  }
176
- `}),m.jsxs("div",{style:{background:"#111827",color:"white",padding:"12px 16px",borderRadius:10,fontFamily:"system-ui, -apple-system, sans-serif",fontSize:13,boxShadow:"0 10px 30px rgba(0,0,0,0.3)",minWidth:240,maxWidth:320},children:[m.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[m.jsx("span",{className:"bugjar-spinner"}),m.jsx("span",{children:i[e]})]}),m.jsx("div",{className:"bugjar-upload-bar"})]})]})}function cw({color:r,url:e,onDismiss:t}){return m.jsxs("div",{style:{background:"white",padding:16,borderRadius:8,border:`2px solid ${r}`,fontFamily:"system-ui",fontSize:13,boxShadow:"0 10px 30px rgba(0,0,0,0.2)",maxWidth:320},children:[m.jsx("div",{style:{fontWeight:600,marginBottom:6},children:"Report sent — thank you!"}),e&&m.jsx("a",{href:e,target:"_blank",rel:"noreferrer",style:{color:r},children:"View in dashboard →"}),m.jsx("div",{style:{marginTop:12,textAlign:"right"},children:m.jsx(xs,{onClick:t,children:"Close"})})]})}function uw({error:r,onDismiss:e,onDownload:t}){return m.jsxs("div",{style:{background:"white",padding:16,borderRadius:8,border:"2px solid #ef4444",fontFamily:"system-ui",fontSize:13,boxShadow:"0 10px 30px rgba(0,0,0,0.2)",maxWidth:360},children:[m.jsx("div",{style:{fontWeight:600,marginBottom:6,color:"#b91c1c"},children:"Upload failed"}),m.jsx("div",{style:{color:"#4b5563",marginBottom:4,fontFamily:"ui-monospace, monospace",fontSize:12,wordBreak:"break-word"},children:r}),m.jsx("div",{style:{color:"#9ca3af",fontSize:11,lineHeight:1.5,marginTop:6},children:"Your report is still in memory. You can save it as a file and email it to support, or dismiss this toast to discard."}),m.jsxs("div",{style:{marginTop:12,display:"flex",gap:8,justifyContent:"flex-end"},children:[m.jsx(xs,{onClick:e,children:"Discard"}),m.jsx(xs,{onClick:t,children:"Download as file"})]})]})}function xs({onClick:r,children:e}){return m.jsx("button",{onClick:r,style:{background:"white",color:"#111827",border:"1px solid #d1d5db",borderRadius:6,padding:"10px 18px",fontWeight:500,fontSize:13,cursor:"pointer"},children:e})}const hw=typeof window<"u"?window.fetch.bind(window):fetch;async function fw(r){const{apiUrl:e,projectKey:t,userToken:i,captureToken:s,report:n,attachments:o}=r,a=n.rrwebEvents.length>0,l={replay:a?{sizeBytes:yw(n.rrwebEvents),durationMs:n.durationMs}:null,audio:n.audioBlob?{sizeBytes:n.audioBlob.size}:null,screenshot:{sizeBytes:n.screenshotBlob.size},attachments:o.map(p=>({filename:p.name,sizeBytes:p.size,mimeType:p.type}))},c=await Es(`${e}/upload-url`,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({projectKey:t,manifest:l,...i?{userToken:i}:{},...s?{captureToken:s}:{}})});if(!c.ok)throw new Error(`upload-url failed: ${c.status} ${(await c.text()).slice(0,200)}`);const{reportId:u,finalizeToken:h,uploads:f}=await c.json(),d=[];f.replay&&a&&d.push(Cr(f.replay.url,new Blob([JSON.stringify(n.rrwebEvents)],{type:"application/json"}))),f.audio&&n.audioBlob&&d.push(Cr(f.audio.url,n.audioBlob)),d.push(Cr(f.screenshot.url,n.screenshotBlob));for(let p=0;p<o.length;p++){const y=o[p],b=f.attachments[p];if(!y||!b)throw new Error(`Server returned ${f.attachments.length} presigns for ${o.length} attachments`);d.push(Cr(b.url,y))}await Promise.all(d);const g=await Es(`${e}/reports/${u}/finalize`,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({projectKey:t,finalizeToken:h,description:n.description,durationMs:n.durationMs,consoleLogs:n.consoleLogs,networkEvents:n.networkEvents,annotations:n.annotations,url:n.url,userAgent:n.userAgent,viewport:n.viewport,redactionSummary:n.redactionSummary,strictMode:n.strictMode,attachmentIds:f.attachments.map(p=>p.id)})});if(!g.ok)throw new Error(`finalize failed: ${g.status}`);const{dashboardUrl:w}=await g.json();return{reportId:u,dashboardUrl:w}}async function Cr(r,e){const t=await Es(r,{method:"PUT",headers:{"Content-Type":e.type||"application/octet-stream"},body:e});if(!t.ok){const i=await t.text().catch(()=>"");throw new Error(`PUT ${Yr(r)} failed: ${t.status} ${i.slice(0,160)}`)}}const xr=[200,800,3200],Ho=3e4;async function Es(r,e){let t=null;for(let i=0;i<=xr.length;i++){try{const o=await gw(r,e);if(!dw(o.status)||i===xr.length)return o}catch(o){if(t=o,i===xr.length)throw o}const s=xr[i],n=(Math.random()-.5)*.5*s;await pw(s+n)}throw t instanceof Error?t:new Error(`retryingFetch exhausted attempts for ${Yr(r)}`)}function dw(r){return r===408||r===502||r===503||r===504}function pw(r){return new Promise(e=>setTimeout(e,Math.max(0,r)))}function mw(r,e){return!r||typeof AbortSignal.any!="function"?e:AbortSignal.any([r,e])}async function gw(r,e){const t=AbortSignal.timeout(Ho),i=mw(e.signal,t);try{return await hw(r,{...e,signal:i})}catch(s){const n=(e.method??"GET").toUpperCase();if(t.aborted&&!e.signal?.aborted)throw new Error(`${n} ${Yr(r)} timed out after ${Ho/1e3}s`);const a=s,l=a?.cause instanceof Error?`: ${a.cause.message}`:a?.cause?`: ${String(a.cause)}`:"",c=s instanceof Error?s.message:String(s);throw new Error(`${n} ${Yr(r)} failed: ${c}${l}`)}}function Yr(r){try{const e=new URL(r),t=e.pathname.length>60?`${e.pathname.slice(0,57)}…`:e.pathname;return`${e.host}${t}`}catch{return r.slice(0,80)}}function yw(r){try{return new Blob([JSON.stringify(r)]).size}catch{return 0}}async function ww(r,e){const t={reportId:r.reportId,createdAt:r.createdAt,durationMs:r.durationMs,description:r.description,url:r.url,userAgent:r.userAgent,viewport:r.viewport,consoleLogs:r.consoleLogs,networkEvents:r.networkEvents,annotations:r.annotations,redactionSummary:r.redactionSummary,strictMode:r.strictMode,attachmentNames:e.map(n=>n.name)},i=new Blob([JSON.stringify({manifest:t,rrwebEvents:r.rrwebEvents},null,2)],{type:"application/json"}),s=document.createElement("a");s.href=URL.createObjectURL(i),s.download=`bugjar-report-${r.reportId}.json`,s.click(),URL.revokeObjectURL(s.href)}class bw{constructor(){M(this,"config",null);M(this,"root",null);M(this,"host",null);M(this,"markupHost",null);M(this,"markupController",null);M(this,"consoleCapture",null);M(this,"networkCapture",null);M(this,"recorder",null);M(this,"view","idle");M(this,"isRecording",!1);M(this,"elapsedMs",0);M(this,"capturedReport",null);M(this,"preview",null);M(this,"previewObjectUrls",[]);M(this,"error",null);M(this,"failedAttachments",null);M(this,"errorObserved",!1);M(this,"sessionId",null);M(this,"persistedActiveMs",0);M(this,"resumingToast",null);M(this,"lastRecording",null);M(this,"finalizingInFlight",!1)}init(e){if(this.config)return this.publicApi();this.config=vw(e),this.host=document.createElement("div"),this.host.setAttribute("data-bugjar-block","true"),this.host.id="bugjar-root",document.body.appendChild(this.host),this.root=Ii(this.host);const t=()=>this.onErrorObserved();this.consoleCapture=Tc(this.config.capture.consoleBufferSize,t),this.networkCapture=$c(this.config.capture.networkBufferSize,t);const i=Sw(this.config.captureTokenParam);return i&&this.applyCaptureToken(i),this.render(),this.attemptRecovery(),this.publicApi()}async attemptRecovery(){if(!this.config)return;const e=this.config.projectKey,t=Zc(e);if(!t)return;if(!Xc(t)){We(e);try{await Yt(t.sessionId)}catch{}return}let i=null;try{i=await Uc(t.sessionId)}catch{We(e);return}if(!i){We(e);return}const s=Math.max(0,i.maxDurationMs-i.activeMs);if(s<500){We(e);try{await Yt(i.sessionId)}catch{}return}try{this.consoleCapture.hydrate(i.consoleEntries),this.networkCapture.hydrate(i.networkEvents)}catch(o){this.config.onError?.(o instanceof Error?o:new Error(String(o)))}this.sessionId=i.sessionId,this.persistedActiveMs=i.activeMs,this.view="active",this.isRecording=!0,this.elapsedMs=i.activeMs,this.resumingToast={remainingMs:s},this.ensureMarkupLayer(),this.render();const n=new pn({sessionId:i.sessionId,projectKey:e,persistedActiveMs:i.activeMs,strictMode:this.config.strictMode,disabledCategories:this.config.disabledCategories,captureMicrophone:this.config.capture.captureMicrophone,maxDurationSec:this.config.capture.maxDurationSec,consoleCapture:this.consoleCapture,networkCapture:this.networkCapture,onTick:o=>{this.elapsedMs=o,this.render()},onStop:o=>{this.lastRecording={events:o.events,audioBlob:o.audioBlob,durationMs:o.durationMs},this.isRecording=!1,this.recorder=null,this.render()}});n.hydrateEvents(i.events),n.hydrateAudioChunks(i.audioChunks),this.recorder=n;try{await n.start()}catch(o){this.recorder=null,this.sessionId=null,this.persistedActiveMs=0,this.isRecording=!1,this.view="idle",this.resumingToast=null,We(e);try{await Yt(i.sessionId)}catch{}this.config.onError?.(o instanceof Error?o:new Error(String(o))),this.render();return}window.setTimeout(()=>{this.resumingToast=null,this.render()},3500)}onErrorObserved(){this.errorObserved||(this.errorObserved=!0,this.render())}publicApi(){return{open:()=>this.open(),close:()=>this.close()}}async applyCaptureToken(e){if(this.config&&this.config.captureToken!==e)try{const t=await fetch(`${this.config.apiUrl}/capture-invitations/${encodeURIComponent(e)}/scope`,{method:"GET",headers:{Accept:"application/json"}});if(!t.ok){const n=await t.json().catch(()=>({}));throw new Error(`capture-token scope fetch failed (${t.status}): ${n.error?.code??"unknown"}`)}const{disableCategories:i}=await t.json(),s=eu(i);this.config.captureToken=e,this.config.disabledCategories=s,this.view==="idle"&&this.open()}catch(t){this.config.onError?.(t instanceof Error?t:new Error(String(t)))}}ensureMarkupLayer(){if(this.markupController)return this.markupController;const e=document.createElement("div");return e.id="bugjar-markup-layer",document.body.appendChild(e),this.markupHost=e,this.markupController=new Pc(e),this.markupController}teardownMarkupLayer(){this.markupController&&(this.markupController.destroy(),this.markupController=null),this.markupHost&&(this.markupHost.remove(),this.markupHost=null)}open(){if(!this.config)throw new Error("BugJar.init() must be called first");this.view="active",this.isRecording=!1,this.elapsedMs=0,this.lastRecording=null,this.ensureMarkupLayer(),this.render()}close(){this.view="idle",this.isRecording=!1,this.elapsedMs=0,this.capturedReport=null,this.preview=null,this.error=null,this.lastRecording=null,this.resumingToast=null,this.releasePreviewObjectUrls(),this.recorder&&(this.recorder.stop().catch(()=>{}),this.recorder=null),this.discardPersistedSession(),this.teardownMarkupLayer(),this.render()}discardPersistedSession(){if(!this.config||!this.sessionId)return;const e=this.config.projectKey,t=this.sessionId;We(e),Yt(t).catch(()=>{}),this.sessionId=null,this.persistedActiveMs=0}releasePreviewObjectUrls(){for(const e of this.previewObjectUrls)try{URL.revokeObjectURL(e)}catch{}this.previewObjectUrls=[]}render(){if(!this.root||!this.config)return;const{showTrigger:e,showOnError:t}=this.config.ui,i=e&&(this.errorObserved||!t);this.root.render(m.jsx(oe.StrictMode,{children:m.jsx(rw,{projectKey:this.config.projectKey,primaryColor:this.config.ui.primaryColor,position:this.config.ui.position,maxDurationSec:this.config.capture.maxDurationSec,strictMode:this.config.strictMode,triggerVisible:i,triggerLabel:this.config.ui.triggerLabel,view:this.view,isRecording:this.isRecording,hasRecording:this.lastRecording!==null,elapsedMs:this.elapsedMs,preview:this.preview,error:this.error,resumingToast:this.resumingToast,onOpenActive:()=>this.open(),onCancel:()=>this.close(),onStartRecording:async()=>{await this.startRecording()},onStopRecording:async()=>{await this.stopRecording()},onToggleMicMute:s=>this.recorder?.toggleMic(s),onFinalize:async()=>{await this.finalizeReport()},onBackToMarkup:()=>this.backToMarkup(),onSendReport:async s=>{await this.sendReport(s)},onDownloadFailed:async()=>{await this.downloadOnDemand()},onSelectTool:s=>this.markupController?.setTool(s),onSelectColor:s=>this.markupController?.setColor(s),onUndoMarkup:()=>this.markupController?.undo()})}))}async startRecording(){if(!this.config||this.isRecording||this.recorder)return;this.discardPersistedSession(),this.isRecording=!0,this.elapsedMs=0,this.lastRecording=null,this.persistedActiveMs=0;const e=hn();this.sessionId=e;const t={sessionId:e,projectKey:this.config.projectKey,startedAt:Date.now(),activeMs:0,maxDurationMs:this.config.capture.maxDurationSec*1e3,events:[],audioChunks:[],consoleEntries:[],networkEvents:[],lastSeenAt:Date.now()};try{await zc(t)}catch(i){this.config.onError?.(i instanceof Error?i:new Error(String(i)))}this.render(),this.recorder=new pn({sessionId:e,projectKey:this.config.projectKey,persistedActiveMs:0,strictMode:this.config.strictMode,disabledCategories:this.config.disabledCategories,captureMicrophone:this.config.capture.captureMicrophone,maxDurationSec:this.config.capture.maxDurationSec,consoleCapture:this.consoleCapture,networkCapture:this.networkCapture,onTick:i=>{this.elapsedMs=i,this.render()},onStop:i=>{this.lastRecording={events:i.events,audioBlob:i.audioBlob,durationMs:i.durationMs},this.isRecording=!1,this.recorder=null,this.render()}});try{await this.recorder.start()}catch(i){await this.recorder.stop().catch(()=>{}),this.recorder=null,this.isRecording=!1,this.lastRecording=null,this.discardPersistedSession(),this.error=i instanceof Error?i.message:String(i),this.config.onError?.(i instanceof Error?i:new Error(String(i))),this.render()}}async stopRecording(){this.recorder&&await this.recorder.stop()}async finalizeReport(){if(this.config&&!this.finalizingInFlight){this.finalizingInFlight=!0;try{this.recorder&&await this.recorder.stop(),this.discardPersistedSession();const e=Jo(),t={disabledCategories:this.config.disabledCategories},i=this.lastRecording,s=i?nu(i.events,e,t):[],n=i?this.consoleCapture.snapshot().map(g=>xt(g,e,t)):[],o=i?this.networkCapture.snapshot().map(g=>{const w=xt(g,e,t);return{...w,url:Di(w.url,e)}}):[],a=await gh(),l={width:window.innerWidth,height:window.innerHeight},c=i?.audioBlob??null,u=i?.durationMs??0,h={reportId:hn(),createdAt:Date.now(),durationMs:u,rrwebEvents:s,audioBlob:c,screenshotBlob:a,consoleLogs:n,networkEvents:o,annotations:[],description:"",url:Di(location.href,e),userAgent:navigator.userAgent,viewport:l,redactionSummary:e,strictMode:this.config.strictMode};this.capturedReport=h,this.releasePreviewObjectUrls();const f=URL.createObjectURL(a),d=c?URL.createObjectURL(c):null;this.previewObjectUrls=[f,d].filter(g=>g!==null),this.preview={hasReplay:s.length>0,durationMs:u,replayEvents:s,replayEventCount:s.length,hasAudio:c!==null,audioBlobUrl:d,consoleLogs:n,networkEvents:o,redactionSummary:e,screenshotUrl:f,capturedViewport:l,pageUrl:location.href,userAgent:navigator.userAgent,reportUrl:null},this.view="preview",this.render()}finally{this.finalizingInFlight=!1}}}backToMarkup(){this.preview=null,this.capturedReport=null,this.view="active",this.render()}async sendReport(e){if(!(!this.capturedReport||!this.config)){this.capturedReport.description=e.description,this.capturedReport.annotations=e.annotations,this.view="uploading",this.render();try{const{reportId:t,dashboardUrl:i}=await fw({apiUrl:this.config.apiUrl,projectKey:this.config.projectKey,userToken:this.config.userToken,captureToken:this.config.captureToken,report:this.capturedReport,attachments:e.attachments});this.preview&&(this.preview.reportUrl=i),this.view="success",this.teardownMarkupLayer(),this.config.onReportSubmitted?.(t),this.render()}catch(t){this.error=t instanceof Error?t.message:String(t),this.failedAttachments=e.attachments,this.view="failed",this.config.onError?.(t instanceof Error?t:new Error(String(t))),this.render()}}}async downloadOnDemand(){if(this.capturedReport)try{await ww(this.capturedReport,this.failedAttachments??[])}catch(e){this.config?.onError?.(e instanceof Error?e:new Error(String(e)))}}}function vw(r){return{projectKey:r.projectKey,apiUrl:Ch,userToken:r.userToken??null,user:r.user??{id:""},strictMode:r.strictMode??!1,capture:{...vh,...r.capture??{}},ui:{...Sh,...r.ui??{}},onReportSubmitted:r.onReportSubmitted??(()=>{}),onError:r.onError??(()=>{}),captureTokenParam:r.captureTokenParam??"bugjar_capture",captureToken:null,disabledCategories:new Set}}function Sw(r){if(typeof window>"u"||!window.location)return null;try{const t=new URLSearchParams(window.location.search).get(r);return t&&t.length>0?t:null}catch{return null}}const yc=new bw,_i=yc,wc={init:r=>_i.init(r),open:()=>_i.open(),close:()=>_i.close()};typeof window<"u"&&(window.BugJar=wc);exports.BugJar=wc;exports._client=yc;
176
+ `}),m.jsxs("div",{style:{background:"#111827",color:"white",padding:"12px 16px",borderRadius:10,fontFamily:"system-ui, -apple-system, sans-serif",fontSize:13,boxShadow:"0 10px 30px rgba(0,0,0,0.3)",minWidth:240,maxWidth:320},children:[m.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[m.jsx("span",{className:"bugjar-spinner"}),m.jsx("span",{children:i[e]})]}),m.jsx("div",{className:"bugjar-upload-bar"})]})]})}function cw({color:r,onDismiss:e}){return m.jsxs("div",{style:{background:"white",padding:16,borderRadius:8,border:`2px solid ${r}`,fontFamily:"system-ui",fontSize:13,boxShadow:"0 10px 30px rgba(0,0,0,0.2)",maxWidth:320},children:[m.jsx("div",{style:{fontWeight:600,marginBottom:6},children:"Report sent — thank you!"}),m.jsx("div",{style:{color:"#475569",fontSize:12,lineHeight:1.5},children:"The team has been notified and will follow up by email if they need more from you."}),m.jsx("div",{style:{marginTop:12,textAlign:"right"},children:m.jsx(xs,{onClick:e,children:"Close"})})]})}function uw({error:r,onDismiss:e,onDownload:t}){return m.jsxs("div",{style:{background:"white",padding:16,borderRadius:8,border:"2px solid #ef4444",fontFamily:"system-ui",fontSize:13,boxShadow:"0 10px 30px rgba(0,0,0,0.2)",maxWidth:360},children:[m.jsx("div",{style:{fontWeight:600,marginBottom:6,color:"#b91c1c"},children:"Upload failed"}),m.jsx("div",{style:{color:"#4b5563",marginBottom:4,fontFamily:"ui-monospace, monospace",fontSize:12,wordBreak:"break-word"},children:r}),m.jsx("div",{style:{color:"#9ca3af",fontSize:11,lineHeight:1.5,marginTop:6},children:"Your report is still in memory. You can save it as a file and email it to support, or dismiss this toast to discard."}),m.jsxs("div",{style:{marginTop:12,display:"flex",gap:8,justifyContent:"flex-end"},children:[m.jsx(xs,{onClick:e,children:"Discard"}),m.jsx(xs,{onClick:t,children:"Download as file"})]})]})}function xs({onClick:r,children:e}){return m.jsx("button",{onClick:r,style:{background:"white",color:"#111827",border:"1px solid #d1d5db",borderRadius:6,padding:"10px 18px",fontWeight:500,fontSize:13,cursor:"pointer"},children:e})}const hw=typeof window<"u"?window.fetch.bind(window):fetch;async function fw(r){const{apiUrl:e,projectKey:t,userToken:i,captureToken:s,report:n,attachments:o}=r,a=n.rrwebEvents.length>0,l={replay:a?{sizeBytes:yw(n.rrwebEvents),durationMs:n.durationMs}:null,audio:n.audioBlob?{sizeBytes:n.audioBlob.size}:null,screenshot:{sizeBytes:n.screenshotBlob.size},attachments:o.map(p=>({filename:p.name,sizeBytes:p.size,mimeType:p.type}))},c=await Es(`${e}/upload-url`,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({projectKey:t,manifest:l,...i?{userToken:i}:{},...s?{captureToken:s}:{}})});if(!c.ok)throw new Error(`upload-url failed: ${c.status} ${(await c.text()).slice(0,200)}`);const{reportId:u,finalizeToken:h,uploads:f}=await c.json(),d=[];f.replay&&a&&d.push(Cr(f.replay.url,new Blob([JSON.stringify(n.rrwebEvents)],{type:"application/json"}))),f.audio&&n.audioBlob&&d.push(Cr(f.audio.url,n.audioBlob)),d.push(Cr(f.screenshot.url,n.screenshotBlob));for(let p=0;p<o.length;p++){const y=o[p],b=f.attachments[p];if(!y||!b)throw new Error(`Server returned ${f.attachments.length} presigns for ${o.length} attachments`);d.push(Cr(b.url,y))}await Promise.all(d);const g=await Es(`${e}/reports/${u}/finalize`,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({projectKey:t,finalizeToken:h,description:n.description,durationMs:n.durationMs,consoleLogs:n.consoleLogs,networkEvents:n.networkEvents,annotations:n.annotations,url:n.url,userAgent:n.userAgent,viewport:n.viewport,redactionSummary:n.redactionSummary,strictMode:n.strictMode,attachmentIds:f.attachments.map(p=>p.id)})});if(!g.ok)throw new Error(`finalize failed: ${g.status}`);const{dashboardUrl:w}=await g.json();return{reportId:u,dashboardUrl:w}}async function Cr(r,e){const t=await Es(r,{method:"PUT",headers:{"Content-Type":e.type||"application/octet-stream"},body:e});if(!t.ok){const i=await t.text().catch(()=>"");throw new Error(`PUT ${Yr(r)} failed: ${t.status} ${i.slice(0,160)}`)}}const xr=[200,800,3200],Ho=3e4;async function Es(r,e){let t=null;for(let i=0;i<=xr.length;i++){try{const o=await gw(r,e);if(!dw(o.status)||i===xr.length)return o}catch(o){if(t=o,i===xr.length)throw o}const s=xr[i],n=(Math.random()-.5)*.5*s;await pw(s+n)}throw t instanceof Error?t:new Error(`retryingFetch exhausted attempts for ${Yr(r)}`)}function dw(r){return r===408||r===502||r===503||r===504}function pw(r){return new Promise(e=>setTimeout(e,Math.max(0,r)))}function mw(r,e){return!r||typeof AbortSignal.any!="function"?e:AbortSignal.any([r,e])}async function gw(r,e){const t=AbortSignal.timeout(Ho),i=mw(e.signal,t);try{return await hw(r,{...e,signal:i})}catch(s){const n=(e.method??"GET").toUpperCase();if(t.aborted&&!e.signal?.aborted)throw new Error(`${n} ${Yr(r)} timed out after ${Ho/1e3}s`);const a=s,l=a?.cause instanceof Error?`: ${a.cause.message}`:a?.cause?`: ${String(a.cause)}`:"",c=s instanceof Error?s.message:String(s);throw new Error(`${n} ${Yr(r)} failed: ${c}${l}`)}}function Yr(r){try{const e=new URL(r),t=e.pathname.length>60?`${e.pathname.slice(0,57)}…`:e.pathname;return`${e.host}${t}`}catch{return r.slice(0,80)}}function yw(r){try{return new Blob([JSON.stringify(r)]).size}catch{return 0}}async function ww(r,e){const t={reportId:r.reportId,createdAt:r.createdAt,durationMs:r.durationMs,description:r.description,url:r.url,userAgent:r.userAgent,viewport:r.viewport,consoleLogs:r.consoleLogs,networkEvents:r.networkEvents,annotations:r.annotations,redactionSummary:r.redactionSummary,strictMode:r.strictMode,attachmentNames:e.map(n=>n.name)},i=new Blob([JSON.stringify({manifest:t,rrwebEvents:r.rrwebEvents},null,2)],{type:"application/json"}),s=document.createElement("a");s.href=URL.createObjectURL(i),s.download=`bugjar-report-${r.reportId}.json`,s.click(),URL.revokeObjectURL(s.href)}class bw{constructor(){M(this,"config",null);M(this,"root",null);M(this,"host",null);M(this,"markupHost",null);M(this,"markupController",null);M(this,"consoleCapture",null);M(this,"networkCapture",null);M(this,"recorder",null);M(this,"view","idle");M(this,"isRecording",!1);M(this,"elapsedMs",0);M(this,"capturedReport",null);M(this,"preview",null);M(this,"previewObjectUrls",[]);M(this,"error",null);M(this,"failedAttachments",null);M(this,"errorObserved",!1);M(this,"sessionId",null);M(this,"persistedActiveMs",0);M(this,"resumingToast",null);M(this,"lastRecording",null);M(this,"finalizingInFlight",!1)}init(e){if(this.config)return this.publicApi();this.config=vw(e),this.host=document.createElement("div"),this.host.setAttribute("data-bugjar-block","true"),this.host.id="bugjar-root",document.body.appendChild(this.host),this.root=Ii(this.host);const t=()=>this.onErrorObserved();this.consoleCapture=Tc(this.config.capture.consoleBufferSize,t),this.networkCapture=$c(this.config.capture.networkBufferSize,t);const i=Sw(this.config.captureTokenParam);return i&&(Cw(this.config.captureTokenParam),this.applyCaptureToken(i)),this.render(),this.attemptRecovery(),this.publicApi()}async attemptRecovery(){if(!this.config)return;const e=this.config.projectKey,t=Zc(e);if(!t)return;if(!Xc(t)){We(e);try{await Yt(t.sessionId)}catch{}return}let i=null;try{i=await Uc(t.sessionId)}catch{We(e);return}if(!i){We(e);return}const s=Math.max(0,i.maxDurationMs-i.activeMs);if(s<500){We(e);try{await Yt(i.sessionId)}catch{}return}try{this.consoleCapture.hydrate(i.consoleEntries),this.networkCapture.hydrate(i.networkEvents)}catch(o){this.config.onError?.(o instanceof Error?o:new Error(String(o)))}this.sessionId=i.sessionId,this.persistedActiveMs=i.activeMs,this.view="active",this.isRecording=!0,this.elapsedMs=i.activeMs,this.resumingToast={remainingMs:s},this.ensureMarkupLayer(),this.render();const n=new pn({sessionId:i.sessionId,projectKey:e,persistedActiveMs:i.activeMs,strictMode:this.config.strictMode,disabledCategories:this.config.disabledCategories,captureMicrophone:this.config.capture.captureMicrophone,maxDurationSec:this.config.capture.maxDurationSec,consoleCapture:this.consoleCapture,networkCapture:this.networkCapture,onTick:o=>{this.elapsedMs=o,this.render()},onStop:o=>{this.lastRecording={events:o.events,audioBlob:o.audioBlob,durationMs:o.durationMs},this.isRecording=!1,this.recorder=null,this.render()}});n.hydrateEvents(i.events),n.hydrateAudioChunks(i.audioChunks),this.recorder=n;try{await n.start()}catch(o){this.recorder=null,this.sessionId=null,this.persistedActiveMs=0,this.isRecording=!1,this.view="idle",this.resumingToast=null,We(e);try{await Yt(i.sessionId)}catch{}this.config.onError?.(o instanceof Error?o:new Error(String(o))),this.render();return}window.setTimeout(()=>{this.resumingToast=null,this.render()},3500)}onErrorObserved(){this.errorObserved||(this.errorObserved=!0,this.render())}publicApi(){return{open:()=>this.open(),close:()=>this.close()}}async applyCaptureToken(e){if(this.config&&this.config.captureToken!==e)try{const t=await fetch(`${this.config.apiUrl}/capture-invitations/${encodeURIComponent(e)}/scope`,{method:"GET",headers:{Accept:"application/json"}});if(!t.ok){const n=await t.json().catch(()=>({}));throw new Error(`capture-token scope fetch failed (${t.status}): ${n.error?.code??"unknown"}`)}const{disableCategories:i}=await t.json(),s=eu(i);this.config.captureToken=e,this.config.disabledCategories=s,this.view==="idle"&&this.open()}catch(t){this.config.onError?.(t instanceof Error?t:new Error(String(t)))}}ensureMarkupLayer(){if(this.markupController)return this.markupController;const e=document.createElement("div");return e.id="bugjar-markup-layer",document.body.appendChild(e),this.markupHost=e,this.markupController=new Pc(e),this.markupController}teardownMarkupLayer(){this.markupController&&(this.markupController.destroy(),this.markupController=null),this.markupHost&&(this.markupHost.remove(),this.markupHost=null)}open(){if(!this.config)throw new Error("BugJar.init() must be called first");this.view="active",this.isRecording=!1,this.elapsedMs=0,this.lastRecording=null,this.ensureMarkupLayer(),this.render()}close(){this.view="idle",this.isRecording=!1,this.elapsedMs=0,this.capturedReport=null,this.preview=null,this.error=null,this.lastRecording=null,this.resumingToast=null,this.releasePreviewObjectUrls(),this.recorder&&(this.recorder.stop().catch(()=>{}),this.recorder=null),this.discardPersistedSession(),this.teardownMarkupLayer(),this.render()}discardPersistedSession(){if(!this.config||!this.sessionId)return;const e=this.config.projectKey,t=this.sessionId;We(e),Yt(t).catch(()=>{}),this.sessionId=null,this.persistedActiveMs=0}releasePreviewObjectUrls(){for(const e of this.previewObjectUrls)try{URL.revokeObjectURL(e)}catch{}this.previewObjectUrls=[]}render(){if(!this.root||!this.config)return;const{showTrigger:e,showOnError:t}=this.config.ui,i=e&&(this.errorObserved||!t);this.root.render(m.jsx(oe.StrictMode,{children:m.jsx(rw,{projectKey:this.config.projectKey,primaryColor:this.config.ui.primaryColor,position:this.config.ui.position,maxDurationSec:this.config.capture.maxDurationSec,strictMode:this.config.strictMode,triggerVisible:i,triggerLabel:this.config.ui.triggerLabel,view:this.view,isRecording:this.isRecording,hasRecording:this.lastRecording!==null,elapsedMs:this.elapsedMs,preview:this.preview,error:this.error,resumingToast:this.resumingToast,onOpenActive:()=>this.open(),onCancel:()=>this.close(),onStartRecording:async()=>{await this.startRecording()},onStopRecording:async()=>{await this.stopRecording()},onToggleMicMute:s=>this.recorder?.toggleMic(s),onFinalize:async()=>{await this.finalizeReport()},onBackToMarkup:()=>this.backToMarkup(),onSendReport:async s=>{await this.sendReport(s)},onDownloadFailed:async()=>{await this.downloadOnDemand()},onSelectTool:s=>this.markupController?.setTool(s),onSelectColor:s=>this.markupController?.setColor(s),onUndoMarkup:()=>this.markupController?.undo()})}))}async startRecording(){if(!this.config||this.isRecording||this.recorder)return;this.discardPersistedSession(),this.isRecording=!0,this.elapsedMs=0,this.lastRecording=null,this.persistedActiveMs=0;const e=hn();this.sessionId=e;const t={sessionId:e,projectKey:this.config.projectKey,startedAt:Date.now(),activeMs:0,maxDurationMs:this.config.capture.maxDurationSec*1e3,events:[],audioChunks:[],consoleEntries:[],networkEvents:[],lastSeenAt:Date.now()};try{await zc(t)}catch(i){this.config.onError?.(i instanceof Error?i:new Error(String(i)))}this.render(),this.recorder=new pn({sessionId:e,projectKey:this.config.projectKey,persistedActiveMs:0,strictMode:this.config.strictMode,disabledCategories:this.config.disabledCategories,captureMicrophone:this.config.capture.captureMicrophone,maxDurationSec:this.config.capture.maxDurationSec,consoleCapture:this.consoleCapture,networkCapture:this.networkCapture,onTick:i=>{this.elapsedMs=i,this.render()},onStop:i=>{this.lastRecording={events:i.events,audioBlob:i.audioBlob,durationMs:i.durationMs},this.isRecording=!1,this.recorder=null,this.render()}});try{await this.recorder.start()}catch(i){await this.recorder.stop().catch(()=>{}),this.recorder=null,this.isRecording=!1,this.lastRecording=null,this.discardPersistedSession(),this.error=i instanceof Error?i.message:String(i),this.config.onError?.(i instanceof Error?i:new Error(String(i))),this.render()}}async stopRecording(){this.recorder&&await this.recorder.stop()}async finalizeReport(){if(this.config&&!this.finalizingInFlight){this.finalizingInFlight=!0;try{this.recorder&&await this.recorder.stop(),this.discardPersistedSession();const e=Jo(),t={disabledCategories:this.config.disabledCategories},i=this.lastRecording,s=i?nu(i.events,e,t):[],n=i?this.consoleCapture.snapshot().map(g=>xt(g,e,t)):[],o=i?this.networkCapture.snapshot().map(g=>{const w=xt(g,e,t);return{...w,url:Di(w.url,e)}}):[],a=await gh(),l={width:window.innerWidth,height:window.innerHeight},c=i?.audioBlob??null,u=i?.durationMs??0,h={reportId:hn(),createdAt:Date.now(),durationMs:u,rrwebEvents:s,audioBlob:c,screenshotBlob:a,consoleLogs:n,networkEvents:o,annotations:[],description:"",url:Di(location.href,e),userAgent:navigator.userAgent,viewport:l,redactionSummary:e,strictMode:this.config.strictMode};this.capturedReport=h,this.releasePreviewObjectUrls();const f=URL.createObjectURL(a),d=c?URL.createObjectURL(c):null;this.previewObjectUrls=[f,d].filter(g=>g!==null),this.preview={hasReplay:s.length>0,durationMs:u,replayEvents:s,replayEventCount:s.length,hasAudio:c!==null,audioBlobUrl:d,consoleLogs:n,networkEvents:o,redactionSummary:e,screenshotUrl:f,capturedViewport:l,pageUrl:location.href,userAgent:navigator.userAgent,reportUrl:null},this.view="preview",this.render()}finally{this.finalizingInFlight=!1}}}backToMarkup(){this.preview=null,this.capturedReport=null,this.view="active",this.render()}async sendReport(e){if(!(!this.capturedReport||!this.config)){this.capturedReport.description=e.description,this.capturedReport.annotations=e.annotations,this.teardownMarkupLayer(),this.view="uploading",this.render();try{const{reportId:t,dashboardUrl:i}=await fw({apiUrl:this.config.apiUrl,projectKey:this.config.projectKey,userToken:this.config.userToken,captureToken:this.config.captureToken,report:this.capturedReport,attachments:e.attachments});this.preview&&(this.preview.reportUrl=i),this.view="success",this.config.onReportSubmitted?.(t),this.render()}catch(t){this.error=t instanceof Error?t.message:String(t),this.failedAttachments=e.attachments,this.view="failed",this.config.onError?.(t instanceof Error?t:new Error(String(t))),this.render()}}}async downloadOnDemand(){if(this.capturedReport)try{await ww(this.capturedReport,this.failedAttachments??[])}catch(e){this.config?.onError?.(e instanceof Error?e:new Error(String(e)))}}}function vw(r){return{projectKey:r.projectKey,apiUrl:Ch,userToken:r.userToken??null,user:r.user??{id:""},strictMode:r.strictMode??!1,capture:{...vh,...r.capture??{}},ui:{...Sh,...r.ui??{}},onReportSubmitted:r.onReportSubmitted??(()=>{}),onError:r.onError??(()=>{}),captureTokenParam:r.captureTokenParam??"bugjar_capture",captureToken:null,disabledCategories:new Set}}function Sw(r){if(typeof window>"u"||!window.location)return null;try{const t=new URLSearchParams(window.location.search).get(r);return t&&t.length>0?t:null}catch{return null}}function Cw(r){if(!(typeof window>"u")&&!(!window.history||typeof window.history.replaceState!="function"))try{const e=new URL(window.location.href);if(!e.searchParams.has(r))return;e.searchParams.delete(r);const t=e.searchParams.toString(),i=e.pathname+(t?`?${t}`:"")+e.hash;window.history.replaceState({},"",i)}catch{}}const yc=new bw,_i=yc,wc={init:r=>_i.init(r),open:()=>_i.open(),close:()=>_i.close()};typeof window<"u"&&(window.BugJar=wc);exports.BugJar=wc;exports._client=yc;
package/dist/index.js CHANGED
@@ -12985,7 +12985,6 @@ function nw(r) {
12985
12985
  fw,
12986
12986
  {
12987
12987
  color: r.primaryColor,
12988
- url: r.preview?.reportUrl ?? null,
12989
12988
  onDismiss: r.onCancel
12990
12989
  }
12991
12990
  ),
@@ -13201,8 +13200,7 @@ function hw({ color: r }) {
13201
13200
  }
13202
13201
  function fw({
13203
13202
  color: r,
13204
- url: e,
13205
- onDismiss: t
13203
+ onDismiss: e
13206
13204
  }) {
13207
13205
  return /* @__PURE__ */ k(
13208
13206
  "div",
@@ -13219,8 +13217,8 @@ function fw({
13219
13217
  },
13220
13218
  children: [
13221
13219
  /* @__PURE__ */ y("div", { style: { fontWeight: 600, marginBottom: 6 }, children: "Report sent — thank you!" }),
13222
- e && /* @__PURE__ */ y("a", { href: e, target: "_blank", rel: "noreferrer", style: { color: r }, children: "View in dashboard " }),
13223
- /* @__PURE__ */ y("div", { style: { marginTop: 12, textAlign: "right" }, children: /* @__PURE__ */ y(As, { onClick: t, children: "Close" }) })
13220
+ /* @__PURE__ */ y("div", { style: { color: "#475569", fontSize: 12, lineHeight: 1.5 }, children: "The team has been notified and will follow up by email if they need more from you." }),
13221
+ /* @__PURE__ */ y("div", { style: { marginTop: 12, textAlign: "right" }, children: /* @__PURE__ */ y(As, { onClick: e, children: "Close" }) })
13224
13222
  ]
13225
13223
  }
13226
13224
  );
@@ -13500,7 +13498,7 @@ class Cw {
13500
13498
  t
13501
13499
  );
13502
13500
  const i = xw(this.config.captureTokenParam);
13503
- return i && this.applyCaptureToken(i), this.render(), this.attemptRecovery(), this.publicApi();
13501
+ return i && (Aw(this.config.captureTokenParam), this.applyCaptureToken(i)), this.render(), this.attemptRecovery(), this.publicApi();
13504
13502
  }
13505
13503
  /** Reload-recovery path. Called once during init(). If a fresh
13506
13504
  * active-session flag exists, hydrate state and restart a recorder
@@ -13824,7 +13822,7 @@ class Cw {
13824
13822
  }
13825
13823
  async sendReport(e) {
13826
13824
  if (!(!this.capturedReport || !this.config)) {
13827
- this.capturedReport.description = e.description, this.capturedReport.annotations = e.annotations, this.view = "uploading", this.render();
13825
+ this.capturedReport.description = e.description, this.capturedReport.annotations = e.annotations, this.teardownMarkupLayer(), this.view = "uploading", this.render();
13828
13826
  try {
13829
13827
  const { reportId: t, dashboardUrl: i } = await mw({
13830
13828
  apiUrl: this.config.apiUrl,
@@ -13834,7 +13832,7 @@ class Cw {
13834
13832
  report: this.capturedReport,
13835
13833
  attachments: e.attachments
13836
13834
  });
13837
- this.preview && (this.preview.reportUrl = i), this.view = "success", this.teardownMarkupLayer(), this.config.onReportSubmitted?.(t), this.render();
13835
+ this.preview && (this.preview.reportUrl = i), this.view = "success", this.config.onReportSubmitted?.(t), this.render();
13838
13836
  } catch (t) {
13839
13837
  this.error = t instanceof Error ? t.message : String(t), this.failedAttachments = e.attachments, this.view = "failed", this.config.onError?.(t instanceof Error ? t : new Error(String(t))), this.render();
13840
13838
  }
@@ -13882,13 +13880,24 @@ function xw(r) {
13882
13880
  return null;
13883
13881
  }
13884
13882
  }
13885
- const Aw = new Cw(), Di = Aw, Rw = {
13883
+ function Aw(r) {
13884
+ if (!(typeof window > "u") && !(!window.history || typeof window.history.replaceState != "function"))
13885
+ try {
13886
+ const e = new URL(window.location.href);
13887
+ if (!e.searchParams.has(r)) return;
13888
+ e.searchParams.delete(r);
13889
+ const t = e.searchParams.toString(), i = e.pathname + (t ? `?${t}` : "") + e.hash;
13890
+ window.history.replaceState({}, "", i);
13891
+ } catch {
13892
+ }
13893
+ }
13894
+ const Rw = new Cw(), Di = Rw, kw = {
13886
13895
  init: (r) => Di.init(r),
13887
13896
  open: () => Di.open(),
13888
13897
  close: () => Di.close()
13889
13898
  };
13890
- typeof window < "u" && (window.BugJar = Rw);
13899
+ typeof window < "u" && (window.BugJar = kw);
13891
13900
  export {
13892
- Rw as BugJar,
13893
- Aw as _client
13901
+ kw as BugJar,
13902
+ Rw as _client
13894
13903
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bugjar/reporter",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Privacy-first bug reporting SDK. DOM replay + redaction + markup, runs only on user consent.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "type": "module",