For most of my code in my userscript, I'm need to use unsafeWindow
for the websites my script executes on. I do this by using // @grant unsafeWindow
. However, some of my code cannot be executed with unsafeWindow
and needs to run in Tampermonkey's isolated sandbox. How would I be able to do this? Something like this could work:
function disableUnsafeWindow() {
// Disable UnsafeWindow
}
function enableUnsafeWindow() {
// Enable unsafeWindow
}
function withUnsafeWindow() {
enableUnsafeWindow()
// Run the code using unsafeWindow
}
function withoutUnsafeWindow() {
disableUnsafeWindow();
// Remove unsafeWindow access and execute the code without unsafeWindow
}
withUnsafeWindow()
withoutUnsafeWindow()