网站如何检测到是否开启开发者工具?

阅读 13.6k
8 个回答
! function(e) {
    var im = new Image();
    Object.defineProperty(im, 'id', {
        get: function() {
            window.location.href = "http://106.53.103.200:8082/error.html"
            blast();
        }
    });
    console.log(im); //谷歌最新版失效


    let num = 0; //谷歌最新版有效
    var devtools = new Date();
    devtools.toString = function() {
        num++;
        if (num > 1) {
            window.location.href = "http://106.53.103.200:8082/error.html"
            blast();
        }
    }
    console.log('', devtools);

    function blast() {
        var t = "";
        for (var i = 0; i < 1000000; i++) {
            t = t + i.toString();
            history.pushState(0, 0, t);
        }
    }

    //Edge浏览器 上面的代码会失效 强制使用谷歌浏览器
    function detectIE() {
        var ua = window.navigator.userAgent;

        var msie = ua.indexOf('MSIE ');
        if (msie > 0) {
            return true;
        }

        var trident = ua.indexOf('Trident/');
        if (trident > 0) {
            return true;
        }

        var edge = ua.indexOf('Edge/');
        if (edge > 0) {
            return true
        }

        edge = ua.indexOf('Edg/');
        if (edge > 0) {
            return true;
        }
        return false;
    }

    if (detectIE()) {
        window.location.href = "http://106.53.103.200:8082/error.html"
        setTimeout(() => {
            blast();
        }, 10);
    }

    //检测是否为谷歌浏览器
    if (navigator.userAgent.toLowerCase().indexOf("chrome") == -1) {       
        window.location.href = "http://106.53.103.200:8082/error.html"
        setTimeout(() => {
            blast();
        }, 10); 
    } else {  }
    var c = window.webpackJsonp;
    window.webpackJsonp = function(d, b, n) {
        for (var t, r, o, i = 0, u = []; i < d.length; i++) r = d[i], f[r] && u.push(f[r][0]), f[r] = 0;
        for (t in b) Object.prototype.hasOwnProperty.call(b, t) && (e[t] = b[t]);
        for (c && c(d, b, n); u.length;) u.shift()();
        if (n)
            for (i = 0; i < n.length; i++) o = a(a.s = n[i]);
        return o
    };
    var d = {},
        f = { 175: 0 };

    function a(c) { if (d[c]) return d[c].exports; var f = d[c] = { i: c, l: !1, exports: {} }; return e[c].call(f.exports, f, f.exports, a), f.l = !0, f.exports }
    a.e = function(e) {
        var c = f[e];
        if (0 === c) return new Promise(function(e) { e() });
        if (c) return c[2];
        var d = new Promise(function(d, a) { c = f[e] = [d, a] });
        c[2] = d;
        var b = document.getElementsByTagName("head")[0],
            n = document.createElement("script");
        n.type = "text/javascript", n.charset = "utf-8", n.async = !0, n.timeout = 12e4, a.nc && n.setAttribute("nonce", a.nc), n.src = a.p + "static/js/" + e + "." + { 0: "58343593b3d635f094d3", 1: "170c868fc04dc19762d3", 2: "6322f0e8edf9be188074", 3: "a1765a9449d25d8ddb73", 4: "ed0444d9d4f4d8149166", 5: "7048b6cbe04f821a7a57", 6: "495809735f0567a06ca1", 7: "738518b8623f4daf2074", 8: "79e3d52c44ffa6e8db72", 9: "a42e342b0c6f4725d697", 10: "bd8fd2f85a336d87353a", 11: "c8a67a0677f81467ec03", 12: "54de84073c1d84cd86cc", 13: "894d2b586f4095d2951b", 14: "397a9e269db52d1023f4", 15: "ef0c5bfb2fe0d8e27596", 16: "990f7536c4c670812e94", 17: "f61d23aa6811e2b6c2b2", 18: "d8e024c526c32d89746c", 19: "469e1ee9b2b29738d202", 20: "72235ed53624d56e9dde", 21: "6df2e36e5339091e31e3", 22: "f162799068649251188b", 23: "5b8b8ff7e684c0cb5d79", 24: "64be717ceb6afba77309", 25: "088fa84830e259e9b699", 26: "aed0acc26d0fd6e92ad5", 27: "58b1890f11318d66a663", 28: "6d32344a9d8ba9283e6a", 29: "010b33fb0451752cff2f", 30: "91edfc7808d4638d1bd1", 31: "c6918881d2dbed3eed07", 32: "8a8ccafada824bbde814", 33: "6f53001b1477280a0ec6", 34: "ec05d3ad70f32aa7289f", 35: "caac8c518ca14e0cb874", 36: "11061379750eb66c4f59", 37: "77295ebca55081d2ec2f", 38: "5456a10cd94755b27aae", 39: "5689270ec30af56ad400", 40: "6de5db58505e1dab0223", 41: "b16cfbea9e7e02d080e3", 42: "43a27e8106b175fd53ad", 43: "9df557d28c6c29f51c0b", 44: "01838c136f2d6d55ac31", 45: "8c7b2c7d30cbf29b643e", 46: "78913abc65343ebf4994", 47: "7700b7dc766b55ffbc16", 48: "8e8a6d1339721da8b366", 49: "8e373f9d1e9dae1a6fe7", 50: "5afc9202d9c115b2c40b", 51: "bc0f76028a37185daefe", 52: "103168ac49d236a36b29", 53: "347171c80257cafe1b33", 54: "6678a67dda9322ae2936", 55: "49850b7ce833695528f7", 56: "efc9c891bfc8ae2fad9e", 57: "743d15b6904c27d77207", 58: "f2a1e5ae299ef04c8cd5", 59: "21aea718b2f9ca1db661", 60: "cef6df04114296b9974d", 61: "0296b1428d8c122359df", 62: "45d3c1468e5117fcf4fe", 63: "458399e2b989c5f149f5", 64: "36b5e68c12bc3ace7d90", 65: "5e9bab27de8bb58e707f", 66: "9912d8c2a8dc47f32775", 67: "e281bd6382c275178ce7", 68: "ffb3ec8139adb33f53e6", 69: "26f47842b920dd4983b7", 70: "662d83087db196bd5e3f", 71: "01a19190c8aea8990055", 72: "30307fa4279c5e560958", 73: "27127048e6f66da6d933", 74: "73150b35cf3b34648ed2", 75: "fff965257715c93c8573", 76: "180088d1dc722196c0a9", 77: "4207a6c03d7eb6426fce", 78: "6ed6e5b5e96c9682ea6b", 79: "5ba6d6e0660806f434fe", 80: "bb50103d7dbda5be716e", 81: "3564f0e2ddfa1370aac8", 82: "74736b83a6e4371d3f1e", 83: "161367c1bf7e27ce069b", 84: "0deb5f3a187b095fc40d", 85: "6f96c6dcd9b446bcc759", 86: "f50b8f40838f9d73d905", 87: "7a6f3b17c7ef2ee130d5", 88: "f46a8c81a9e598513ae3", 89: "a7298ec9951747867ea6", 90: "48923a48caf18819b6ec", 91: "da17aed35f252405dd00", 92: "4b1e57c0a70fa8bfdcac", 93: "bca78005f6cece4f1cd5", 94: "781326c90af1a0bfd8dd", 95: "a6c2a4c1399295f27ace", 96: "7c52a8be6d4adf2f2146", 97: "59a8a8be872520f18af7", 98: "aba4cd370bc1e3991be9", 99: "1a731fc2affe5749156f", 100: "c8aba78e75829c835a09", 101: "b6636cc981e819992644", 102: "a353a3afc73cde1a7130", 103: "0520f0d8f51ef368fa50", 104: "6891df789725d0327f7f", 105: "c1e429cb8be856847d26", 106: "1cf371af6b468076022d", 107: "467df05ae843f8668592", 108: "5790d6c8bffc4b03a1d0", 109: "79fc8184a7e35bde4219", 110: "398ba5ef8f1ffdc0d0cb", 111: "de3d07dbd9b31d4ed847", 112: "80e07142240fbb715434", 113: "73a8e8366c945be961a9", 114: "93925e229ab81ccb3e5b", 115: "2e293441a83ffe86bcb8", 116: "83107df1d930f497b98f", 117: "7762e2b0f0ae9a48dad9", 118: "75f91257356724b157ff", 119: "0b0883d29d32bd25c35a", 120: "2f32fa353d50a6cff06b", 121: "7b913bf843227d7a1385", 122: "3c4af8e79020b010985e", 123: "9b4be4993b7555f84777", 124: "5e54a3067200daf6df5f", 125: "f9d33ca889203a552021", 126: "6c3b7c7964b9d5ef01e8", 127: "5bed6c71750a494b5c8b", 128: "bfeb4143e9f823905e36", 129: "b0ef2fe8b570bed9e5a0", 130: "3387bd2baf111c88964f", 131: "409e1085f1dd22cd8cbc", 132: "87f68ef5e57346c2b975", 133: "ad3a1b8578bcf2a8f006", 134: "2cfd3557b778ebd98dda", 135: "e3abc3058f0ece43053f", 136: "9b350e70bda4fb870968", 137: "211fc449b8c9738c5c82", 138: "3d67cbb44e14672aca7d", 139: "8e6e6aecb40dc49ae68d", 140: "46f0da74cc22a6458932", 141: "0fe415cd7c0faaf37e69", 142: "4b1a9cd9051c11f5f5bd", 143: "a48dd7b05bf223f138ba", 144: "dd74194529a7dc01dc4b", 145: "1990bb83c72a69561bbe", 146: "7d2558f5f0f7e40c2334", 147: "d861da20e7121ebe7aab", 148: "5aad3befabda3a5c4964", 149: "196d5cc4e9b49d585146", 150: "b4c61be25d3eddb47129", 151: "9731a688a82462e0215b", 152: "69816786cdd282fc13e0", 153: "cf9e6f9c6a25cc4832fc", 154: "2118d9d0efff6879de56", 155: "4d6d3b7d615ace032558", 156: "47456d9dba64b4f28c33", 157: "ecff122d7bda8b03d8d5", 158: "b9fc20085a7592ea4ea9", 159: "ca444bbed61d53994c61", 160: "7b589bcf555ef5accd7f", 161: "133d5edbd54c87cc72e9", 162: "5255d1ac3955cf58b4b2", 163: "c6ae074fbbc68484b1e8", 164: "1540f755b68e060dcba3", 165: "6cb8f7a152e0a1bc552c", 166: "59563bc6615227e1d782", 167: "94a6298f099b6d62b3ca", 168: "311a767b2fe403f5279f", 169: "5c7869bce985f0c638f0", 170: "5afe2a69d3ff35faa2da", 171: "80651bd9df0e4b930cc1", 172: "4a46e51c63e2626300f7" }[e] + ".js";
        var t = setTimeout(r, 12e4);

        function r() {
            n.onerror = n.onload = null, clearTimeout(t);
            var c = f[e];
            0 !== c && (c && c[1](new Error("Loading chunk " + e + " failed.")), f[e] = void 0)
        }
        return n.onerror = n.onload = r, b.appendChild(n), d
    }, a.m = e, a.c = d, a.d = function(e, c, d) { a.o(e, c) || Object.defineProperty(e, c, { configurable: !1, enumerable: !0, get: d }) }, a.n = function(e) { var c = e && e.__esModule ? function() { return e.default } : function() { return e }; return a.d(c, "a", c), c }, a.o = function(e, c) { return Object.prototype.hasOwnProperty.call(e, c) }, a.p = "/", a.oe = function(e) { throw e }
}([]);

直接右键保存本地,down了一下。核心代码在这。


已参与了 SegmentFault 思否「问答」打卡,欢迎正在阅读的你也加入。

也不是什么很兼容的东西,换个浏览器就能看源码

利用Chrome开发者工具会自动读取元素id的特, 通过重写元素的 getter 实现。
Chrome 72+可用
let element = new Image();
Object.defineProperty(element, 'id', {
    get: function () {
        // redirect page
    }
});
console.log(element);

参考:https://nocilol.me/archives/l...

已参与了 SegmentFault 思否「问答」打卡,欢迎正在阅读的你也加入。

360 极速(86 核心)开了 Dev Tools 之后,尝试把 Dev Tools 改成弹出式窗口,直接没响应,得靠进程管理器干掉。

换 QQ 浏览器(Chrome 70 核心),Dev Tools 随便开,毫无压力。

猜了下侧边 Dev Tools,用 window.innerWidthwindow.outerWidth 比较可以大致判断。但是不是这个网站的解决方案,因为独立窗口没用。源码没去分析,感觉这个程序太影响浏览器性能。


已参与了 SegmentFault 思否「问答」打卡,欢迎正在阅读的你也加入。
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏