electron中的IPC通信报错

electron 中用IPC通信
如果传递的对象有方法就会报错
Uncaught (in promise) Error: An object could not be cloned.

at EventEmitter.i.invoke (electron/js2c/renderer_init.js:71)
at VueComponent.ipcTest (webpack-internal:///./src/renderer/mixins/index.js:8)

electron的IPC使用结构化克隆算法,可以理解没办法传function,但是尼玛为什么非要报错呢
他不能像序列化一样,直接忽略掉吗?
就很烦!我还得自己先json.stringify一下
各位大神有什么好的建议,能节省一点性能吗

阅读 12.9k
1 个回答

看下这里有没有帮助:https://github.com/electron/e...

For anyone googling this error, this can also happen if a formerly synchronous function is suddenly made asynchronous, without the corresponding await in the caller. If the result was then sent via IPC, the serializer may not be able to handle this.

This isn't a problem with Electron and the IPC, it's effectively the missing await before the IPC.(这不是Electron和IPC的问题,这是缺少await的问题)

I ran into this with the undocumented breaking changes made in electron-settings in its 4.0 major update (e.g. get and set are now async). I suspect the IPC is having trouble serializing a promise...

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题