cordova-plugin-wkwebview-engine
cordova-plugin-wkwebview-engine copied to clipboard
unable to call web worker
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!
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.
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.