UnhandledPromiseRejectionWarning: Error: An object could not be cloned.

Preflight Checklist

  • [ ] I have read the Contributing Guidelines for this project.
  • [ ] I agree to follow the Code of Conduct that this project adheres to.
  • [ ] I have searched the issue tracker for an issue that matches the one I want to file, without success.

Issue Details

  • Electron Version:
    9.0.0
  • Operating System:
    mac 10.15.3
  • Last Known Working Electron version:
    8.3.0

Expected Behavior

executeJavaScript doesn’t throw an error.

Actual Behavior

$ npm start

Tracup@2.3.5 start /Users/allengu/Desktop/tracup-client_4
electron .

(node:2169) UnhandledPromiseRejectionWarning: Error: An object could not be cloned.
at EventEmitter../lib/renderer/ipc-renderer-internal.ts.exports.ipcRendererInternal.send (electron/js2c/re
nderer_init.js:2324:20)
at EventEmitter. (electron/js2c/renderer_init.js:2286:26)
(node:2169) UnhandledPromiseRejectionWarning: Error: An object could not be cloned.
at EventEmitter../lib/renderer/ipc-renderer-internal.ts.exports.ipcRendererInternal.send (electron/js2c/re
nderer_init.js:2324:20)
at EventEmitter. (electron/js2c/renderer_init.js:2286:26)
(node:2169) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by thr
owing inside of an async function without a catch block, or by rejecting a promise which was not handled with
.catch(). (rejection id: 1)
(node:2169) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by thr
owing inside of an async function without a catch block, or by rejecting a promise which was not handled with
.catch(). (rejection id: 1)
(node:2169) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise
rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:2169) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise
rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:2169) UnhandledPromiseRejectionWarning: Error: An object could not be cloned.
at EventEmitter../lib/renderer/ipc-renderer-internal.ts.exports.ipcRendererInternal.send (electron/js2c/re
nderer_init.js:2324:20)

To Reproduce

Screenshots

Additional Information

upgrade the electron to the latest version, i found the error, i reviewed the document but I didn’t get it, how can I solve this problem?

1 possible answer(s) on “UnhandledPromiseRejectionWarning: Error: An object could not be cloned.

  1. This is expected – see

    ### Behavior Changed: Values sent over IPC are now serialized with Structured Clone Algorithm
    The algorithm used to serialize objects sent over IPC (through
    `ipcRenderer.send`, `ipcRenderer.sendSync`, `WebContents.send` and related
    methods) has been switched from a custom algorithm to V8’s built-in [Structured
    Clone Algorithm][SCA], the same algorithm used to serialize messages for
    `postMessage`. This brings about a 2x performance improvement for large
    messages, but also brings some breaking changes in behavior.
    Sending Functions, Promises, WeakMaps, WeakSets, or objects containing any
    such values, over IPC will now throw an exception, instead of silently
    converting the functions to `undefined`.
    “`js
    // Previously:
    ipcRenderer.send(channel, { value: 3, someFunction: () => {} })
    // => results in { value: 3 } arriving in the main process
    // From Electron 8:
    ipcRenderer.send(channel, { value: 3, someFunction: () => {} })
    // => throws Error(“() => {} could not be cloned.”)
    “`
    `NaN`, `Infinity` and `-Infinity` will now be correctly serialized, instead
    of being converted to `null`.
    Objects containing cyclic references will now be correctly serialized,
    instead of being converted to `null`.
    `Set`, `Map`, `Error` and `RegExp` values will be correctly serialized,
    instead of being converted to `{}`.
    `BigInt` values will be correctly serialized, instead of being converted to
    `null`.
    Sparse arrays will be serialized as such, instead of being converted to dense
    arrays with `null`s.
    `Date` objects will be transferred as `Date` objects, instead of being
    converted to their ISO string representation.
    Typed Arrays (such as `Uint8Array`, `Uint16Array`, `Uint32Array` and so on)
    will be transferred as such, instead of being converted to Node.js `Buffer`.
    Node.js `Buffer` objects will be transferred as `Uint8Array`s. You can
    convert a `Uint8Array` back to a Node.js `Buffer` by wrapping the underlying
    `ArrayBuffer`:
    “`js
    Buffer.from(value.buffer, value.byteOffset, value.byteLength)
    “`
    Sending any objects that aren’t native JS types, such as DOM objects (e.g.
    `Element`, `Location`, `DOMMatrix`), Node.js objects (e.g. `process.env`,
    `Stream`), or Electron objects (e.g. `WebContents`, `BrowserWindow`,
    `WebFrame`) is deprecated. In Electron 8, these objects will be serialized as
    before with a DeprecationWarning message, but starting in Electron 9, sending
    these kinds of objects will throw a ‘could not be cloned’ error.
    [SCA]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm

    for more details.