From 99c4dfffc2ccca1bf3b22e1bbcf1603c61d24ed8 Mon Sep 17 00:00:00 2001 From: gorhill Date: Wed, 28 Oct 2015 09:35:13 -0400 Subject: [PATCH] this fixes #876 --- platform/firefox/frameModule.js | 10 +++++----- platform/firefox/vapi-client.js | 14 ++++++++++++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/platform/firefox/frameModule.js b/platform/firefox/frameModule.js index 37de2b535..d952b7dc1 100644 --- a/platform/firefox/frameModule.js +++ b/platform/firefox/frameModule.js @@ -258,12 +258,12 @@ var contentObserver = { sandbox.injectScript = function(script) { var svc = Services; - if ( svc !== undefined ) { - svc.scriptloader.loadSubScript(script, sandbox); - } else { - // Sandbox appears void. - // I've seen this happens, need to investigate why. + // Sandbox appears void. + // I've seen this happens, need to investigate why. + if ( svc === undefined ) { + return; } + svc.scriptloader.loadSubScript(script, sandbox); }; // The goal is to have content scripts removed from web pages. This diff --git a/platform/firefox/vapi-client.js b/platform/firefox/vapi-client.js index b8715e820..abbc59957 100644 --- a/platform/firefox/vapi-client.js +++ b/platform/firefox/vapi-client.js @@ -116,10 +116,20 @@ vAPI.messaging = { return; } var details = msg.details; - if ( !details.allFrames && window !== window.top ) { + if ( details.allFrames !== true && window !== window.top ) { return; } - self.injectScript(details.file); + // https://github.com/gorhill/uBlock/issues/876 + // Enforce `details.runAt`. Default to `document_end`. + if ( details.runAt === 'document_start' || document.readyState !== 'loading' ) { + self.injectScript(details.file); + return; + } + var injectScriptDelayed = function() { + document.removeEventListener('DOMContentLoaded', injectScriptDelayed); + self.injectScript(details.file); + }; + document.addEventListener('DOMContentLoaded', injectScriptDelayed); return; } if ( msg.cmd === 'shutdownSandbox' ) {