diff --git a/main.js b/main.js index 15d05b3e..9e4740da 100644 --- a/main.js +++ b/main.js @@ -7646,8 +7646,14 @@ ipcMain.on("wiz-link", (e, uri) => { }); ipcMain.handle("addon-page-msg", async (e, addonId, msg, payload) => { + // Sidebar panels (quickPanel, leftPanel) count as pages for inject + // round-trips too — see injectionsForSender for the same gate. const tab = tabForSender(e.sender); - if (!tab || !addonHost) throw new Error("not a page"); + const isPanel = !tab && ( + (quickPanel && e.sender === quickPanel.webContents) || + (leftPanel && e.sender === leftPanel.webContents) + ); + if ((!tab && !isPanel) || !addonHost) throw new Error("not a page"); // Only the tab's top-level document speaks for its origin. The inject // preload runs in the main frame alone, so a message from any other frame // did not come through it — and it would be credited with the top-level @@ -7672,14 +7678,23 @@ ipcMain.handle("addon-page-msg", async (e, addonId, msg, payload) => { // Assigning event.returnValue sends the reply at once, so it is set exactly // once at the end. function injectionsForSender(e, href) { + // Normally the sender must be a web tab. Sidebar panels (the sparkle-opened + // AI chat, the quick-link apps like Telegram/WhatsApp) are not in `tabs` + // but DO load third-party origins, so cookie-consent rules, page-inject + // wallets and friends should run there too — otherwise the AI panel in + // the strip shows every consent banner the matching tab wouldn't. const tab = tabForSender(e.sender); - if (!tab || !addonHost) return []; + const isPanel = !tab && ( + (quickPanel && e.sender === quickPanel.webContents) || + (leftPanel && e.sender === leftPanel.webContents) + ); + if ((!tab && !isPanel) || !addonHost) return []; const url = e.sender.getURL(); if (!url || url.startsWith("file:")) return []; if (href && href !== url) console.log(`[addons] inject: preload href ${href} ≠ committed ${url}`); const origin = pageOriginOf(url); const list = addonHost.injectionsFor(url).map((x) => ({ ...x, origin })); - if (list.length) console.log(`[addons] inject ${list.map((x) => x.id).join(",")} into ${origin}`); + if (list.length) console.log(`[addons] inject ${list.map((x) => x.id).join(",")} into ${origin}${isPanel ? " (sidebar panel)" : ""}`); return list; } ipcMain.on("addon-inject-scripts", (e, href) => { e.returnValue = injectionsForSender(e, href); });