gpt4 book ai didi

javascript - chrome扩展InjectDetails中文档的含义

转载 作者:行者123 更新时间:2023-11-30 10:31:31 33 4
gpt4 key购买 nike

我在我的 chrome 扩展代码中使用了 InjectDetails 对象。我对 runAt 字段中引用的文档有点困惑。

这是来自 documentation 的片段

runAt ( optional enum of "document_start", "document_end", or "document_idle" )

这里引用了哪个文档?可能的选项是:-

  • 原始文档(在浏览器中加载的父框架)。
  • 将要注入(inject) JS/Css 的文档。 (原始文档中可能有多个 iframe)
  • 在后台运行的文档作为 background.html

我应该如何验证这一点?

最佳答案

如果allFramestrue,则“文档”仅指顶层文档。
否则,它引用每个匹配框架的文档(例如顶级,iframe)。

您可以在 Content scripts 找到有关 run_at 的更多信息文档:

run_at    string

Optional. Controls when the files in js are injected. Can be "document_start", "document_end", or "document_idle". Defaults to "document_idle".

In the case of "document_start", the files are injected after any files from css, but before any other DOM is constructed or any other script is run.

In the case of "document_end", the files are injected immediately after the DOM is complete, but before subresources like images and frames have loaded.

In the case of "document_idle", the browser chooses a time to inject scripts between "document_end" and immediately after the window.onload event fires. The exact moment of injection depends on how complex the document is and how long it is taking to load, and is optimized for page load speed.

Note: With "document_idle", content scripts may not necessarily receive the window.onload event, because they may run after it has already fired. In most cases, listening for the onload event is unnecessary for content scripts running at "document_idle" because they are guaranteed to run after the DOM is complete. If your script definitely needs to run after window.onload, you can check if onload has already fired by using the document.readyState property.

附言。 chrome.tabs.executeScript 的属性名称是驼峰式的(runAt, allFrames),但在 list 文件中用下划线拼写 (run_at, all_frames)。

关于javascript - chrome扩展InjectDetails中文档的含义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16647799/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com