Bypass CDP Detection

2025/3/23 14:17:37

  1. // ==UserScript==
  2. // @name Bypass CDP Detection
  3. // @namespace http://fulicat.com
  4. // @author Jack.Chan (971546@qq.com)
  5. // @version 1.0.2
  6. // @run-at document-start
  7. // @match *://*/*
  8. // @match file:///*
  9. // @url https://greasyfork.org/zh-CN/scripts/530590-bypass-cdp-detection
  10. // @grant none
  11. // @description 2025/3/23 14:17:37
  12. // @license MIT
  13. // ==/UserScript==
  14.  
  15.  
  16.  
  17.  
  18.  
  19. ;(function() {
  20.  
  21. var originalError = Error;
  22.  
  23. // Lock down the stack property on Error.prototype to prevent modification
  24. Object.defineProperty(Error.prototype, 'stack', {
  25. configurable: false,
  26. enumerable: true,
  27. writable: false,
  28. value: (function() {
  29. try {
  30. throw new originalError();
  31. } catch (e) {
  32. return e.stack;
  33. }
  34. })()
  35. });
  36.  
  37. // Proxy the Error constructor to prevent any instance-specific stack modifications
  38. window.Error = new Proxy(originalError, {
  39. construct(target, args) {
  40. return originalError(...args);
  41. try {
  42. var instance = new target(...args);
  43. // Freeze the instance to prevent any modifications
  44. return Object.freeze(instance);
  45. } catch(ex) {
  46. console.log('// [bypass_CDP_Detection] ex:', ex);
  47. }
  48. return originalError(...args);
  49. }
  50. });
  51.  
  52.  
  53. // Override Object.defineProperty
  54. var stackLookupCount = 0;
  55. var originalObjectDefineProperty = Object.defineProperty;
  56. Object.defineProperty = function defineProperty(obj, prop, descriptor) {
  57. if (prop === 'stack') {
  58. if (stackLookupCount < 10) {
  59. console.log('// [bypass_CDP_Detection] Object.defineProperty', stackLookupCount, String.fromCharCode(10), 'obj:', obj, String.fromCharCode(10), 'prop:', prop, String.fromCharCode(10), 'descriptor:', descriptor, String.fromCharCode(10), String.fromCharCode(10), String.fromCharCode(10) );
  60. } else {
  61. console.log('// [bypass_CDP_Detection] Object.defineProperty', 'too many times');
  62. }
  63. stackLookupCount++;
  64. return {};
  65. }
  66. return originalObjectDefineProperty.apply(Object, arguments);
  67. }
  68. Object.defineProperty.toString = function toString() {
  69. return originalObjectDefineProperty.toString();
  70. };
  71.  
  72.  
  73. // bypass https://kaliiiiiiiiii.github.io/brotector/
  74. const context = console.context;
  75. console.context = function() {
  76. return {
  77. ...console,
  78. clear(){},
  79. log(){},
  80. debug(){},
  81. }
  82. };
  83. console.context.toString = function() {
  84. return context.toString();
  85. }
  86.  
  87.  
  88. // alert('bypass_CDP_detection injected');
  89. })();