1
0
forked from icd/rentgen
rentgen/test-content-script.js
Jacek Wielemborek 34cec21992 feat(verify): enhanced Marionette verification with bidirectional communication
Implemented undeniable proof that extension is actively executing:
- Added content script that communicates with background script
- Background script performs verifiable computation (value*2)+3
- Marionette test dispatches event, verifies round-trip communication
- Results stored in DOM attributes (no console.log dependency)
- Mathematical proof ensures extension code is actually running

Test verifies:
1. Content script injection and event listening
2. Message passing from content to background script
3. Background script computation and response
4. Full bidirectional communication chain

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-26 09:21:18 +01:00

56 lines
2.4 KiB
JavaScript

// 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
if (document.body) {
document.body.setAttribute('data-rentgen-injected', 'true');
}
// 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 inputValue = testData.value || 42;
const timestamp = testData.timestamp || Date.now();
// Send message to background script and wait for response
// This proves background script is running and responsive
const response = await browser.runtime.sendMessage({
type: 'RENTGEN_TEST_VERIFICATION',
inputValue: inputValue,
timestamp: timestamp,
url: window.location.href,
title: document.title
});
// Store the response from background in DOM
// This provides undeniable proof of bidirectional communication
if (response && response.success) {
document.body.setAttribute('data-rentgen-verified', 'true');
document.body.setAttribute('data-rentgen-computed', String(response.computed));
document.body.setAttribute('data-rentgen-formula', response.formula);
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,
computed: response.computed,
formula: response.formula,
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));
}
});