(()=>{function n(t){try{return JSON.parse(JSON.stringify(t))}catch{return String(t)}}function a(t){return!t||!Array.isArray(t)?[]:t.map(s=>{if(typeof s!="function"){if(typeof s=="object"&&s!==null)try{return JSON.parse(JSON.stringify(s))}catch{return String(s)}return s}})}window.addEventListener("message",t=>{if(t.source!==window||!t.data.type?.startsWith("BB_BROWSER_"))return;let{type:s,id:r,args:i}=t.data,o=a(i);s==="BB_BROWSER_RUNTIME_SEND_MESSAGE"?browser.runtime.sendMessage(...o).then(e=>{window.postMessage({type:"BB_BROWSER_RESPONSE",id:r,response:n(e)},"*")}).catch(e=>{window.postMessage({type:"BB_BROWSER_ERROR",id:r,error:e.message},"*")}):s==="BB_BROWSER_STORAGE_GET"?browser.storage.local.get(...o).then(e=>{window.postMessage({type:"BB_BROWSER_RESPONSE",id:r,response:n(e)},"*")}).catch(e=>{window.postMessage({type:"BB_BROWSER_ERROR",id:r,error:e.message},"*")}):s==="BB_BROWSER_STORAGE_SET"&&browser.storage.local.set(...o).then(e=>{window.postMessage({type:"BB_BROWSER_RESPONSE",id:r,response:n(e)},"*")}).catch(e=>{window.postMessage({type:"BB_BROWSER_ERROR",id:r,error:e.message},"*")})});browser.runtime.onMessage.addListener((t,s)=>new Promise(r=>{let i=`${Date.now()}-${Math.random()}`;window.postMessage({type:"BB_BROWSER_ON_MESSAGE",message:n(t),sender:n(s),messageId:i},"*"),window.addEventListener("message",function o(e){e.source===window&&e.data.type==="BB_BROWSER_MESSAGE_RESPONSE"&&e.data.messageId===i&&(window.removeEventListener("message",o),r(n(e.data.response)))})}));})();
