From f8b15ed6ccfbbfb34a22a19a2799b5dc56ed207c Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Wed, 2 Dec 2020 10:46:59 -0500 Subject: [PATCH] Fix calls to tab.removeCSS() Related issue: - https://github.com/uBlockOrigin/uBlock-issues/issues/1375 --- platform/chromium/vapi-background.js | 35 +++++++++++++++++----------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/platform/chromium/vapi-background.js b/platform/chromium/vapi-background.js index 36fdf742b..077211831 100644 --- a/platform/chromium/vapi-background.js +++ b/platform/chromium/vapi-background.js @@ -1024,22 +1024,29 @@ vAPI.messaging = { } case 'userCSS': if ( tabId === undefined ) { break; } - const details = { - code: undefined, - frameId: portDetails.frameId, - matchAboutBlank: true - }; - if ( msg.add ) { - details.runAt = 'document_start'; - } const promises = []; - for ( const cssText of msg.add ) { - details.code = cssText; - promises.push(vAPI.tabs.insertCSS(tabId, details)); + if ( msg.add ) { + const details = { + code: undefined, + frameId: portDetails.frameId, + matchAboutBlank: true, + runAt: 'document_start', + }; + for ( const cssText of msg.add ) { + details.code = cssText; + promises.push(vAPI.tabs.insertCSS(tabId, details)); + } } - for ( const cssText of msg.remove ) { - details.code = cssText; - promises.push(vAPI.tabs.removeCSS(tabId, details)); + if ( msg.remove ) { + const details = { + code: undefined, + frameId: portDetails.frameId, + matchAboutBlank: true, + }; + for ( const cssText of msg.remove ) { + details.code = cssText; + promises.push(vAPI.tabs.removeCSS(tabId, details)); + } } Promise.all(promises).then(( ) => { callback();