const PENDING_KEY = "bb_pending_credential"; const PENDING_TAB_KEY = "bb_pending_tab_id"; function openPopup() { if (typeof chrome === "undefined" || !chrome.action?.openPopup) return; chrome.action.openPopup().catch(() => { // ignore if popup cannot be opened (no user gesture) }); } chrome.runtime.onMessage.addListener((msg, sender) => { if (!msg || msg.type !== "CREDENTIAL_CAPTURED") return; const payload = msg.payload || {}; chrome.storage.local.set({ [PENDING_KEY]: payload, [PENDING_TAB_KEY]: sender?.tab?.id || null }, () => { openPopup(); }); });