0

I am trying to get the Chrome Native Messaging example found here to work. I have had to make some changes to the host script to work with Python 3.

I successfully ran the install_host.sh file which created the file /Library/Application Support/Google/Chrome/NativeMessagingHosts/com.google.chrome.example.echo.json. This file correctly contains the path to the python host file.

Changes to example

I have edited the host file as advised here to fix the issues relating to the type. The send message function now reads

def send_message(message):
    encodedContent = json.dumps(message)
    encodedLength = struct.pack('@I', len(encodedContent))
    encodedMessage = {'length': encodedLength, 'content': encodedContent}
    sys.stdout.buffer.write(encodedMessage['length'])
    sys.stdout.write(encodedMessage['content'])
    sys.stdout.flush()

Problem

I think the issue is connecting the chrome application to the python script. When i run the the chrome extension at chrome-extension://knldjmfmopnpolahpmmgbagdohdnhkik/main.html i get this error

Connecting to native messaging host com.google.chrome.example.echo

Failed to connect: Specified native messaging host not found.

Could anyone please advise as to what step i might be missing in order to get the Chrome web extension to send and receive messages to the python script.

  • The "user-specific" path should be inside the user directory e.g. `~/Library/........` – wOxxOm Nov 20 '19 at 05:16
  • the path is actually the full path to the file, i just removed my username when sharing on here – Eddy Herman Nov 20 '19 at 09:54
  • sorry my mistake the path to the file is `~/Library/Application Support/Google/Chrome/NativeMessagingHosts/com.google.chrome.example.echo.json` but the path inside the json file contains the relative path to the python script. – Eddy Herman Nov 20 '19 at 10:51
  • The documentation says "On Linux and OSX the `path` [in json] must be absolute". – wOxxOm Nov 20 '19 at 11:03
  • i changed to an absolute path but have the same error – Eddy Herman Nov 20 '19 at 14:23
  • Try restarting the browser. Try [enabling logging](https://www.chromium.org/for-testers/enable-logging) and inspect the result. – wOxxOm Nov 20 '19 at 14:25

0 Answers0