chrome扩展chome.tabs.onUpdate运行两次? [英] chrome extension chome.tabs.onUpdate running twice?
问题描述
//在background.js中
chrome.tabs.onUpdated.addListener(函数(tabid,info,tab){
console.log(info);
});
我试着将其设置为onUpdate每次加载YouTube视频页面时都会运行一次。我想在YouTube视频加载后等待加载。当我直接从URL加载时,我可以得到我所期望的,但是当我导航到建议的视频时,有2个加载/完成周期。一个用于当前视频,另一个用于下一个视频。
这是直接url youtube视频的输出。
<如果我在观看另一个YouTube视频时导航到YouTube视频,会发生什么情况。
在我的清单中,我有一个简单的background.js脚本,webNaviagtion权限和标签。
我不知道它为什么会运行两次。
tabs.onUpdated
> frame / iframe
,Youtube观看页面会加载一个。
webNavigation API
提供了 frameId
给事件侦听器,主页面有 frameId == 0
。
注意当用户从一个视频转到另一个视频或从主要Youtube页面转到视频页面时,YouTube不会重新加载页面,以便检测到您可能使用的这些更改
//In background.js
chrome.tabs.onUpdated.addListener(function(tabid, info, tab) {
console.log(info);
});
I'm try to set it up so onUpdate runs once every time a youtube video page loads. I want wait for load after a youtube video loads. When I load directly from a url I get what I expect, but when I navigate to a suggested video, there are 2 loading/complete cycles. One for the current video, One for the next video.
This is the output for a direct url youtube video.
This is what happens if I navigate to a youtube video while watching another youtube video.
In my manifest I have a simple background.js script, permission for webNaviagtion and Tabs.
I don't know why it's running twice.
tabs.onUpdated
is invoked for each frame
/iframe
, the Youtube watch page loads one.
webNavigation API
provides frameId
to the event listeners, the main page has frameId == 0
.
Note that Youtube doesn't reload the page when the user goes from one video to another or from the main Youtube page to a video page so to detect these changes you may use chrome.webNavigation.onHistoryStateUpdated
event listener or a content script that will listen to the DOM events used by the site, namely "spfdone".
这篇关于chrome扩展chome.tabs.onUpdate运行两次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!