Search code examples
javascriptfirefox-addonfirefox-addon-sdk

How to get notified whenever the URL in the address bar changes Firefox JPM


Is it possible to detect whether an URL changes, while developing Firefox addons using the new SDK/JPM?

It's not exactly hashchange what I want to detect, but any changes to the URL, like ajax request changing search terms or things like that.

Is it a way to do it? Thanks.


Solution

  • I came up with a solution which includes using a combination of MutationObserver and "old location value checking".

    Basically I implemented a value check on location.href but using a MutationObserver to detect changes in the DOM, instead of using an interval which would kill the performance and waste some precious milliseconds.

    Thanks for the contributions. Hope this helps anyone.