import"./_virtual_wxt-html-plugins-Cu3V18IV.js";var e=new Map,t,n,r,i;chrome.runtime.onMessage.addListener((e,t,n)=>e.type===`firebase-auth:offscreen-request`?e.action===`ping`?(n({source:`irsp-offscreen-auth`,ok:!0,ready:!0,...i?{activeSignOutMutationId:i.mutationId}:{}}),!1):((e.action===`sign-out`?a(e):o(e)).then(({source:e,requestId:t,...r})=>n({source:`irsp-offscreen-auth`,...r})).catch(e=>n({source:`irsp-offscreen-auth`,ok:!1,status:`error`,message:e instanceof Error?e.message:`Firebase Auth offscreen request failed.`})),!0):!1);function a(e){let t=e.mutationId;if(!t)return Promise.reject(Error(`Hosted sign-out mutation ID is missing.`));if(i)return i.mutationId===t?i.promise:Promise.reject(Error(`Another hosted sign-out is still active.`));let n=(async()=>{let t=await o(e);if(t.ok!==!0||t.status!==`signed-out`)throw Error(t.message??`Hosted sign-out was not confirmed.`);return t})().finally(()=>{i?.mutationId===t&&(i=void 0)});return i={mutationId:t,promise:n},n}globalThis.addEventListener(`message`,t=>{if(!n||t.origin!==n)return;let r=t.data;if(r?.source!==`irsp-auth-helper`||!r.requestId)return;let i=e.get(r.requestId);i&&(e.delete(r.requestId),i.timer!==void 0&&clearTimeout(i.timer),i.resolve(r))});async function o(r){await s(c(r.helperUrl));let i=crypto.randomUUID();return new Promise((a,o)=>{let s=r.action===`sign-out`?void 0:globalThis.setTimeout(()=>{e.delete(i),o(Error(`Firebase Auth helper timed out.`))},6e4);e.set(i,{resolve:a,reject:o,...s===void 0?{}:{timer:s}}),t?.contentWindow?.postMessage({source:`irsp-offscreen-auth`,requestId:i,action:r.action},n)})}async function s(e){let i=e.origin;if(t&&n===i&&t.src===e.toString()){await r;return}t?.remove(),n=i,r=new Promise((n,r)=>{let i=document.createElement(`iframe`);i.src=e.toString(),i.title=`StockPopover Firebase Auth`,i.style.display=`none`,i.onload=()=>n(),i.onerror=()=>r(Error(`Firebase Auth helper failed to load.`)),document.body.append(i),t=i}),await r}function c(e){let t=new URL(e);if(t.protocol!==`https:`&&t.hostname!==`localhost`&&t.hostname!==`127.0.0.1`)throw Error(`Firebase Auth helper URL must use HTTPS.`);return t}