From b2193a2b54ed4fe72e7359b5b109f6b782172de3 Mon Sep 17 00:00:00 2001 From: gorhill Date: Sat, 29 Oct 2016 11:15:04 -0400 Subject: [PATCH] probably fix #2053 --- src/js/messaging.js | 11 +++++++++++ src/js/uritools.js | 16 ++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/js/messaging.js b/src/js/messaging.js index 654c71f28..be1a23ff9 100644 --- a/src/js/messaging.js +++ b/src/js/messaging.js @@ -309,6 +309,17 @@ var popupDataFromTabId = function(tabId, tabTitle) { var pageStore = µb.pageStoreFromTabId(tabId); if ( pageStore ) { + // https://github.com/gorhill/uBlock/issues/2105 + // Be sure to always include the current page's hostname -- it might + // not be present when the page itself is pulled from the browser's + // short-term memory cache. This needs to be done before calling + // getHostnameDict(). + if ( + pageStore.hostnameToCountMap.has(rootHostname) === false && + µb.URI.isNetworkURI(tabContext.rawURL) + ) { + pageStore.hostnameToCountMap.set(rootHostname, 0); + } r.pageBlockedRequestCount = pageStore.perLoadBlockedRequestCount; r.pageAllowedRequestCount = pageStore.perLoadAllowedRequestCount; r.netFilteringSwitch = pageStore.getNetFilteringSwitch(); diff --git a/src/js/uritools.js b/src/js/uritools.js index 9bd1271a8..661d6c608 100644 --- a/src/js/uritools.js +++ b/src/js/uritools.js @@ -21,6 +21,8 @@ /* global publicSuffixList */ +'use strict'; + /******************************************************************************* RFC 3986 as reference: http://tools.ietf.org/html/rfc3986#appendix-A @@ -33,8 +35,6 @@ Naming convention from https://en.wikipedia.org/wiki/URI_scheme#Examples µBlock.URI = (function() { -'use strict'; - /******************************************************************************/ // Favorite regex tool: http://regex101.com/ @@ -402,6 +402,18 @@ URI.domainFromURI = function(uri) { /******************************************************************************/ +URI.isNetworkURI = function(uri) { + return /^(?:ftps?|https?|wss?):\/\//.test(uri); +}; + +/******************************************************************************/ + +URI.isNetworkScheme = function(scheme) { + return /^(?:ftps?|https?|wss?)$/.test(scheme); +}; + +/******************************************************************************/ + // Normalize the way µBlock expects it URI.normalizedURI = function() {