DevTools Anti-Detector

Simple tool to temporarily prevent site from using popular methods of DevTools detection. Do not leave enabled!

  1. // ==UserScript==
  2. // @name DevTools Anti-Detector
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3
  5. // @description Simple tool to temporarily prevent site from using popular methods of DevTools detection. Do not leave enabled!
  6. // @author lainverse
  7. // @match *://*/*
  8. // @grant unsafeWindow
  9. // @run-at document-start
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. let knownRoots = new WeakSet();
  16. function wrapRegExp(root) {
  17. if (knownRoots.has(root))
  18. return;
  19. let _proto = void 0;
  20. try {
  21. _proto = root.RegExp.prototype;
  22. } catch(ignore) {
  23. return;
  24. }
  25. // Prevent RegExpt + toString trick (technically possible with any other object, but I encountered only this one
  26. let _RE_tS = Object.getOwnPropertyDescriptor(_proto, 'toString');
  27. let _RE_tSV = _RE_tS.value || _RE_tS.get();
  28. let fts = Function.prototype.toString;
  29. Object.defineProperty(_proto, 'toString', {
  30. enumerable: _RE_tS.enumerable,
  31. configurable: _RE_tS.configurable,
  32. get: () => _RE_tSV,
  33. set: function(val) {
  34. console.warn('Attempt to change toString for', this, 'with', fts.call(val));
  35. //throw 'stop it!';
  36. return true;
  37. }
  38. });
  39. }
  40.  
  41. wrapRegExp(unsafeWindow);
  42.  
  43. let _contentWindow = Object.getOwnPropertyDescriptor(HTMLIFrameElement.prototype, 'contentWindow');
  44. let _get_contentWindow = _contentWindow.get;
  45. _contentWindow.get = function() {
  46. let _cw = _get_contentWindow.apply(this, arguments);
  47. if (_cw)
  48. wrapRegExp(_cw);
  49. return _cw;
  50. };
  51. Object.defineProperty(HTMLIFrameElement.prototype, 'contentWindow', _contentWindow);
  52. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址