From 221983646e4603b50e62a79eeb0a6ad515529e3a Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Sun, 19 Jul 2020 09:06:19 -0400 Subject: [PATCH] Injects user styles and content scripts in `about:blank` frames Related issues: - https://github.com/uBlockOrigin/uBlock-issues/issues/688 - https://github.com/uBlockOrigin/uBlock-issues/issues/1164 `match_about_blank` is now used for content scripts and user styles. --- platform/chromium/manifest.json | 5 +++-- platform/firefox/manifest.json | 5 +++-- platform/opera/manifest.json | 11 ++++++----- platform/thunderbird/manifest.json | 5 +++-- src/js/contentscript.js | 17 ++--------------- src/js/cosmetic-filtering.js | 6 ++++-- 6 files changed, 21 insertions(+), 28 deletions(-) diff --git a/platform/chromium/manifest.json b/platform/chromium/manifest.json index 0f620cf9e..d59ada391 100644 --- a/platform/chromium/manifest.json +++ b/platform/chromium/manifest.json @@ -39,8 +39,9 @@ "/js/vapi-client.js", "/js/contentscript.js" ], - "run_at": "document_start", - "all_frames": true + "all_frames": true, + "match_about_blank": true, + "run_at": "document_start" }, { "matches": [ diff --git a/platform/firefox/manifest.json b/platform/firefox/manifest.json index 517c67c3a..012153ffa 100644 --- a/platform/firefox/manifest.json +++ b/platform/firefox/manifest.json @@ -49,8 +49,9 @@ "/js/vapi-client.js", "/js/contentscript.js" ], - "run_at": "document_start", - "all_frames": true + "all_frames": true, + "match_about_blank": true, + "run_at": "document_start" }, { "matches": [ diff --git a/platform/opera/manifest.json b/platform/opera/manifest.json index e512bbe11..257de5a9a 100644 --- a/platform/opera/manifest.json +++ b/platform/opera/manifest.json @@ -30,16 +30,17 @@ }, "content_scripts": [ { - "all_frames": true, + "matches": [ + "http://*/*", + "https://*/*" + ], "js": [ "js/vapi.js", "js/vapi-client.js", "js/contentscript.js" ], - "matches": [ - "http://*/*", - "https://*/*" - ], + "all_frames": true, + "match_about_blank": true, "run_at": "document_start" }, { diff --git a/platform/thunderbird/manifest.json b/platform/thunderbird/manifest.json index a224d8283..496bf6f4f 100644 --- a/platform/thunderbird/manifest.json +++ b/platform/thunderbird/manifest.json @@ -30,8 +30,9 @@ "/js/vapi-client.js", "/js/contentscript.js" ], - "run_at": "document_start", - "all_frames": true + "all_frames": true, + "match_about_blank": true, + "run_at": "document_start" }, { "matches": [ diff --git a/src/js/contentscript.js b/src/js/contentscript.js index f65c3b94f..c2b3506b8 100644 --- a/src/js/contentscript.js +++ b/src/js/contentscript.js @@ -1053,27 +1053,14 @@ vAPI.domCollapser = (function() { attributeFilter: [ 'src' ] }; - // The injected scriptlets are those which were injected in the current - // document, from within `bootstrapPhase1`, and which scriptlets are - // selectively looked-up from: - // https://github.com/uBlockOrigin/uAssets/blob/master/filters/resources.txt - const primeLocalIFrame = function(iframe) { - if ( vAPI.injectedScripts ) { - vAPI.injectScriptlet(iframe.contentDocument, vAPI.injectedScripts); - } - }; - // https://github.com/gorhill/uBlock/issues/162 - // Be prepared to deal with possible change of src attribute. + // Be prepared to deal with possible change of src attribute. const addIFrame = function(iframe, dontObserve) { if ( dontObserve !== true ) { iframeSourceObserver.observe(iframe, iframeSourceObserverOptions); } const src = iframe.src; - if ( src === '' || typeof src !== 'string' ) { - primeLocalIFrame(iframe); - return; - } + if ( typeof src !== 'string' || src === '' ) { return; } if ( src.startsWith('http') === false ) { return; } toFilter.push({ type: 'sub_frame', url: iframe.src }); add(iframe); diff --git a/src/js/cosmetic-filtering.js b/src/js/cosmetic-filtering.js index 4d71216c8..a1ce10b34 100644 --- a/src/js/cosmetic-filtering.js +++ b/src/js/cosmetic-filtering.js @@ -959,7 +959,8 @@ FilterContainer.prototype.retrieveGenericSelectors = function(request) { code: out.injected + '\n{display:none!important;}', cssOrigin: 'user', frameId: request.frameId, - runAt: 'document_start' + matchAboutBlank: true, + runAt: 'document_start', }); } @@ -1151,7 +1152,8 @@ FilterContainer.prototype.retrieveSpecificSelectors = function( code: '', cssOrigin: 'user', frameId: request.frameId, - runAt: 'document_start' + matchAboutBlank: true, + runAt: 'document_start', }; if ( out.injectedHideFilters.length !== 0 ) { details.code = out.injectedHideFilters + '\n{display:none!important;}';