如何在Firefox Webextensions中执行命令行程序? [英] How to execute a command line program in Firefox Webextensions?

查看:175
本文介绍了如何在Firefox Webextensions中执行命令行程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用一个简单的WebExtensions插件运行一个命令(在磁盘上的exe文件),并且可能会得到它的stdout。有没有办法在WebExtensions中这样做,因为旧的API已被弃用?

解决方案

这个博客文章提到 - a href =https://blog.mozilla.org/addons/2016/06/09/webextensions-for-firefox-49/ =nofollow> https://blog.mozilla.org/addons/2016 / 06/09 / webextensions-for-firefox-49 /

阅读 runtime.connectNative 。他们说:


runtime.connectNative



这个API允许你与主机操作系统上的其他进程。它是密码管理器和安全软件的常用API,需要与外部进程进行通信。

为了与本地进程通信,有两个步骤。首先,您的安装程序需要在目标计算机上的适当文件位置安装JSON清单文件。该JSON清单提供了Firefox和进程之间的链接。其次,用户安装附加组件。然后这个插件可以调用connectNative,sendNativeMessage和其他API:
$ b $ $ $ $ $ $ $ $ $ $ chrome.runtime.sendNativeMessage('your-application' ,
{text:Hello},
function(response){
console.log(Received+ response);
});

如果Firefox尚未启动,则会启动该进程,并将命令传递给进程。跟随Bugzilla上runtime.connectNative的进度。



I'd like to run a command (exe somewhere on disk) with arguments in a simple WebExtensions addon, and possibly get its stdout. Is there a way to do so in WebExtensions, since the older APIs are being deprecated?

解决方案

This blog post mentions how - https://blog.mozilla.org/addons/2016/06/09/webextensions-for-firefox-49/

Read the section runtime.connectNative. They say:

runtime.connectNative

This API allows you to communicate with other processes on the host’s operating system. It’s a commonly used API for password managers and security software which needs to communicate with external processes.

To communicate with a native process, there’s a two-step process. First, your installer needs to install a JSON manifest file at an appropriate file location on the target computer. That JSON manifest provides the link between Firefox and the process. Secondly, the user installs the add-on. Then the add-on can call the connectNative, sendNativeMessage and other APIs:

chrome.runtime.sendNativeMessage('your-application',
  { text: "Hello" },
  function(response) {
    console.log("Received " + response);
});

Firefox will start the process if it hasn’t started already, and pipe commands through to the process. Follow along with the progress of runtime.connectNative on Bugzilla.

这篇关于如何在Firefox Webextensions中执行命令行程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆