简体   繁体   中英

Worker works on Firefox, and older version of Chrome but not on the latest Chrome

I have a directive with Canvas that communicate with a webWorker. On Firefox and versions of Chrome < 43.0.2357.65 (64-bit) everything work good, but on Chrome >= 43.0.2357.65 (64-bit) the directive is not receiving messages from the Worker.

  restrict: 'E'
  replace: true
  templateUrl: 'some.html'
  link: ($scope, element, attrs) ->
    ...
    worker = new Worker('js/myworker.js')
    ...


    #
    # Initialize Worker with the canvas image
    #
    initializeWorker = (imgData, imgWidth, imgHeight, length) ->
      worker.postMessage(
        type: 'init'
        imgData: imgData
        width: imgWidth
        height: imgHeight
        length: length
        calculateBoundingBox: true
      )

    ...
    ...
    initializeWorker(...)

    worker.onmessage = (event) ->
      console.log('Worker message', event)

    worker.onerror = ->
      console.log('error on the web worker')

Even from a dummy Worker like this:

var onmessage;

onmessage = function(event) {
  return postMessage('message');
};

I tried using Blob instead of loading the `js´ Worker file but the problem remains.

On Firefox and Chrome < 43.0.2357.65 (64-bit) I can see the message like:

Worker message message { target: Worker, isTrusted: true, data: "message", origin: "", lastEventId: "", currentTarget: Worker, eventPhase: 2, bubbles: false, cancelable: true, defaultPrevented: false, timeStamp: 1432625927407334 }

But not on Chrome >= 43.0.2357.65 (64-bit).

Try This!!

var onmessage;

self.onmessage = function(event) {
  return self.postMessage('message');
};

must use 'self'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM