在 Javascript 中覆盖本机方法
我正在对一些 Javascript 进行一些分析,我想保持 javascript 启用,但禁用所有alert() 框和 self.location 重定向。
目前我正在使用正则表达式代理,但这似乎有点矫枉过正。
我可以覆盖一些本机方法,但不能覆盖 Firefox 中的其他方法,
window.alert = function('') { return null; }
alert('test!') // works as expected
但是当我尝试类似地覆盖 window.location = (这是方法调用 window.assign() 的别名)时,它不起作用,
window.location.assign = function('') { return null; }
window.location.assign('#') // redirects :(
我尝试设置 Window.prototype .location.assign 但我收到“无法修改 WrappedNative 的属性”异常。
对于细粒度 JS 控制,是否有 NoScript 的替代方案,或者是否可以覆盖某些 Native JS 方法?
I'm doing some analysis of some Javascript and I want to keep javascript enabled, but disable all alert() boxes and self.location redirects.
Currently I'm using a regex proxy, but that seems like overkill.
I can override some native methods but not others in Firefox i.e.
window.alert = function('') { return null; }
alert('test!') // works as expected
However when I try to similarly overwrite window.location = (which is an alias for the method call window.assign() ) it does not work
window.location.assign = function('') { return null; }
window.location.assign('#') // redirects :(
I've tried setting Window.prototype.location.assign but i get a "Cannot modify properties of a WrappedNative" exception.
Any alternatives to NoScript for fine grained JS control, or is it possible to overwrite certain Native JS methods?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此建议的解决方案禁用
alert
可能会起作用。This suggested solution for disabling
alert
might work.