@runtimescope/sdk 0.10.0 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -182,6 +182,31 @@ interface RuntimeScopeConfig {
182
182
  maxEventsPerSecond?: number;
183
183
  /** Initial user context attached to all events */
184
184
  user?: UserContext;
185
+ /**
186
+ * When true, the SDK prints lifecycle messages (connect, disconnect, reconnect)
187
+ * to `console.debug`. Off by default — most users never need to see this and
188
+ * it stacks up in DevTools quickly. Equivalent to setting
189
+ * `localStorage.RUNTIMESCOPE_DEBUG = '1'` in a browser.
190
+ */
191
+ verbose?: boolean;
192
+ /**
193
+ * Suppress duplicate `console.*` output to the browser DevTools. The collector
194
+ * still receives every event so the dashboard stays accurate — only the
195
+ * visible console output is collapsed.
196
+ *
197
+ * - `true` → enable with sensible defaults: 5s window, first 3 occurrences
198
+ * print, the rest are suppressed; a single summary line ("[RuntimeScope]
199
+ * suppressed N…") prints every 5s if anything was hidden.
200
+ * - `false` (default) → no suppression; the original console.* call passes
201
+ * through unchanged.
202
+ * - object → fine-grained control over `windowMs`, `maxBurst`,
203
+ * `summaryIntervalMs`.
204
+ */
205
+ dedupeConsole?: boolean | {
206
+ windowMs?: number;
207
+ maxBurst?: number;
208
+ summaryIntervalMs?: number;
209
+ };
185
210
  }
186
211
 
187
212
  /**
@@ -218,6 +243,8 @@ declare class RuntimeScope {
218
243
  private static restoreFns;
219
244
  private static _sessionId;
220
245
  private static _state;
246
+ /** Cached config fingerprint from the last init() call — used to detect double-init with conflicting config. */
247
+ private static _initSignature;
221
248
  private static _sampleRate;
222
249
  private static _maxEventsPerSecond;
223
250
  private static _windowCount;
package/dist/index.d.ts CHANGED
@@ -182,6 +182,31 @@ interface RuntimeScopeConfig {
182
182
  maxEventsPerSecond?: number;
183
183
  /** Initial user context attached to all events */
184
184
  user?: UserContext;
185
+ /**
186
+ * When true, the SDK prints lifecycle messages (connect, disconnect, reconnect)
187
+ * to `console.debug`. Off by default — most users never need to see this and
188
+ * it stacks up in DevTools quickly. Equivalent to setting
189
+ * `localStorage.RUNTIMESCOPE_DEBUG = '1'` in a browser.
190
+ */
191
+ verbose?: boolean;
192
+ /**
193
+ * Suppress duplicate `console.*` output to the browser DevTools. The collector
194
+ * still receives every event so the dashboard stays accurate — only the
195
+ * visible console output is collapsed.
196
+ *
197
+ * - `true` → enable with sensible defaults: 5s window, first 3 occurrences
198
+ * print, the rest are suppressed; a single summary line ("[RuntimeScope]
199
+ * suppressed N…") prints every 5s if anything was hidden.
200
+ * - `false` (default) → no suppression; the original console.* call passes
201
+ * through unchanged.
202
+ * - object → fine-grained control over `windowMs`, `maxBurst`,
203
+ * `summaryIntervalMs`.
204
+ */
205
+ dedupeConsole?: boolean | {
206
+ windowMs?: number;
207
+ maxBurst?: number;
208
+ summaryIntervalMs?: number;
209
+ };
185
210
  }
186
211
 
187
212
  /**
@@ -218,6 +243,8 @@ declare class RuntimeScope {
218
243
  private static restoreFns;
219
244
  private static _sessionId;
220
245
  private static _state;
246
+ /** Cached config fingerprint from the last init() call — used to detect double-init with conflicting config. */
247
+ private static _initSignature;
221
248
  private static _sampleRate;
222
249
  private static _maxEventsPerSecond;
223
250
  private static _windowCount;
@@ -1,9 +1,12 @@
1
- "use strict";var RuntimeScope=(()=>{var M=Object.defineProperty;var pe=Object.getOwnPropertyDescriptor;var le=Object.getOwnPropertyNames;var fe=Object.prototype.hasOwnProperty;var me=(t,e,r)=>e in t?M(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var he=(t,e)=>{for(var r in e)M(t,r,{get:e[r],enumerable:!0})},ge=(t,e,r,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of le(e))!fe.call(t,n)&&n!==r&&M(t,n,{get:()=>e[n],enumerable:!(o=pe(e,n))||o.enumerable});return t};var ve=t=>ge(M({},"__esModule",{value:!0}),t);var f=(t,e,r)=>me(t,typeof e!="symbol"?e+"":e,r);var Ve={};he(Ve,{RuntimeScope:()=>b,buildDsn:()=>ue,default:()=>We,parseDsn:()=>j});var D=console.debug.bind(console),S=class S{constructor(e){f(this,"ws",null);f(this,"batch",[]);f(this,"offlineQueue",[]);f(this,"flushTimer",null);f(this,"reconnectTimer",null);f(this,"reconnectDelay",500);f(this,"reconnectAttempt",0);f(this,"connected",!1);f(this,"stopped",!1);f(this,"config");f(this,"commandHandler",null);f(this,"hasEverConnected",!1);f(this,"connectionWarningTimer",null);f(this,"visibilityHandler",null);f(this,"onlineHandler",null);this.config=e}isConnected(){return this.connected}connect(){this.stopped=!1,this.doConnect(),this.connectionWarningTimer=setTimeout(()=>{!this.hasEverConnected&&!this.stopped&&console.warn(`[RuntimeScope] SDK has not connected to ${this.config.serverUrl} after 10s. Is the collector running? Start it with: npx @runtimescope/collector`)},S.CONNECTION_WARNING_DELAY),typeof document<"u"&&(this.visibilityHandler=()=>{document.visibilityState==="visible"&&!this.connected&&!this.stopped&&(D("[RuntimeScope] Tab visible \u2014 attempting immediate reconnect"),this.resetReconnectState(),this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this.doConnect())},document.addEventListener("visibilitychange",this.visibilityHandler)),typeof window<"u"&&(this.onlineHandler=()=>{!this.connected&&!this.stopped&&(D("[RuntimeScope] Network online \u2014 attempting immediate reconnect"),this.resetReconnectState(),this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this.doConnect())},window.addEventListener("online",this.onlineHandler))}doConnect(){if(!this.stopped){try{this.ws=new WebSocket(this.config.serverUrl)}catch{this.scheduleReconnect();return}this.ws.onmessage=e=>{try{let r=JSON.parse(String(e.data));r.type==="command"&&r.payload&&this.commandHandler&&this.commandHandler(r.payload),r.type==="__server_restart"&&(D("[RuntimeScope] Server restart notice received \u2014 will reconnect immediately"),this.resetReconnectState()),r.type==="error"&&r.payload?.code==="AUTH_FAILED"&&(D("[RuntimeScope] Authentication failed \u2014 stopping reconnection"),this.stopped=!0)}catch{}},this.ws.onopen=()=>{if(this.connected=!0,this.hasEverConnected=!0,this.resetReconnectState(),D(`[RuntimeScope] Connected to ${this.config.serverUrl}`),this.sendRaw({type:"handshake",payload:{appName:this.config.appName,sdkVersion:this.config.sdkVersion,sessionId:this.config.sessionId,...this.config.authToken?{authToken:this.config.authToken}:{},...this.config.projectId?{projectId:this.config.projectId}:{}},timestamp:Date.now(),sessionId:this.config.sessionId}),this.offlineQueue.length>0){let e=this.offlineQueue.splice(0);for(let r of e)this.batch.push(r);this.flush()}this.flushTimer=setInterval(()=>this.flush(),this.config.flushIntervalMs)},this.ws.onclose=()=>{this.connected=!1,this.clearFlushTimer(),this.stopped||(D("[RuntimeScope] Disconnected, will reconnect..."),this.scheduleReconnect())},this.ws.onerror=()=>{D(`[RuntimeScope] WebSocket error connecting to ${this.config.serverUrl}`)}}}send(e){this.connected?(this.batch.push(e),this.batch.length>=this.config.batchSize&&this.flush()):this.offlineQueue.length<S.MAX_OFFLINE_QUEUE&&this.offlineQueue.push(e)}flush(){if(this.batch.length===0||!this.connected||!this.ws)return;let e=this.batch.splice(0);this.sendRaw({type:"event",payload:{events:e},timestamp:Date.now(),sessionId:this.config.sessionId})}sendRaw(e){if(this.ws&&this.ws.readyState===WebSocket.OPEN)try{this.ws.send(JSON.stringify(e))}catch{}}scheduleReconnect(){if(this.stopped||this.reconnectTimer)return;this.reconnectAttempt++;let e;if(this.reconnectAttempt<=S.FAST_RETRY_COUNT)e=S.FAST_RETRY_DELAY;else{let r=this.reconnectDelay*.25*(Math.random()*2-1);e=Math.min(this.reconnectDelay+r,S.MAX_RECONNECT_DELAY),this.reconnectDelay=Math.min(this.reconnectDelay*2,S.MAX_RECONNECT_DELAY)}this.reconnectTimer=setTimeout(()=>{this.reconnectTimer=null,this.doConnect()},e)}resetReconnectState(){this.reconnectDelay=500,this.reconnectAttempt=0}clearFlushTimer(){this.flushTimer&&(clearInterval(this.flushTimer),this.flushTimer=null)}onCommand(e){this.commandHandler=e}sendCommandResponse(e,r,o){this.sendRaw({type:"command_response",requestId:e,command:r,payload:o,timestamp:Date.now(),sessionId:this.config.sessionId})}disconnect(){this.stopped=!0,this.clearFlushTimer(),this.connectionWarningTimer&&(clearTimeout(this.connectionWarningTimer),this.connectionWarningTimer=null),this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this.visibilityHandler&&typeof document<"u"&&(document.removeEventListener("visibilitychange",this.visibilityHandler),this.visibilityHandler=null),this.onlineHandler&&typeof window<"u"&&(window.removeEventListener("online",this.onlineHandler),this.onlineHandler=null),this.flush(),this.ws&&(this.ws.onclose=null,this.ws.onerror=null,this.ws.close(),this.ws=null),this.connected=!1,this.batch=[],this.offlineQueue=[]}};f(S,"MAX_OFFLINE_QUEUE",1e3),f(S,"MAX_RECONNECT_DELAY",3e4),f(S,"CONNECTION_WARNING_DELAY",1e4),f(S,"FAST_RETRY_COUNT",3),f(S,"FAST_RETRY_DELAY",500);var P=S;function m(){let t=new Uint8Array(8);return crypto.getRandomValues(t),Array.from(t,e=>e.toString(16).padStart(2,"0")).join("")}function W(){let t=new Uint8Array(16);return crypto.getRandomValues(t),Array.from(t,e=>e.toString(16).padStart(2,"0")).join("")}var we=1e3,ye=1e4,Re=5e3,L=new Map,H=null,B=0;function Ee(){B++,!H&&(H=setInterval(()=>{let t=Date.now()-ye;for(let[e,r]of L)r<t&&L.delete(e)},Re))}function Se(){B--,B<=0&&H&&(clearInterval(H),H=null,B=0)}function V(t,e,r,o){let n=window.fetch,u=new Set(r.map(i=>i.toLowerCase())),a=o?.captureBody??!1,s=o?.maxBodySize??65536;return Ee(),window.fetch=async function(i,d){let l=performance.now(),c=typeof i=="string"?i:i instanceof URL?i.href:i.url,p=(d?.method??"GET").toUpperCase(),h=be(d?.headers,u),g=Te(d?.body),_=ke(d?.body),R;a&&d?.body&&(R=Ie(d.body,s));let T=`${p}:${c}:${l}`;if(L.size>=we){let v=L.keys().next().value;v!==void 0&&L.delete(v)}L.set(T,Date.now());try{let v=await n.call(window,i,d),k=performance.now()-l,x=parseInt(v.headers.get("content-length")||"0",10),C=_e(v.headers,u),w;if(a)try{let O=await v.clone().text();w=O.length>s?O.slice(0,s):O}catch{}let E={eventId:m(),sessionId:e,timestamp:Date.now(),eventType:"network",url:c,method:p,status:v.status,requestHeaders:h,responseHeaders:C,requestBodySize:g,responseBodySize:x,duration:k,ttfb:k,graphqlOperation:_,requestBody:R,responseBody:w,source:"fetch"};if(o?.beforeSend){let I=o.beforeSend(E);I&&t(I)}else t(E);return v}catch(v){let k=performance.now()-l,x="error",C="";v instanceof DOMException&&v.name==="AbortError"?(x="abort",C="Request aborted"):v instanceof Error&&(C=v.message);let w={eventId:m(),sessionId:e,timestamp:Date.now(),eventType:"network",url:c,method:p,status:0,requestHeaders:h,responseHeaders:{},requestBodySize:g,responseBodySize:0,duration:k,ttfb:0,graphqlOperation:_,requestBody:R,errorPhase:x,errorMessage:C,source:"fetch"};if(o?.beforeSend){let E=o.beforeSend(w);E&&t(E)}else t(w);throw v}},()=>{window.fetch=n,Se()}}function be(t,e){let r={};if(!t)return r;if(t instanceof Headers)t.forEach((o,n)=>{r[n]=e.has(n.toLowerCase())?"[REDACTED]":o});else if(Array.isArray(t))for(let[o,n]of t)r[o]=e.has(o.toLowerCase())?"[REDACTED]":n;else for(let[o,n]of Object.entries(t))r[o]=e.has(o.toLowerCase())?"[REDACTED]":n;return r}function _e(t,e){let r={};return t.forEach((o,n)=>{r[n]=e.has(n.toLowerCase())?"[REDACTED]":o}),r}function Te(t){return t?typeof t=="string"?new Blob([t]).size:t instanceof Blob?t.size:t instanceof ArrayBuffer||ArrayBuffer.isView(t)?t.byteLength:t instanceof FormData?0:t instanceof URLSearchParams?new Blob([t.toString()]).size:0:0}function Ie(t,e){if(t){if(typeof t=="string")return t.length>e?t.slice(0,e):t;if(t instanceof URLSearchParams){let r=t.toString();return r.length>e?r.slice(0,e):r}if(t instanceof FormData)return"[FormData]";if(t instanceof Blob)return`[Blob ${t.size} bytes]`;if(t instanceof ArrayBuffer)return`[ArrayBuffer ${t.byteLength} bytes]`;if(ArrayBuffer.isView(t))return`[TypedArray ${t.byteLength} bytes]`}}function ke(t){if(!(!t||typeof t!="string"))try{let e=JSON.parse(t);if(typeof e.query=="string"){let r=e.query.trim(),o="query";r.startsWith("mutation")?o="mutation":r.startsWith("subscription")&&(o="subscription");let n=e.operationName||Ce(r)||"anonymous";return{type:o,name:n}}}catch{}}function Ce(t){return t.match(/^(?:query|mutation|subscription)\s+(\w+)/)?.[1]}function y(t,e=5){let r=new WeakSet;function o(n,u){if(u>e)return"[max depth]";if(n==null)return n;if(typeof n=="function")return`[Function: ${n.name||"anonymous"}]`;if(typeof n=="symbol"||typeof n=="bigint")return n.toString();if(typeof n!="object")return n;if(n instanceof Error)return{name:n.name,message:n.message,stack:n.stack};if(n instanceof Date)return n.toISOString();if(n instanceof RegExp)return n.toString();if(r.has(n))return"[Circular]";if(r.add(n),Array.isArray(n))return n.map(d=>o(d,u+1));let a={},s;try{s=Object.keys(n)}catch{return"[Object]"}let i=50;for(let d=0;d<Math.min(s.length,i);d++)try{a[s[d]]=o(n[s[d]],u+1)}catch{a[s[d]]="[Error accessing property]"}return s.length>i&&(a["..."]=`${s.length-i} more keys`),a}return o(t,0)}var G=["log","warn","error","info","debug","trace"];function Q(t){if(!t)return;let e=t.split(`
2
- `).slice(3);for(let r of e){let o=r.match(/(?:at\s+)?(?:.*?\()?(.+?):(\d+):(\d+)\)?/);if(o&&!o[1].includes("interceptor")&&!o[1].includes("runtimescope"))return`${o[1]}:${o[2]}`}}function Y(t,e,r){let o={},n=new Map,u=new Map;for(let p of G)o[p]=console[p].bind(console),console[p]=(...h)=>{let g=new Error().stack,_=h.map(T=>typeof T=="string"?T:K(T)).join(" "),R={eventId:m(),sessionId:e,timestamp:Date.now(),eventType:"console",level:p,message:_,args:h.map(T=>y(T,3)),stackTrace:p==="error"||p==="trace"?g?.split(`
1
+ "use strict";var RuntimeScope=(()=>{var F=Object.defineProperty;var he=Object.getOwnPropertyDescriptor;var ge=Object.getOwnPropertyNames;var ve=Object.prototype.hasOwnProperty;var we=(e,t,n)=>t in e?F(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var ye=(e,t)=>{for(var n in t)F(e,n,{get:t[n],enumerable:!0})},Re=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of ge(t))!ve.call(e,s)&&s!==n&&F(e,s,{get:()=>t[s],enumerable:!(r=he(t,s))||r.enumerable});return e};var Se=e=>Re(F({},"__esModule",{value:!0}),e);var m=(e,t,n)=>we(e,typeof t!="symbol"?t+"":t,n);var rt={};ye(rt,{RuntimeScope:()=>T,buildDsn:()=>pe,default:()=>nt,parseDsn:()=>q});var Ee=console.debug.bind(console),ot=console.warn.bind(console),P=!1;function be(){if(!P&&typeof localStorage<"u")try{localStorage.getItem("RUNTIMESCOPE_DEBUG")==="1"&&(P=!0)}catch{}}be();function N(...e){P&&Ee(...e)}function V(e){P=e}var k=class k{constructor(t){m(this,"ws",null);m(this,"batch",[]);m(this,"offlineQueue",[]);m(this,"flushTimer",null);m(this,"reconnectTimer",null);m(this,"reconnectDelay",500);m(this,"reconnectAttempt",0);m(this,"connected",!1);m(this,"stopped",!1);m(this,"config");m(this,"commandHandler",null);m(this,"hasEverConnected",!1);m(this,"connectionWarningTimer",null);m(this,"visibilityHandler",null);m(this,"onlineHandler",null);this.config=t}isConnected(){return this.connected}connect(){this.stopped=!1,this.doConnect(),this.connectionWarningTimer=setTimeout(()=>{!this.hasEverConnected&&!this.stopped&&console.warn(`[RuntimeScope] SDK has not connected to ${this.config.serverUrl} after 10s. Is the collector running? Start it with: npx @runtimescope/collector`)},k.CONNECTION_WARNING_DELAY),typeof document<"u"&&(this.visibilityHandler=()=>{document.visibilityState==="visible"&&!this.connected&&!this.stopped&&(N("[RuntimeScope] Tab visible \u2014 attempting immediate reconnect"),this.resetReconnectState(),this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this.doConnect())},document.addEventListener("visibilitychange",this.visibilityHandler)),typeof window<"u"&&(this.onlineHandler=()=>{!this.connected&&!this.stopped&&(N("[RuntimeScope] Network online \u2014 attempting immediate reconnect"),this.resetReconnectState(),this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this.doConnect())},window.addEventListener("online",this.onlineHandler))}doConnect(){if(!this.stopped){try{this.ws=new WebSocket(this.config.serverUrl)}catch{this.scheduleReconnect();return}this.ws.onmessage=t=>{try{let n=JSON.parse(String(t.data));n.type==="command"&&n.payload&&this.commandHandler&&this.commandHandler(n.payload),n.type==="__server_restart"&&(N("[RuntimeScope] Server restart notice received \u2014 will reconnect immediately"),this.resetReconnectState()),n.type==="error"&&n.payload?.code==="AUTH_FAILED"&&(N("[RuntimeScope] Authentication failed \u2014 stopping reconnection"),this.stopped=!0)}catch{}},this.ws.onopen=()=>{if(this.connected=!0,this.hasEverConnected=!0,this.resetReconnectState(),N(`[RuntimeScope] Connected to ${this.config.serverUrl}`),this.sendRaw({type:"handshake",payload:{appName:this.config.appName,sdkVersion:this.config.sdkVersion,sessionId:this.config.sessionId,...this.config.authToken?{authToken:this.config.authToken}:{},...this.config.projectId?{projectId:this.config.projectId}:{}},timestamp:Date.now(),sessionId:this.config.sessionId}),this.offlineQueue.length>0){let t=this.offlineQueue.splice(0);for(let n of t)this.batch.push(n);this.flush()}this.flushTimer=setInterval(()=>this.flush(),this.config.flushIntervalMs)},this.ws.onclose=()=>{this.connected=!1,this.clearFlushTimer(),this.stopped||(N("[RuntimeScope] Disconnected, will reconnect..."),this.scheduleReconnect())},this.ws.onerror=()=>{N(`[RuntimeScope] WebSocket error connecting to ${this.config.serverUrl}`)}}}send(t){this.connected?(this.batch.push(t),this.batch.length>=this.config.batchSize&&this.flush()):this.offlineQueue.length<k.MAX_OFFLINE_QUEUE&&this.offlineQueue.push(t)}flush(){if(this.batch.length===0||!this.connected||!this.ws)return;let t=this.batch.splice(0);this.sendRaw({type:"event",payload:{events:t},timestamp:Date.now(),sessionId:this.config.sessionId})}sendRaw(t){if(this.ws&&this.ws.readyState===WebSocket.OPEN)try{this.ws.send(JSON.stringify(t))}catch{}}scheduleReconnect(){if(this.stopped||this.reconnectTimer)return;this.reconnectAttempt++;let t;if(this.reconnectAttempt<=k.FAST_RETRY_COUNT)t=k.FAST_RETRY_DELAY;else{let n=this.reconnectDelay*.25*(Math.random()*2-1);t=Math.min(this.reconnectDelay+n,k.MAX_RECONNECT_DELAY),this.reconnectDelay=Math.min(this.reconnectDelay*2,k.MAX_RECONNECT_DELAY)}this.reconnectTimer=setTimeout(()=>{this.reconnectTimer=null,this.doConnect()},t)}resetReconnectState(){this.reconnectDelay=500,this.reconnectAttempt=0}clearFlushTimer(){this.flushTimer&&(clearInterval(this.flushTimer),this.flushTimer=null)}onCommand(t){this.commandHandler=t}sendCommandResponse(t,n,r){this.sendRaw({type:"command_response",requestId:t,command:n,payload:r,timestamp:Date.now(),sessionId:this.config.sessionId})}disconnect(){this.stopped=!0,this.clearFlushTimer(),this.connectionWarningTimer&&(clearTimeout(this.connectionWarningTimer),this.connectionWarningTimer=null),this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this.visibilityHandler&&typeof document<"u"&&(document.removeEventListener("visibilitychange",this.visibilityHandler),this.visibilityHandler=null),this.onlineHandler&&typeof window<"u"&&(window.removeEventListener("online",this.onlineHandler),this.onlineHandler=null),this.flush(),this.ws&&(this.ws.onclose=null,this.ws.onerror=null,this.ws.close(),this.ws=null),this.connected=!1,this.batch=[],this.offlineQueue=[]}};m(k,"MAX_OFFLINE_QUEUE",1e3),m(k,"MAX_RECONNECT_DELAY",3e4),m(k,"CONNECTION_WARNING_DELAY",1e4),m(k,"FAST_RETRY_COUNT",3),m(k,"FAST_RETRY_DELAY",500);var $=k;function g(){let e=new Uint8Array(8);return crypto.getRandomValues(e),Array.from(e,t=>t.toString(16).padStart(2,"0")).join("")}function K(){let e=new Uint8Array(16);return crypto.getRandomValues(e),Array.from(e,t=>t.toString(16).padStart(2,"0")).join("")}var _e=1e3,Te=1e4,Ie=5e3,L=new Map,A=null,B=0;function Ce(){B++,!A&&(A=setInterval(()=>{let e=Date.now()-Te;for(let[t,n]of L)n<e&&L.delete(t)},Ie))}function ke(){B--,B<=0&&A&&(clearInterval(A),A=null,B=0)}function Q(e,t,n,r){let s=window.fetch,o=new Set(n.map(c=>c.toLowerCase())),i=r?.captureBody??!1,a=r?.maxBodySize??65536;return Ce(),window.fetch=async function(c,u){let d=performance.now(),l=typeof c=="string"?c:c instanceof URL?c.href:c.url,p=(u?.method??"GET").toUpperCase(),R=De(u?.headers,o),v=Ne(u?.body),I=Oe(u?.body),f;i&&u?.body&&(f=xe(u.body,a));let w=`${p}:${l}:${d}`;if(L.size>=_e){let h=L.keys().next().value;h!==void 0&&L.delete(h)}L.set(w,Date.now());try{let h=await s.call(window,c,u),b=performance.now()-d,_=parseInt(h.headers.get("content-length")||"0",10),S=Le(h.headers,o),y;if(i)try{let x=await h.clone().text();y=x.length>a?x.slice(0,a):x}catch{}let C={eventId:g(),sessionId:t,timestamp:Date.now(),eventType:"network",url:l,method:p,status:h.status,requestHeaders:R,responseHeaders:S,requestBodySize:v,responseBodySize:_,duration:b,ttfb:b,graphqlOperation:I,requestBody:f,responseBody:y,source:"fetch"};if(r?.beforeSend){let D=r.beforeSend(C);D&&e(D)}else e(C);return h}catch(h){let b=performance.now()-d,_="error",S="";h instanceof DOMException&&h.name==="AbortError"?(_="abort",S="Request aborted"):h instanceof Error&&(S=h.message);let y={eventId:g(),sessionId:t,timestamp:Date.now(),eventType:"network",url:l,method:p,status:0,requestHeaders:R,responseHeaders:{},requestBodySize:v,responseBodySize:0,duration:b,ttfb:0,graphqlOperation:I,requestBody:f,errorPhase:_,errorMessage:S,source:"fetch"};if(r?.beforeSend){let C=r.beforeSend(y);C&&e(C)}else e(y);throw h}},()=>{window.fetch=s,ke()}}function De(e,t){let n={};if(!e)return n;if(e instanceof Headers)e.forEach((r,s)=>{n[s]=t.has(s.toLowerCase())?"[REDACTED]":r});else if(Array.isArray(e))for(let[r,s]of e)n[r]=t.has(r.toLowerCase())?"[REDACTED]":s;else for(let[r,s]of Object.entries(e))n[r]=t.has(r.toLowerCase())?"[REDACTED]":s;return n}function Le(e,t){let n={};return e.forEach((r,s)=>{n[s]=t.has(s.toLowerCase())?"[REDACTED]":r}),n}function Ne(e){return e?typeof e=="string"?new Blob([e]).size:e instanceof Blob?e.size:e instanceof ArrayBuffer||ArrayBuffer.isView(e)?e.byteLength:e instanceof FormData?0:e instanceof URLSearchParams?new Blob([e.toString()]).size:0:0}function xe(e,t){if(e){if(typeof e=="string")return e.length>t?e.slice(0,t):e;if(e instanceof URLSearchParams){let n=e.toString();return n.length>t?n.slice(0,t):n}if(e instanceof FormData)return"[FormData]";if(e instanceof Blob)return`[Blob ${e.size} bytes]`;if(e instanceof ArrayBuffer)return`[ArrayBuffer ${e.byteLength} bytes]`;if(ArrayBuffer.isView(e))return`[TypedArray ${e.byteLength} bytes]`}}function Oe(e){if(!(!e||typeof e!="string"))try{let t=JSON.parse(e);if(typeof t.query=="string"){let n=t.query.trim(),r="query";n.startsWith("mutation")?r="mutation":n.startsWith("subscription")&&(r="subscription");let s=t.operationName||Me(n)||"anonymous";return{type:r,name:s}}}catch{}}function Me(e){return e.match(/^(?:query|mutation|subscription)\s+(\w+)/)?.[1]}function E(e,t=5){let n=new WeakSet;function r(s,o){if(o>t)return"[max depth]";if(s==null)return s;if(typeof s=="function")return`[Function: ${s.name||"anonymous"}]`;if(typeof s=="symbol"||typeof s=="bigint")return s.toString();if(typeof s!="object")return s;if(s instanceof Error)return{name:s.name,message:s.message,stack:s.stack};if(s instanceof Date)return s.toISOString();if(s instanceof RegExp)return s.toString();if(n.has(s))return"[Circular]";if(n.add(s),Array.isArray(s))return s.map(u=>r(u,o+1));let i={},a;try{a=Object.keys(s)}catch{return"[Object]"}let c=50;for(let u=0;u<Math.min(a.length,c);u++)try{i[a[u]]=r(s[a[u]],o+1)}catch{i[a[u]]="[Error accessing property]"}return a.length>c&&(i["..."]=`${a.length-c} more keys`),i}return r(e,0)}var Y=["log","warn","error","info","debug","trace"];function Ae(e,t){let n=new Map,r=setInterval(()=>{let s=0;for(let i of n.values())i.suppressed>0&&(s+=i.suppressed,i.suppressed=0);s>0&&t(`[RuntimeScope] suppressed ${s} duplicate console message${s===1?"":"s"} in the last ${e.summaryIntervalMs/1e3}s \u2014 full data in the dashboard.`);let o=Date.now()-e.windowMs;for(let[i,a]of n)a.firstAt<o&&a.suppressed===0&&n.delete(i)},e.summaryIntervalMs);return typeof r.unref=="function"&&r.unref(),{shouldPrint(s,o){let i=Date.now(),a=`${s}|${o}`,c=n.get(a);return c&&i-c.firstAt>e.windowMs&&(c=void 0),c?(c.count++,c.count<=e.maxBurst?!0:(c.suppressed++,!1)):(n.set(a,{count:1,firstAt:i,suppressed:0,level:s,preview:o.slice(0,80)}),!0)},dispose(){clearInterval(r)}}}function J(e){if(!e)return;let t=e.split(`
2
+ `).slice(3);for(let n of t){let r=n.match(/(?:at\s+)?(?:.*?\()?(.+?):(\d+):(\d+)\)?/);if(r&&!r[1].includes("interceptor")&&!r[1].includes("runtimescope"))return`${r[1]}:${r[2]}`}}function ee(e,t,n,r){let s={},o=new Map,i=new Map,a=r?{windowMs:(typeof r=="object"?r.windowMs:void 0)??5e3,maxBurst:(typeof r=="object"?r.maxBurst:void 0)??3,summaryIntervalMs:(typeof r=="object"?r.summaryIntervalMs:void 0)??5e3}:null,c=console.info.bind(console),u=a?Ae(a,f=>c(f)):null;for(let f of Y)s[f]=console[f].bind(console),console[f]=(...w)=>{let h=new Error().stack,b=w.map(S=>typeof S=="string"?S:Z(S)).join(" "),_={eventId:g(),sessionId:t,timestamp:Date.now(),eventType:"console",level:f,message:b,args:w.map(S=>E(S,3)),stackTrace:f==="error"||f==="trace"?h?.split(`
3
3
  `).slice(2).join(`
4
- `):void 0,sourceFile:Q(g),source:"browser"};if(r){let T=r(R);T&&t(T)}else t(R);o[p](...h)};let a=console.assert?.bind(console);a&&(console.assert=(p,...h)=>{if(!p){let g=new Error().stack,_=`Assertion failed: ${h.map(R=>typeof R=="string"?R:K(R)).join(" ")}`;t({eventId:m(),sessionId:e,timestamp:Date.now(),eventType:"console",level:"error",message:_,args:h.map(R=>y(R,3)),stackTrace:g?.split(`
4
+ `):void 0,sourceFile:J(h),source:"browser"};if(n){let S=n(_);S&&e(S)}else e(_);u&&!u.shouldPrint(f,b)||s[f](...w)};let d=console.assert?.bind(console);d&&(console.assert=(f,...w)=>{if(!f){let h=new Error().stack,b=`Assertion failed: ${w.map(_=>typeof _=="string"?_:Z(_)).join(" ")}`;e({eventId:g(),sessionId:t,timestamp:Date.now(),eventType:"console",level:"error",message:b,args:w.map(_=>E(_,3)),stackTrace:h?.split(`
5
5
  `).slice(2).join(`
6
- `),sourceFile:Q(g),source:"browser"})}a(p,...h)});let s=console.time?.bind(console),i=console.timeEnd?.bind(console);s&&(console.time=(p="default")=>{n.set(p,performance.now()),s(p)}),i&&(console.timeEnd=(p="default")=>{let h=n.get(p);if(h!==void 0){let g=performance.now()-h;n.delete(p),t({eventId:m(),sessionId:e,timestamp:Date.now(),eventType:"console",level:"info",message:`${p}: ${g.toFixed(2)}ms`,args:[{label:p,duration:g}],source:"browser"})}i(p)});let d=console.count?.bind(console),l=console.countReset?.bind(console);d&&(console.count=(p="default")=>{let h=(u.get(p)??0)+1;u.set(p,h),t({eventId:m(),sessionId:e,timestamp:Date.now(),eventType:"console",level:"info",message:`${p}: ${h}`,args:[{label:p,count:h}],source:"browser"}),d(p)}),l&&(console.countReset=(p="default")=>{u.delete(p),l(p)});let c=console.table?.bind(console);return c&&(console.table=(p,h)=>{t({eventId:m(),sessionId:e,timestamp:Date.now(),eventType:"console",level:"info",message:`[table] ${Array.isArray(p)?`${p.length} rows`:typeof p}`,args:[y(p,3)],source:"browser"}),c(p,h)}),()=>{for(let p of G)console[p]=o[p];a&&(console.assert=a),s&&(console.time=s),i&&(console.timeEnd=i),d&&(console.count=d),l&&(console.countReset=l),c&&(console.table=c)}}function K(t){try{return JSON.stringify(t)}catch{return String(t)}}function J(t,e,r,o){let n=new Set(r.map(c=>c.toLowerCase())),u=o?.captureBody??!1,a=o?.maxBodySize??65536,s=new AbortController,i=XMLHttpRequest.prototype.open,d=XMLHttpRequest.prototype.setRequestHeader,l=XMLHttpRequest.prototype.send;return XMLHttpRequest.prototype.open=function(c,p){return this.__rs_method=c.toUpperCase(),this.__rs_url=typeof p=="string"?p:p.href,this.__rs_headers={},i.apply(this,arguments)},XMLHttpRequest.prototype.setRequestHeader=function(c,p){return this.__rs_headers&&(this.__rs_headers[c.toLowerCase()]=n.has(c.toLowerCase())?"[REDACTED]":p),d.call(this,c,p)},XMLHttpRequest.prototype.send=function(c){let p=this.__rs_method??"GET",h=this.__rs_url??"",g=`${p}:${h}`,_=!1;for(let w of L.keys())if(w.startsWith(g)){_=!0;break}if(_)return this.__rs_fetchIntercepted=!0,l.call(this,c);let R={...this.__rs_headers??{}},T=performance.now(),v,k=0;if(c){if(typeof c=="string")k=new Blob([c]).size,u&&(v=c.length>a?c.slice(0,a):c);else if(c instanceof Blob)k=c.size,u&&(v=`[Blob ${c.size} bytes]`);else if(c instanceof ArrayBuffer)k=c.byteLength,u&&(v=`[ArrayBuffer ${c.byteLength} bytes]`);else if(c instanceof FormData)u&&(v="[FormData]");else if(c instanceof URLSearchParams){let w=c.toString();k=new Blob([w]).size,u&&(v=w.length>a?w.slice(0,a):w)}}let x=De(c),C=w=>{let E={eventId:m(),sessionId:e,timestamp:Date.now(),eventType:"network",url:h,method:p,status:0,requestHeaders:R,responseHeaders:{},requestBodySize:k,responseBodySize:0,duration:0,ttfb:0,graphqlOperation:x,requestBody:v,source:"xhr",...w};if(o?.beforeSend){let I=o.beforeSend(E);I&&t(I)}else t(E)};return this.addEventListener("loadend",()=>{let w=performance.now()-T;if(this.status>0){let E=Le(this.getAllResponseHeaders(),n),I=parseInt(this.getResponseHeader("content-length")||"0",10),O;if(u&&(this.responseType===""||this.responseType==="text"))try{let U=this.responseText;O=U.length>a?U.slice(0,a):U}catch{}C({status:this.status,responseHeaders:E,responseBodySize:I,responseBody:O,duration:w,ttfb:w})}else{let E="error",I="Network error";this.readyState===0||this.status,this.timeout>0&&w>=this.timeout&&(E="timeout",I=`Request timed out after ${this.timeout}ms`),C({duration:w,errorPhase:E,errorMessage:I})}},{once:!0,signal:s.signal}),l.call(this,c)},()=>{s.abort(),XMLHttpRequest.prototype.open=i,XMLHttpRequest.prototype.setRequestHeader=d,XMLHttpRequest.prototype.send=l}}function Le(t,e){let r={};if(!t)return r;for(let o of t.trim().split(/[\r\n]+/)){let n=o.indexOf(":");if(n===-1)continue;let u=o.slice(0,n).trim().toLowerCase(),a=o.slice(n+1).trim();r[u]=e.has(u)?"[REDACTED]":a}return r}function De(t){if(!(!t||typeof t!="string"))try{let e=JSON.parse(t);if(typeof e.query=="string"){let r=e.query.trim(),o="query";r.startsWith("mutation")?o="mutation":r.startsWith("subscription")&&(o="subscription");let n=e.operationName||Ne(r)||"anonymous";return{type:o,name:n}}}catch{}}function Ne(t){return t.match(/^(?:query|mutation|subscription)\s+(\w+)/)?.[1]}function ee(t,e,r,o){let n=[],u=new Map;for(let[a,s]of Object.entries(r)){let i=xe(s);if(i==="zustand"){let d=s;$(t,e,o?.beforeSend,{storeId:a,library:i,phase:"init",state:y(d.getState(),4)});let l=d.subscribe((c,p)=>{let h=Z(p,c);$(t,e,o?.beforeSend,{storeId:a,library:i,phase:"update",state:y(c,4),previousState:y(p,4),diff:h?y(h,3):void 0})});n.push(l)}else if(i==="redux"){let d=s;$(t,e,o?.beforeSend,{storeId:a,library:i,phase:"init",state:y(d.getState(),4)});let l,c=d.dispatch.bind(d);u.set(a,c),d.dispatch=g=>(g&&typeof g=="object"&&"type"in g&&(l={type:String(g.type),payload:g.payload}),c(g));let p=d.getState(),h=d.subscribe(()=>{let g=d.getState(),_=Z(p,g);$(t,e,o?.beforeSend,{storeId:a,library:i,phase:"update",state:y(g,4),previousState:y(p,4),diff:_?y(_,3):void 0,action:l?y(l,3):void 0}),p=g,l=void 0});n.push(h)}}return()=>{for(let a of n)a();for(let[a,s]of u){let i=r[a];i&&(i.dispatch=s)}}}function xe(t){if(!t||typeof t!="object")return"unknown";let e=t;return typeof e.getState=="function"&&typeof e.setState=="function"&&typeof e.subscribe=="function"?"zustand":typeof e.dispatch=="function"&&typeof e.getState=="function"&&typeof e.subscribe=="function"?"redux":"unknown"}function Z(t,e){if(!t||!e||typeof t!="object"||typeof e!="object")return null;let r={},o=t,n=e,u=new Set([...Object.keys(o),...Object.keys(n)]);for(let a of u)o[a]!==n[a]&&(r[a]={from:o[a],to:n[a]});return Object.keys(r).length>0?r:null}function $(t,e,r,o){let n={eventId:m(),sessionId:e,timestamp:Date.now(),eventType:"state",...o};if(r){let u=r(n);u&&t(u)}else t(n)}var Oe={LCP:[2500,4e3],FCP:[1800,3e3],CLS:[.1,.25],TTFB:[800,1800],FID:[100,300],INP:[200,500]};function Ae(t,e){let[r,o]=Oe[t]??[1/0,1/0];return e<=r?"good":e<=o?"needs-improvement":"poor"}var F=null;function te(t,e,r){if(F)for(let s of F)try{s.disconnect()}catch{}let o=[];F=o;let n=(s,i,d)=>{let l={eventId:m(),sessionId:e,timestamp:Date.now(),eventType:"performance",metricName:s,value:Math.round(i*100)/100,rating:Ae(s,i),element:d};if(r?.beforeSend){let c=r.beforeSend(l);c&&t(c)}else t(l)};A(o,"largest-contentful-paint",s=>{let i=s[s.length-1];if(!i)return;let d=i.element;n("LCP",i.startTime,d?.tagName?.toLowerCase())}),A(o,"paint",s=>{for(let i of s)i.name==="first-contentful-paint"&&n("FCP",i.startTime)});let u=0;A(o,"layout-shift",s=>{for(let i of s){let d=i;!d.hadRecentInput&&d.value&&(u+=d.value,n("CLS",u))}}),A(o,"first-input",s=>{let i=s[0];if(!i)return;let d=i;d.processingStart&&n("FID",d.processingStart-i.startTime)}),A(o,"navigation",s=>{let i=s[0];i&&n("TTFB",i.responseStart-i.requestStart)});let a=0;return A(o,"event",s=>{for(let i of s)i.duration>a&&(a=i.duration,n("INP",a))},{durationThreshold:16}),()=>{for(let s of o)try{s.disconnect()}catch{}F===o&&(F=null)}}function A(t,e,r,o){try{let n=new PerformanceObserver(u=>{r(u.getEntries())});n.observe({type:e,buffered:!0,...o}),t.push(n)}catch{}}var He=0,Fe=1,oe=1e4,ne=100,Me=6e4,re=500;function se(t,e,r){let o=new Map,n=r?.snapshotIntervalMs??5e3,u=null,a=Pe();if(!a)return()=>{};let s=a.onCommitFiberRoot;return a._runtimescope_original=s,a.onCommitFiberRoot=(i,d)=>{if(s)try{s(i,d)}catch{}d.current&&X(d.current,o)},u=setInterval(()=>{ze(o,t,e,r?.beforeSend)},n),()=>{u&&(clearInterval(u),u=null),a&&(a._runtimescope_original?a.onCommitFiberRoot=a._runtimescope_original:delete a.onCommitFiberRoot,delete a._runtimescope_original)}}function Pe(){if(typeof window>"u")return null;let t=window;return t.__REACT_DEVTOOLS_GLOBAL_HOOK__||(t.__REACT_DEVTOOLS_GLOBAL_HOOK__={}),t.__REACT_DEVTOOLS_GLOBAL_HOOK__}function X(t,e){Be(t,e),t.child&&X(t.child,e),t.sibling&&X(t.sibling,e)}function Be(t,e){if(t.tag!==He&&t.tag!==Fe)return;let r=$e(t);if(!r)return;let o=Date.now(),n=t.alternate===null,u=t.actualDuration??0,a=je(t,n),s=e.get(r);s||(s={renderCount:0,totalDuration:0,lastRenderTime:0,lastRenderPhase:"mount",lastRenderCause:"unknown",renderTimestamps:[]},e.set(r,s)),s.renderCount++,s.totalDuration+=u,s.lastRenderTime=o,s.lastRenderPhase=n?"mount":"update",s.lastRenderCause=a??"unknown",s.renderTimestamps.push(o),s.renderTimestamps.length>ne&&(s.renderTimestamps=s.renderTimestamps.slice(-ne))}function $e(t){if(t.type&&typeof t.type!="string")return t.type.displayName||t.type.name||void 0}function je(t,e){return e?"props":t.alternate?t.memoizedProps!==t.alternate.memoizedProps?"props":t.memoizedState!==t.alternate.memoizedState?"state":"parent":"unknown"}function qe(t){if(t.length<2)return 0;let e=Date.now(),r=e-oe,o=t.filter(u=>u>=r);if(o.length<2)return 0;let n=e-o[0];return n===0?0:o.length/(n/1e3)}function ze(t,e,r,o){if(t.size===0)return;let n=[],u=[],a=0;for(let[d,l]of t){let c=qe(l.renderTimestamps),p=c>4||l.renderCount>20;n.push({componentName:d,renderCount:l.renderCount,totalDuration:Math.round(l.totalDuration*100)/100,avgDuration:l.renderCount>0?Math.round(l.totalDuration/l.renderCount*100)/100:0,lastRenderPhase:l.lastRenderPhase,lastRenderCause:l.lastRenderCause,renderVelocity:Math.round(c*100)/100,suspicious:p}),p&&u.push(d),a+=l.renderCount}n.sort((d,l)=>l.renderCount-d.renderCount);let s={eventId:m(),sessionId:r,timestamp:Date.now(),eventType:"render",profiles:n,snapshotWindowMs:oe,totalRenders:a,suspiciousComponents:u};if(o){let d=o(s);d&&e(d)}else e(s);let i=Date.now();for(let[d,l]of t)i-l.lastRenderTime>Me?t.delete(d):(l.renderCount=0,l.totalDuration=0);if(t.size>re){let d=[...t.entries()].sort((c,p)=>c[1].lastRenderTime-p[1].lastRenderTime),l=t.size-re;for(let c=0;c<l;c++)t.delete(d[c][0])}}function ie(t,e,r){let o=u=>{let a,s,i;if(u instanceof ErrorEvent)a=u.message||"Uncaught error",s=u.error?.stack,i=u.filename?`${u.filename}:${u.lineno}:${u.colno}`:void 0;else{let l=u.target;if(l&&l!==window){let c=l.tagName?.toLowerCase()??"unknown",p=l.src??l.src??l.href??"unknown";a=`Failed to load resource: <${c}> ${p}`}else return}let d={eventId:m(),sessionId:e,timestamp:Date.now(),eventType:"console",level:"error",message:`[Uncaught] ${a}`,args:[y(a,3)],stackTrace:s,sourceFile:i};if(r){let l=r(d);l&&t(l)}else t(d)},n=u=>{let a=u.reason,s,i;if(a instanceof Error)s=a.message,i=a.stack;else if(typeof a=="string")s=a;else try{s=JSON.stringify(a)}catch{s=String(a)}let d={eventId:m(),sessionId:e,timestamp:Date.now(),eventType:"console",level:"error",message:`[Unhandled Rejection] ${s}`,args:[y(a,3)],stackTrace:i,sourceFile:void 0};if(r){let l=r(d);l&&t(l)}else t(d)};return window.addEventListener("error",o,!0),window.addEventListener("unhandledrejection",n),()=>{window.removeEventListener("error",o,!0),window.removeEventListener("unhandledrejection",n)}}function ae(t,e){let r=window.location.href;function o(i,d){let l=r;l!==i&&(r=i,t({eventId:m(),sessionId:e,timestamp:Date.now(),eventType:"navigation",from:l,to:i,trigger:d}))}let n=history.pushState.bind(history),u=history.replaceState.bind(history);history.pushState=function(...i){n(...i),o(window.location.href,"pushState")},history.replaceState=function(...i){u(...i),o(window.location.href,"replaceState")};let a=()=>o(window.location.href,"popstate");window.addEventListener("popstate",a);let s=()=>o(window.location.href,"hashchange");return window.addEventListener("hashchange",s),()=>{history.pushState=n,history.replaceState=u,window.removeEventListener("popstate",a),window.removeEventListener("hashchange",s)}}function ce(t,e){let r=o=>{let n=o.target;if(!(n instanceof Element)||n.closest("[data-runtimescope]"))return;let u=Ue(n),a=Xe(n),s={eventId:m(),sessionId:e,timestamp:Date.now(),eventType:"ui",action:"click",target:u,...a&&{text:a}};t(s)};return document.addEventListener("click",r,!0),()=>{document.removeEventListener("click",r,!0)}}function Ue(t){let e=t.tagName.toLowerCase();if(t.id)return`${e}#${t.id}`;let r=t.getAttribute("data-testid")??t.getAttribute("data-test-id");if(r)return`${e}[data-testid="${r}"]`;let o=t.getAttribute("role"),n=t.getAttribute("aria-label");if(o&&n)return`${e}[role="${o}"][aria-label="${n}"]`;let u=t.className;if(typeof u=="string"&&u.trim()){let s=u.split(/\s+/).find(i=>i.length>2&&!i.startsWith("_")&&!i.includes("__"));if(s)return`${e}.${s}`}let a=t.parentElement;if(a){let s=a.children,i=Array.from(s).filter(d=>d.tagName===t.tagName);if(i.length>1){let d=i.indexOf(t)+1;return`${e}:nth-child(${d})`}}return e}function Xe(t){let e=t.getAttribute("aria-label");if(e)return e.slice(0,80);let r=t.innerText??t.textContent;if(!r)return;let o=r.trim().replace(/\s+/g," ");if(o.length!==0)return o.length>80?o.slice(0,77)+"...":o}function j(t){let e=t.startsWith("runtimescopes://");if(!t.startsWith("runtimescope://")&&!e)throw new Error("Invalid RuntimeScope DSN: must start with runtimescope:// or runtimescopes://");let r=new URL(t.replace(/^runtimescopes?:\/\//,"http://")),o=r.username;if(!o||!o.startsWith("proj_"))throw new Error("Invalid RuntimeScope DSN: missing projectId (expected proj_xxx@host)");let n=r.password?decodeURIComponent(r.password):void 0,u=r.hostname,a=r.port?parseInt(r.port):6768,s=a-1,i=r.pathname.replace(/^\//,"")||void 0,d=e?"wss":"ws",l=e?"https":"http";return{projectId:o,authToken:n,wsEndpoint:`${d}://${u}:${s}`,httpEndpoint:`${l}://${u}:${a}`,appName:i,tls:e}}function ue(t){let e=t.tls?"runtimescopes":"runtimescope",r=t.host??"localhost",o=t.port??6768,n=t.appName?`/${t.appName}`:"",u=t.authToken?`:${encodeURIComponent(t.authToken)}`:"";return`${e}://${t.projectId}${u}@${r}:${o}${n}`}var q="0.10.0",N=console.debug.bind(console),z=Symbol.for("__runtimescope_originals__");function de(){let t=globalThis;return t[z]||(t[z]={fetch:window.fetch,xhrOpen:XMLHttpRequest.prototype.open,xhrSend:XMLHttpRequest.prototype.send,xhrSetRequestHeader:XMLHttpRequest.prototype.setRequestHeader,consoleMethods:{log:console.log.bind(console),warn:console.warn.bind(console),error:console.error.bind(console),info:console.info.bind(console),debug:console.debug.bind(console),trace:console.trace.bind(console)}}),t[z]}var b=class{static get sessionId(){return this._sessionId}static get isConnected(){return this._state==="started"}static shouldSample(){if(this._sampleRate<1&&Math.random()>this._sampleRate)return!1;if(this._maxEventsPerSecond!==void 0){let e=Date.now();if(e-this._windowStart>=1e3&&(this._windowCount=0,this._windowStart=e),this._windowCount>=this._maxEventsPerSecond)return!1;this._windowCount++}return!0}static connect(e={}){if(e.enabled===!1)return;let r=!1;if(e.dsn)try{let c=j(e.dsn);e={...e,serverUrl:c.wsEndpoint,projectId:c.projectId,...c.authToken?{authToken:c.authToken}:{},...c.appName&&!e.appName?{appName:c.appName}:{}},r=!0}catch(c){N("[RuntimeScope] Invalid DSN:",c.message)}if(!(!!(e.serverUrl||e.endpoint)||r)&&typeof window<"u"){let c=window.location?.hostname;if(c&&c!=="localhost"&&c!=="127.0.0.1"&&!c.startsWith("192.168.")&&!c.startsWith("10.")){N("[RuntimeScope] No endpoint configured and not on localhost \u2014 SDK disabled for production");return}}this._state==="started"&&(N("[RuntimeScope] Already connected \u2014 disconnecting before re-init"),this.disconnect());let n={serverUrl:e.serverUrl??e.endpoint??"ws://localhost:6767",appName:e.appName??"unknown",captureNetwork:e.captureNetwork??!0,captureConsole:e.captureConsole??!0,captureXhr:e.captureXhr??!0,captureBody:e.captureBody??!1,maxBodySize:e.maxBodySize??65536,capturePerformance:e.capturePerformance??!0,captureRenders:e.captureRenders??!0,captureNavigation:e.captureNavigation??!0,captureClicks:e.captureClicks??!0,stores:e.stores??{},beforeSend:e.beforeSend,redactHeaders:e.redactHeaders??["authorization","cookie"],batchSize:e.batchSize??50,flushIntervalMs:e.flushIntervalMs??100};de(),this._sessionId=W(),this._state="started",this.transport=new P({serverUrl:n.serverUrl,appName:n.appName,sessionId:this._sessionId,sdkVersion:q,authToken:e.authToken,projectId:e.projectId,batchSize:n.batchSize,flushIntervalMs:n.flushIntervalMs}),this._sampleRate=e.sampleRate??1,this._maxEventsPerSecond=e.maxEventsPerSecond,this._windowCount=0,this._windowStart=Date.now(),this._user=e.user,this.transport.connect(),N(`[RuntimeScope] SDK v${q} initializing \u2014 app: ${n.appName}, server: ${n.serverUrl}`);let u=de().consoleMethods.warn,a=this.transport,s=n.serverUrl;setTimeout(()=>{if(this.transport!==a||a.isConnected?.())return;let p=/localhost|127\.0\.0\.1/.test(s)?"Run `npx runtimescope start` in a terminal.":`Check that ${s} is reachable and the collector is running.`;u(`[RuntimeScope] Couldn't connect to ${s} after 10s. No events are being captured.`,`
7
- Fix: ${p}`)},1e4);let i=c=>{c.eventType!=="session"&&c.eventType!=="custom"&&c.eventType!=="ui"&&!this.shouldSample()||this.transport?.send(c)};i({eventId:m(),sessionId:this._sessionId,timestamp:Date.now(),eventType:"session",appName:n.appName,connectedAt:Date.now(),sdkVersion:q,buildMeta:e.buildMeta,user:this._user,projectId:e.projectId});let d=this._sessionId;this.transport.onCommand(c=>{this.handleCommand(c,i,d)}),n.captureNetwork&&this.restoreFns.push(V(i,this._sessionId,n.redactHeaders,{captureBody:n.captureBody,maxBodySize:n.maxBodySize,beforeSend:n.beforeSend})),n.captureXhr&&this.restoreFns.push(J(i,this._sessionId,n.redactHeaders,{captureBody:n.captureBody,maxBodySize:n.maxBodySize,beforeSend:n.beforeSend})),n.captureConsole&&this.restoreFns.push(Y(i,this._sessionId,n.beforeSend)),e.captureErrors!==!1&&this.restoreFns.push(ie(i,this._sessionId,n.beforeSend)),Object.keys(n.stores).length>0&&this.restoreFns.push(ee(i,this._sessionId,n.stores,{beforeSend:n.beforeSend})),n.capturePerformance&&this.restoreFns.push(te(i,this._sessionId,{beforeSend:n.beforeSend})),n.captureRenders&&this.restoreFns.push(se(i,this._sessionId,{beforeSend:n.beforeSend})),n.captureNavigation&&this.restoreFns.push(ae(i,this._sessionId)),n.captureClicks&&this.restoreFns.push(ce(i,this._sessionId));let l=[n.captureNetwork&&"fetch",n.captureXhr&&"xhr",n.captureConsole&&"console, errors",Object.keys(n.stores).length>0&&"state",n.capturePerformance&&"performance",n.captureRenders&&"renders",n.captureNavigation&&"navigation",n.captureClicks&&"clicks"].filter(Boolean);N(`[RuntimeScope] Interceptors active \u2014 ${l.join(", ")}`),this._sampleRate<1&&N(`[RuntimeScope] Sampling at ${(this._sampleRate*100).toFixed(0)}%`),this._maxEventsPerSecond!==void 0&&N(`[RuntimeScope] Rate limited to ${this._maxEventsPerSecond} events/sec`)}static handleCommand(e,r,o){if(e.command==="capture_dom_snapshot"){let n=e.params?.maxSize??5e5,u=document.documentElement.outerHTML,a=u.length>n;a&&(u=u.slice(0,n));let s={eventId:m(),sessionId:o,timestamp:Date.now(),eventType:"dom_snapshot",html:u,url:window.location.href,viewport:{width:window.innerWidth,height:window.innerHeight},scrollPosition:{x:window.scrollX,y:window.scrollY},elementCount:document.querySelectorAll("*").length,truncated:a};r(s),this.transport?.sendCommandResponse(e.requestId,e.command,s)}else this.transport?.sendCommandResponse(e.requestId,e.command,{error:"Unknown command"})}static init(e={}){return this.connect(e)}static track(e,r){if(!this.transport||!this._sessionId)return;let o={eventId:m(),sessionId:this._sessionId,timestamp:Date.now(),eventType:"custom",name:e,properties:r};this.transport.send(o)}static setUser(e){this._user=e??void 0,this.transport&&this._sessionId&&this.transport.send({eventId:m(),sessionId:this._sessionId,timestamp:Date.now(),eventType:"session",appName:"user_update",connectedAt:Date.now(),sdkVersion:q,user:this._user})}static addBreadcrumb(e,r){if(!this.transport||!this._sessionId)return;let o={eventId:m(),sessionId:this._sessionId,timestamp:Date.now(),eventType:"ui",action:"breadcrumb",target:"manual",text:e,...r&&{data:r}};this.transport.send(o)}static disconnect(){for(let r of this.restoreFns)try{r()}catch{}this.restoreFns=[];let e=globalThis[z];if(e){window.fetch!==e.fetch&&(window.fetch=e.fetch);for(let[r,o]of Object.entries(e.consoleMethods)){let n=console;n[r]!==o&&(n[r]=o)}}this.transport?.disconnect(),this.transport=null,this._sessionId=null,this._state="stopped"}};f(b,"transport",null),f(b,"restoreFns",[]),f(b,"_sessionId",null),f(b,"_state","stopped"),f(b,"_sampleRate",1),f(b,"_maxEventsPerSecond"),f(b,"_windowCount",0),f(b,"_windowStart",0),f(b,"_user");var We=b;return ve(Ve);})();
6
+ `),sourceFile:J(h),source:"browser"})}d(f,...w)});let l=console.time?.bind(console),p=console.timeEnd?.bind(console);l&&(console.time=(f="default")=>{o.set(f,performance.now()),l(f)}),p&&(console.timeEnd=(f="default")=>{let w=o.get(f);if(w!==void 0){let h=performance.now()-w;o.delete(f),e({eventId:g(),sessionId:t,timestamp:Date.now(),eventType:"console",level:"info",message:`${f}: ${h.toFixed(2)}ms`,args:[{label:f,duration:h}],source:"browser"})}p(f)});let R=console.count?.bind(console),v=console.countReset?.bind(console);R&&(console.count=(f="default")=>{let w=(i.get(f)??0)+1;i.set(f,w),e({eventId:g(),sessionId:t,timestamp:Date.now(),eventType:"console",level:"info",message:`${f}: ${w}`,args:[{label:f,count:w}],source:"browser"}),R(f)}),v&&(console.countReset=(f="default")=>{i.delete(f),v(f)});let I=console.table?.bind(console);return I&&(console.table=(f,w)=>{e({eventId:g(),sessionId:t,timestamp:Date.now(),eventType:"console",level:"info",message:`[table] ${Array.isArray(f)?`${f.length} rows`:typeof f}`,args:[E(f,3)],source:"browser"}),I(f,w)}),()=>{for(let f of Y)console[f]=s[f];d&&(console.assert=d),l&&(console.time=l),p&&(console.timeEnd=p),R&&(console.count=R),v&&(console.countReset=v),I&&(console.table=I),u?.dispose()}}function Z(e){try{return JSON.stringify(e)}catch{return String(e)}}function te(e,t,n,r){let s=new Set(n.map(l=>l.toLowerCase())),o=r?.captureBody??!1,i=r?.maxBodySize??65536,a=new AbortController,c=XMLHttpRequest.prototype.open,u=XMLHttpRequest.prototype.setRequestHeader,d=XMLHttpRequest.prototype.send;return XMLHttpRequest.prototype.open=function(l,p){return this.__rs_method=l.toUpperCase(),this.__rs_url=typeof p=="string"?p:p.href,this.__rs_headers={},c.apply(this,arguments)},XMLHttpRequest.prototype.setRequestHeader=function(l,p){return this.__rs_headers&&(this.__rs_headers[l.toLowerCase()]=s.has(l.toLowerCase())?"[REDACTED]":p),u.call(this,l,p)},XMLHttpRequest.prototype.send=function(l){let p=this.__rs_method??"GET",R=this.__rs_url??"",v=`${p}:${R}`,I=!1;for(let y of L.keys())if(y.startsWith(v)){I=!0;break}if(I)return this.__rs_fetchIntercepted=!0,d.call(this,l);let f={...this.__rs_headers??{}},w=performance.now(),h,b=0;if(l){if(typeof l=="string")b=new Blob([l]).size,o&&(h=l.length>i?l.slice(0,i):l);else if(l instanceof Blob)b=l.size,o&&(h=`[Blob ${l.size} bytes]`);else if(l instanceof ArrayBuffer)b=l.byteLength,o&&(h=`[ArrayBuffer ${l.byteLength} bytes]`);else if(l instanceof FormData)o&&(h="[FormData]");else if(l instanceof URLSearchParams){let y=l.toString();b=new Blob([y]).size,o&&(h=y.length>i?y.slice(0,i):y)}}let _=Fe(l),S=y=>{let C={eventId:g(),sessionId:t,timestamp:Date.now(),eventType:"network",url:R,method:p,status:0,requestHeaders:f,responseHeaders:{},requestBodySize:b,responseBodySize:0,duration:0,ttfb:0,graphqlOperation:_,requestBody:h,source:"xhr",...y};if(r?.beforeSend){let D=r.beforeSend(C);D&&e(D)}else e(C)};return this.addEventListener("loadend",()=>{let y=performance.now()-w;if(this.status>0){let C=He(this.getAllResponseHeaders(),s),D=parseInt(this.getResponseHeader("content-length")||"0",10),x;if(o&&(this.responseType===""||this.responseType==="text"))try{let W=this.responseText;x=W.length>i?W.slice(0,i):W}catch{}S({status:this.status,responseHeaders:C,responseBodySize:D,responseBody:x,duration:y,ttfb:y})}else{let C="error",D="Network error";this.readyState===0||this.status,this.timeout>0&&y>=this.timeout&&(C="timeout",D=`Request timed out after ${this.timeout}ms`),S({duration:y,errorPhase:C,errorMessage:D})}},{once:!0,signal:a.signal}),d.call(this,l)},()=>{a.abort(),XMLHttpRequest.prototype.open=c,XMLHttpRequest.prototype.setRequestHeader=u,XMLHttpRequest.prototype.send=d}}function He(e,t){let n={};if(!e)return n;for(let r of e.trim().split(/[\r\n]+/)){let s=r.indexOf(":");if(s===-1)continue;let o=r.slice(0,s).trim().toLowerCase(),i=r.slice(s+1).trim();n[o]=t.has(o)?"[REDACTED]":i}return n}function Fe(e){if(!(!e||typeof e!="string"))try{let t=JSON.parse(e);if(typeof t.query=="string"){let n=t.query.trim(),r="query";n.startsWith("mutation")?r="mutation":n.startsWith("subscription")&&(r="subscription");let s=t.operationName||Pe(n)||"anonymous";return{type:r,name:s}}}catch{}}function Pe(e){return e.match(/^(?:query|mutation|subscription)\s+(\w+)/)?.[1]}function re(e,t,n,r){let s=[],o=new Map;for(let[i,a]of Object.entries(n)){let c=$e(a);if(c==="zustand"){let u=a;j(e,t,r?.beforeSend,{storeId:i,library:c,phase:"init",state:E(u.getState(),4)});let d=u.subscribe((l,p)=>{let R=ne(p,l);j(e,t,r?.beforeSend,{storeId:i,library:c,phase:"update",state:E(l,4),previousState:E(p,4),diff:R?E(R,3):void 0})});s.push(d)}else if(c==="redux"){let u=a;j(e,t,r?.beforeSend,{storeId:i,library:c,phase:"init",state:E(u.getState(),4)});let d,l=u.dispatch.bind(u);o.set(i,l),u.dispatch=v=>(v&&typeof v=="object"&&"type"in v&&(d={type:String(v.type),payload:v.payload}),l(v));let p=u.getState(),R=u.subscribe(()=>{let v=u.getState(),I=ne(p,v);j(e,t,r?.beforeSend,{storeId:i,library:c,phase:"update",state:E(v,4),previousState:E(p,4),diff:I?E(I,3):void 0,action:d?E(d,3):void 0}),p=v,d=void 0});s.push(R)}}return()=>{for(let i of s)i();for(let[i,a]of o){let c=n[i];c&&(c.dispatch=a)}}}function $e(e){if(!e||typeof e!="object")return"unknown";let t=e;return typeof t.getState=="function"&&typeof t.setState=="function"&&typeof t.subscribe=="function"?"zustand":typeof t.dispatch=="function"&&typeof t.getState=="function"&&typeof t.subscribe=="function"?"redux":"unknown"}function ne(e,t){if(!e||!t||typeof e!="object"||typeof t!="object")return null;let n={},r=e,s=t,o=new Set([...Object.keys(r),...Object.keys(s)]);for(let i of o)r[i]!==s[i]&&(n[i]={from:r[i],to:s[i]});return Object.keys(n).length>0?n:null}function j(e,t,n,r){let s={eventId:g(),sessionId:t,timestamp:Date.now(),eventType:"state",...r};if(n){let o=n(s);o&&e(o)}else e(s)}var Be={LCP:[2500,4e3],FCP:[1800,3e3],CLS:[.1,.25],TTFB:[800,1800],FID:[100,300],INP:[200,500]};function je(e,t){let[n,r]=Be[e]??[1/0,1/0];return t<=n?"good":t<=r?"needs-improvement":"poor"}var H=null;function se(e,t,n){if(H)for(let a of H)try{a.disconnect()}catch{}let r=[];H=r;let s=(a,c,u)=>{let d={eventId:g(),sessionId:t,timestamp:Date.now(),eventType:"performance",metricName:a,value:Math.round(c*100)/100,rating:je(a,c),element:u};if(n?.beforeSend){let l=n.beforeSend(d);l&&e(l)}else e(d)};O(r,"largest-contentful-paint",a=>{let c=a[a.length-1];if(!c)return;let u=c.element;s("LCP",c.startTime,u?.tagName?.toLowerCase())}),O(r,"paint",a=>{for(let c of a)c.name==="first-contentful-paint"&&s("FCP",c.startTime)});let o=0;O(r,"layout-shift",a=>{for(let c of a){let u=c;!u.hadRecentInput&&u.value&&(o+=u.value,s("CLS",o))}}),O(r,"first-input",a=>{let c=a[0];if(!c)return;let u=c;u.processingStart&&s("FID",u.processingStart-c.startTime)}),O(r,"navigation",a=>{let c=a[0];c&&s("TTFB",c.responseStart-c.requestStart)});let i=0;return O(r,"event",a=>{for(let c of a)c.duration>i&&(i=c.duration,s("INP",i))},{durationThreshold:16}),()=>{for(let a of r)try{a.disconnect()}catch{}H===r&&(H=null)}}function O(e,t,n,r){try{let s=new PerformanceObserver(o=>{n(o.getEntries())});s.observe({type:t,buffered:!0,...r}),e.push(s)}catch{}}var qe=0,Ue=1,ae=1e4,oe=100,ze=6e4,ie=500;function ce(e,t,n){let r=new Map,s=n?.snapshotIntervalMs??5e3,o=null,i=Xe();if(!i)return()=>{};let a=i.onCommitFiberRoot;return i._runtimescope_original=a,i.onCommitFiberRoot=(c,u)=>{if(a)try{a(c,u)}catch{}u.current&&G(u.current,r)},o=setInterval(()=>{Qe(r,e,t,n?.beforeSend)},s),()=>{o&&(clearInterval(o),o=null),i&&(i._runtimescope_original?i.onCommitFiberRoot=i._runtimescope_original:delete i.onCommitFiberRoot,delete i._runtimescope_original)}}function Xe(){if(typeof window>"u")return null;let e=window;return e.__REACT_DEVTOOLS_GLOBAL_HOOK__||(e.__REACT_DEVTOOLS_GLOBAL_HOOK__={}),e.__REACT_DEVTOOLS_GLOBAL_HOOK__}function G(e,t){We(e,t),e.child&&G(e.child,t),e.sibling&&G(e.sibling,t)}function We(e,t){if(e.tag!==qe&&e.tag!==Ue)return;let n=Ge(e);if(!n)return;let r=Date.now(),s=e.alternate===null,o=e.actualDuration??0,i=Ve(e,s),a=t.get(n);a||(a={renderCount:0,totalDuration:0,lastRenderTime:0,lastRenderPhase:"mount",lastRenderCause:"unknown",renderTimestamps:[]},t.set(n,a)),a.renderCount++,a.totalDuration+=o,a.lastRenderTime=r,a.lastRenderPhase=s?"mount":"update",a.lastRenderCause=i??"unknown",a.renderTimestamps.push(r),a.renderTimestamps.length>oe&&(a.renderTimestamps=a.renderTimestamps.slice(-oe))}function Ge(e){if(e.type&&typeof e.type!="string")return e.type.displayName||e.type.name||void 0}function Ve(e,t){return t?"props":e.alternate?e.memoizedProps!==e.alternate.memoizedProps?"props":e.memoizedState!==e.alternate.memoizedState?"state":"parent":"unknown"}function Ke(e){if(e.length<2)return 0;let t=Date.now(),n=t-ae,r=e.filter(o=>o>=n);if(r.length<2)return 0;let s=t-r[0];return s===0?0:r.length/(s/1e3)}function Qe(e,t,n,r){if(e.size===0)return;let s=[],o=[],i=0;for(let[u,d]of e){let l=Ke(d.renderTimestamps),p=l>4||d.renderCount>20;s.push({componentName:u,renderCount:d.renderCount,totalDuration:Math.round(d.totalDuration*100)/100,avgDuration:d.renderCount>0?Math.round(d.totalDuration/d.renderCount*100)/100:0,lastRenderPhase:d.lastRenderPhase,lastRenderCause:d.lastRenderCause,renderVelocity:Math.round(l*100)/100,suspicious:p}),p&&o.push(u),i+=d.renderCount}s.sort((u,d)=>d.renderCount-u.renderCount);let a={eventId:g(),sessionId:n,timestamp:Date.now(),eventType:"render",profiles:s,snapshotWindowMs:ae,totalRenders:i,suspiciousComponents:o};if(r){let u=r(a);u&&t(u)}else t(a);let c=Date.now();for(let[u,d]of e)c-d.lastRenderTime>ze?e.delete(u):(d.renderCount=0,d.totalDuration=0);if(e.size>ie){let u=[...e.entries()].sort((l,p)=>l[1].lastRenderTime-p[1].lastRenderTime),d=e.size-ie;for(let l=0;l<d;l++)e.delete(u[l][0])}}function ue(e,t,n){let r=o=>{let i,a,c;if(o instanceof ErrorEvent)i=o.message||"Uncaught error",a=o.error?.stack,c=o.filename?`${o.filename}:${o.lineno}:${o.colno}`:void 0;else{let d=o.target;if(d&&d!==window){let l=d.tagName?.toLowerCase()??"unknown",p=d.src??d.src??d.href??"unknown";i=`Failed to load resource: <${l}> ${p}`}else return}let u={eventId:g(),sessionId:t,timestamp:Date.now(),eventType:"console",level:"error",message:`[Uncaught] ${i}`,args:[E(i,3)],stackTrace:a,sourceFile:c};if(n){let d=n(u);d&&e(d)}else e(u)},s=o=>{let i=o.reason,a,c;if(i instanceof Error)a=i.message,c=i.stack;else if(typeof i=="string")a=i;else try{a=JSON.stringify(i)}catch{a=String(i)}let u={eventId:g(),sessionId:t,timestamp:Date.now(),eventType:"console",level:"error",message:`[Unhandled Rejection] ${a}`,args:[E(i,3)],stackTrace:c,sourceFile:void 0};if(n){let d=n(u);d&&e(d)}else e(u)};return window.addEventListener("error",r,!0),window.addEventListener("unhandledrejection",s),()=>{window.removeEventListener("error",r,!0),window.removeEventListener("unhandledrejection",s)}}function de(e,t){let n=window.location.href;function r(c,u){let d=n;d!==c&&(n=c,e({eventId:g(),sessionId:t,timestamp:Date.now(),eventType:"navigation",from:d,to:c,trigger:u}))}let s=history.pushState.bind(history),o=history.replaceState.bind(history);history.pushState=function(...c){s(...c),r(window.location.href,"pushState")},history.replaceState=function(...c){o(...c),r(window.location.href,"replaceState")};let i=()=>r(window.location.href,"popstate");window.addEventListener("popstate",i);let a=()=>r(window.location.href,"hashchange");return window.addEventListener("hashchange",a),()=>{history.pushState=s,history.replaceState=o,window.removeEventListener("popstate",i),window.removeEventListener("hashchange",a)}}function le(e,t){let n=r=>{let s=r.target;if(!(s instanceof Element)||s.closest("[data-runtimescope]"))return;let o=Ye(s),i=Je(s),a={eventId:g(),sessionId:t,timestamp:Date.now(),eventType:"ui",action:"click",target:o,...i&&{text:i}};e(a)};return document.addEventListener("click",n,!0),()=>{document.removeEventListener("click",n,!0)}}function Ye(e){let t=e.tagName.toLowerCase();if(e.id)return`${t}#${e.id}`;let n=e.getAttribute("data-testid")??e.getAttribute("data-test-id");if(n)return`${t}[data-testid="${n}"]`;let r=e.getAttribute("role"),s=e.getAttribute("aria-label");if(r&&s)return`${t}[role="${r}"][aria-label="${s}"]`;let o=e.className;if(typeof o=="string"&&o.trim()){let a=o.split(/\s+/).find(c=>c.length>2&&!c.startsWith("_")&&!c.includes("__"));if(a)return`${t}.${a}`}let i=e.parentElement;if(i){let a=i.children,c=Array.from(a).filter(u=>u.tagName===e.tagName);if(c.length>1){let u=c.indexOf(e)+1;return`${t}:nth-child(${u})`}}return t}function Je(e){let t=e.getAttribute("aria-label");if(t)return t.slice(0,80);let n=e.innerText??e.textContent;if(!n)return;let r=n.trim().replace(/\s+/g," ");if(r.length!==0)return r.length>80?r.slice(0,77)+"...":r}function q(e){let t=e.startsWith("runtimescopes://");if(!e.startsWith("runtimescope://")&&!t)throw new Error("Invalid RuntimeScope DSN: must start with runtimescope:// or runtimescopes://");let n=new URL(e.replace(/^runtimescopes?:\/\//,"http://")),r=n.username;if(!r||!r.startsWith("proj_"))throw new Error("Invalid RuntimeScope DSN: missing projectId (expected proj_xxx@host)");let s=n.password?decodeURIComponent(n.password):void 0,o=n.hostname,i=n.port?parseInt(n.port):6768,a=i-1,c=n.pathname.replace(/^\//,"")||void 0,u=t?"wss":"ws",d=t?"https":"http";return{projectId:r,authToken:s,wsEndpoint:`${u}://${o}:${a}`,httpEndpoint:`${d}://${o}:${i}`,appName:c,tls:t}}function pe(e){let t=e.tls?"runtimescopes":"runtimescope",n=e.host??"localhost",r=e.port??6768,s=e.appName?`/${e.appName}`:"",o=e.authToken?`:${encodeURIComponent(e.authToken)}`:"";return`${t}://${e.projectId}${o}@${n}:${r}${s}`}var U="0.10.1",Ze=console.debug.bind(console),et=console.warn.bind(console),z=!1;function M(...e){z&&Ze(...e)}var fe=new Set;function tt(e,...t){fe.has(e)||(fe.add(e),et(e,...t))}var X=Symbol.for("__runtimescope_originals__");function me(){let e=globalThis;return e[X]||(e[X]={fetch:window.fetch,xhrOpen:XMLHttpRequest.prototype.open,xhrSend:XMLHttpRequest.prototype.send,xhrSetRequestHeader:XMLHttpRequest.prototype.setRequestHeader,consoleMethods:{log:console.log.bind(console),warn:console.warn.bind(console),error:console.error.bind(console),info:console.info.bind(console),debug:console.debug.bind(console),trace:console.trace.bind(console)}}),e[X]}var T=class{static get sessionId(){return this._sessionId}static get isConnected(){return this._state==="started"}static shouldSample(){if(this._sampleRate<1&&Math.random()>this._sampleRate)return!1;if(this._maxEventsPerSecond!==void 0){let t=Date.now();if(t-this._windowStart>=1e3&&(this._windowCount=0,this._windowStart=t),this._windowCount>=this._maxEventsPerSecond)return!1;this._windowCount++}return!0}static connect(t={}){if(t.enabled===!1)return;let n=!1;if(t.dsn)try{let p=q(t.dsn);t={...t,serverUrl:p.wsEndpoint,projectId:p.projectId,...p.authToken?{authToken:p.authToken}:{},...p.appName&&!t.appName?{appName:p.appName}:{}},n=!0}catch(p){M("[RuntimeScope] Invalid DSN:",p.message)}if(!(!!(t.serverUrl||t.endpoint)||n)&&typeof window<"u"){let p=window.location?.hostname;if(p&&p!=="localhost"&&p!=="127.0.0.1"&&!p.startsWith("192.168.")&&!p.startsWith("10.")){M("[RuntimeScope] No endpoint configured and not on localhost \u2014 SDK disabled for production");return}}if(t.verbose===!0)z=!0;else if(typeof localStorage<"u")try{localStorage.getItem("RUNTIMESCOPE_DEBUG")==="1"&&(z=!0)}catch{}V(z);let s=`${t.appName??""}|${t.serverUrl??t.endpoint??""}|${t.dsn??""}|${t.projectId??""}`;if(this._state==="started"){if(this._initSignature===s)return;tt(`[RuntimeScope] init() called twice with different config \u2014 disconnecting and re-initializing.
7
+ previous: ${this._initSignature}
8
+ next: ${s}
9
+ If the SDK is loaded by @runtimescope/vite, drop your manual RuntimeScope.init() call \u2014 the plugin handles it.`),this.disconnect()}this._initSignature=s;let o={serverUrl:t.serverUrl??t.endpoint??"ws://localhost:6767",appName:t.appName??"unknown",captureNetwork:t.captureNetwork??!0,captureConsole:t.captureConsole??!0,captureXhr:t.captureXhr??!0,captureBody:t.captureBody??!1,maxBodySize:t.maxBodySize??65536,capturePerformance:t.capturePerformance??!0,captureRenders:t.captureRenders??!0,captureNavigation:t.captureNavigation??!0,captureClicks:t.captureClicks??!0,stores:t.stores??{},beforeSend:t.beforeSend,redactHeaders:t.redactHeaders??["authorization","cookie"],batchSize:t.batchSize??50,flushIntervalMs:t.flushIntervalMs??100,dedupeConsole:t.dedupeConsole??!1};me(),this._sessionId=K(),this._state="started",this.transport=new $({serverUrl:o.serverUrl,appName:o.appName,sessionId:this._sessionId,sdkVersion:U,authToken:t.authToken,projectId:t.projectId,batchSize:o.batchSize,flushIntervalMs:o.flushIntervalMs}),this._sampleRate=t.sampleRate??1,this._maxEventsPerSecond=t.maxEventsPerSecond,this._windowCount=0,this._windowStart=Date.now(),this._user=t.user,this.transport.connect(),M(`[RuntimeScope] SDK v${U} initializing \u2014 app: ${o.appName}, server: ${o.serverUrl}`);let i=me().consoleMethods.warn,a=this.transport,c=o.serverUrl;setTimeout(()=>{if(this.transport!==a||a.isConnected?.())return;let R=/localhost|127\.0\.0\.1/.test(c)?"Run `npx runtimescope start` in a terminal.":`Check that ${c} is reachable and the collector is running.`;i(`[RuntimeScope] Couldn't connect to ${c} after 10s. No events are being captured.`,`
10
+ Fix: ${R}`)},1e4);let u=p=>{p.eventType!=="session"&&p.eventType!=="custom"&&p.eventType!=="ui"&&!this.shouldSample()||this.transport?.send(p)};u({eventId:g(),sessionId:this._sessionId,timestamp:Date.now(),eventType:"session",appName:o.appName,connectedAt:Date.now(),sdkVersion:U,buildMeta:t.buildMeta,user:this._user,projectId:t.projectId});let d=this._sessionId;this.transport.onCommand(p=>{this.handleCommand(p,u,d)}),o.captureNetwork&&this.restoreFns.push(Q(u,this._sessionId,o.redactHeaders,{captureBody:o.captureBody,maxBodySize:o.maxBodySize,beforeSend:o.beforeSend})),o.captureXhr&&this.restoreFns.push(te(u,this._sessionId,o.redactHeaders,{captureBody:o.captureBody,maxBodySize:o.maxBodySize,beforeSend:o.beforeSend})),o.captureConsole&&this.restoreFns.push(ee(u,this._sessionId,o.beforeSend,o.dedupeConsole)),t.captureErrors!==!1&&this.restoreFns.push(ue(u,this._sessionId,o.beforeSend)),Object.keys(o.stores).length>0&&this.restoreFns.push(re(u,this._sessionId,o.stores,{beforeSend:o.beforeSend})),o.capturePerformance&&this.restoreFns.push(se(u,this._sessionId,{beforeSend:o.beforeSend})),o.captureRenders&&this.restoreFns.push(ce(u,this._sessionId,{beforeSend:o.beforeSend})),o.captureNavigation&&this.restoreFns.push(de(u,this._sessionId)),o.captureClicks&&this.restoreFns.push(le(u,this._sessionId));let l=[o.captureNetwork&&"fetch",o.captureXhr&&"xhr",o.captureConsole&&"console, errors",Object.keys(o.stores).length>0&&"state",o.capturePerformance&&"performance",o.captureRenders&&"renders",o.captureNavigation&&"navigation",o.captureClicks&&"clicks"].filter(Boolean);M(`[RuntimeScope] Interceptors active \u2014 ${l.join(", ")}`),this._sampleRate<1&&M(`[RuntimeScope] Sampling at ${(this._sampleRate*100).toFixed(0)}%`),this._maxEventsPerSecond!==void 0&&M(`[RuntimeScope] Rate limited to ${this._maxEventsPerSecond} events/sec`)}static handleCommand(t,n,r){if(t.command==="capture_dom_snapshot"){let s=t.params?.maxSize??5e5,o=document.documentElement.outerHTML,i=o.length>s;i&&(o=o.slice(0,s));let a={eventId:g(),sessionId:r,timestamp:Date.now(),eventType:"dom_snapshot",html:o,url:window.location.href,viewport:{width:window.innerWidth,height:window.innerHeight},scrollPosition:{x:window.scrollX,y:window.scrollY},elementCount:document.querySelectorAll("*").length,truncated:i};n(a),this.transport?.sendCommandResponse(t.requestId,t.command,a)}else this.transport?.sendCommandResponse(t.requestId,t.command,{error:"Unknown command"})}static init(t={}){return this.connect(t)}static track(t,n){if(!this.transport||!this._sessionId)return;let r={eventId:g(),sessionId:this._sessionId,timestamp:Date.now(),eventType:"custom",name:t,properties:n};this.transport.send(r)}static setUser(t){this._user=t??void 0,this.transport&&this._sessionId&&this.transport.send({eventId:g(),sessionId:this._sessionId,timestamp:Date.now(),eventType:"session",appName:"user_update",connectedAt:Date.now(),sdkVersion:U,user:this._user})}static addBreadcrumb(t,n){if(!this.transport||!this._sessionId)return;let r={eventId:g(),sessionId:this._sessionId,timestamp:Date.now(),eventType:"ui",action:"breadcrumb",target:"manual",text:t,...n&&{data:n}};this.transport.send(r)}static disconnect(){for(let n of this.restoreFns)try{n()}catch{}this.restoreFns=[];let t=globalThis[X];if(t){window.fetch!==t.fetch&&(window.fetch=t.fetch);for(let[n,r]of Object.entries(t.consoleMethods)){let s=console;s[n]!==r&&(s[n]=r)}}this.transport?.disconnect(),this.transport=null,this._sessionId=null,this._state="stopped"}};m(T,"transport",null),m(T,"restoreFns",[]),m(T,"_sessionId",null),m(T,"_state","stopped"),m(T,"_initSignature",null),m(T,"_sampleRate",1),m(T,"_maxEventsPerSecond"),m(T,"_windowCount",0),m(T,"_windowStart",0),m(T,"_user");var nt=T;return Se(rt);})();
8
11
  if(typeof RuntimeScope!=="undefined"&&RuntimeScope.RuntimeScope){RuntimeScope=RuntimeScope.RuntimeScope;}
9
12
  //# sourceMappingURL=index.global.js.map