python - How to get Chrome Native Messaging example to work with Python script on Mac
问题描述
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.
解决方案
推荐阅读
- django - 'function' 对象没有属性 'order_by'
- latex - 如何在 Latex 中创建此表?
- gluon - Tornadofx2 - 使用 Gluon 的 NativeBuild
- reactjs - React-Leaflet:尽管 Redux 存储更新中的颜色值,但折线不会改变颜色
- css - 如何在垫子按钮,右边框/左边框上添加边框颜色?
- linux - 单击鼠标时 vs code 终端总是有自动换行
- c# - 拆分已经拆分的字符串
- sockets - 1个端口如何同时监听http和websocket
- c# - OFFFILT.DLL.from 程序文件在 C# 中的少数服务器中不起作用。获取 System.AccessViolationException 异常
- php - wordpress 过滤器动态更改某些页面上的徽标