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.