cordova-plugin-wkwebview-engine icon indicating copy to clipboard operation
cordova-plugin-wkwebview-engine copied to clipboard

unable to call web worker

Open abhayastudios opened this issue 9 years ago • 2 comments

I added the plugin to try out WKWebView for my app and confirmed that indeed WKWebView is loaded, i.e. window.indexedDB is available.

However, as soon as I try to run a web worker I get a SecurityError: DOM Exception 18:

console.debug('pre!')
let webWorker = new Worker('assets/js/cache-phonebook-worker.js');
console.debug('post!')

In the above example I see the pre console output and then the security error mentioned above. I assume it has to do with the web worker trying to load the js file as a local file?

Is this expected behavior? I was under the impression that this plugin is supposed to fix this issue?

Thanks!

abhayastudios avatar Nov 08 '16 20:11 abhayastudios

I didn't try it yet (because it doesn't work currently), but I am assuming that also any JS scripts that the web worker imports using importScripts will fail because they are also loaded as a file.

abhayastudios avatar Nov 08 '16 20:11 abhayastudios

Invoke your worker inline.

Eg. Copy/paste this example to safari > develop > iPhone > console:

var blob = new Blob(["onmessage = function(e) { postMessage('msg from worker'); }"]);
var blobURL = window.URL.createObjectURL(blob); 
var worker = new Worker(blobURL);
worker.onmessage = function(e) {
  console.log('webworker e',e);
};
worker.postMessage('go'); // Start the worker.

michaelpeterlee avatar Jan 10 '17 21:01 michaelpeterlee