From 339e4e3526ec265d2ca897640e07df46fa3969bc Mon Sep 17 00:00:00 2001 From: Bill Arbuckle Date: Sat, 4 Apr 2026 18:04:01 -0500 Subject: [PATCH] Guard background messaging and detection --- background/detect.js | 4 ++++ background/messages.js | 14 +++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/background/detect.js b/background/detect.js index ab3bff9..f47aecf 100644 --- a/background/detect.js +++ b/background/detect.js @@ -79,6 +79,10 @@ md.detect = ({storage: {state}, inject}) => { } var detect = (content, url) => { + if (!url || !state.origins) { + return + } + var location = new URL(url) var origin = diff --git a/background/messages.js b/background/messages.js index 14a1603..81471c1 100644 --- a/background/messages.js +++ b/background/messages.js @@ -165,7 +165,19 @@ md.messages = ({storage: {defaults, state, set}, compilers, mathjax, xhr, webreq function notifyContent (req, res) { chrome.tabs.query({active: true, currentWindow: true}, (tabs) => { - chrome.tabs.sendMessage(tabs[0].id, req, res) + if (!tabs.length) { + res && res() + return + } + + chrome.tabs.sendMessage(tabs[0].id, req, (response) => { + if (chrome.runtime.lastError) { + res && res() + return + } + + res && res(response) + }) }) } }