Javascript 网站检测devtools。代码附在网站源代码中的DevToolDectect.js文件后

Javascript 网站检测devtools。代码附在网站源代码中的DevToolDectect.js文件后,javascript,google-chrome-devtools,Javascript,Google Chrome Devtools,我不是开发人员,对Javascript代码有非常基本的理解。我试图打开网站上的开发工具,但它检测到开发工具已打开,并弹出一个写为“DevTools detected”的弹出窗口,然后在我按ok后关闭网站选项卡。这是源代码中名为devtooldetext.js的文件。我试图理解它是如何检测到devtools已被打开的,即使在菜单未锁定的情况下也是如此。如果问题中有问题,请告诉我,以便我可以提供所需的任何信息。 我不需要逐行解释,只要一个摘要就行了。 谢谢 对于非Chrome浏览器和基于Chrome

我不是开发人员,对Javascript代码有非常基本的理解。我试图打开网站上的开发工具,但它检测到开发工具已打开,并弹出一个写为“DevTools detected”的弹出窗口,然后在我按ok后关闭网站选项卡。这是源代码中名为devtooldetext.js的文件。我试图理解它是如何检测到devtools已被打开的,即使在菜单未锁定的情况下也是如此。如果问题中有问题,请告诉我,以便我可以提供所需的任何信息。 我不需要逐行解释,只要一个摘要就行了。 谢谢


对于非Chrome浏览器和基于Chrome的浏览器使用
devtools
对象,看起来像是历史上发展起来的启发式尝试和错误

对于非Chrome浏览器,它通过计算浏览器窗口中是否有一部分不显示网页,并且可能足够大,可以托管devtools来进行一些猜测,它还检查任何明智的devtools的光荣教父的踪迹,尽管现在仍然找到它的可能性非常非常低

在Chrome的一个简短测试中,该脚本无法检测到分离的devtools窗口


感觉受邀深入了解这些提示。你可能会学到很多,至少考虑到这是一个人类知道的Sindre Sorhus脚本。

谢谢你的回复,我终于能够阻止网站检测到DevTools(未锁定)。在我每次打开devtools之前,我都会看到一个覆盖图,上面写着“暂停在调试器中”,无论devtools是停靠的还是未停靠的。解决方案是在devtools完全加载之前按ctrl+f8(取消激活断点的快捷键)。如果我等待devtools完全加载,叠加会再次出现,在按下resume script execution(恢复脚本执行)后,网站选项卡会在弹出消息“devtools detected”(devtools检测到)后自动关闭。不知道为什么它有效,但它有效。
/*!
devtools-detect
Detect if DevTools is open
https://github.com/sindresorhus/devtools-detect
By Sindre Sorhus
MIT License
*/
(function () {
    'use strict';

    const devtools = {
        isOpen: false,
        orientation: undefined
    };

    const threshold = 160;

    const emitEvent = (isOpen, orientation) => {
        window.dispatchEvent(new CustomEvent('devtoolschange', {
            detail: {
                isOpen,
                orientation
            }
        }));
    };

    const main = ({emitEvents = true} = {}) => {
        const widthThreshold = window.outerWidth - window.innerWidth > threshold;
        const heightThreshold = window.outerHeight - window.innerHeight > threshold;
        const orientation = widthThreshold ? 'vertical' : 'horizontal';

        if (
            !(heightThreshold && widthThreshold) &&
            ((window.Firebug && window.Firebug.chrome && window.Firebug.chrome.isInitialized) || widthThreshold || heightThreshold)
        ) {
            if ((!devtools.isOpen || devtools.orientation !== orientation) && emitEvents) {
                emitEvent(true, orientation);
            }

            devtools.isOpen = true;
            devtools.orientation = orientation;
        } else {
            if (devtools.isOpen && emitEvents) {
                emitEvent(false, undefined);
            }

            devtools.isOpen = false;
            devtools.orientation = undefined;
        }
    };

    main({emitEvents: false});
    setInterval(main, 500);

    if (typeof module !== 'undefined' && module.exports) {
        module.exports = devtools;
    } else {
        window.devtools = devtools;
    }
})();