首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >网站检测到devtools。代码是附加的DevToolDectect.js文件从网站来源

网站检测到devtools。代码是附加的DevToolDectect.js文件从网站来源
EN

Stack Overflow用户
提问于 2021-05-22 18:23:51
回答 1查看 158关注 0票数 0

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

代码语言:javascript
复制
/*!
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;
    }
})();
EN

回答 1

Stack Overflow用户

发布于 2021-05-22 19:08:33

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

对于非Chrome浏览器,它会通过计算浏览器窗口中是否有一部分不显示网页,是否足够大来托管devtools来进行一些猜测,它还会检查Firebug的痕迹,尽管现在仍然有非常非常低的概率找到它。

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

我觉得很受邀请来深入了解这些提示。你可能会学到很多,至少考虑到这是Sindre Sorhus的脚本,人类知道的man with the most npm packages and GitHub repos

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67648393

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档