If URL changes, go back to the original URL

Hello, I’m sorry for wasting your time, I’m sure this is way too simple to do and my brain is just overloaded, but I would appreciate it if someone helped me on this quick thing.

Basically, let’s say I have https://www.google.com open and that URL changes (due to redirection or whatever) I want to constantly check that URL and if it does change I want to go back to it and have that script in a loop repeating it-self all the time. Does someone have an easy and quick solution to provide?

Thanks a lot, sorry for being dumb again.

TRY THIS MAY BE A LITTLE HELP

{
  "Command": "store",
  "Target": "1",
  "Value": "tes",
  "Description": ""
},
{
  "Command": "while_v2",
  "Target": "${TES} < 100",
  "Value": "",
  "Description": ""
},
{
  "Command": "open",
  "Target": "https://www.google.com/",
  "Value": "",
  "Description": ""
},
{
  "Command": "end",
  "Target": "",
  "Value": "",
  "Description": ""
}

Hello, thanks for your quick reply, your solution is within the idea, although, a new issue arises,

  1. if the URL changes from https://www.google.com/ to something like https://www.google.com/test the script does not detect it as a change in the URL (I’m assuming its because it starts with the same domain?)

Is there a workaround to this?

Thanks for your time.

 {
  "Name": "TEST",
  "CreationDate": "2022-4-27",
  "Commands": [
    {
      "Command": "times",
      "Target": "1000",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "executeScript",
      "Target": "var base = 'https://www.w3schools.com/html/default.asp';\n\nif (base == window.location.href) {\n  return \"url not change\";\n} else {\n  return \"url change\"\n}",
      "Value": "A",
      "Description": ""
    },
    {
      "Command": "if_v2",
      "Target": "${A} === \"url change\"",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "open",
      "Target": "https://www.w3schools.com/html/default.asp",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "end",
      "Target": "",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "end",
      "Target": "",
      "Value": "",
      "Description": ""
    }
  ]
}

Works like a charm, I would have never figured this out, thank you a lot for your help, I have much to learn from this script alone, Thanks again, you’re the best.