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.
This commit is contained in:
Raymond Hill 2020-07-19 09:06:19 -04:00
parent fb0a442a9a
commit 221983646e
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
6 changed files with 21 additions and 28 deletions

View File

@ -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": [

View File

@ -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": [

View File

@ -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"
},
{

View File

@ -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": [

View File

@ -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);

View File

@ -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;}';