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

32 lines
1.0 KiB
JavaScript

/**
* SharedWorker test for importScripts() on local://.
* Tests whether importScripts() can load scripts from the local:// scheme.
*/
console.log('[Import-Test] Worker script executing');
console.log('[Import-Test] self.location.href:', self.location.href);
console.log('[Import-Test] self.location.origin:', self.location.origin);
// Try importScripts with a relative path
try {
importScripts('./shared-worker-test.js');
console.log('[Import-Test] importScripts succeeded');
} catch (e) {
console.log('[Import-Test] importScripts FAILED:', e.message);
}
self.onconnect = function(e) {
var port = e.ports[0];
port.postMessage('worker_ready');
port.onmessage = function(e) {
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
}));
}
};
};