(()=>{"use strict";var e={},t={};function r(a){var n=t[a];if(void 0!==n)return n.exports;var o=t[a]={exports:{}};return e[a](o,o.exports,r),o.exports}async function a(){try{if(!chrome.management.getAll)return[];return(await new Promise(e=>{chrome.management.getAll(e)})||[]).filter(e=>{let t;return e.id!==chrome.runtime.id&&"igcijhgmihmjbbahdabahfbpffalcfnn"!==e.id&&"development"===e.installType&&"theme"!==e.type&&!0===e.enabled&&!((t=String(e.name||"").toLowerCase()).includes("extension.js built-in developer tools")||t.includes("extension.js theme"))})}catch{return[]}}async function n(){let e=await a();return e[e.length-1]}function o(e,t){let r="about:addons";chrome.tabs.query({url:r},t=>{t.length>0||chrome.tabs.create({url:r,active:!1},function(t){chrome.tabs.move(t.id,{index:0},()=>{setTimeout(()=>{chrome.tabs.update(e.id,{active:!0})},500)})})})}async function i(){let e,t,r="about:addons";try{chrome.tabs.query({active:!0,currentWindow:!0},t=>{let r=Array.isArray(t)?t[0]:void 0;r&&"number"==typeof r.id&&(e=r.id)})}catch{console.error("Error querying active tab")}t=await n();let a=String("firefox").toLowerCase(),o=t?.id||`__first_run__:${a}`;chrome.storage.local.get(o,e=>{if(e?.[o]?.didRun)return;let t=()=>{try{let e=chrome.runtime.getURL("pages/welcome.html");0;try{chrome.tabs.create({url:e,active:!0})}catch{console.error("Error opening welcome tab")}try{chrome.tabs.query({url:"about:addons"},e=>{if(!Array.isArray(e)||0===e.length)try{chrome.tabs.create({url:"about:addons",active:!1})}catch{console.error("Error creating addons tab")}})}catch{console.error("Error querying addons tab")}}catch{try{chrome.tabs.create({url:"pages/welcome.html",active:!0})}catch{console.error("Error creating welcome tab")}}};try{chrome.tabs.query({url:chrome.runtime.getURL("pages/welcome.html")},e=>{Array.isArray(e)&&e.length>0||t()})}catch{t()}chrome.storage.local.set({[o]:{didRun:!0}})})}async function s(){try{chrome.tabs.query({active:!0,currentWindow:!0},async e=>{let t=Array.isArray(e)?e[0]:void 0,r="about",a="about:addons";if(console.log(`%c
██████████████████████████████████████████████████████████
██████████████████████████████████████████████████████████
████████████████████████████    ██████████████████████████
█████████████████████████        ██████    ███████████████
███████████████████████     ███   ███         ████████████
██████████████████████    ██████        ███    ███████████
███████████████████████     ██████    ██████   ███████████
████████████████   ██████   ██████████████     ███████████
█████████████       ████    ████████████      ████████████
███████████     ██         █████████████   ███████████████
██████████    ██████    █████████████████    █████████████
███████████    ████████████████████████████    ███████████
█████████████    █████████████████    ██████    ██████████
███████████████   ██████████████        ██      ██████████
████████████      ████████████    ████       █████████████
███████████      █████████████   ██████    ███████████████
███████████   ██████    ██████     ███████████████████████
███████████    ████       ██████    ██████████████████████
████████████         ██    ███     ███████████████████████
███████████████    ██████        █████████████████████████
██████████████████████████    ████████████████████████████
██████████████████████████████████████████████████████████
██████████████████████████████████████████████████████████
MIT (c) ${new Date().getFullYear()} - Cezar Augusto and the Extension.js Authors.
`,"background: transparent; color: #0971fe; "),!t){try{await i()}catch{try{chrome.tabs.create({url:a})}catch{}}return}let n=String(t.url||""),s=n.startsWith("about:home")||n.startsWith("about:welcome")||n.startsWith("about:newtab")||"about:blank"===n;1;await i(),s||o(t,a)})}catch{}}r.rv=()=>"1.7.5",r.ruid="bundler=rspack@1.7.5";let d=[],c=new Map,l=new Set;try{chrome.storage.session.get(["logger_capture_stacks"],e=>{e?.logger_capture_stacks}),chrome.storage.session.onChanged.addListener((e,t)=>{"session"===t&&"logger_capture_stacks"in e&&e.logger_capture_stacks?.newValue})}catch{}function u(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)})}function m(e){if(d.push(e),d.length>2e3&&d.shift(),"number"==typeof e.tabId){let t=c.get(e.tabId)||[];t.push(e),t.length>1e3&&t.shift(),c.set(e.tabId,t)}for(let t of l)try{let r={type:"append",event:e};t.postMessage(r)}catch{}}chrome.runtime.onConnect.addListener(e=>{if("logger"!==e.name)return;let t=t=>(function(e,t){var r;let a,n;if("subscribe"===t.type){l.add(e);try{e.postMessage({type:"init",events:d})}catch{}return}let o=e.sender?.id;if(o&&o===chrome.runtime.id)return;let i=e.sender?.tab?.id,s=e.sender?.frameId,c=e.sender?.tab?.incognito,m=e.sender?.tab?.windowId;if(r=o||`tab:${i??"unknown"}`,a=Date.now(),(n=y.get(r))?a-n.ts>1e3?(n.ts=a,n.count=1,!!0):(n.count+=1,!!(n.count>200)):(y.set(r,{ts:a,count:1}),!!0))return;let g=x(t.messageParts),h={id:u(),timestamp:Date.now(),level:t.level,context:t.context,messageParts:g,eventType:"dx.signal"===t.eventType||"log"===t.eventType?t.eventType:"log",code:"string"==typeof t.code?p(t.code,128):void 0,status:"ok"===t.status||"warn"===t.status||"fail"===t.status?t.status:void 0,data:w(t.data),remediation:"string"==typeof t.remediation?p(t.remediation,512):void 0,url:t.url,stack:t.stack,errorName:t.errorName,tabId:i,frameId:s,sourceExtensionId:o,incognito:c,windowId:m};b(h)})(e,t);e.onMessage.addListener(t),e.onDisconnect.addListener(()=>{l.delete(e);try{e.onMessage.removeListener(t)}catch{}})}),chrome.action.onClicked.addListener(async()=>{try{await chrome.sidePanel.setPanelBehavior({openPanelOnActionClick:!0})}catch{}});let g=[],h=new Set;function f(e){try{return JSON.stringify(e)}catch{return String(e)}}function b(e){let t=`${e.eventType??"log"}|${e.code??""}|${e.status??""}|${e.level}|${e.context}|${e.tabId??""}|${e.frameId??""}|${e.url??""}|${f(e.messageParts)}|${f(e.data)}`.slice(0,512);if(!h.has(t)){if(h.add(t),g.push(t),g.length>2e3){let e=g.shift();e&&h.delete(e)}if(e.url&&!e.hostname)try{let t=new URL(e.url);e.hostname=`${t.hostname}${t.pathname}`}catch{}if(null!=e.tabId&&null==e.title)try{chrome.tabs.get(e.tabId,t=>{if(chrome.runtime.lastError)return m(e);e.title=t?.title||e.title,m(e)});return}catch{}m(e)}}let y=new Map;function p(e,t=2048){return e.length<=t?e:e.slice(0,t)+"..."}function v(e){try{return JSON.stringify(e)}catch{try{return String(e)}catch{return"[unserializable]"}}}function x(e){try{let t=[];for(let r of e??[])if("string"==typeof r?t.push(p(r)):r instanceof Error?t.push(p(`${r.name}: ${r.message}`)):t.push(p(v(r))),t.join(" ").length>8192)break;return t}catch{return[v(e)]}}function w(e){if(e&&"object"==typeof e)try{let t=JSON.stringify(e);if(!t)return;let r=JSON.parse(t);if(0===Object.keys(r).length)return;return r}catch{return}}function I(e,t,r={}){b({id:u(),timestamp:Date.now(),level:e,context:"background",messageParts:t,url:"string"==typeof r.url?r.url:void 0,tabId:"number"==typeof r.tabId?r.tabId:void 0,frameId:"number"==typeof r.frameId?r.frameId:void 0})}async function k(){let e=(await new Promise(e=>{chrome.management.getAll(e)})||[]).filter(e=>{let t;return e.id!==chrome.runtime.id&&"igcijhgmihmjbbahdabahfbpffalcfnn"!==e.id&&"development"===e.installType&&"theme"!==e.type&&!((t=String(e.name||"").toLowerCase()).includes("extension.js built-in developer tools")||t.includes("extension.js theme"))});if(0===e.length)return{ok:!0,extensionEnabled:null};let t=e.find(e=>e.enabled)||e[e.length-1];return{ok:!0,extensionEnabled:!!t?.enabled,extensionName:t?.name,extensionId:t?.id}}async function L(e){if(e.startsWith("data:"))return e;let t=await fetch(e);if(!t.ok)throw Error(`Failed to fetch icon: ${t.status}`);let r=await t.blob();return await new Promise((e,t)=>{let a=new FileReader;a.onload=()=>e(String(a.result||"")),a.onerror=()=>t(Error("Failed to read icon blob")),a.readAsDataURL(r)})}chrome.runtime.onInstalled.addListener(e=>{I("info",["extension installed",e.reason,e.previousVersion??null])}),chrome.storage.session.get(["logger_events"],e=>{let t=Array.isArray(e?.logger_events)?e.logger_events:[];if(t.length)for(let e of t.slice(-2e3))d.push(e)}),setInterval(()=>{chrome.storage.session.set({logger_events:d.slice(-200)})},2e3),chrome.runtime.onStartup.addListener(()=>{I("info",["extension startup"]);try{I("info",["TEST_LOG: background-start"])}catch{}}),chrome.tabs.onCreated.addListener(e=>{I("info",["tab created"],{tabId:e.id??void 0,url:e.url})}),chrome.tabs.onUpdated.addListener((e,t,r)=>{"loading"===t.status&&I("debug",["tab loading"],{tabId:e,url:r.url}),"complete"===t.status&&I("debug",["tab complete"],{tabId:e,url:r.url}),"string"==typeof t.url&&I("info",["tab url changed",t.url],{tabId:e,url:t.url})}),chrome.tabs.onRemoved.addListener((e,t)=>{I("info",["tab removed",{windowId:t.windowId,isWindowClosing:t.isWindowClosing}],{tabId:e})}),chrome.webNavigation.onBeforeNavigate.addListener(e=>{0===e.frameId&&I("info",["Before navigate"],{tabId:e.tabId,frameId:e.frameId,url:e.url,title:"[navigation]"})}),chrome.webNavigation.onCommitted.addListener(e=>{0===e.frameId&&I("info",["Navigation committed"],{tabId:e.tabId,frameId:e.frameId,url:e.url,title:"[navigation]"})}),chrome.webNavigation.onCompleted.addListener(e=>{0===e.frameId&&I("info",["Navigation completed"],{tabId:e.tabId,frameId:e.frameId,url:e.url,title:"[navigation]"})}),chrome.webNavigation.onErrorOccurred.addListener(e=>{0===e.frameId&&I("error",["Navigation error",e.error],{tabId:e.tabId,frameId:e.frameId,url:e.url,title:"[navigation]"})}),chrome.webNavigation.onHistoryStateUpdated.addListener(e=>{0===e.frameId&&I("info",["History state updated"],{tabId:e.tabId,frameId:e.frameId,url:e.url,title:"[navigation]"})}),chrome.runtime.onMessage.addListener((e,t,r)=>e&&"get-events"===e.type?(r({events:d.slice(-500)}),!0):!!e&&"clear-events"===e.type&&(d.length=0,r({ok:!0}),!0)),chrome.runtime.onMessage.addListener((e,t,r)=>{if((!t?.id||t.id===chrome.runtime.id)&&e){if("resolve-icon-url"===e.type)return e.url&&function(e){if(e.startsWith("data:"))return!0;try{let t=new URL(e);return"moz-extension:"===t.protocol||"chrome-extension:"===t.protocol}catch{return!1}}(e.url)?(L(e.url).then(e=>r({ok:!0,dataUrl:e})).catch(e=>r({ok:!1,error:String(e)})),!0):void r({ok:!1,error:"Unsupported icon URL"});if("get-dx-status"===e.type)return k().then(e=>r(e)).catch(e=>r({ok:!1,error:String(e||"Unknown error")})),!0;if("dx-signal"===e.type){try{var a={level:e.level||"info",context:e.context||"content",messageParts:Array.isArray(e.messageParts)&&e.messageParts.length>0?e.messageParts:[e.code||"DX_SIGNAL"],eventType:e.eventType||"dx.signal",code:e.code,status:e.status,data:e.data,remediation:e.remediation,url:"string"==typeof e.url?e.url:void 0,stack:"string"==typeof e.stack?e.stack:void 0,errorName:"string"==typeof e.errorName?e.errorName:void 0};b({id:u(),timestamp:Date.now(),level:a.level,context:a.context,messageParts:x(a.messageParts||[]),eventType:"dx.signal"===a.eventType||"log"===a.eventType?a.eventType:"log",code:"string"==typeof a.code?p(String(a.code),128):void 0,status:"ok"===a.status||"warn"===a.status||"fail"===a.status?a.status:void 0,data:w(a.data),remediation:"string"==typeof a.remediation?p(a.remediation,512):void 0,url:a.url,stack:a.stack,errorName:a.errorName,tabId:a.tabId,frameId:a.frameId}),r({ok:!0})}catch(e){r({ok:!1,error:String(e||"Unknown error")})}return!0}}}),chrome.runtime.onStartup.addListener(async()=>{await s()}),chrome.runtime.onInstalled.addListener(async()=>{await s()})})();