So what you really want to do is prevent pages from navigating (“changing their URL”) while your browserAction
is in an active sate?
I that case, I don’t think that just saving the url on button press and “restoring” it when it changes will give you good results.
I think the best way to (temporary) stop pages from navigating is to add an beforeunload
listener from a content script. When the page is about to navigate for whatever reason, you will get a prompt that you can dismiss to cancel the navigation.
Pages will still be able to update the path and query of the URL without navigating (e.g. YouTube). If you want to prevent that for whatever reason, you could replace the history.replaceState
function on the page.
Along that path you will probably also find a solution for page initiated redirects.
if you want to prevent HTTP redirects (which don’t set the tab title to “redirect”), you can use the browser.ewbRequest
API.