diff --git a/platform/chromium/vapi-background.js b/platform/chromium/vapi-background.js index 5c316f867..e5ff19456 100644 --- a/platform/chromium/vapi-background.js +++ b/platform/chromium/vapi-background.js @@ -134,28 +134,44 @@ vAPI.tabs.registerListeners = function() { } }; + // The chrome.webRequest.onBeforeRequest() won't be called for everything + // else than `http`/`https`. Thus, in such case, we will bind the tab as + // early as possible in order to increase the likelihood of a context + // properly setup if network requests are fired from within the tab. + // Example: Chromium + case #6 at + // http://raymondhill.net/ublock/popup.html + var reGoodForWebRequestAPI = /^https?:\/\//; + var onCreatedNavigationTarget = function(details) { - //console.debug('onCreatedNavigationTarget: popup candidate', details.tabId); + //console.debug('onCreatedNavigationTarget: popup candidate tab id %d = "%s"', details.tabId, details.url); + if ( reGoodForWebRequestAPI.test(details.url) === false ) { + details.frameId = 0; + onNavigationClient(details); + } popupCandidateCreate(details); - popupCandidateTest(details); + if ( popupCandidateTest(details) === true ) { + return; + } }; var onBeforeNavigate = function(details) { - if ( details.frameId === 0 ) { - //console.debug('onBeforeNavigate: popup candidate', details.tabId); - popupCandidateTest(details); + if ( details.frameId !== 0 ) { + return; } + //console.debug('onBeforeNavigate: popup candidate tab id %d = "%s"', details.tabId, details.url); + popupCandidateTest(details); }; var onCommitted = function(details) { - if ( details.frameId === 0 ) { - //console.debug('onCommitted: popup candidate', details.tabId); - if ( popupCandidateTest(details) === true ) { - return; - } - popupCandidateDestroy(details); + if ( details.frameId !== 0 ) { + return; } onNavigationClient(details); + //console.debug('onCommitted: popup candidate tab id %d = "%s"', details.tabId, details.url); + if ( popupCandidateTest(details) === true ) { + return; + } + popupCandidateDestroy(details); }; chrome.webNavigation.onCreatedNavigationTarget.addListener(onCreatedNavigationTarget); diff --git a/src/js/pagestore.js b/src/js/pagestore.js index 86dabacd3..ced62ce1a 100644 --- a/src/js/pagestore.js +++ b/src/js/pagestore.js @@ -508,6 +508,12 @@ PageStore.prototype.init = function(tabId, pageURL) { /******************************************************************************/ PageStore.prototype.reuse = function(pageURL, context) { + // This can very well happen under normal circumstances. Leave the context + // unchanged when this happens. + if ( pageURL === this.pageURL ) { + return this; + } + // If URL changes without a page reload (more and more common), then we // need to keep all that we collected for reuse. In particular, not // doing so was causing a problem in `videos.foxnews.com`: clicking a diff --git a/src/js/traffic.js b/src/js/traffic.js index e8ab570bf..501492fe8 100644 --- a/src/js/traffic.js +++ b/src/js/traffic.js @@ -65,26 +65,30 @@ var onBeforeRequest = function(details) { var µb = µBlock; var pageStore = µb.pageStoreFromTabId(tabId); if ( !pageStore ) { - if ( mostRecentRootDocURL === '' ) { - return; - } // https://github.com/gorhill/uBlock/issues/1025 // Google Hangout popup opens without a root frame. So for now we will // just discard that best-guess root frame if it is too far in the // future, at which point it ceases to be a "best guess". if ( (Date.now() - mostRecentRootDocURLTimestamp) >= 500 ) { mostRecentRootDocURL = ''; - return; } // https://github.com/gorhill/uBlock/issues/1001 // Not a behind-the-scene request, yet no page store found for the // tab id: we will thus bind the last-seen root document to the // unbound tab. It's a guess, but better than ending up filtering // nothing at all. - vAPI.tabs.onNavigation({ tabId: tabId, frameId: 0, url: mostRecentRootDocURL }); - pageStore = µb.pageStoreFromTabId(tabId); + if ( mostRecentRootDocURL !== '' ) { + vAPI.tabs.onNavigation({ tabId: tabId, frameId: 0, url: mostRecentRootDocURL }); + pageStore = µb.pageStoreFromTabId(tabId); + } + // If all else fail at finding a page store, re-categorize the + // request as behind-the-scene. At least this ensures that ultimately + // the user can still inspect/filter those net requests which were + // about to fall through the cracks. + // Example: Chromium + case #12 at + // http://raymondhill.net/ublock/popup.html if ( !pageStore ) { - return; + return onBeforeBehindTheSceneRequest(details); } }