1(function () { 2 // ------------------------------------------------- 3 // 1. Prevent Duplicate Initialization 4 // ------------------------------------------------- 5 if (typeof window === "undefined" || window.__scriptLoadShieldInstalled__) { 6 return; 7 } 8 window.__scriptLoadShieldInstalled__ = true; 9 10 // ------------------------------------------------- 11 // 2. Global State Management 12 // ------------------------------------------------- 13 window.__scriptLoadState__ = window.__scriptLoadState__ || { 14 scriptLoadFailure: false, 15 suppressErrors: false, 16 suppressionReason: null, 17 firstFailureTime: null, 18 failedScripts: [] 19 }; 20 21 // Safely initialize the map, handling ancient browsers (IE8) 22 var failedScriptMap = typeof Object.create === "function" ? Object.create(null) : {}; 23 24 // ------------------------------------------------- 25 // 3. Deduplication & Metadata 26 // ------------------------------------------------- 27 function recordFailedScript(src) { 28 src = src || "[unknown]"; 29 30 // Strict equality prevents collisions with inherited Object properties 31 if (failedScriptMap[src] === true) { 32 return; 33 } 34 35 failedScriptMap[src] = true; 36 37 window.__scriptLoadState__.failedScripts.push({ 38 src: src, 39 timestamp: new Date().getTime() 40 }); 41 } 42 43 // ------------------------------------------------- 44 // 4. Error Suppression Activation 45 // ------------------------------------------------- 46 function enableErrorSuppression() { 47 if (window.__scriptLoadState__.suppressErrors) { 48 return; 49 } 50 51 window.__scriptLoadState__.suppressErrors = true; 52 53 // Optional: If you ever want to re-enable Sentry after a few minutes, 54 // you would add a setTimeout here to set suppressErrors back to false. 55 56 // A. Classic uncaught JS errors 57 var oldOnError = window.onerror; 58 window.onerror = function () { 59 if (window.__scriptLoadState__.suppressErrors) { 60 return true; 61 } 62 if (typeof oldOnError === "function") { 63 return oldOnError.apply(this, arguments); 64 } 65 return false; 66 }; 67 68 // B. Unhandled Promise Rejections 69 var oldUnhandledRejection = window.onunhandledrejection; 70 window.onunhandledrejection = function (e) { 71 if (window.__scriptLoadState__.suppressErrors) { 72 if (e && typeof e.preventDefault === "function") { 73 e.preventDefault(); 74 } 75 return; 76 } 77 if (typeof oldUnhandledRejection === "function") { 78 return oldUnhandledRejection.apply(this, arguments); 79 } 80 }; 81 } 82 83 // ------------------------------------------------- 84 // 5. Capture-Phase Event Listeners 85 // ------------------------------------------------- 86 if (window.addEventListener) { 87 88 window.addEventListener("error", function (e) { 89 var target = e.target || e.srcElement; 90 91 var isResourceError = target && target !== window && typeof target.tagName === "string"; 92 var isScriptError = isResourceError && target.tagName.toUpperCase() === "SCRIPT"; 93 94 // A. A script failed to load. Shield up, and kill this event immediately. 95 if (isScriptError) { 96 var src = target.src || "[unknown]"; 97 recordFailedScript(src); 98 99 window.__scriptLoadState__.scriptLoadFailure = true; 100 window.__scriptLoadState__.suppressionReason = "script-load-failure"; 101 window.__scriptLoadState__.firstFailureTime = window.__scriptLoadState__.firstFailureTime || new Date().getTime(); 102 103 enableErrorSuppression(); 104 105 // CRITICAL: Stop the initial script error from bubbling up to Sentry. 106 if (e) { 107 if (typeof e.stopImmediatePropagation === "function") { 108 e.stopImmediatePropagation(); 109 } else if (typeof e.stopPropagation === "function") { 110 e.stopPropagation(); // Legacy browser fallback 111 } 112 if (typeof e.preventDefault === "function") { 113 e.preventDefault(); 114 } 115 } 116 return; 117 } 118 119 // B. If suppression is active, aggressively kill runtime errors. 120 if (window.__scriptLoadState__.suppressErrors && !isResourceError) { 121 if (e) { 122 if (typeof e.stopImmediatePropagation === "function") { 123 e.stopImmediatePropagation(); 124 } else if (typeof e.stopPropagation === "function") { 125 e.stopPropagation(); // Legacy browser fallback 126 } 127 if (typeof e.preventDefault === "function") { 128 e.preventDefault(); 129 } 130 } 131 } 132 }, true); 133 134 window.addEventListener("unhandledrejection", function (e) { 135 if (!window.__scriptLoadState__.suppressErrors) { 136 return; 137 } 138 if (e) { 139 if (typeof e.stopImmediatePropagation === "function") { 140 e.stopImmediatePropagation(); 141 } else if (typeof e.stopPropagation === "function") { 142 e.stopPropagation(); // Legacy browser fallback 143 } 144 if (typeof e.preventDefault === "function") { 145 e.preventDefault(); 146 } 147 } 148 }, true); 149 } 150 151 // ------------------------------------------------- 152 // 6. Public API for proactive (non-event-driven) checks 153 // ------------------------------------------------- 154 window.__scriptLoadState__.reportMissingDependency = function (name) { 155 recordFailedScript(name); 156 window.__scriptLoadState__.scriptLoadFailure = true; 157 window.__scriptLoadState__.suppressionReason = "dependency-missing"; 158 window.__scriptLoadState__.firstFailureTime = 159 window.__scriptLoadState__.firstFailureTime || new Date().getTime(); 160 enableErrorSuppression(); 161 }; 162 163})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.