@juraj.masiar I understand it must be frustrating for you all this back and forth. But my JS knowledge is fine in general, it is just that the tips you have sent do not fully work for my use-case at the moment. I am sure if we did a screenshare that we would probably find the tiny nuance that I am missing specific for my use-case.
With your recent updates I can definitely see it firing (though the fetch version doesn’t work, no errors, so I stuck with the script HTML method). But when you unregister and then refresh the page, the script still comes through, so the unregister stop a new one coming through, but doesn’t remove the old ones previously injected.
You did mention before that some things in the DOM cannot be removed. So that leave us with trying to get the fetch
version working I guess. This is what I have at the moment (light example version again):
/* Inject Bootstrap */
var insertBootstrapReg = null;
async function insertBootstrap(e) {
var host = "nexus.ensighten.com",
clientId = "client_id",
space = "test_space";
const insertBootstrapFetch = await (await fetch('https://' + host + '/' + clientId + space + '/Bootstrap.js')).text();
insertBootstrapReg = await browser.userScripts.register({
matches: ["<all_urls>"],
js: [{ code: `(() => { ${insertBootstrapFetch} })();` }]
});
}
}
/* Remove Inject */
function removeInsert() {
if (insertBootstrapReg) {
insertBootstrapReg.unregister();
insertBootstrapReg = null;
}
}
I get no errors at all, so we can rule out syntax being the cuplrit, maybe you can see what could be causing it not to work?