When does a run_at: document_idle content script run?

前端 未结 1 1048
说谎
说谎 2021-01-18 22:32

There are three options for running content scripts:

  1. document_start - injected at the start of the
  2. docume
相关标签:
1条回答
  • 2021-01-18 23:07

    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.

    0 讨论(0)
提交回复
热议问题