Global Anti-Debugger

Removes and neutralizes any `debugger;` commands before the site runs them

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Global Anti-Debugger
// @namespace    https://github.com/FabioSmuu
// @version      1.0
// @description  Removes and neutralizes any `debugger;` commands before the site runs them
// @author       Fabio Smuu
// @match        *://*/*
// @run-at       document-start
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
  'use strict'

  const originalConstructor = Function.prototype.constructor
  Function.prototype.constructor = function(...args) {
    const code = args.join('')
    const sanitized = code.replace(/\bdebugger\s*;?/gi, '')
    return originalConstructor.call(this, sanitized)
  }

  const originalEval = window.eval
  window.eval = function(code) {
    if (typeof code === 'string') code = code.replace(/\bdebugger\s*;?/gi, '')
    return originalEval(code)
  }

  const observer = new MutationObserver(mutations => {
    mutations.forEach(mutation => {
      mutation.addedNodes.forEach(node => {
        if (node.tagName === 'SCRIPT' && node.textContent.includes('debugger')) {
          node.textContent = node.textContent.replace(/\bdebugger\s*;?/gi, '')
        }
      })
    })
  })

  observer.observe(document.documentElement, { childList: true, subtree: true })
})()