什么时候run_at:document_idle内容脚本运行? [英] When does a run_at: document_idle content script run?

查看:2090
本文介绍了什么时候run_at:document_idle内容脚本运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行内容脚本有三种选择:


  1. document_start - 注入在< head>

  2. document_end 开头 - 在> DOMContentLoaded 之后

  3. document_idle


解决方案

根据到当前的Chromium源代码


我们尝试在两处闲置:Here和DidFinishLoad。
DidFinishDocumentLoad()对应于完成文档的加载,
,而DidFinishLoad对应于完成文档和所有
子资源的加载。我们不想为
特别慢的子资源阻止脚本注入,所以我们从这里设置了延迟任务 - 但是如果
我们在该点之前完成了所有操作(即,DidFinishLoad()是
$引发),那么就没有理由继续等待。


转换成web开发人员说这基本上意味着...



document_idle 脚本将会运行最早的这些事情之一:


  1. window.onload 已被触发

  2. 自< c $ c> DOMContentLoaded 已被解雇。

在典型页面上,这些脚本可能会在#2 。

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???

解决方案

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.

这篇关于什么时候run_at:document_idle内容脚本运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆