diff --git a/frontend/app.html b/frontend/app.html index dcaafd9..fcbfaae 100644 --- a/frontend/app.html +++ b/frontend/app.html @@ -12,14 +12,15 @@ if (isDebugMode) return; // 调试模式下跳过检测 let devtoolsOpen = false; + let checkCount = 0; // 检测次数计数器 - // 方法1: Console对象toString检测(最有效) + // 方法1: Console对象toString检测(最可靠) const checkElement = /./; checkElement.toString = function() { devtoolsOpen = true; }; - // 方法2: debugger暂停检测 + // 方法2: debugger暂停检测(可能误判,需要多次确认) function detectDebugger() { const start = performance.now(); debugger; @@ -27,12 +28,34 @@ return (end - start) > 100; } - // 立即检测 - console.log('%c', checkElement); - console.clear(); + // 方法3: 窗口尺寸检测(辅助判断) + function detectWindowSize() { + const widthDiff = window.outerWidth - window.innerWidth; + const heightDiff = window.outerHeight - window.innerHeight; + // 提高阈值,避免误判 + return widthDiff > 200 || heightDiff > 200; + } - if (devtoolsOpen || detectDebugger()) { - // 立即阻止页面渲染 + // 综合检测(需要多个条件同时满足才判定) + function checkDevTools() { + devtoolsOpen = false; + console.log('%c', checkElement); + console.clear(); + + const consoleOpen = devtoolsOpen; + const debuggerPause = detectDebugger(); + const windowSizeAbnormal = detectWindowSize(); + + // 严格判定:console检测为主,其他为辅助 + // 只有console明确检测到才触发警告 + return consoleOpen && (debuggerPause || windowSizeAbnormal); + } + + // 立即检测(页面加载时) + const initialCheck = checkDevTools(); + + if (initialCheck) { + // 检测到开发者工具,显示警告 document.write(''); document.write('
如需使用开发者工具,请联系管理员开启调试模式
'); document.write('