当前位置: 代码迷 >> 综合 >> Passing functions, DOM objects to IPC methods is deprecated and will throw an exception
  详细解决方案

Passing functions, DOM objects to IPC methods is deprecated and will throw an exception

热度:54   发布时间:2024-02-11 13:39:18.0

目录

 

问题

原因

解决


问题

使用Electron做IPC进程间通讯的过程中,遇到了如下警告。

警告信息具体内容如下:

DeprecationWarning: Passing functions, DOM objects and other non-cloneable JavaScript objects to IPC methods is deprecated and will throw an exception beginning with Electron 9.

警告信息的大概意思是,采用了不推荐使用的方式:将函数、DOM对象和其他不可克隆的JavaScript对象传递给IPC方法,这样可能会引发以Electron的异常报错。

原因

后来分析代码发现,渲染进程使用ipcRender.send方法向主进程发送了一个异步消息,但是接收端还没有做好接收准备,导致了相同消息频繁转发,造成了后续一系列问题。

解决

通过渲染进程增加状态控制,已经接收端窗口完全创建后主动通知对端再进行二者的消息通讯。可能会涉及到具体的流程问题,细节不过多透露。如有疑问或者其他见解可以私信沟通。

  相关解决方案