Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to execute a command line program in Firefox Webextensions?

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?

like image 712
dismantle Avatar asked Jun 11 '16 23:06

dismantle


People also ask

How do I open the command line in firefox?

You can open the command line interface by pressing Shift+F2.

How do I run an extension in firefox?

In Firefox: Open the about:debugging page, click the This Firefox option, click the Load Temporary Add-on button, then select any file in your extension's directory. The extension now installs, and remains installed until you restart Firefox.

How do I start firefox from command line Linux?

Use nohup firefox & to run firefox from terminal and you can use terminal for other process, if you close terminal, firefox will not quit. If you get error like Another instance is running then use nohup firefox -P --no-remote & and create a new user profile and browse. Save this answer.


1 Answers

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.

like image 106
Noitidart Avatar answered Sep 28 '22 09:09

Noitidart