simple-web-worker
simple-web-worker copied to clipboard
DOMException: Failed to execute 'postMessage' on 'Worker': function (a, b, c) {
Hi So thanks by the repo, it's great!! I can't run the code, it throw me:
DOMException: Failed to execute 'postMessage' on 'Worker': function (a, b, c) {
if (this instanceof C) {
switch (arguments.length) {
case 0:...<omitted>... } could not be cloned.
And my code it's this:
worker.run(() => {
if ('indexedDB' in self) {
return new Promise((resolve, reject) => {
var openRequest = indexedDB.open('database', 1)
var db
openRequest.onsuccess = (event) => {
db = openRequest.result
console.log(db)
getData(db)
}
function getData(db) {
var transaction = db.transaction(['database'], 'readwrite')
var objectStore = transaction.objectStore('database')
var objectStoreRequest = objectStore.get('entries')
objectStoreRequest.onsuccess = function(event) {
console.log((objectStoreRequest.result))
resolve(objectStoreRequest.result)
}
objectStore.onerror = function(event) {
reject(transaction.error)
}
}
})
}
})
.then(console.log)
.catch(console.log)
Any idea? Thanks
Edit: I have to send 'Promise', cause webpack transform 'Promise'
The error was the Promise
, in this case, but now show another error, I removed the polyfills
Code:
Error: Line 34 in blob:http://localhost:9080/ea8378f9-59f9-4efe-a27a-d181c29da420: Uncaught DataCloneError: Failed to execute 'postMessage' on 'DedicatedWorkerGlobalScope': #<Promise> could not be cloned.
But
I can see that function in run not accept a Promise
, but then I don't know how to return the values, 🤔
cause as parameters doesn't i can't pass a function...