I have a very simple need, I need to spawn a webworker with a small data uri script:
new Worker('data:,console.log("HI")');
In Firefox this is giving me instead an error. Error is:
SecurityError: Failed to load worker script at "data:,console.log("HI")"
Is there anyway to get worker to work with data URI?
You could definitely try Freelancer which:
function that it transforms to a string using Function.prototype.toStringBlob with application/javascript as the typeURL.createObjectURL.Freelancer is equivalent to these 5 lines of code (if you don't care about error messages when your browser doesn't support Web Workers).
class Worker extends globalThis.Worker {
constructor(fn, ...params) {
return super(URL.createObjectURL(new Blob([`(${fn.toString()})(${params.map(JSON.stringify)})`], {type: 'application/javascript'})))
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With