gptLogsremove.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. (function () {
  2. // Store original console methods
  3. const originalLog = console.log;
  4. const originalWarn = console.warn;
  5. const originalError = console.error;
  6. // Override console methods
  7. function filterLogs(logMethod, type) {
  8. // return () => {}
  9. return function (...args) {
  10. const stack = new Error().stack.split("\n")[2]; // Get caller stack
  11. if (stack.includes("<anonymous>") || stack.includes("iframe")) {
  12. originalError('aaaaaaaa')
  13. logMethod.apply(console, args); // Only log if it's from an iframe
  14. }
  15. };
  16. }
  17. console.log = filterLogs(originalLog, "log");
  18. console.warn = filterLogs(originalWarn, "warn");
  19. console.error = filterLogs(originalError, "error");
  20. // Suppress errors not originating from the iframe
  21. window.onerror = function (message, source, lineno, colno, error) {
  22. alert('aokk')
  23. if (source.includes("iframe")) {
  24. originalError(message, source, lineno, colno, error)
  25. return true; // Block non-iframe errors
  26. }
  27. };
  28. // Suppress unhandled promise rejections from the main page
  29. window.onunhandledrejection = function (event) {
  30. if (event.reason.stack && !event.reason.stack.includes("iframe")) {
  31. event.preventDefault();
  32. }
  33. };
  34. window.addEventListener("error", function (event) {
  35. if (event.target.tagName === "SCRIPT" || event.target.tagName === "LINK" || event.target.tagName === "IMG") {
  36. event.preventDefault();
  37. event.stopPropagation();
  38. }
  39. }, true);
  40. })();
  41. (function () {
  42. const originalFetch = window.fetch;
  43. window.fetch = function (...args) {
  44. return originalFetch(...args).catch(error => {
  45. // More informative logging (but only in your own console, not the user's)
  46. console.error("Fetch error suppressed:", error); // Log to your console for debugging
  47. // You might want to handle different error types differently
  48. let errorMessage = "An error occurred."; // Default message
  49. if (error instanceof TypeError) {
  50. errorMessage = "Network error or CORS issue.";
  51. } else if (error instanceof Error) {
  52. errorMessage = error.message;
  53. }
  54. return new Response(JSON.stringify({ error: errorMessage }), { status: 500 }); // Use a 500 status for errors
  55. });
  56. };
  57. const originalXHR = window.XMLHttpRequest;
  58. window.XMLHttpRequest = function () {
  59. const xhr = new originalXHR();
  60. xhr.addEventListener("error", function (event) {
  61. console.error("XHR error suppressed"); // Log to your console
  62. event.preventDefault();
  63. });
  64. return xhr;
  65. };
  66. })();