1

Cannot create inline web workers using BLOB-URL in IE11. Works fine in Edge, Firefox, Chrome. (All browsers are up-to-date.)

For example below JavaScript code fails to create web worker.

try{
 var blob = new Blob(["(" + function1.toString() + ")(" + parametersJSON + ")"], {type: 'application/javascript'}); 
 var x = window.URL.createObjectURL(blob); 
 var worker = new Worker(x);
} catch(err){
 console.log(err);// displays "invalid function" in IE11.
}

Any help?

Is there any other alternative? to achieve the goal of creating a web worker from a string without using the external file? (Should work in InternetExplorer 11+)

Full code is as follows:

<html>
    <head>
        <title>Web Worker Test</title>
        <script>

            function function1(parametersJSON){

                console.log(parametersJSON.testKey1);
            }
            try{
                var parametersJSON = {'testKey1':'foo','testKey2':'bar'};
                var parametersJSONString = JSON.stringify(parametersJSON);
                var blob = new Blob(["(" + function1.toString() + ")(" + parametersJSONString + ")"], {type: 'application/javascript'}); 
                var x = window.URL.createObjectURL(blob); 
                var worker = new Worker(x);
            } catch(err){
                console.log(err);// displays "invalid function" in IE11.
            }
        </script>
    </head>
    <body>
        Test
    </body>
</html>
  • Can you please inform us, What are the values stored in function1.toString() and parametersJSON. After that we can make a test with your code to check for the issue. Thanks for your understanding. – Deepak-MSFT Dec 21 '18 at 02:03
  • @Deepak-MSFTI have updated the question with complete code which does not work in IE 11. – Vaibhav Khandekar Dec 21 '18 at 06:35
  • I try to make a several tests and based on the results, I find that in IE we need to use External file to create web worker. Without that IE is producing the error. So at present, It looks like it is not possible to create web worker in IE without using an external file. – Deepak-MSFT Dec 25 '18 at 05:10
  • @Deepak-MSFT There is a workaround for IE here: https://stackoverflow.com/questions/10343913/how-to-create-a-web-worker-from-a-string – Mörre Jun 30 '19 at 16:23

0 Answers0