Can I detect history.pushState
url changes from a chrome user script (not extension), without polling (or breaking out of the script's isolated world to intercept the call in the web page's javascript context)?
My problem, in more detail:
As Github uses history.pushState
[WHAT-WG specs] by way of pjax [minimized example] for in-site page-to-page site navigation, instead of reloading the whole page as you browse the site, user scripts targeting a specific url on the site will only fire when you enter the site at that url or manually forcefully reload the page.
I am writing a little user script library on.js for DRY:ing up user scripts, handling that kind of thing for them by intercepting pushState
calls to see when we're on a new page the host script wants to run on and only invoking it where relevant.
This would be relatively easy if history.pushState
fired events when called, but as best I can tell, no popstate
event gets fired except when the first page loads or the user triggers back / forward movement through history, which is fairly useless for my purposes.
I explored limiting it to a pjax/github-only solution too – when a new page loads, github fires a $(document).trigger('pageUpdate')
event, but as jQuery
implements these internally rather than via DOM events, I can't hear those from the isolated world my user script runs in, unless I inject a little listener in the page itself to have its jQuery
instance report this event back to me, and then I might as well hijack the page's history.pushState
itself.
Does anyone see other tidy ways of achieving this?