Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WebWorker make by a string.
<script>
const WORKER_RESOURCE = `
self.onmessage = (event) => {
debugger;
postMessage(event.data + " worker"); // hello worker
}`;
const blob = new Blob( [ WORKER_RESOURCE ], { type: "application/javascript" } );
const blobURL = URL.createObjectURL(blob); // -> URL.revokeObjectURL(blobURL);
const worker = new Worker(blobURL);
worker.onmessage = (event) => { // @arg EventObject - { data: "hello worker" }
alert('resp: ' + event.data);
};
worker.postMessage('hello');
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.