Anti-Disable-Devtool

Intercepts scripts from disabling devtools.

  1. // ==UserScript==
  2. // @name Anti-Disable-Devtool
  3. // @description Intercepts scripts from disabling devtools.
  4. // @author Snipcola
  5. // @namespace https://snipcola.com
  6. // @license MIT
  7. // @match *://*/*
  8. // @version 1.0
  9. // @run-at document-start
  10. // ==/UserScript==
  11.  
  12. const blacklistedHooks = ["contextmenu"];
  13. const blacklistedScripts = ["disabledevtool", "disable-devtool", "disableinspect", "disable-inspect", "blockdevtool", "block-devtool", "blockinspect", "block-inspect"];
  14.  
  15. const name = "Anti-Disable-Devtool";
  16. const originalAddEventListener = document.addEventListener;
  17.  
  18. document.addEventListener = function (type, listener, options) {
  19. if (blacklistedHooks.includes(type)) console.error(`[${name}] Intercepted event from being hooked:`, { type, listener });
  20. else originalAddEventListener.call(document, type, listener, options);
  21. };
  22.  
  23. function observe () {
  24. if (!document.documentElement) {
  25. setTimeout(observe, 10);
  26. return;
  27. }
  28.  
  29. new MutationObserver((mutations) => {
  30. mutations.forEach(({ addedNodes }) => {
  31. addedNodes.forEach((node) => {
  32. if (node.nodeType === 1 && node.tagName === "SCRIPT" && blacklistedScripts.map((s) => node.src?.includes(s)).includes(true)) {
  33. node.type = "javascript/intercepted";
  34. node.remove();
  35. console.error(`[${name}] Intercepted script from being executed:`, { node, source: node.src });
  36. }
  37. });
  38. });
  39. }).observe(document.documentElement, {
  40. childList: true,
  41. subtree: true
  42. });
  43. }
  44.  
  45. observe();