晓杰最近在研究如何防止用户恶意调试前端网页代码,防止打开控制台进行调试,首先禁用了浏览器页面右键事件和F12等快捷键!然后利用了创建元素是否成功方式进行校验,具体实现代码如下。
<script disable-devtool-auto src='https://cdn.jsdelivr.net/npm/disable-devtool'></script>
<script >
document.addEventListener('keydown', function(event) {
// 检查 F12 键
if (event.key === 'F12') {
event.preventDefault();
}
// 检查 Ctrl + Shift + I 组合键
if (event.ctrlKey && event.shiftKey && event.key === 'i') {
event.preventDefault();
}
// 检查 Ctrl + Shift + J 组合键
if (event.ctrlKey && event.shiftKey && event.key === 'j') {
event.preventDefault();
}
// 检查 Ctrl + Shift + C 组合键
if (event.ctrlKey && event.shiftKey && event.key === 'c') {
event.preventDefault();
}
});
document.addEventListener('contextmenu', function(event) {
event.preventDefault();
});
var ConsoleManager={
onOpen(){
},
onClose(){
},
init(){
var self = this;
var x = document.createElement('div');
var isOpening = false,isOpened=false;
Object.defineProperty(x, 'id', {
get(){
if(!isOpening){
self.onOpen();
isOpening=true;
}
isOpened=true;
}
});
setInterval(function(){
isOpened=false;
console.info(x);
console.clear();
if(!isOpened && isOpening){
self.onClose();
isOpening=false;
}
},200)
}
}
//检测到打开 直接跳转到其他网址 或者做其他方式自己改
ConsoleManager.onOpen = function(){
location.href="https://125.confly.eu.org/";
}
ConsoleManager.init();
DisableDevtool({
ondevtoolopen: (type) => {
const info = 'devtool opened!; type =' + type;
},
})
</script>
Soujer
chenyuqi1230 发表于 2024-8-19 20:44
无痕访问,就能正常进了,昨天刚给朋友测试了
12121212.png (213.33 KB, 下载次数: 48)
Awesome·LYG 发表于 2024-8-20 07:51
所以检查快捷键有啥用。。。
https://github.com/theajack/disable-devtool
无敌灰灰 发表于 2024-8-20 09:41
别自己写了,直接用这个
Awesome·LYG 发表于 2024-8-20 07:51
所以检查快捷键有啥用。。。
Awesome·LYG 发表于 2024-8-20 16:05
这不还是。。。
Awesome·LYG 发表于 2024-8-20 16:05
这不还是。。。
开发人员工具.gif (2.44 MB, 下载次数: 47)
2.png (372.13 KB, 下载次数: 44)
Awesome·LYG 发表于 2024-8-20 18:22
[quote]郝单纯
郝单纯💋 发表于 2024-8-21 09:17
浏览器什么版本
Awesome·LYG 发表于 2024-8-21 10:02
Microsoft Edge
版本 127.0.2651.105 (正式版本) (64 位)
Awesome·LYG 发表于 2024-8-21 16:27
无痕模式不会加载js
ctrl+F5刷新的会检测开发人员工具自动关闭页面。
欢迎光临 精易论坛 (https://125.confly.eu.org/) | Powered by Discuz! X3.4 |