17

There are three options for running content scripts:

  1. document_start - injected at the start of the <head>
  2. document_end - injected right after DOMContentLoaded
  3. document_idle - injected when???
Paul Irish
  • 47,354
  • 22
  • 98
  • 132

1 Answers1

22

According to the current Chromium source:

We try to run idle in two places: here and DidFinishLoad. DidFinishDocumentLoad() corresponds to completing the document's load, whereas DidFinishLoad corresponds to completing the document and all subresources' load. We don't want to hold up script injection for a particularly slow subresource, so we set a delayed task from here - but if we finish everything before that point (i.e., DidFinishLoad() is triggered), then there's no reason to keep waiting.

Translated into web developer speak that basically means…

document_idle scripts will run the earliest one of these things is true:

  1. window.onload has fired
  2. It's been 200ms since DOMContentLoaded has fired.

On typical pages, these scripts will likely run at #2.

Paul Irish
  • 47,354
  • 22
  • 98
  • 132