How do inject a script into a website *before* the first script on this website is able to run?

Manuel Reimer manuel.reimer at gmx.de
Tue Aug 15 13:17:50 UTC 2017


I have the following code in my content script. I expected that I get at 
least something logged into console, but this seems to happen very 
rarely. My guess is that the DOM, created by parsing the HTML file, 
doesn't trigger the observer? So I'll never see an event for the <head> 
creation?


var target = document;

var observer = new MutationObserver(function(mutations) {
   mutations.forEach(function(mutation) {
     console.log(mutation.type);
   });
});

var config = { attributes: true, childList: true, characterData: true };

observer.observe(target, config);


On 08/15/2017 03:07 PM, The 8472 wrote:
> MutationObserver should be the right approach. Maybe post your attempt?
> 
> On 15.08.2017 14:52, Manuel Reimer wrote:
>> Hello,
>>
>> before Firefox 55 I was able to do the following:
>>
>> Register my content script to run at "document_start".
>> Then I was able to access "document.head" from there and inject my <script> as the very first script to load.
>>
>> I need my script to run right in website context as my script is meant to do heavy exchange with page javascript which is difficult or impossible with a content script directly.
>>
>> Since Firefox 55 it seems to be impossible to do so. "document_start" seems to fire before "<head>" even exists.
>>
>> I tried to fix this with the "DOMContentLoaded" but this now is too late. Scripts embedded into <body> already ran at this point...
>>
>> Then I tried a "MutationObserver" to maybe wait for the point when <head> is inserted, but for me the MutationObserver is never fired.
>>
>> Can someone please point me into the right direction?
>>
>> Thanks in advance
>>
>> Manuel
>> _______________________________________________
>> Dev-addons mailing list
>> Dev-addons at mozilla.org
>> https://mail.mozilla.org/listinfo/dev-addons
>>
> 
> _______________________________________________
> Dev-addons mailing list
> Dev-addons at mozilla.org
> https://mail.mozilla.org/listinfo/dev-addons
> 



More information about the Dev-addons mailing list