当前位置:网站首页>谈谈基于JS实现阻止别人调试通过控制台调试网站的问题
谈谈基于JS实现阻止别人调试通过控制台调试网站的问题
2022-07-28 09:56:00 【InfoQ】
前言
- F12
- 右键==》检查
- 浏览器==》更多工具==》开发者工具(快捷键:ctrl+shift+i)
阻止打开控制台
阻止F12事件
window.onkeydown = window.onkeyup = window.onkeypress = function (event) {
// 判断是否按下F12,F12键码为123
if (event.keyCode = 123) {
event.preventDefault() // 阻止默认事件行为
window.event.returnValue = false
}
}

阻止右键事件
oncontextmenuwindow.oncontextmenu = function() {
event.preventDefault() // 阻止默认事件行为
return false
}

JS操作控制台
浏览器==》更多工具==》开发者工具(快捷键:ctrl+shift+i)定时检查浏览器窗口变化
let threshold = 160 // 打开控制台的宽或高阈值
window.setInterval(function() {
if (window.outerWidth - window.innerWidth > threshold ||
window.outerHeight - window.innerHeight > threshold) {
// 如果打开控制台,则刷新页面
window.location.reload()
}
}, 1000)

打开控制台弹窗,启用调试debug调试
debuggerdebuggerdebugger第一种debug调试
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();

第二种debug调试
if(window.location.href.indexOf('#debug')==-1){
setInterval(function(){
(function (a) {return (function (a) {return (Function('Function(arguments[0]+"' + a + '")()'))})(a)})('bugger')('de', 0, 0, (0, 0))
}, 1000)
}

打开控制台提示(可实现跳转url或刷新)
function toDevtools(){
let num = 0
var devtools = new Date()
devtools.toString = function() {
num++;
if(num>0){
alert('控制台打开了')
// 可以写刷新或者跳转的逻辑
}
}
console.log(devtools);
}
toDevtools()

后记
边栏推荐
猜你喜欢
![[ESP32][esp-idf] esp32s3快速搭建LVGLV7.9](/img/39/8efef047d0a9223b97819a54b5edf8.png)
[ESP32][esp-idf] esp32s3快速搭建LVGLV7.9

并查集

Digital construction of pharmaceutical industry is on the verge

Extreme deflation and perpetual motion machine model will promote the outbreak of platofarm
JWT 登录认证 + Token 自动续期方案,写得太好了!

【JZOF】14剪绳子

In hot weather, the line of defense for safe production was strengthened, and Guangzhou Haizhu District carried out emergency drills for gas stations

21. 合并两个有序链表

Basic examples that must be mastered by beginners of C #

Installing MySQL for Linux operating system (centos7)
随机推荐
Several innovative economic models of platofarm have inspired the current metacosmic market
Xiao Hei stands up again and looks at leetcode:653. Sum of two IV - enter BST
Edge team explains how to improve the comprehensive performance experience through disk cache compression technology
腾讯技术专家:解密亿级用户产品 微信、QQ、王者荣耀...全面上云实践!
Pycharm uses CONDA to call the remote server
[learning notes] border and period
【JZOF】15二进制中1的位数
Skiasharp's WPF self drawn drag ball (case version)
The victory of Dao community, tiger Dao VC wins in governance and consensus
【MySQL】查询多个ID返回字符串拼接
银行入职考试要点汇总
LinkedList源码按摩,啊舒服
为报复公司解雇,我更改了项目的所有代码注释!
我用小程序容器让移动研发效率提升了5倍!
ADVANCE.AI出海指南助力企业出海印尼,掌握东南亚市场半边天
工业品MRO采购网站有哪些优势?一文带你读懂
双指针技巧
leetcode——旋转数组的最小数字
Redis面试题必知必会
uni-app进阶之创建组件/原生渲染