一个包含用于webextensions的基本本地消息传递api的包

nativemessaging的Python项目详细描述


#native messaging
一个python包,用于在webextensions中与本机消息交互

[参见mdn上的本机消息传递](https://developer.mozilla.org/en-us/docs/mozilla/add-ons/webextensions/native-messaging)

mdn](https://developer.mozilla.org/en-us/docs/mozilla/add-ons/webextensions/native_messaging_app_side)和[mdn上的本机消息/webextension示例](https://github.com/mdn/webextensions-examples/tree/master/native-messaging)(MPL 2.0许可证)

`pip3 install nativemessaging`

##` get_message()`
`nativemessaging.get_message()`将从浏览器轮询消息。
如果使用了[`runtime.connectnative`](https://developer.mozilla.org/en-us/docs/mozilla/add-ons/webextensions/api/runtime/connectnative),则必须在循环中重复调用“get_message()”来轮询消息。
如果使用了[`runtime.sendNativeMessage`](https://developer.mozilla.org/en-us/docs/mozilla/add-ons/webextensions/api/runtime/sendNativeMessage),则只需调用一次“get戋u message()”。

“encode戋u message(message戋content)”`
“nativeMessaging.encode戋message()”只需要一个参数,即要编码的消息。
返回要返回到浏览器的消息的编码版本。与“send_u message()”一起使用。

\send_u message(encoded_u message)`
`nativemessaging.send_u message()`接受一个参数,即来自“encode_u message()”的编码消息。向浏览器返回消息。

示例
浏览器端:
``javascript
函数onreceived(response){
console.log(response);
}

//runtime.connectnative
var port=browser.runtime.connectnative(“application_name”);
port.onMessage.addListener(onReceived);
port.postmessage(“hello”);

//runtime.sendNativeMessage
browser.runtime.sendNativeMessage(“应用程序名”,“你好”)。然后(onReceived);
```

app-side:
``python
import nativemessaging

while true:
message=nativemessaging.get_message()
if message==“hello”:
nativemessaging.send_message(nativemessaging.encode_message(“world”))
````

nativemessaging install
`nativemessaging install`是一个命令行脚本与软件包一起提供。

\arguments
`nativemessaging install browser[--manifest manifest]`
*`browser`-位置参数,一个或多个参数。必须是“chrome”或“firefox”。
*`--manifest`-要用于安装的清单文件的路径。

除非传递了“-manifest”。
格式必须与chrome或firefox的本机清单格式相似,但有两个主要区别:
*`path`必须是相对于当前工作目录的本机应用程序的相对路径。
*必须在清单中同时包含“允许的扩展名”和“允许的源代码”才能与chrome一起使用以及火狐。
``json
{
“name”:“application_-name”,
“description”:“description”,
“path”:“application_-name.py”,
“type”:“stdio”,
“allowed_扩展名”:“extension@id”],
“allowed_起源名”:“chrome extension://extension id”]

````



我是说,它将在与“<;path>;”相同的目录中创建“<;application\u name>;\u firefox.json”和“<;application\u name>;\u chrome.json”。
还将为windows上的python应用程序创建批处理文件。
在“hkey_current_user\software\google\chrome\nativemessaginghosts”<;application_name>;`或“hkey_current_user\software\mozilla\nativemessaginghosts”<;application_name>;`

在Linux上,它将创建` ~/.config/google chrome/nativemessaginghosts/<;application_name>;.json或`~/.mozilla/native messaging hosts/<;application_name>;.json `

在Mac上,它将创建e`~/library/application-support/google/chrome/nativemessaginghosts/<;application-name>;.json`或`~/library/application-support/mozilla/nativemessaginghosts/<;application-name>;.json`

;另请参见:
*[chrome文档的本地消息](https://developer.chrome.com/extensions/native messaging)


欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java不支持org。阿帕奇。平民数学3。分配二元分布(1,p)`会带来很多性能开销吗?   java Android开发人员新手无法在模拟器中启动代码   显示不同版本的java版本和javac版本   java在这种情况下如何使用Spring和Hibernate正确更新对象?   java改变了我整个安卓 studio应用程序的主题   java在LIBGDX中生成可执行Jar文件   mysql对sql结果进行排序,并在java中通过循环在表中显示所有结果   swing如何在java中的textArea中新添加的文本末尾自动显示插入符号?   java需要验证时间,但会不断遇到问题   java像字符串一样拆分“数组”   java Apache Camel:具有属性和属性占位符的RecipientList不起作用   java中的文件子目录和主目录监视   java这样使用Spring规范谓词安全吗?   带Eclipselink的java Oracle 12c标识列   java为什么我在socket inputstream中遇到奇怪的字符   java Hibernate+swing检查登录/密码   java Log4j如何仅禁用致命条目   会话失效后找到的java数据   MySql查询:如何使用MySql和java同时执行两个查询?