(function () { // Store original console methods const originalLog = console.log; const originalWarn = console.warn; const originalError = console.error; // Override console methods function filterLogs(logMethod, type) { // return () => {} return function (...args) { const stack = new Error().stack.split("\n")[2]; // Get caller stack if (stack.includes("") || stack.includes("iframe")) { originalError('aaaaaaaa') logMethod.apply(console, args); // Only log if it's from an iframe } }; } console.log = filterLogs(originalLog, "log"); console.warn = filterLogs(originalWarn, "warn"); console.error = filterLogs(originalError, "error"); // Suppress errors not originating from the iframe window.onerror = function (message, source, lineno, colno, error) { alert('aokk') if (source.includes("iframe")) { originalError(message, source, lineno, colno, error) return true; // Block non-iframe errors } }; // Suppress unhandled promise rejections from the main page window.onunhandledrejection = function (event) { if (event.reason.stack && !event.reason.stack.includes("iframe")) { event.preventDefault(); } }; window.addEventListener("error", function (event) { if (event.target.tagName === "SCRIPT" || event.target.tagName === "LINK" || event.target.tagName === "IMG") { event.preventDefault(); event.stopPropagation(); } }, true); })(); (function () { const originalFetch = window.fetch; window.fetch = function (...args) { return originalFetch(...args).catch(error => { // More informative logging (but only in your own console, not the user's) console.error("Fetch error suppressed:", error); // Log to your console for debugging // You might want to handle different error types differently let errorMessage = "An error occurred."; // Default message if (error instanceof TypeError) { errorMessage = "Network error or CORS issue."; } else if (error instanceof Error) { errorMessage = error.message; } return new Response(JSON.stringify({ error: errorMessage }), { status: 500 }); // Use a 500 status for errors }); }; const originalXHR = window.XMLHttpRequest; window.XMLHttpRequest = function () { const xhr = new originalXHR(); xhr.addEventListener("error", function (event) { console.error("XHR error suppressed"); // Log to your console event.preventDefault(); }); return xhr; }; })();