0

SCENARIO


I'm on Windows 10 x64 with Firefox v51.0, and I'm completely newbie on the Mozilla's extension development world (and also with JavaScript lang.)

For writing my very first "Hello world" extension I followed the Borderify example on Mozilla's website, which worked fine on my side.

PROBLEM


Now I'm trying to modify the original sample to write a simple script that must run a external application when the user is on a mozilla.org webpage. To accomplish this task I'm trying to use the nsiProcess interface. The problem is that the application doesn't execute.

manifest.json

{

  "manifest_version": 2,
  "name": "Test",
  "version": "1.0",

  "description": "Runs a external application.",

  "icons": {
    "48": "icons/border-48.png"
  },

  "content_scripts": [
    {
      "matches": ["*://*.mozilla.org/*"],
      "js": ["test.js"]
    }
  ]

}

test.js

// create an nsIFile for the executable
var file = Components.classes["@mozilla.org/file/local;1"]
                     .createInstance(Components.interfaces.nsIFile);
file.initWithPath("c:\\myapp.exe");

// create an nsIProcess
var process = Components.classes["@mozilla.org/process/util;1"]
                        .createInstance(Components.interfaces.nsIProcess);
process.init(file);

// Run the process.
process.run(false);

myapp.exe (which yes, it is located in C:\ root) is an application that just has an empty/default form, it is developed in .NET platform (C#), targetting .NET Framework 4.5 on WinForms technology. I also tried to run other applications like Notepad (specifying the full filepath) with no results. I also tried to change the "://.mozilla.org/*" pattern to match other websites.

QUESTION


I'm doing something wrong?, how can I run that executable?.

Additionally and optionally, I will apreciate so much if someone could explain me how could I debug what is happening in my code (to discover errors/exceptions) after the script is loaded in Firefox, because I'm totally blind in that manner, I just can say the script "does nothing" (because it does not run the external execuaable) but I have no control over the code at all because I'm missing where to find the debugging instrumental.

7
  • Related/partial duplicate of: Unable to use Components in WebExtensions: get "ReferenceError: Cu is not defined" Commented Jul 27, 2017 at 6:33
  • Another partial duplicate: Google Chrome / Firefox do not see extension output in console Commented Jul 27, 2017 at 6:38
  • Please keep your Questions to one question per Question. Questions which contain multiple questions which are not very tightly related are considered too broad and tend to be closed. The reason for this is that the Stack Overflow format is intended to provide a base of questions and answers which are useful to people in the future, not just the person currently asking. Questions with multiple issues tend to be too specific to be useful to others searching for help to their problems. Often, to solve a larger issue it is necessary to combine the answers from multiple questions. Commented Jul 27, 2017 at 6:45
  • In addition, having one Question per question allows us to use questions and answers as targets to close other questions as duplicates of them. While a decent answer explaining installation or use of native messaging could be written, the additional issues in your question make using as a duplicate-target less desirable. Commented Jul 27, 2017 at 6:51
  • The partial duplicate links are directly relevant to your question. They explicitly answer two of the three issues you have in your question. Commented Jul 27, 2017 at 11:38

3 Answers 3

7

WebExtensions do not have access to XPCOM (or more specifically, to Components which your code references). The WebExtensions replacement for nsIProcess is native messaging: https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Native_messaging

Documentation on how to debug WebExtensions is here: https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Debugging

Sign up to request clarification or add additional context in comments.

9 Comments

Thankyou for answer. It seems very complicated, firstly I only would need to run the graphical application, I don't pretend to read the stdIn/stdOut buffer,and secondly I don't have any clear which must be the filename of the "App manifest" that explains in the article you linked, there is any information in all the article about that neither how to do the installation of that "App manifest" from the extension itself.Almost all the steps are unclear for me,please,¿could you provide a simple premade example/extension that just connect (run) a external graphical application on Windows?.Thankyou.
Distribution and installation of native applications is deliberately separated from extensions so you'll need to arrange to install the app manifest in a separate (native) installer. I'm sorry I don't know much about Windows, perhaps another question in a different category...
This is a Mozilla official example for Native Messaging.
As Andrew Swan told, ElektroStudios, you need install it, the old legacy Mozilla extensions had security issues, imagine if with only an extension you can run anything, also it's possible to run malware... Even before to migrate to WebExtensions Mozilla was disabling some features because the security issues, and fixing others. Also the behaviour that you wanted is PUA for many anti-malwares.
The feature is supported in the way explained in the answer, I only told the reasons why that way to support it and not the old way, because the way you think is the correct is a big security hole.
|
1

It's possible, but only indirectly through Native Messaging.

https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Examples

You'll need an external program supporting this type of interfacing.

The example in question: https://github.com/mdn/webextensions-examples/tree/master/native-messaging

I'm not quite sure, though, how/if that works in a page's script context.

Comments

-1

This is not supported for safety reason. And altough you manage doing it today, it won't work anymore in few months next to a firefox release... if you want to launch a binary, I would suggest create a webservice you communicate with http requests . the webservice will be responsible to launch the application. a minimal webservice can be done with python BaseHttpServer.Furthermore it will work on any browser ..

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.