2

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?

abhisek
  • 924
  • 1
  • 13
  • 27
  • 2
    Yes this is tricky youtube does something like PJAX I think. So what I did was use state progress listeners. But a more familiar way would be to insert a content script and listen to the youtube loading bar. @RobW says they are doing push state stuff though so thats interesting, but the solution is here: http://stackoverflow.com/questions/18397962/chrome-extension-is-not-loading-on-browser-navigation-at-youtube/18398921#18398921 – Noitidart Sep 27 '15 at 18:23
  • 1
    Thank you! That's exactly what I wanted. If you could please put this as an answer, I can accept it. Thanks again! – abhisek Sep 28 '15 at 17:22

1 Answers1

2

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

Community
  • 1
  • 1
Noitidart
  • 35,443
  • 37
  • 154
  • 323