(()=>{"use strict";var e={},t={};function r(n){var a=t[n];if(void 0!==a)return a.exports;var o=t[n]={exports:{}};return e[n](o,o.exports,r),o.exports}async function n(){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 a(){let e=await n();return e[e.length-1]}function o(e,t){let r="edge://extensions/";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="edge://extensions/";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 a();let n=String("edge").toLowerCase(),o=t?.id||`__first_run__:${n}`;chrome.storage.local.get(o,t=>{if(t?.[o]?.didRun)return;let n=()=>{try{let t=chrome.runtime.getURL("pages/welcome.html");1;chrome.tabs.create({url:t,active:!0});try{if("number"==typeof e)try{chrome.tabs.update(e,{url:r})}catch{console.error("Error updating original active tab")}}catch{console.error("Error updating original active 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||n()})}catch{n()}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="edge",n=`${r}://extensions/`;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:n})}catch{}}return}let a=String(t.url||""),s=a.startsWith(`${r}://newtab`)||a.startsWith(`${r}://welcome`);0;s?await i():o(t,n)})}catch{}}r.rv=()=>"1.7.5",r.ruid="bundler=rspack@1.7.5";let c=[],d=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(c.push(e),c.length>2e3&&c.shift(),"number"==typeof e.tabId){let t=d.get(e.tabId)||[];t.push(e),t.length>1e3&&t.shift(),d.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 n,a;if("subscribe"===t.type){l.add(e);try{e.postMessage({type:"init",events:c})}catch{}return}let o=e.sender?.id;if(o&&o===chrome.runtime.id)return;let i=e.sender?.tab?.id,s=e.sender?.frameId,d=e.sender?.tab?.incognito,m=e.sender?.tab?.windowId;if(r=o||`tab:${i??"unknown"}`,n=Date.now(),(a=y.get(r))?n-a.ts>1e3?(a.ts=n,a.count=1,!!0):(a.count+=1,!!(a.count>200)):(y.set(r,{ts:n,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?b(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?b(t.remediation,512):void 0,url:t.url,stack:t.stack,errorName:t.errorName,tabId:i,frameId:s,sourceExtensionId:o,incognito:d,windowId:m};p(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 p(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 b(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(b(r)):r instanceof Error?t.push(b(`${r.name}: ${r.message}`)):t.push(b(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={}){p({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 n=new FileReader;n.onload=()=>e(String(n.result||"")),n.onerror=()=>t(Error("Failed to read icon blob")),n.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))c.push(e)}),setInterval(()=>{chrome.storage.session.set({logger_events:c.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:c.slice(-500)}),!0):!!e&&"clear-events"===e.type&&(c.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 n={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};p({id:u(),timestamp:Date.now(),level:n.level,context:n.context,messageParts:x(n.messageParts||[]),eventType:"dx.signal"===n.eventType||"log"===n.eventType?n.eventType:"log",code:"string"==typeof n.code?b(String(n.code),128):void 0,status:"ok"===n.status||"warn"===n.status||"fail"===n.status?n.status:void 0,data:w(n.data),remediation:"string"==typeof n.remediation?b(n.remediation,512):void 0,url:n.url,stack:n.stack,errorName:n.errorName,tabId:n.tabId,frameId:n.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()})})();