3

I'm developing an extension that needs to be triggered when a user switched videos on youtube.

I've tried to listen to load or pageshow but they are not triggered when a user is watching a video and clicks another one

var tabs = require("sdk/tabs");

tabs.on('pageshow', function(tab) {
    //do something
});
tiagosilva
  • 1,695
  • 17
  • 31
  • I don't think youtube uses pageshow, here is an addon that watches page switching: https://addons.mozilla.org/en-US/firefox/addon/listenonrepeat/ i would look into how this guy does it. I also did it in the past but i was experimenting with some complex methods (using nsIWebProgressListener here: https://github.com/Noitidart/Listen-on-Repeat-Youtube-Video-Repeater ) – Noitidart May 20 '15 at 16:31
  • 1
    I think the simplest solution was to attach mutation observer to the the red loading bar on page load of youtube, as page loads dont trigger after that. From here: http://stackoverflow.com/a/18398921/1828637 – Noitidart May 20 '15 at 16:33
  • 1
    This solution: http://stackoverflow.com/questions/30464941/detect-tab-url-change-inside-firefox-add-on works for youtube url changes – tiagosilva Jun 08 '15 at 15:13
  • Thanks for sharing Tiago! He put the solution all nice and neat, you can see in here I have onLocationChange too haha but mine had lots of code around it so it looked scary. – Noitidart Jun 08 '15 at 17:09

1 Answers1

0

Use a history pushstate listener if you want this to work with any modern webapp that changes the URL without refreshing the page. See my answer here

Community
  • 1
  • 1
willlma
  • 7,353
  • 2
  • 30
  • 45