@juraj.masiar Like I said, using const or let didn’t work as the unregister action is in a different fucntion, so there is a scoping issues. I don’t really want to use window variables but struggling to see what other options I have.
I think my code works okay in general (so no debugging necessary), I just need to understand if (and hopefully how) I can re-register a userScript once it has it has been un-registered. Or, failing that; know a way to clear off all the existing userScript so it cannot re-trigger again so I can add it in afresh when the user toggles the feature back on. That is my only remaining issue is that when I un-register and then add a new register action it fires the script twice, then if I disable and re-enable the feature another time then I get three hits and so on.
Yeah we are actually firing remote code, but it is a secure script for our technology only. I get why they are restricting it, but as we already have had this feature for many years that our customers rely on, we want to ensure we can keep this option available to them for as long as possible.