Need help with add on, want to press a button have script read/save URL and then if any changes ot url occur revert back to saved url

Need help with add on for firefox quantum, want to press a button have script read URL and then if any changes to url occur revert back to saved url or even better simply disable the ability for the site to change to any other page until i press the button again… a ‘lock url’ button next to the ad block plus button.

Also, i want a script to read the text at the top of every tab/window and if the text ever reads ‘redirect’ i want it to revert to homepage.

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.

NilkasG,

That sounds fantastic. I just started trying to learn how to script add-ons for firefox yesterday would you mind making me a simple add on that can do this?

Thanks

Then I think this would be a good first exercise.
What you want is a browserAction without panel and a background script that listens for clicks on the browserAction. On click, you would use the tabs API to executeScript in the current window’s active tab that adds a beforeunload listener: