Skip to content

Commit

Permalink
Injects user styles and content scripts in about:blank frames
Browse files Browse the repository at this point in the history
Related issues:
- uBlockOrigin/uBlock-issues#688
- uBlockOrigin/uBlock-issues#1164

`match_about_blank` is now used for content scripts and
user styles.
  • Loading branch information
gorhill committed Jul 19, 2020
1 parent fb0a442 commit 2219836
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 28 deletions.
5 changes: 3 additions & 2 deletions platform/chromium/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
5 changes: 3 additions & 2 deletions platform/firefox/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
11 changes: 6 additions & 5 deletions platform/opera/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
{
Expand Down
5 changes: 3 additions & 2 deletions platform/thunderbird/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
17 changes: 2 additions & 15 deletions src/js/contentscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions src/js/cosmetic-filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
});
}

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

0 comments on commit 2219836

Please sign in to comment.