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) + }) }) } }