加载视频页面时YouTube触发的事件

问题描述:

我正在构建一个Firefox插件,以便在YouTube加载视频页面时解析URL(例如https://www.youtube.com/watch?v=6tOQsswD4Tc ).使用Firefox的附件用于标签的api ,视频页面加载完成后,我无法捕捉到该事件.这可能是由于YT的新异步加载所致.因为如果我按F5,则可以捕获该事件.我正在使用此代码:

I am building a Firefox add-on that parses the URL when YouTube loads a video page (e.g. https://www.youtube.com/watch?v=6tOQsswD4Tc). Using Firefox's Add-on api for Tabs, I can't catch the event when the video page is finished loading. This might be due to YT's new asynchronous loading. Because if I hit F5, I can capture the event. I am using this code:

tabs.on("ready", function(tab) {
  if(tab.url.search(/youtube\.com\/watch\?v=/)!=-1){
    // do stuff
  }
});

我尝试将其更改为就绪",加载",页面显示",但似乎无济于事.如何捕获页面加载事件?

I tried changing it to 'ready', 'load', 'pageshow' but nothing seems to work. How can I capture the page-load event?

解决方案链接提到 chrome.webNavigation.onHistoryStateUpdated,相当于Firefox中的 onStateChange in nsIWebProgressListener`: https://developer.mozilla.org/zh-CN/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIWebProgressListener

The linked to solution mentions chrome.webNavigation.onHistoryStateUpdated, the equivalent of that in Firefox isonStateChangeinnsIWebProgressListener`: https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIWebProgressListener

另一种选择是插入内容脚本,以在youtube加载栏上收听过渡动画结束,如该堆栈文章中所指出的那样.

The other option is to insert content script to listen to transition animation end on the youtube loading bar as also pointed out in that stack post.

Chrome扩展程序未加载在YouTube上的浏览器导航中