From 5386558e6827cef762d94892e2935f8da90949f4 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Sat, 21 Apr 2018 12:34:54 -0400 Subject: [PATCH] fix https://www.reddit.com/r/uBlockOrigin/comments/8dkvqn/116_broken_loading_custom_filters_from_my_filters/ --- platform/chromium/vapi-background.js | 11 ++++++++--- platform/chromium/vapi-common.js | 2 ++ src/js/cosmetic-filtering.js | 5 +++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/platform/chromium/vapi-background.js b/platform/chromium/vapi-background.js index 4ba0a1595..12be4a9d9 100644 --- a/platform/chromium/vapi-background.js +++ b/platform/chromium/vapi-background.js @@ -49,6 +49,12 @@ vAPI.resetLastError = function() { }; vAPI.supportsUserStylesheets = vAPI.webextFlavor.soup.has('user_stylesheet'); +// The real actual webextFlavor value may not be set in stone, so listen +// for possible future changes. +window.addEventListener('webextFlavor', function() { + vAPI.supportsUserStylesheets = + vAPI.webextFlavor.soup.has('user_stylesheet'); +}, { once: true }); vAPI.insertCSS = function(tabId, details) { return chrome.tabs.insertCSS(tabId, details, vAPI.resetLastError); @@ -721,8 +727,7 @@ vAPI.messaging.listen = function(listenerName, callback) { /******************************************************************************/ vAPI.messaging.onPortMessage = (function() { - var messaging = vAPI.messaging, - supportsUserStylesheets = vAPI.supportsUserStylesheets; + var messaging = vAPI.messaging; // Use a wrapper to avoid closure and to allow reuse. var CallbackWrapper = function(port, request) { @@ -806,7 +811,7 @@ vAPI.messaging.onPortMessage = (function() { frameId: sender.frameId, matchAboutBlank: true }; - if ( supportsUserStylesheets ) { + if ( vAPI.supportsUserStylesheets ) { details.cssOrigin = 'user'; } if ( msg.add ) { diff --git a/platform/chromium/vapi-common.js b/platform/chromium/vapi-common.js index 57a9a5b9b..19f465963 100644 --- a/platform/chromium/vapi-common.js +++ b/platform/chromium/vapi-common.js @@ -69,7 +69,9 @@ vAPI.webextFlavor = { flavor.major = parseInt(info.version, 10) || 0; soup.add(info.vendor.toLowerCase()) .add(info.name.toLowerCase()); + soup.delete('user_stylesheet'); if ( flavor.major >= 53 ) { soup.add('user_stylesheet'); } + soup.delete('html_filtering'); if ( flavor.major >= 57 ) { soup.add('html_filtering'); } dispatch(); }); diff --git a/src/js/cosmetic-filtering.js b/src/js/cosmetic-filtering.js index a5590b00d..cf8dee775 100644 --- a/src/js/cosmetic-filtering.js +++ b/src/js/cosmetic-filtering.js @@ -543,6 +543,11 @@ FilterContainer.prototype.freeze = function() { this.highlyGeneric.simple.str = µb.arrayFrom(this.highlyGeneric.simple.dict).join(',\n'); this.highlyGeneric.complex.str = µb.arrayFrom(this.highlyGeneric.complex.dict).join(',\n'); + // https://www.reddit.com/r/uBlockOrigin/comments/8dkvqn/116_broken_loading_custom_filters_from_my_filters/ + // Just in case. This can be removed once Firefox 60 ESR is out + // and widespread. + this.supportsUserStylesheets = vAPI.supportsUserStylesheets; + this.frozen = true; };