【发布时间】:2021-01-03 00:01:02
【问题描述】:
对于我的用户脚本中的大部分代码,我需要在我的脚本执行的网站上使用unsafeWindow。我通过使用// @grant unsafeWindow 来做到这一点。但是,我的一些代码无法使用unsafeWindow 执行,需要在 Tampermonkey 的隔离沙箱中运行。我怎么能做到这一点?像这样的东西可以工作:
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()
【问题讨论】:
标签: javascript function sandbox execution userscripts