When does a run_at: document_idle content script run?

自古美人都是妖i 提交于 2019-12-31 00:49: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???

回答1:


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.



来源:https://stackoverflow.com/questions/33248629/when-does-a-run-at-document-idle-content-script-run

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!