0

I'm trying to make an extension that adds a certain HTML into a page, however it must be done before any javascript of the page is executed and after the elements are there.

I plan to insert something on the body tag, so using "run_at": "document_start" makes me unable to add anything to the page as everything is null at that moment.

L3n
  • 524
  • 7
  • 28
  • 2
    *before any javascript of the page is executed and after the elements are there.* This is contradictory. Script tags will generally be executed *immediately* once the HTML parser encounters them, unless they have an `async` or `defer` attribute. This is why some people have problems like these: https://stackoverflow.com/questions/14028959/why-does-jquery-or-a-dom-method-such-as-getelementbyid-not-find-the-element – CertainPerformance Aug 10 '19 at 22:14
  • ...so this question needs more clarification as to the moment, when you need to have your code to intervene. – Nickolay Aug 11 '19 at 02:17
  • The question makes perfect sense as is. All you need here is MutationObserver to wait for the moment when `body` appears. Examples: [one](/a/54812559) - replace `head` with `body`, [two](/a/42013659), [three](/a/39347807)). – wOxxOm Aug 11 '19 at 04:22
  • How is this question too broad? I'm asking a single question with a specific problem... – L3n Aug 11 '19 at 14:06

1 Answers1

0

Turns out I can accomplish this by writing in manifest.json run_at: "document_start" and in my content.js instead of writing to head or body I can use document.documentElement.appendChild.

L3n
  • 524
  • 7
  • 28