Closed mouday closed 8 months ago
破案了
解决方法:取消自动授权,让js运行在window环境中,而非unsafeWindow
monkey({
userscript: {
grant: 'none',
},
build: {
autoGrant: false,
}
})
最后打包出的产物
// @grant none
昨日遇到的坑。当脚本中调用window时,若grant unsafeWindow,则window是tampermonkey虚拟出来的一个不完全的window,里面东西少很多。
若要使用完整window,则要grant none。
参考:
这个 window.event = windowEvent;
是哪个框架的代码?
如果是库的话,写个 vite plugin 在这些用到 window 的代码文件上加一个 import {unsafeWindow as window} from '$'
就行
具体也可参考 https://github.com/lisonge/vite-plugin-monkey/issues/139
reactv18.2.0 work in chrome v122, also has this error.
window.event = windowEvent;
TypeError: Cannot set property event of # which has only a getter