From 574f30ed43a02355c49c09d5b970619f1174f3b3 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Fri, 10 Mar 2023 08:48:48 -0500 Subject: [PATCH] Context of `about:blank` is that of parent frame (`popup` option) Related feedback: - https://github.com/uBlockOrigin/uBlock-issues/discussions/2534#discussioncomment-5264792 --- src/js/tab.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/js/tab.js b/src/js/tab.js index e13e0a00b..5ae990a6b 100644 --- a/src/js/tab.js +++ b/src/js/tab.js @@ -316,9 +316,24 @@ const onPopupUpdated = (( ) => { if ( tabContext === null ) { return; } const rootOpenerURL = tabContext.rawURL; if ( rootOpenerURL === '' ) { return; } - const localOpenerURL = openerDetails.frameId !== 0 + const pageStore = µb.pageStoreFromTabId(openerTabId); + + // https://github.com/uBlockOrigin/uBlock-issues/discussions/2534#discussioncomment-5264792 + // An `about:blank` frame's context is that of the parent context + let localOpenerURL = openerDetails.frameId !== 0 ? openerDetails.frameURL : undefined; + if ( localOpenerURL === 'about:blank' && pageStore !== null ) { + let openerFrameId = openerDetails.frameId; + do { + const frame = pageStore.getFrameStore(openerFrameId); + if ( frame === null ) { break; } + openerFrameId = frame.parentId; + const parentFrame = pageStore.getFrameStore(openerFrameId); + if ( parentFrame === null ) { break; } + localOpenerURL = parentFrame.frameURL; + } while ( localOpenerURL === 'about:blank' && openerFrameId !== 0 ); + } // Popup details. tabContext = µb.tabContextManager.lookup(targetTabId); @@ -392,7 +407,6 @@ const onPopupUpdated = (( ) => { // Only if a popup was blocked do we report it in the dynamic // filtering pane. - const pageStore = µb.pageStoreFromTabId(openerTabId); if ( pageStore ) { pageStore.journalAddRequest(fctxt, result); pageStore.popupBlockedCount += 1;