How to execute a command line program in Firefox Webextensions?
Asked Answered
C

1

7

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?

Counterstroke answered 11/6, 2016 at 23:59 Comment(0)
F
5

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.

F answered 14/6, 2016 at 12:56 Comment(2)
Since the blog lists this API as "in progress" I'm guessing it can't be used right now?Scuttlebutt
@MichaelBednarek probably can only be used in Nightly and Dev Edition. If you want to make a Firefox Addon SDK addon though, you can use child_process - developer.mozilla.org/en-US/Add-ons/SDK/Low-Level_APIs/…F

© 2022 - 2024 — McMap. All rights reserved.