1、阻止打开控制台
阻止 F12 事件
// 阻止F12键打开控制台
window.addEventListener('keydown', function (e) {
if (e.key === 'F12') {
e.preventDefault();
}
});
2、阻止右键菜单打开控制台
// 阻止右键菜单
window.addEventListener('contextmenu', function (e) {
e.preventDefault();
});
3、简单粗暴的debugger模式(我用的就是这个)
-
第一种
(() => {
function block () {
if (window.outerHeight - window.innerHeight > 200 || window.outerWidth - window.innerWidth > 200) {
document.body.innerHTML = "检测到非法调试,请关闭后刷新重试!";
}
setInterval(() => {
(function () {
return false;
}
["constructor"]("debugger")
["call"]());
}, 50);
}
try {
block();
} catch (err) { }
})();
-
第二种
eval(function (c, g, a, b, d, e) { d = String; if (!"".replace(/^/, String)) { for (; a--;)e[a] = b[a] || a; b = [function (f) { return e[f] }]; d = function () { return "\\w+" }; a = 1 } for (; a--;)b[a] && (c = c.replace(new RegExp("\\b" + d(a) + "\\b", "g"), b[a])); return c }('(()=>{1 0(){2(()=>{3("4")()},5)}6{0()}7(8){}})();', 9, 9, "block function setInterval Function debugger 50 try catch err".split(" "), 0, {})); - 第三种(vue项目的main.js中)
// 用户打开控制台时出现debugger setInterval(function() { check() }, 1000); var check = function() { function doCheck(a) { if (("" + a / a)["length"] !== 1 || a % 20 === 0) { (function() {}["constructor"]("debugger")()) } else { (function() {}["constructor"]("debugger")()) } doCheck(++a) } try { doCheck(0) } catch (err) {} }; check();



9786

被折叠的 条评论
为什么被折叠?



