mirror of https://github.com/gorhill/uBlock.git
shield content script against exceptions in injected scriptlets
This commit is contained in:
parent
213c4e4de8
commit
63be43a365
|
@ -129,6 +129,20 @@ vAPI.SafeAnimationFrame.prototype.clear = function() {
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
vAPI.injectScriptlet = function(doc, text) {
|
||||||
|
if ( !doc ) { return; }
|
||||||
|
try {
|
||||||
|
var script = doc.createElement('script');
|
||||||
|
script.appendChild(doc.createTextNode(text));
|
||||||
|
(doc.head || doc.documentElement).appendChild(script);
|
||||||
|
} catch (ex) {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
/******************************************************************************/
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
// The DOM filterer is the heart of uBO's cosmetic filtering.
|
// The DOM filterer is the heart of uBO's cosmetic filtering.
|
||||||
|
|
||||||
vAPI.domFilterer = (function() {
|
vAPI.domFilterer = (function() {
|
||||||
|
@ -838,7 +852,6 @@ return domFilterer;
|
||||||
// Library of resources is located at:
|
// Library of resources is located at:
|
||||||
// https://github.com/gorhill/uBlock/blob/master/assets/ublock/resources.txt
|
// https://github.com/gorhill/uBlock/blob/master/assets/ublock/resources.txt
|
||||||
if ( cfeDetails.scripts ) {
|
if ( cfeDetails.scripts ) {
|
||||||
elem = document.createElement('script');
|
|
||||||
// Have the injected script tag remove itself when execution completes:
|
// Have the injected script tag remove itself when execution completes:
|
||||||
// to keep DOM as clean as possible.
|
// to keep DOM as clean as possible.
|
||||||
text = cfeDetails.scripts +
|
text = cfeDetails.scripts +
|
||||||
|
@ -850,8 +863,7 @@ return domFilterer;
|
||||||
" p.removeChild(c);\n" +
|
" p.removeChild(c);\n" +
|
||||||
" }\n" +
|
" }\n" +
|
||||||
"})();";
|
"})();";
|
||||||
elem.appendChild(document.createTextNode(text));
|
vAPI.injectScriptlet(document, text);
|
||||||
parent.appendChild(elem);
|
|
||||||
vAPI.injectedScripts = text;
|
vAPI.injectedScripts = text;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1168,12 +1180,7 @@ vAPI.domCollapser = (function() {
|
||||||
// and which scripts are selectively looked-up from:
|
// and which scripts are selectively looked-up from:
|
||||||
// https://github.com/gorhill/uBlock/blob/master/assets/ublock/resources.txt
|
// https://github.com/gorhill/uBlock/blob/master/assets/ublock/resources.txt
|
||||||
if ( vAPI.injectedScripts ) {
|
if ( vAPI.injectedScripts ) {
|
||||||
var scriptTag = document.createElement('script');
|
vAPI.injectScriptlet(iframe.contentDocument, vAPI.injectedScripts);
|
||||||
scriptTag.appendChild(document.createTextNode(vAPI.injectedScripts));
|
|
||||||
var parent = iframe.contentDocument && iframe.contentDocument.head;
|
|
||||||
if ( parent ) {
|
|
||||||
parent.appendChild(scriptTag);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue