javascript - OnHistoryStateUpdated filter not working as expected -
i'm working on firefox add-on add pageaction when watching video in youtube. background script works until go youtube video other youtube page, pageaction doesn't disappear. code:
var filter = { url:[ { pathcontains: "watch", hostsuffix: "youtube.com" } ] } function showpageaction(details) { browser.pageaction.show(details.tabid); } browser.webnavigation.oncommitted.addlistener(showpageaction, filter); browser.webnavigation.onhistorystateupdated.addlistener(showpageaction, filter); it happens first time press other youtube link youtube video page (history, main, channel, etc), because when go youtube page first click, disappears. like:
- open new tab
- go directly www.youtube.com (doesn´t appear)
- press video (it appears, expected)
- press other link youtube page (main, history, cannel) (it's still there, shoudn't disappear?)
- press again other link different video (it disappears)
i thinking add filter in showpageaction function but, isn't filter of onhistorystateupdated supposed that?
the filter works expected; it's default resetting behavior doesn't.
the point of history state update based navigation no actual navigation happens (unlike oncommitted events). means ff doesn't hide automatically.
which means have take care of on navigations result in non-watch pages.
your best bet filter within listener:
// since history manipulation must preserve origin, // can limit youtube domains performance const hostfilter = { url: [{hostsuffix: "youtube.com"}] } function updatepageaction(details) { if (details.url.includes("watch")) { browser.pageaction.show(details.tabid); } else { browser.pageaction.hide(details.tabid); } } browser.webnavigation.onhistorystateupdated.addlistener( updatepageaction, hostfilter );
Comments
Post a Comment