1// TMX Profiling Bootstrap - ensures global hooks and events are set before Angular loads 2window.tmx_tags_started = function(callback) { 3 // If profiling is already complete, call callback with sessionId and timing 4 if (window.tmx_profiling_started_at && window.tmx_profiling_completed_at && window.tmx_profiling_session_id) { 5 if (typeof callback === 'function') { 6 callback({ 7 profilingSessionID: window.tmx_profiling_session_id, 8 profilingStatus: 'completed', 9 profilingStatusCode: PROFILING_STATUS_CODE_MAP['completed'], 10 profilingTime: window.tmx_profiling_completed_at - window.tmx_profiling_started_at 11 }); 12 } 13 return; 14 } 15 // If profiling just started, call as before 16 if (!window.tmx_profiling_started_at) { 17 window.tmx_profiling_started_at = Date.now(); 18 window.dispatchEvent(new Event('tmx_profiling_started')); 19 } 20 // DO NOT set window.tmx_profiling_started = true here! 21 // Only the real TMX JS (tags.js) should set this flag. 22 if (typeof callback === 'function') callback({ 23 profilingSessionID: null, 24 profilingStatus: 'started', 25 profilingStatusCode: PROFILING_STATUS_CODE_MAP['started'], 26 profilingTime: 0 27 }); 28}; 29 30// --- TMX Profiling Started Handler --- 31// Calls the provided callback with the profiling started status after DOM is ready. 32function tmx_tags_started(onStarted, delayMs = 1000) { 33 if (typeof onStarted !== "function") return; 34 35 function checkProfilingStarted() { 36 const didStart = typeof tmx_profiling_started !== "undefined" && tmx_profiling_started === true; 37 if (didStart) { 38 tmxTaggingStartedAt = Date.now(); 39 // Log tagging started (without taggingKey) 40 const bootstrapLog = { 41 startedAt: tmxTaggingStartedAt 42 }; 43 console.log("[TMX] Bootstrap loaded event:", bootstrapLog); 44 postToBackend(BOOTSTRAP_ENDPOINT, bootstrapLog); // Uncomment when backend is ready 45 // Set timeout to detect incomplete/blocked 46 tmxProfilingTimeout = setTimeout(() => { 47 if (!tmxProfilingCompletedAt) { 48 // If profiling never completed, log as incomplete/blocked 49 const incompleteLog = { 50 sessionId: null, 51 startedAt: tmxTaggingStartedAt, 52 completedAt: null, 53 durationMs: null, 54 status: 'incomplete_or_blocked', 55 profilingStatusCode: PROFILING_STATUS_CODE_MAP['incomplete_or_blocked'] 56 }; 57 console.log("[TMX] Profiling incomplete or blocked:", incompleteLog); 58 postToBackend(PROFILING_ENDPOINT, incompleteLog); // Uncomment when backend is ready 59 } 60 }, TMX_PROFILING_TIMEOUT_MS); 61 } 62 onStarted(didStart); 63 } 64 65 // If document is already loaded, call after a short delay 66 if (document.readyState === "complete" && document.body) { 67 setTimeout(checkProfilingStarted, delayMs); 68 } else { 69 // Wait for DOMContentLoaded event 70 document.addEventListener("DOMContentLoaded", function () { 71 setTimeout(checkProfilingStarted, delayMs); 72 }); 73 } 74} 75 76// --- Profiling status to code mapping --- 77const PROFILING_STATUS_CODE_MAP = { 78 'skipped': 0, 79 'incomplete': 1, 80 'completed': 2, 81 'blocked': 3, 82 'blocked-bootstrap': 3, 83 'started': 4, // Optional: for internal use, not sent to backend 84 'blocked_or_never_loaded': 3, 85 'incomplete_or_blocked': 1 86}; 87 88// --- TMX Blocked Detection --- 89function detectTmxBlocked(timeoutMs = 10000) { 90 setTimeout(() => { 91 const didStart = typeof tmx_profiling_started !== "undefined" && tmx_profiling_started === true; 92 if (!didStart) { 93 window.tmx_profiling_blocked = true; 94 const blockedLog = { 95 sessionId: null, 96 startedAt: null, 97 completedAt: null, 98 durationMs: null, 99 status: 'blocked_or_never_loaded', 100 profilingStatusCode: PROFILING_STATUS_CODE_MAP['blocked_or_never_loaded'] 101 }; 102 console.log("[TMX] TMX script blocked or never loaded:", blockedLog); 103 // postToBackend(PROFILING_ENDPOINT, blockedLog); // Uncomment when backend is ready 104 } 105 }, timeoutMs); 106} 107 108window.addEventListener('message', function(event) { 109 if (typeof event.data === 'string' && event.data.startsWith('tmx_profiling_complete:')) { 110 var sessionId = event.data.split(':')[1]; 111 window.tmx_profiling_completed_at = Date.now(); 112 window.tmx_profiling_session_id = sessionId; 113 window.dispatchEvent(new Event('tmx_profiling_completed')); 114 } 115});
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.