WebExtensions 本机消息传递太快关闭目标应用程序

WebExtensions Native messaging shuts down targeted application too quickly

在 background.js 文件中,我使用以下命令在我的计算机上启动程序:

var 发送 = browser.runtime.sendNativeMessage("program",json_obj);

即使程序需要 运行 更长时间,它也会在几秒钟后关闭程序。在我测试过的其他计算机上,程序 运行 的速度足以完成执行。

文档说:

A new instance of the application is launched for call to runtime.sendNativeMessage(). The browser will terminate the native application after getting a reply. To terminate a native application, the browser will close the pipe, give the process a few seconds to exit gracefully, and then kill it if it has not exited.

看来程序的回复消息导致关机。

我使用的示例类似于此处显示的示例:https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Native_messaging

除了我正在 运行 一个 jar 文件而不是 python 一个。我没有将 @echo off 放入批处理文件中,因为这样 Java 程序根本不会启动。我需要延迟本机应用程序的回复,以便 Java 程序可以完成执行。

谢谢。

如果您使用 connectNative() 而不是 sendNativeMessage(),只要创建的端口在浏览器中处于活动状态(即直到您明确关闭它或来自它创建的已卸载)