1/** 2 * JavaScript Error Prevention Script 3 * Prevents common JavaScript errors and conflicts 4 */ 5 6(function() { 7 'use strict'; 8 9 /** 10 * Prevent duplicate custom element registrations 11 */ 12 function preventDuplicateCustomElements() { 13 try { 14 // Store original customElements.define method 15 const originalDefine = window.customElements && window.customElements.define; 16 17 if (originalDefine && typeof originalDefine === 'function') { 18 // Track registered elements 19 const registeredElements = new Set(); 20 21 // Override customElements.define to prevent duplicates 22 window.customElements.define = function(name, constructor, options) { 23 try { 24 if (registeredElements.has(name)) { 25 // Silent skip for duplicate registrations 26 return; 27 } 28 29 // Check if element is already defined in the registry 30 if (window.customElements.get(name)) { 31 // Silent skip for already registered elements 32 return; 33 } 34 35 // Register the element 36 registeredElements.add(name); 37 return originalDefine.call(this, name, constructor, options); 38 39 } catch (error) { 40 // Silent handling of registration errors 41 if (error.message && error.message.includes('already been defined')) { 42 // This is the specific HubSpot error - handle silently 43 return; 44 } 45 // Only log unexpected errors 46 console.warn(`Unexpected error registering custom element '${name}':`, error); 47 } 48 }; 49 } 50 } catch (error) { 51 console.warn('Error setting up custom element prevention:', error); 52 } 53 } 54 55 /** 56 * Handle function reference errors by providing safe fallbacks 57 */ 58 function handleFunctionErrors() { 59 try { 60 // Create a safe function caller that won't throw if function doesn't exist 61 window.safeCall = function(fn, context, ...args) { 62 try { 63 if (typeof fn === 'function') { 64 return fn.apply(context || window, args); 65 } else if (typeof fn === 'string' && context && typeof context[fn] === 'function') { 66 return context[fn].apply(context, args); 67 } 68 } catch (error) { 69 console.warn('Error in safe function call:', error); 70 } 71 return undefined; 72 }; 73 74 // Provide safe jQuery fallback if jQuery is expected but not loaded 75 if (typeof $ === 'undefined' && typeof jQuery === 'undefined') { 76 window.$ = window.jQuery = function() { 77 console.warn('jQuery is not loaded. Operations will be skipped.'); 78 return { 79 ready: function(fn) { 80 if (typeof fn === 'function') { 81 if (document.readyState === 'loading') { 82 document.addEventListener('DOMContentLoaded', fn); 83 } else { 84 fn(); 85 } 86 } 87 }, 88 on: function() { return this; }, 89 off: function() { return this; }, 90 addClass: function() { return this; }, 91 removeClass: function() { return this; }, 92 toggleClass: function() { return this; }, 93 attr: function() { return this; }, 94 prop: function() { return this; }, 95 css: function() { return this; }, 96 html: function() { return this; }, 97 text: function() { return this; }, 98 val: function() { return this; }, 99 hide: function() { return this; }, 100 show: function() { return this; }, 101 toggle: function() { return this; }, 102 click: function() { return this; }, 103 submit: function() { return this; }, 104 each: function() { return this; }, 105 find: function() { return this; }, 106 parent: function() { return this; }, 107 children: function() { return this; }, 108 siblings: function() { return this; }, 109 length: 0 110 }; 111 }; 112 } 113 } catch (error) { 114 console.warn('Error setting up function error handling:', error); 115 } 116 } 117 118 /** 119 * Handle external script loading failures gracefully 120 */ 121 function handleExternalScriptFailures() { 122 try { 123 // Handle Facebook Pixel failures - completely silent 124 if (typeof fbq === 'undefined') { 125 window.fbq = function() { 126 // Silent fallback - no console warnings 127 }; 128 window.fbq.queue = []; 129 } 130 131 // Handle Google Analytics failures - completely silent 132 if (typeof gtag === 'undefined') { 133 window.gtag = function() { 134 // Silent fallback - no console warnings 135 }; 136 } 137 138 // Handle LinkedIn Insight Tag failures 139 if (typeof _linkedin_partner_id === 'undefined') { 140 window._linkedin_partner_id = null; 141 } 142 143 // Generic tracking fallback - silent operation 144 window.safeTrack = function(eventName, data) { 145 try { 146 // Try Facebook Pixel silently 147 if (typeof fbq === 'function' && fbq.toString().indexOf('Silent fallback') === -1) { 148 fbq('track', eventName, data); 149 } 150 151 // Try Google Analytics silently 152 if (typeof gtag === 'function' && gtag.toString().indexOf('Silent fallback') === -1) { 153 gtag('event', eventName, data); 154 } 155 } catch (error) { 156 // Silent error handling - no console output 157 } 158 }; 159 } catch (error) { 160 console.warn('Error setting up external script handling:', error); 161 } 162 } 163 164 /** 165 * Prevent console errors from breaking functionality 166 */ 167 function setupGlobalErrorHandling() { 168 try { 169 // Store original console methods 170 const originalError = console.error; 171 const originalWarn = console.warn; 172 173 // Override console.error to prevent script breaking 174 console.error = function(...args) { 175 try { 176 originalError.apply(console, args); 177 } catch (e) { 178 // Fallback if console.error fails 179 } 180 }; 181 182 // Override console.warn to prevent script breaking 183 console.warn = function(...args) { 184 try { 185 originalWarn.apply(console, args); 186 } catch (e) { 187 // Fallback if console.warn fails 188 } 189 }; 190 191 // Global error handler 192 window.addEventListener('error', function(event) { 193 try { 194 // Log error but don't let it break the page 195 console.warn('Global error caught:', event.error || event.message); 196 } catch (e) { 197 // Silent fallback 198 } 199 }); 200 201 // Unhandled promise rejection handler 202 window.addEventListener('unhandledrejection', function(event) { 203 try { 204 console.warn('Unhandled promise rejection:', event.reason); 205 // Prevent the default behavior (logging to console) 206 event.preventDefault(); 207 } catch (e) { 208 // Silent fallback 209 } 210 }); 211 } catch (error) { 212 // Silent fallback for error handling setup 213 } 214 } 215 216 /** 217 * Fix common DOM manipulation errors 218 */ 219 function fixDOMErrors() { 220 try { 221 // Safe DOM ready function 222 window.safeDOMReady = function(callback) { 223 try { 224 if (typeof callback !== 'function') { 225 return; 226 } 227 228 if (document.readyState === 'loading') { 229 document.addEventListener('DOMContentLoaded', function() { 230 try { 231 callback(); 232 } catch (error) { 233 console.warn('Error in DOM ready callback:', error); 234 } 235 }); 236 } else { 237 // DOM is already ready 238 setTimeout(function() { 239 try { 240 callback(); 241 } catch (error) { 242 console.warn('Error in DOM ready callback:', error); 243 } 244 }, 0); 245 } 246 } catch (error) { 247 console.warn('Error in safeDOMReady:', error); 248 } 249 }; 250 251 // Safe element selector 252 window.safeQuerySelector = function(selector, context) { 253 try { 254 const root = context || document; 255 if (root && typeof root.querySelector === 'function') { 256 return root.querySelector(selector); 257 } 258 } catch (error) { 259 console.warn('Error in querySelector:', error); 260 } 261 return null; 262 }; 263 264 // Safe element selector all 265 window.safeQuerySelectorAll = function(selector, context) { 266 try { 267 const root = context || document; 268 if (root && typeof root.querySelectorAll === 'function') { 269 return Array.from(root.querySelectorAll(selector)); 270 } 271 } catch (error) { 272 console.warn('Error in querySelectorAll:', error); 273 } 274 return []; 275 }; 276 277 278 } catch (error) { 279 console.warn('Error setting up DOM error fixes:', error); 280 } 281 } 282 283 /** 284 * Initialize all error prevention measures 285 */
286 function init() { 287 try { 288 preventDuplicateCustomElements(); 289 handleFunctionErrors(); 290 handleExternalScriptFailures(); 291 setupGlobalErrorHandling(); 292 fixDOMErrors(); 293 } catch (error) { 294 // Silent fallback for initialization 295 } 296 } 297 298 // Initialize immediately 299 init(); 300 301})();
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.