diff --git a/plugin/js/main.js b/plugin/js/main.js index 24fa1288..38ebe0e1 100644 --- a/plugin/js/main.js +++ b/plugin/js/main.js @@ -241,25 +241,29 @@ var main = (function() { } } - function injectContentScript(tabId) { + async function injectContentScript(tabId) { + // Checking for firefox here because `browser.*` requires minimum chrome version 148 + const tab = util.isFirefox() + ? await browser.tabs.get(tabId) + : await chrome.tabs.get(tabId); + + const cannotReadUrl = !tab.url; + if (cannotReadUrl) { + return; + } + if (util.isFirefox()) { return Firefox.injectContentScript(tabId); } else { - chromeInjectContentScript(tabId); + return chromeInjectContentScript(tabId); } } function chromeInjectContentScript(tabId) { - try { - chrome.scripting.executeScript({ - target: {tabId: tabId}, - files: ["js/ContentScript.js"] - }); - } catch { - if (chrome.runtime.lastError) { - util.log(chrome.runtime.lastError.message); - } - } + return chrome.scripting.executeScript({ + target: {tabId: tabId}, + files: ["js/ContentScript.js"], + }); } function populateControls() {