// Test content script - only for automated testing // This script proves bidirectional communication between content script and background // Set initial DOM marker to prove content script is injected (function() { function setMarker() { if (document.body) { document.body.setAttribute('data-rentgen-injected', 'true'); } else { // Wait for DOM ready if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', () => { document.body.setAttribute('data-rentgen-injected', 'true'); }); } } } setMarker(); })(); // Listen for test request from Marionette test script document.addEventListener('rentgen_test_request', async (event) => { try { // Mark that we received the event document.body.setAttribute('data-rentgen-event-received', 'true'); // Extract test data from event const testData = event.detail || {}; const timestamp = testData.timestamp || Date.now(); // Send message to background script to get badge count for this origin // This tests real Rentgen functionality: counting third-party domains const response = await browser.runtime.sendMessage({ type: 'RENTGEN_TEST_VERIFICATION', origin: window.location.origin, url: window.location.href, title: document.title, timestamp: timestamp }); // Store the response from background in DOM // This provides the badge count (number of third-party domains) if (response && response.success) { document.body.setAttribute('data-rentgen-verified', 'true'); document.body.setAttribute('data-rentgen-badge-count', String(response.badgeCount)); document.body.setAttribute('data-rentgen-origin', response.origin); document.body.setAttribute('data-rentgen-cluster-ids', JSON.stringify(response.clusterIds)); document.body.setAttribute('data-rentgen-background-timestamp', String(response.backgroundTimestamp)); // Also dispatch a custom event with the results document.dispatchEvent(new CustomEvent('rentgen_test_complete', { detail: { success: true, badgeCount: response.badgeCount, origin: response.origin, clusterIds: response.clusterIds, backgroundTimestamp: response.backgroundTimestamp } })); } else { document.body.setAttribute('data-rentgen-verified', 'false'); document.body.setAttribute('data-rentgen-error', 'No response from background'); } } catch (error) { // Store error in DOM for debugging document.body.setAttribute('data-rentgen-verified', 'false'); document.body.setAttribute('data-rentgen-error', String(error)); } });