import{r as e}from"./chunk-BPLyUllO.js";import{o as t}from"./src-D8DRHLtD.js";import{n,t as r}from"./chunk-VCGWCGR7-BsHMpZ7V.js";import{t as i}from"./chunk-ODNERRIQ-Byy9t2rn.js";var a,o=(e,t,n)=>a??=new Promise(r=>{let i=a=>{let{data:{cmd:o,scope:s,context:c},ports:l}=a;if(o===`webext-port-offer`&&s===t&&c!==e)return window.removeEventListener(`message`,i),l[0].onmessage=n,l[0].postMessage(`port-accepted`),r(l[0])},a=()=>{let a=new MessageChannel;a.port1.onmessage=e=>{if(e.data===`port-accepted`)return window.removeEventListener(`message`,i),r(a.port1);n?.(e)},window.postMessage({cmd:`webext-port-offer`,scope:t,context:e},`*`,[a.port2])};window.addEventListener(`message`,i),e===`window`?setTimeout(a,0):a()}),s=e=>{let t,n=!1,r,i;return{enable:()=>n=!0,onMessage:e=>r=e,postMessage:async r=>{if(e!==`content-script`&&e!==`window`)throw Error(`Endpoint does not use postMessage`);if(!n)throw Error(`Communication with window has not been allowed`);return c(t),(await i).postMessage(r)},setNamespace:n=>{if(t)throw Error(`Namespace once set cannot be changed`);t=n,i=o(e,n,({data:e})=>r?.(e))}}};function c(e){if(typeof e!=`string`||e.trim().length===0)throw Error(`webext-bridge uses window.postMessage to talk with other "window"(s) for message routingwhich is global/conflicting operation in case there are other scripts using webext-bridge. Call Bridge#setNamespace(nsps) to isolate your app. Example: setNamespace('com.facebook.react-devtools'). Make sure to use same namespace across all your scripts whereever window.postMessage is likely to be used\``)}var l=e({allowWindowMessaging:()=>p,onMessage:()=>h,onOpenStreamChannel:()=>_,openStream:()=>g,sendMessage:()=>m}),u=s(`content-script`),d=i(),f=r(`content-script`,e=>{e.destination.context===`window`?u.postMessage(e):d.postMessage(e)});u.onMessage(e=>{f.handleMessage(Object.assign({},e,{origin:{context:`window`,tabId:null}}))}),d.onMessage(f.handleMessage),d.onFailure(e=>{if(e.origin.context===`window`){u.postMessage({type:`error`,transactionID:e.transactionId});return}f.endTransaction(e.transactionId)});function p(e){u.setNamespace(e),u.enable()}var{sendMessage:m,onMessage:h}=f,{openStream:g,onOpenStreamChannel:_}=n(f);t(l);