Using the Tampermonkey extension in Chrome, my script will fail to execute as soon as a variable is undefined. I've tried using an if
conditional but the console just spits out the "ERROR! Execution of script..." message as soon as it reads the variable.
The variable is undefined because, using JSON.parse
, it grabs a value that exists in another part of the website. I would like to make it so it avoids this undefined variable and continues with the rest of the script instead of stopping right after failing to get the value.
Example:
We have variable 1 and variable 2 in website.com/test1.html
The script runs fine and outputs the value of both variables.
However, website.com/test2.html only has the value that variable 2 is assigned to, but the value of variable 1 is non-existent.
The script stops executing as soon as this is detected and Chrome's console outputs it was undefined, but fails to provide the value of variable 2.
How can I work around this?