From 8f2d07ec6655966a4faeaf7029121bd4baf0db05 Mon Sep 17 00:00:00 2001 From: AlexVallat Date: Wed, 1 Apr 2015 15:09:22 +0100 Subject: [PATCH 1/2] Candidate for fix for #1140 as described in https://github.com/gorhill/uBlock/issues/1140#issuecomment-88398777 --- platform/firefox/frameModule.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/platform/firefox/frameModule.js b/platform/firefox/frameModule.js index aab44730b..cee9af609 100644 --- a/platform/firefox/frameModule.js +++ b/platform/firefox/frameModule.js @@ -293,6 +293,13 @@ const contentObserver = { let docReady = (e) => { let doc = e.target; doc.removeEventListener(e.type, docReady, true); + + let messageManager = doc.docShell.getInterface(Ci.nsIContentFrameMessageManager); + + messageManager.sendSyncMessage(locationChangedMessageName, { + url: loc.href, + }); + lss(this.contentBaseURI + 'contentscript-end.js', sandbox); if ( doc.querySelector('a[href^="abp:"]') ) { From f280c61698bc4522485180082b1f3217d0877bf0 Mon Sep 17 00:00:00 2001 From: AlexVallat Date: Thu, 2 Apr 2015 09:35:52 +0100 Subject: [PATCH 2/2] Prevent resetting of block count statistics in the more normal case of onLocationChange occurring before document-element-inserted --- platform/firefox/frameModule.js | 2 ++ platform/firefox/vapi-background.js | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/platform/firefox/frameModule.js b/platform/firefox/frameModule.js index cee9af609..f258a2d8d 100644 --- a/platform/firefox/frameModule.js +++ b/platform/firefox/frameModule.js @@ -294,10 +294,12 @@ const contentObserver = { let doc = e.target; doc.removeEventListener(e.type, docReady, true); + // It is possible, in some cases (#1140) for document-element-inserted to occur *before* nsIWebProgressListener.onLocationChange, so ensure that the URL is correct before continuing let messageManager = doc.docShell.getInterface(Ci.nsIContentFrameMessageManager); messageManager.sendSyncMessage(locationChangedMessageName, { url: loc.href, + noRefresh: true, // If the URL is the same, then don't refresh it so that if this occurs after onLocationChange, no the block count isn't reset }); lss(this.contentBaseURI + 'contentscript-end.js', sandbox); diff --git a/platform/firefox/vapi-background.js b/platform/firefox/vapi-background.js index 58f3d4cc1..21b214020 100644 --- a/platform/firefox/vapi-background.js +++ b/platform/firefox/vapi-background.js @@ -1325,6 +1325,12 @@ vAPI.net.registerListeners = function() { var locationChangedListener = function(e) { var details = e.data; var browser = e.target; + + if (details.noRefresh && details.url === browser.currentURI.asciiSpec) { // If the location changed message specified not to refresh, and the URL is the same, no need to do anything + //console.debug("nsIWebProgressListener: ignoring onLocationChange: " + details.url); + return; + } + var tabId = vAPI.tabs.getTabId(browser); //console.debug("nsIWebProgressListener: onLocationChange: " + details.url + " (" + details.flags + ")");