From 24e62269ba69c14b0bc96beb420c3e0fded782fe Mon Sep 17 00:00:00 2001 From: magnolia1234 <7676006-magnolia1234@users.noreply.gitlab.com> Date: Sun, 24 May 2020 20:56:32 +0200 Subject: [PATCH] Limit contentScript on external content --- background.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/background.js b/background.js index e180bc0..405bf74 100644 --- a/background.js +++ b/background.js @@ -477,13 +477,17 @@ ext_api.webRequest.onBeforeSendHeaders.addListener(function(details) { } if (tabId !== -1) { - // run contentScript inside tab - ext_api.tabs.executeScript(tabId, { - file: 'contentScript.js', - runAt: 'document_start' - }, function(res) { - if (ext_api.runtime.lastError || res[0]) { - return; + ext_api.tabs.get(tabId, function (currentTab) { + if (isSiteEnabled(currentTab)) { + // run contentScript inside tab + ext_api.tabs.executeScript(tabId, { + file: 'contentScript.js', + runAt: 'document_start' + }, function(res) { + if (ext_api.runtime.lastError || res[0]) { + return; + } + }); } }); } @@ -556,7 +560,7 @@ function matchDomain(domains, hostname) { } function urlHost(url) { - if (url.startsWith('http')) { + if (url && url.startsWith('http')) { try { return new URL(url).hostname; } catch (e) {