// Test content script - RUNS INSIDE THE BROWSER EXTENSION // Only loaded during automated testing (ENABLE_TESTS=true) // This script proves bidirectional communication between content script and background // Browser API polyfill for Chrome/Chromium compatibility if (typeof browser === 'undefined') { var browser = chrome; } // 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 test script (test-lib.js) document.addEventListener('DEBUG_rentgen_test_request', async (event) => { try { // 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: event.detail?.timestamp || Date.now() }); // Store the badge count in DOM for the test script to read if (response && response.success) { document.body.setAttribute('data-rentgen-badge-count', String(response.badgeCount)); } } catch (error) { // If there's an error, the test will timeout waiting for badge count console.error('Test verification error:', error); } });