Re. #1250: propagate injected scripts to local iframes

This commit is contained in:
gorhill 2016-01-21 09:33:54 -05:00
parent cdfdb570bb
commit 3eff3c62b0
2 changed files with 14 additions and 0 deletions

View File

@ -223,6 +223,18 @@ var uBlockCollapser = (function() {
attributeFilter: [ 'src' ] attributeFilter: [ 'src' ]
}; };
var primeLocalIFrame = function(iframe) {
// Should probably also copy injected styles.
if ( vAPI.injectedScripts ) {
var scriptTag = document.createElement('script');
scriptTag.appendChild(document.createTextNode(vAPI.injectedScripts));
var parent = iframe.contentDocument && iframe.contentDocument.head;
if ( parent ) {
parent.appendChild(scriptTag);
}
}
};
var addIFrame = function(iframe, dontObserve) { var addIFrame = function(iframe, dontObserve) {
// https://github.com/gorhill/uBlock/issues/162 // 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.
@ -232,6 +244,7 @@ var uBlockCollapser = (function() {
var src = iframe.src; var src = iframe.src;
if ( src === '' || typeof src !== 'string' ) { if ( src === '' || typeof src !== 'string' ) {
primeLocalIFrame(iframe);
return; return;
} }
if ( src.lastIndexOf('http', 0) !== 0 ) { if ( src.lastIndexOf('http', 0) !== 0 ) {

View File

@ -136,6 +136,7 @@ var injectScripts = function(scripts) {
var scriptTag = document.createElement('script'); var scriptTag = document.createElement('script');
scriptTag.appendChild(document.createTextNode(scripts)); scriptTag.appendChild(document.createTextNode(scripts));
parent.appendChild(scriptTag); parent.appendChild(scriptTag);
vAPI.injectedScripts = scripts;
}; };
/******************************************************************************/ /******************************************************************************/