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.

6
  • The "user-specific" path should be inside the user directory e.g. ~/Library/........ Commented Nov 20, 2019 at 5:16
  • the path is actually the full path to the file, i just removed my username when sharing on here Commented Nov 20, 2019 at 9: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. Commented Nov 20, 2019 at 10:51
  • The documentation says "On Linux and OSX the path [in json] must be absolute". Commented Nov 20, 2019 at 11:03
  • i changed to an absolute path but have the same error Commented Nov 20, 2019 at 14:23

0

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.