webNavigation.onDOMContentLoaded

这篇翻译不完整。请帮忙从英语翻译这篇文章

在页面中触发DOMContentLoaded 事件时触发。此时,文档被加载和解析,并且DOM被完全构造,但链接的资源(例如图像,样式表和子框架(subframes))可能尚未被加载。

Syntax

browser.webNavigation.onDOMContentLoaded.addListener(
  listener,                   // function
  filter                      // optional object 
)
browser.webNavigation.onDOMContentLoaded.removeListener(listener)
browser.webNavigation.onDOMContentLoaded.hasListener(listener)

事件有三个方法:

addListener(callback)
为此事件添加监听方法.
removeListener(listener)
停止监听此事件. listener 参数为需要移出的监听方法.
hasListener(listener)
检测是否有 listener 被注册在事件上. 如果有返回 true , 否则返回false .

addListener syntax

参数

callback

为当此事件发生是需要被调用的函数. 该函数将传递以下参数:

details
object. 有关导航(navigation)事件的详细信息.
filter可选

object. 包含单个属性 url 的对象,  这是一个  events.UrlFilter 数组对象. 如果包含此参数,则该事件将仅触发转换为与数组中至少一个UrlFilter匹配的URL。 在数组中。如果您省略此参数,则该事件将触发所有转换。

Additional objects

details

tabId
integer. The ID of the tab in which the navigation has occurred.
url
string. The URL to which the given frame has navigated.
processId
integer. The ID of the process in which this tab is being rendered.
frameId
integer. Frame in which the navigation is occurring. 0 indicates that navigation happens in the tab's top-level browsing context, not in a nested iframe. A positive value indicates that navigation happens in a nested iframe. Frame IDs are unique for a given tab and process.
timeStamp
number. The time at which DOMContentLoaded was fired, in milliseconds since the epoch.

Browser compatibility

ChromeEdgeFirefoxFirefox for AndroidOpera
Basic support Yes1142453 4483 4175

1. If the filter parameter is empty, Chrome matches all URLs.

2. Filtering is not supported.

3. Filtering is supported from version 50.

4. If the filter parameter is empty, Firefox raises an exception.

5. If the filter parameter is empty, Opera matches all URLs.

Examples

Logs the target URLs for onDOMContentLoaded, if the target URL's hostname contains "example.com" or starts with "developer".

var filter = {
  url:
  [
    {hostContains: "example.com"},
    {hostPrefix: "developer"}
  ]
}

function logOnDOMContentLoaded(details) {
  console.log("onDOMContentLoaded: " + details.url);
}

browser.webNavigation.onDOMContentLoaded.addListener(logOnDOMContentLoaded, filter);

Acknowledgements

This API is based on Chromium's chrome.webNavigation API. This documentation is derived from web_navigation.json in the Chromium code.

Microsoft Edge compatibility data is supplied by Microsoft Corporation and is included here under the Creative Commons Attribution 3.0 United States License.

文档标签和贡献者

此页面的贡献者: Tommy-White, xgqfrms-GitHub
最后编辑者: Tommy-White,