Files

72 lines
2.2 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>SharedWorker Test</title>
<style>
body { font-family: sans-serif; background: #1a1a2e; color: #eee; padding: 40px; }
h1 { margin-bottom: 10px; }
.pass { color: #0f0; }
.fail { color: #f00; }
.info { color: #ff0; }
#output { background: #16213e; padding: 16px; border-radius: 8px; margin-top: 20px; font-family: monospace; white-space: pre-wrap; }
</style>
</head>
<body>
<h1>🔄 SharedWorker Test</h1>
<p>Tests whether <code>SharedWorker</code> works when loaded from a <code>local://</code> URI.</p>
<div id="output">Running tests...</div>
<script>
var output = document.getElementById('output');
function log(msg, cls) {
output.innerHTML += '<span class="' + (cls || '') + '">' + msg + '</span>\n';
}
log('=== SharedWorker Test ===\n', 'info');
// Test 1: Is SharedWorker supported?
if (typeof SharedWorker !== 'undefined') {
log('✓ SharedWorker is supported by this browser', 'pass');
} else {
log('✗ SharedWorker is NOT supported by this browser', 'fail');
}
// Test 2: Try to create a SharedWorker
try {
var worker = new SharedWorker('shared-worker-test.js');
log('✓ SharedWorker constructor succeeded', 'pass');
worker.port.onmessage = function(e) {
log('✓ Received message from worker: ' + e.data, 'pass');
};
worker.port.onerror = function(e) {
log('✗ Worker error: ' + (e.message || 'unknown'), 'fail');
};
// Send a ping
worker.port.postMessage('ping');
// Timeout after 3 seconds
setTimeout(function() {
log('\n--- Timeout reached ---', 'info');
log('If you see "Received message from worker" above, SharedWorker works.', 'info');
log('If not, SharedWorker failed to load or communicate.', 'info');
}, 3000);
} catch (e) {
log('✗ SharedWorker constructor threw: ' + e.message, 'fail');
}
// Test 3: What is our current origin?
log('\n=== Origin Info ===', 'info');
log('location.href: ' + location.href, 'info');
log('location.origin: ' + (location.origin || 'null'), 'info');
log('location.protocol: ' + location.protocol, 'info');
</script>
</body>
</html>