Files
sovereign_browser/tests/local-site/shared-worker-test.js
T

30 lines
1010 B
JavaScript

/**
* Minimal SharedWorker test script.
* Responds to 'ping' with 'pong' and reports its own URL and origin.
*/
console.log('[SharedWorker-Test] Worker script executing...');
console.log('[SharedWorker-Test] self.location.href:', self.location.href);
console.log('[SharedWorker-Test] self.location.origin:', self.location.origin);
console.log('[SharedWorker-Test] self.location.protocol:', self.location.protocol);
self.onconnect = function(e) {
var port = e.ports[0];
console.log('[SharedWorker-Test] Connected from port');
port.postMessage('worker_ready');
port.onmessage = function(e) {
console.log('[SharedWorker-Test] Received:', e.data);
if (e.data === 'ping') {
port.postMessage('pong');
} else if (e.data === 'get_info') {
port.postMessage(JSON.stringify({
href: self.location.href,
origin: self.location.origin,
protocol: self.location.protocol
}));
}
};
};