问题
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 is
onStateChangein
nsIWebProgressListener`: 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