@juraj.masiar I think I need to simplify my issue a bit to find out whether this option is feasible for my use-case.
This is a simplified view of my set-up:
/* Inject Function */
async function insertBootstrap(e) {
var host = "nexus.ensighten.com",
clientId = "client_id",
space = "test_space";
if(!window.insertBootstrapReg){
window.insertBootstrapReg = await browser.userScripts.register({
matches: ["<all_urls>"],
js: [{ code: 'link=document.createElement(\'script\'); link.src=\'https://' + host + '/' + clientId + "/" + space + '/Bootstrap.js\';document.getElementsByTagName(\'head\')[0].appendChild(link);' }]
});
}
}
/* Remove Inject */
async function removeInsert() {
if(window.insertBootstrapReg){
window.insertBootstrapReg.unregister();
}
}
The top function is called whenever the user selects the inject functionality of the extension.
The remove function is called whenever the inject option is turned off or changed to another rival feature (like re-write an existing on-page Bootstrap script or block existing Bootstrap).
If you mocked up something similar, you will see what is happening to me too. Essentially once the script is unregistered, then any redeclaration of the a userScript using the same variable name will not work. So essentially I would need a way to create a brand new userScript variable for each time I need to toggle the feature on which doesnât seem very maintainable.
Given this summary, how would you suggest to move forward with this or another solution to allow our users to toggle the feature on and off on demand without any issues?