Detect URL change (including hashchange)

Is there any event I can subscribe to, and how, to be able to monitor URL change (including hash change)?
Currently I do this with an setInterval() method, and check every second if url is changed…
But there must be some more efficient way I suppose?

I know in Javascript there is window.onhashchange event, but how do I get reference to window inside my AddOn code?

I’m not sure how to do it with the SDK.

But in non-sdk (bootstrap and overlay) you can do it like this:

nsIWebProgressListener:

https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIWebProgressListener#onStatusChange()

You can see how i used it here -

https://github.com/Noitidart/Full-Stop/blob/master/resources/scripts/framescript.js

You can tap into this with require('chrome') from SDK.

Thank you, but this seems too complicated to me, can you send me part of code which just detects each URL (including hash) change, and logs it to console?

Or we could just write the whole addon for you :wink:

If you are only interested in hash changes, then use the hashchange event. However, the relevant window is in the content process (in multiprocess Firefox) so that might not be convenient. Using the progress listeners is something that can be done from the chrome process.