simple-web-worker icon indicating copy to clipboard operation
simple-web-worker copied to clipboard

DOMException: Failed to execute 'postMessage' on 'Worker': function (a, b, c) {

Open fortil opened this issue 7 years ago • 2 comments

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'

fortil avatar Nov 30 '17 19:11 fortil

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

fortil avatar Nov 30 '17 23:11 fortil

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...

fortil avatar Nov 30 '17 23:11 fortil