import{e as m,i as y,d as w,b as M,A as u,c as T,g as L,a as b,T as S}from"./chunk-d_KsLFbx.js";function Y(e){const t=e.maxBatch??50,o=e.flushMs??250;let n=[],r=null;function s(){if(r!==null&&(e.cancel(r),r=null),n.length===0)return;const d=n;n=[],e.send(d)}function i(d){n.push(d),n.length>=t?s():r===null&&(r=e.schedule(s,o))}return{enqueue:i,flush:s,size:()=>n.length}}function l(e,t){const o={source:S,kind:"control",enabled:e,streams:t};document.dispatchEvent(new CustomEvent(b,{detail:o}))}const E=window;function _(){try{return chrome.runtime?.id!=null}catch{return!1}}let a=!1,h=null;function f(e){if(!a){a=!0;try{l(!1,u)}catch{}h?.(),h=null,E.__tcrRelayLoaded=!1,console.info(`[TCR] Telemetry relay stopped: ${e}. Reload the page to capture again.`)}}let g=Promise.resolve();const R=Y({send:e=>{if(!a){if(!_()){f("the extension was reloaded or updated");return}try{g=Promise.resolve(chrome.runtime.sendMessage({type:"TELEMETRY/EVENTS",events:e})?.catch(()=>{}))}catch(t){f(t instanceof Error?t.message:"the messaging channel is gone")}}},schedule:(e,t)=>setTimeout(e,t),cancel:e=>clearTimeout(e),maxBatch:50,flushMs:250});function p(e,t){a||R.enqueue({kind:e,payload:t})}function c(){a||R.flush()}async function v(){try{const e=await chrome.storage.local.get([T,L]),t=e[L];return{enabled:!!e[T],streams:t?{network:!!t.network,console:!!t.console}:u}}catch{return _()||f("the extension was reloaded or updated"),{enabled:!1,streams:u}}}if(!E.__tcrRelayLoaded){E.__tcrRelayLoaded=!0;const e=n=>{const r=n.detail;if(y(r)){if(r.kind==="ready"){v().then(s=>l(s.enabled,s.streams));return}p(r.kind,r.payload)}},t=()=>{document.visibilityState==="hidden"&&c()},o=(n,r,s)=>{if(a)return;if(n?.type===w)return c(),g.then(()=>s({flushed:!0})).catch(()=>s({flushed:!1})),!0;if(n?.type!==M)return;const i=n.streams;l(!!n.enabled,i?{network:!!i.network,console:!!i.console}:u)};document.addEventListener(m,e),window.addEventListener("pagehide",c),window.addEventListener("visibilitychange",t),chrome.runtime.onMessage.addListener(o),h=()=>{document.removeEventListener(m,e),window.removeEventListener("pagehide",c),window.removeEventListener("visibilitychange",t);try{chrome.runtime.onMessage.removeListener(o)}catch{}},v().then(n=>l(n.enabled,n.streams))}
//# sourceMappingURL=chunk-CdT2160e.js.map
