How to get web workers to function cross domain, m

2019-05-17 02:45发布

问题:

I have created web workers that are being called from both a separate file and inline workers (blobs). Neither of which will work consistently in most browsers. I am using CORs following the the tutorials below.

http://www.html5rocks.com/en/tutorials/workers/basics/

http://www.html5rocks.com/en/tutorials/cors/

The issues is that when I use inline workers (blobs) they work in Chrome and Firefox but not in IE, Safari, or Opera. This code will be used for tracking purpose, so will need to work across many domains.

On the backend I have:

Response.AppendHeader("Access-Control-Allow-Origin", "*");

on the front end I have

            var blob = new Blob([
                "POST to a page that colllects information about what has been clicked usng CORs"]);

            // Obtain a blob URL reference
            var blobURL = window.URL.createObjectURL(blob);

            var workerBlob = new Worker(blobURL);

            workerBlob.onmessage = function (event) {
                withWorker.removeEventListener('click', addBtnClickListener, false);
                withWorker.click();
                return true;
                //the worker is tracking a button click
            };
            workerBlob.postMessage(url);

            //release the blob
            window.URL.revokeObjectURL(blobURL);

Is there another way to get web workers inline (blobs) or other wise to work cross domain?