How To Fix Original Host Chrome Extension Came Out Error - Native Messaging

How do I fix the outgoing host exited error in my Chrome browser extension for Mac? The docs here Native Messaging specifically mention this error at the bottom and suggest the likely cause, but it is stated as a whole ("This is most likely initiated from your own messaging server) and it is not clear what to do to fix this issue ...

The log output in Terminal (if you launch Chrome from the Mac terminal, you can view the logging information) made me believe that a process for a native host application itself never starts successfully. I keep getting:

LaunchProcess: failed to execvp:
/Users/mycomputer1/Documents/myhost.app

      

However, the actual code that prints "Source host exited" to the console for the background javascript page is:

function onDisconnected() {
  console.log("Inside onDisconnected(): " + chrome.runtime.lastError.message);
  port = null;
}

      

The onDisconnected () listener is actually called as a result of the connectNative () call I made here according to the documentation:

chrome.runtime.onMessageExternal.addListener(
function(request, sender, sendResponse) {
//var imgdata = JSON.stringify(request.imgdata);
//process it somehow here

    port = chrome.runtime.connectNative("com.allinlearning.ailhost");

    if (port)
    {
       console.log("connectNative() returned a non-null port");
    }
});

      

I know connectNative () succeeds at some bc level, it returns a valid port. However, connectNative () keeps looking for the local host app and tries to start it. The docs suggest that the host app is the culprit, somehow initiating a pipe break between Chrome and the native app, even though my host app doesn't interact with stdout or stdin at all. Also, the Chrome logs log ("LaunchProcess: failed, execvp:") seems to indicate that my Mac app never started successfully.

There's more: some source code I found on the internet (possibly out of date? Source file ) shows exactly where this "main host came out" msg originates and research shows why Google Chrome code closes everything. In HandleReadResult (), the Close () function is called delivering the message itself, and then closes everything in response to a Posix read () message that returns 0. But what in the wide, wide world of sports am I doing wrong (or not doing at all) in my Mac app so that this reading does not work? Mac app Mac does not write anything to stdout since nothing is written, what causes the read error? Or is all this misleading me and execvp is not starting my host application for a deeper reason? If so, why? This is an app with a simple jen, barebone Mac.

+4


source to share


3 answers


Your "myhost.app" is not binary, but a directory (as shown by the X in your permissions u+w,go-w,a+rX

).

You have two options:



  • DO NOT create an app package for your command line, but a simple command line app (File> New> Project> Command Line Tool in Xcode ( tutorial )).

  • Specify the path to the application bundle binary instead of the package itself. You can list all the files in an application bundle by right-clicking on the .app file and choosing Show Package Contents. Or run the following command from Terminal (Console) to list all the files in your bundle:

    find /Users/mycomputer1/Documents/myhost.app -type f
    
          

+1


source


Your native app and Chrome communicate through the console, which is hidden in most cases. If your application is using the console for more than just communicating with chrome (like executing a system command), chrome will catch this and interpret it as a bad response from your application and close the communication between them.

Therefore, it is recommended that you use one of the following workarounds:

  • Don't use the (same) console to launch anything other than chatting with Chrome
  • Buffer console output instead of sending it to standard output


Another thing to note is that in some languages ​​(like php) some commands (like preg_match) do not seem to have any output as they manipulate data based on their arguments, BUT they do return a result (like true / false) and if you don't suppress that result (@function () in php) or store it in a variable, it goes to stdout and causes chrome to shutdown.

Sorry if this is not directly relevant to the question, but I hope this helps some people as this question shows up in search results. I myself have been struggling with this problem for several hours.

0


source


Happened to me on Linux (RHEL 7.6). To find the root cause, you need to launch Chrome from the console (from the command line) and open the gnome extensions page:

$ /opt/google/chrome/chrome "https://extensions.gnome.org"

      

Then look in the console if you see any errors. For me it was 'chrome-gnome-shell' error due to missing python module named 'gi':

Traceback (most recent call last):
Traceback (most recent call last):
  File "/usr/bin/chrome-gnome-shell", line 16, in <module>
    from gi.repository import GLib, Gio
ModuleNotFoundError: No module named 'gi'

      

To fix this, I had to install PyGObject :

$ sudo yum install python36-gobject.x86_64
# or directly with pip: pip3 install PyGObject

      

Once the installation is complete, go back to https://extensions.gnome.org (you may need to close and reopen Chrome) - now it shows no errors and works fine.

0


source







All Articles