worker-polyfill

Polyfill for the Web Worker API that works in Internet Explorer and other old browsers that don't support this API

Usage no npm install needed!

<script type="module">
  import workerPolyfill from 'https://cdn.skypack.dev/worker-polyfill';
</script>

README

A simple script that emulates web worker threads in non compatible browsers. The code will still be slow (single threaded) but you can keep you code consistent.

Usage:

// You must check for compatibility before loading the polyfill
if ( !Worker ) { require('worker-loader'); }

Workers can be loaded and used as usual:

var worker = new Worker("your_script.js");  

worker.onmessage = function(event) {  
    alert("Got: " + event.data);  
};  

worker.onerror = function(error) {  
    alert("Worker error: " + error);  
};

worker.postMessage("Hello World"); 

'addEventListener' methods are also supported:

var worker = new Worker("your_script.js");

worker.addEventListener("message", function(event) {  
    alert("Got: " + event.data);  
});

worker.addEventListener("error", function(error) {  
    alert("Worker error: " + error);  
});

worker.postMessage("Hello World");