A
A
Andrey Dyrkov2015-09-25 20:03:51
JavaScript
Andrey Dyrkov, 2015-09-25 20:03:51

Worker via Blob not working properly?

I am running this code

if(!!window.Worker){
      if(!!window.Blob){
        var bb = new Blob(["self.addEventListener('message',function(e){self.postMessage(e.data);},false);"]);

        var blobURL = window.URL.createObjectURL(bb);
        console.log(blobURL);

        var worker = new Worker(blobURL[0]);
        console.log(worker);

        worker.addEventListener('message',function(e){
          console.log("worker message : "+e.data);
        },false);

        worker.postMessage('Hello, worker!'); // Start the worker.
      }else{
        // fallback
      }
    }else{
      // fallback
    }

There are no errors, everything displays, but does not work as it should)) In theory, it should display a worker message : Hello, worker!
It's probably a jamb somewhere, but now I don't see it)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis Ineshin, 2015-09-25
@IonDen

So the worker can only be an external file. Emulation won't help here.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question