1(function() { 2 'use strict'; 3 4 if (typeof smMonitor === 'undefined') { 5 return; 6 } 7 8 var reported = {}; 9 var maxReports = 5; 10 var env = { adblock_css: 'unknown', adblock_net: 'unknown', script_errors: 0 }; 11 12 // --- environment detection: ad/privacy blockers (extensions can't be 13 // enumerated, but their blocking effects can be measured) --- 14 15 function detectAdblockCss() { 16 try { 17 var bait = document.createElement('div'); 18 bait.className = 'adsbox ad-banner textAd pub_300x250 sponsored-ad'; 19 bait.style.cssText = 'position:absolute;left:-9999px;top:-9999px;height:10px;width:10px;'; 20 document.body.appendChild(bait); 21 setTimeout(function() { 22 env.adblock_css = (bait.offsetHeight === 0 || bait.offsetParent === null) ? 'yes' : 'no'; 23 bait.remove(); 24 }, 150); 25 } catch (e) {} 26 } 27 28 function detectAdblockNet() { 29 // Blocked at network level by uBlock/AdBlock/Privacy Badger/Ghostery/Brave etc. 30 fetch('https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js', { 31 mode: 'no-cors', 32 cache: 'no-store' 33 }).then(function() { 34 env.adblock_net = 'no'; 35 }).catch(function() { 36 env.adblock_net = 'yes'; 37 }); 38 } 39 40 if (document.body) { 41 detectAdblockCss(); 42 } else { 43 document.addEventListener('DOMContentLoaded', detectAdblockCss); 44 } 45 detectAdblockNet(); 46 47 function shouldReport(filename, message) { 48 // Cross-origin/extension noise: browsers report these as "Script error." 49 // with no filename â nothing actionable, but count them as a signal. 50 if (!filename && (!message || message === 'Script error.')) { 51 env.script_errors++; 52 return false; 53 } 54 // Empty filename: inline scripts. 'unhandledrejection': failed AJAX/promises. 55 if (!filename || filename === 'unhandledrejection') { 56 return true; 57 } 58 // Anything served from this site: theme, plugin, and core JS 59 if (window.location.origin && filename.indexOf(window.location.origin) === 0) { 60 return true; 61 } 62 return filename.indexOf('/wp-content/') !== -1 || 63 filename.indexOf('/wp-includes/') !== -1 || 64 filename.indexOf('/themes/') !== -1; 65 } 66 67 function sendReport(errorData) { 68 if (!shouldReport(errorData.filename, errorData.message)) { 69 return; 70 } 71 72 var key = errorData.message + '|' + (errorData.filename || '') + '|' + (errorData.lineno || ''); 73 if (reported[key] || Object.keys(reported).length >= maxReports) { 74 return; 75 } 76 reported[key] = true; 77 78 try { 79 var xhr = new XMLHttpRequest(); 80 xhr.open('POST', smMonitor.ajaxUrl, true); 81 xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 82 var params = 'action=sm_report_js_error' + 83 '&nonce=' + encodeURIComponent(smMonitor.nonce) + 84 '&message=' + encodeURIComponent(errorData.message || '') + 85 '&filename=' + encodeURIComponent(errorData.filename || '') + 86 '&lineno=' + encodeURIComponent(errorData.lineno || '') + 87 '&colno=' + encodeURIComponent(errorData.colno || '') + 88 '&stack=' + encodeURIComponent(errorData.stack || '') + 89 '&url=' + encodeURIComponent(window.location.href) + 90 '&userAgent=' + encodeURIComponent(navigator.userAgent) + 91 '&env=' + encodeURIComponent(JSON.stringify(env)); 92 xhr.send(params); 93 } catch (e) {} 94 } 95 96 window.addEventListener('error', function(event) { 97 sendReport({ 98 message: event.message || 'Unknown error', 99 filename: event.filename || '', 100 lineno: event.lineno || 0, 101 colno: event.colno || 0, 102 stack: event.error && event.error.stack ? event.error.stack : '' 103 }); 104 }); 105 106 window.addEventListener('unhandledrejection', function(event) {
107 var msg = 'Unhandled Promise Rejection'; 108 var stack = ''; 109 if (event.reason) { 110 if (typeof event.reason === 'string') { 111 msg = event.reason; 112 } else if (event.reason.message) { 113 msg = event.reason.message; 114 stack = event.reason.stack || ''; 115 } 116 } 117 sendReport({ 118 message: msg, 119 filename: 'unhandledrejection', 120 lineno: 0, 121 colno: 0, 122 stack: stack 123 }); 124 }); 125})();
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.