What is difference between chrome.webNavigation.onCompleted and chrome.tabs.onUpdated.addListener with 'complete'

别等时光非礼了梦想. 提交于 2019-12-21 17:52:48

问题


In chrome APIs there are two functions that theoretically points to the same evet.

chrome.webNavigation.onCompleted and chrome.tabs.onUpdated.addListener with changeinfo=complete.

What is the difference between these two and which one guarantee that everthing in the page have loaded. I have found that chrome.tabs.onUpdated.addListener sometimes fire even when few http requests are remaining.


回答1:


The chrome.webNavigation.onCompleted is invoked even when the navigation occurs in a subframe whereas the chrome.tabs.onUpdated.addListener is only triggered when a tab is updated due to change in a tab's property like status or url. Observe the changeInfo object that is passed to the callback function here.

Also, the chrome.webNavigation.onCompleted supports filtered events, thus you can specify the filter so that the event is triggered only when the filter is passed. Observe here how to apply filters to an event.

So, if you use both the event listeners, you will observer that the chrome.webNavigation.onCompleted is fired many a times for a single tab whereas the chrome.tabs.onUpdated.addListener might fire only once or twice (due to status change from loading to complete).

I hope this helps.



来源:https://stackoverflow.com/questions/35030705/what-is-difference-between-chrome-webnavigation-oncompleted-and-chrome-tabs-onup

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