(()=>{var i=0,o=new Map;function d(s){return!s||!Array.isArray(s)?[]:s.map(e=>{if(typeof e!="function"){if(typeof e=="object"&&e!==null)try{return JSON.parse(JSON.stringify(e))}catch{return String(e)}return e}})}var c={runtime:{sendMessage:function(...s){return new Promise((e,t)=>{let n=i++;o.set(n,{resolve:e,reject:t});let r=d(s);window.postMessage({type:"BB_BROWSER_RUNTIME_SEND_MESSAGE",id:n,args:r},"*")})},onMessage:{addListener:function(s){window.addEventListener("message",e=>{if(e.source!==window||e.data.type!=="BB_BROWSER_ON_MESSAGE")return;let{message:t,sender:n,messageId:r}=e.data;s(t,n,a=>{window.postMessage({type:"BB_BROWSER_MESSAGE_RESPONSE",messageId:r,response:a},"*")})})}}},storage:{local:{get:function(...s){return new Promise((e,t)=>{let n=i++;o.set(n,{resolve:e,reject:t});let r=d(s);window.postMessage({type:"BB_BROWSER_STORAGE_GET",id:n,args:r},"*")})},set:function(...s){return new Promise((e,t)=>{let n=i++;o.set(n,{resolve:e,reject:t});let r=d(s);window.postMessage({type:"BB_BROWSER_STORAGE_SET",id:n,args:r},"*")})}}}};window.browser=c;window.addEventListener("message",s=>{if(s.source===window){if(s.data.type==="BB_BROWSER_RESPONSE"){let{id:e,response:t}=s.data,n=o.get(e);n&&(o.delete(e),n.resolve(t))}else if(s.data.type==="BB_BROWSER_ERROR"){let{id:e,error:t}=s.data,n=o.get(e);n&&(o.delete(e),n.reject(new Error(t)))}}});})();
