Event Fired by YouTube When Video Page is Loaded

爱⌒轻易说出口 提交于 2021-01-28 00:08:56

问题


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?


回答1:


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

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 extension is not loading on browser navigation at YouTube



来源:https://stackoverflow.com/questions/32810912/event-fired-by-youtube-when-video-page-is-loaded

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