From 9c319b574fff128850e0ebe04d0d95d301bef554 Mon Sep 17 00:00:00 2001 From: Nicholas Tay Date: Wed, 22 Feb 2023 21:08:18 +0100 Subject: Set icon only for relevant tab id --- background.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/background.js b/background.js index 0df541a..5295d9f 100644 --- a/background.js +++ b/background.js @@ -4,14 +4,17 @@ let certs = []; // On header receive, inspect cert and update app icon as required async function onHeaderReceive(details) { + if (details.tabId < 0) // tabId < 0 means non-user tab + return; + try { - await certInspectUpdate(details.requestId); + await certInspectUpdate(details.requestId, details.tabId); } catch(error) { console.error(error); } } -async function certInspectUpdate(requestId) { +async function certInspectUpdate(requestId, tabId) { let securityInfo = await browser.webRequest.getSecurityInfo( requestId, { @@ -20,7 +23,7 @@ async function certInspectUpdate(requestId) { ); if (securityInfo.state !== "secure" || securityInfo.isUntrusted) { - setIcon("nope"); + setIcon("nope", tabId); return; } @@ -31,16 +34,19 @@ async function certInspectUpdate(requestId) { for (let cert of certs) { if (rootCA.subject.includes(cert)) { - setIcon("nope"); + setIcon("nope", tabId); return; } } - setIcon("ok"); + setIcon("ok", tabId); } -function setIcon(icon) { - browser.browserAction.setIcon({ path: "icons/" + icon + ".png" }); +function setIcon(icon, tabId) { + browser.browserAction.setIcon({ + path: "icons/" + icon + ".png", + tabId: tabId + }); } // Listen for all header receive events, which contain the cert details we want -- cgit