如何用usercript完全禁用所有退出警告/确认消息? [英] How to completely disable all exit warning/confirm messages with userscript?

查看:101
本文介绍了如何用usercript完全禁用所有退出警告/确认消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在隔离环境中使用chrome来扫描恶意网站以分析其数据以创建黑名单。用户脚本和浏览器扩展程序完全自动完成此过程。

I am using chrome in an isolated environment to scan malicious websites to analyze their data to create blacklists. This process is completely automated by userscripts and browser extensions.

问题是某些网站能够在之前显示退出对话框卸载(我将这些称为事件)。

The problem is that some sites are able to show an exit dialog on beforeunload or unload (I will refer to these as events).

我已经覆盖了这些事件,但是当网站再次覆盖我的覆盖时,整个过程就会停止。我的意思是他们可以使用AJAX调用,混淆脚本,evals等重新定义事件

I already override these events, but when the site override my override again, the whole process stops. I mean they can redefine the events with AJAX calls, obfuscated scripts, evals, etc.

有没有办法摆脱这些消息,或保护我的覆盖?
也许unsafeWindow会处理这个,但我会避免在这个讨厌的环境中使用它。

Is there any way to get rid of these messages, or protect my override? Maybe unsafeWindow would handle this, but I would avoid to use it in this nasty environment.

编辑 - 目前我用这个我的用户名中的代码:

EDIT - Currently I use this code in my userscript:

location.href = "javascript:(" + function() {
    window.onbeforeunload = null;
    window.onunload = null;
} + ")()";

setInterval(function(){
    location.href = "javascript:(" + function() {
        window.onbeforeunload = null;
        window.onunload = null;
    } + ")()";
}, 3000);


推荐答案

尝试 Object.defineProperty

Object.defineProperty(window, 'onunload', { 
    value: null,
    configurable: false
});

window.onunload = 1;

window.onunload;
// null

可配置设置为false表示无法更改属性。

configurable is set to false which means the property can't be changed.

这篇关于如何用usercript完全禁用所有退出警告/确认消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆