diff --git a/src/background/background.js b/src/background/background.js index bb100c08e38845ed29402416cf41c26c5f7ef244..5567a890ff4b0cb6bff2c591af148f75f3b23eb1 100644 --- a/src/background/background.js +++ b/src/background/background.js @@ -132,12 +132,28 @@ worker.onmessage = (event) => { if (event.data.type === "pyodide-simplemma" && event.data.status === "success") { browser.tabs.query({}).then((tabs) => { tabs.forEach((tab) => { - browser.tabs.sendMessage(tab.id, { command: "pyodide-simplemma-ready" }) - .catch((error) => console.warn(`[Background] Impossible d'envoyer un message à l'onglet ${tab.id} : ${error}`)); + if (!tab.url || (!tab.url.startsWith("https://") && (!tab.url.startsWith("https://")))) { + return; + } + if (tab.url.includes("sidebar.html")) { + return; + } + + try { + let response = browser.tabs.sendMessage(tab.id, { command: "pyodide-simplemma-ready" }) + if (response && typeof response.then === "function") { + response.then(() => { + }).catch((error) => { + log("[Background] Impossible d'envoyer un message à l'onglet ${tab.id} : ${error}"); + }); + } + } catch (error) { + log("[Background] Erreur lors de l'envoi d'un message à l'onglet ${tab.id} : ${error}"); + } }); - }); + }) } -}; +} // ───────────────────────────────────────────────────────────────────────────── // Fonctions d'authentification & de redirection