加载视频页面时YouTube触发的事件 [英] Event Fired by YouTube When Video Page is Loaded

查看:73
本文介绍了加载视频页面时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上的浏览器导航中

这篇关于加载视频页面时YouTube触发的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆