<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
I'm not sure what you were doing prior to Firefox 55 which allowed
you to access an existing document.head when your content script was
injected at "document_start". It's normal, and has been such going
back to Firefox versions in the 40's (I don't remember where I first
tested) and Chrome before WebExtensions, that content scripts
declared in manifest.json using a content_scripts entry with
"run_at" = "document_start" are injected prior to the <head>
and <body> being inserted into the DOM (i.e. when
document.head === null && document.body === null). This is
normal, expected and desired behavior. Is this not what you are
experiencing? were experiencing?<br>
<br>
If your intent is to <i>insert</i> a script into the page context,
that's easily done at that time (i.e. at "document_start") by
appending a <script> element to the document.documentElement.
That's the normal way to do so at that time. If you are wanting to
wait until the <head> and/or <body> are created, then
you can do so by using a MutationObserver, as has already been
mentioned. However, you need to insert the code as text, not as a
<script src="someFile">. If the contents of the <script>
is text, then the code is executed immediately. If it's a <script
src="someFile">, then it's non-blocking and the order of
execution is not guaranteed. Given that such referenced file is
sourced from within your extension (i.e. on local disk with no
network delay), it's likely that it will execute first, but it's not
guaranteed.<br>
<br>
For more detailed information, you can see <a
moz-do-not-send="true"
href="https://stackoverflow.com/questions/38577656/how-can-i-make-a-firefox-add-on-contentscript-inject-and-run-a-script-before-oth">this
Stack Overflow question</a>, which is specifically about this
issue.<br>
<br>
<br>
<br>
<div class="moz-cite-prefix">On 8/15/2017 5:52 AM, Manuel Reimer
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:879ab890-1fcd-f628-f593-30a03713f416@gmx.de">Hello,
<br>
<br>
before Firefox 55 I was able to do the following:
<br>
<br>
Register my content script to run at "document_start".
<br>
Then I was able to access "document.head" from there and inject my
<script> as the very first script to load.
<br>
<br>
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.
<br>
<br>
Since Firefox 55 it seems to be impossible to do so.
"document_start" seems to fire before "<head>" even exists.
<br>
<br>
I tried to fix this with the "DOMContentLoaded" but this now is
too late. Scripts embedded into <body> already ran at this
point...
<br>
<br>
Then I tried a "MutationObserver" to maybe wait for the point when
<head> is inserted, but for me the MutationObserver is never
fired.
<br>
<br>
Can someone please point me into the right direction?
<br>
<br>
Thanks in advance
<br>
<br>
Manuel
<br>
_______________________________________________
<br>
Dev-addons mailing list
<br>
<a class="moz-txt-link-abbreviated" href="mailto:Dev-addons@mozilla.org">Dev-addons@mozilla.org</a>
<br>
<a class="moz-txt-link-freetext" href="https://mail.mozilla.org/listinfo/dev-addons">https://mail.mozilla.org/listinfo/dev-addons</a>
<br>
<br>
</blockquote>
<br>
</body>
</html>