This is a very simple example of how to use [native messaging](https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Native_messaging) to exchange messages between a WebExtension and a native application.
The WebExtension, which can be found under "add-on", connects to the native application and listens to messages from it. It then sends a message to the native application when the user clicks on the WebExtension's browser action. The message payload is just "ping".
The native application, which can be found under "app", listens for messages from the WebExtension. When it receives a message, the native application sends a response message whose payload is just "pong". The native application is written in Python.
## Setup ##
To get this working, there's a little setup to do.
### Mac OS/Linux setup ###
1. Check that the [file permissions](https://en.wikipedia.org/wiki/File_system_permissions) for "ping_pong.py" include the `execute` permission.
2. Edit the "path" property of "ping_pong.json" to point to the location of "ping_pong.py" on your computer.
3. copy "ping_pong.json" to the correct location on your computer. See [App manifest location ](https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Native_messaging#App_manifest_location) to find the correct location for your OS.
### Windows setup ###
1. Check you have Python installed, and that your system's PATH environment variable includes the path to Python. See [Using Python on Windows](https://docs.python.org/2/using/windows.html). You'll need to restart the web browser after making this change, or the browser won't pick up the new environment variable.
2. Edit the "path" property of "ping_pong.json" to point to the location of "ping_pong_win.bat" on your computer. Note that you'll need to escape the Windows directory separator, like this: `"path": "C:\\Users\\MDN\\native-messaging\\app\\ping_pong_win.bat"`.
3. Edit "ping_pong_win.bat" to refer to the location of "ping_pong.py" on your computer.
4. Add a registry key containing the path to "ping_pong.json" on your computer. See [App manifest location ](https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Native_messaging#App_manifest_location) to find details of the registry key to add.
## Testing the example ##
Then just install the add-on as usual, by visiting about:debugging, clicking "Load Temporary Add-on", and selecting the add-on's "manifest.json".
You should see a new browser action icon in the toolbar. Open the console ("Tools/Web Developer/Browser Console" in Firefox), and click the browser action icon. You should see output like this in the console:
Sending: ping
Received: pong
If you don't see this output, see the [Troubleshooting guide](https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Native_messaging#Troubleshooting) for ideas.
没有合适的资源?快使用搜索试试~ 我知道了~
使用 WebExtensions API 创建的 Firefox 附加组件示例
共383个文件
js:90个
png:65个
json:59个
0 下载量 127 浏览量
2023-12-03
12:04:26
上传
评论
收藏 2.13MB ZIP 举报
温馨提示
WebExtensions 是一种编写浏览器扩展的方法:即程序 安装在修改浏览器行为的 Web 浏览器中,或 浏览器加载的网页。它们建立在一组 跨浏览器 API,因此为 Google Chrome 或 Opera 编写的 WebExtensions 将 在大多数情况下,也可以在Firefox或Edge中运行。“webextensions-examples”存储库是一个简单但完整的集合 和可安装的 WebExtensions。您可以使用这些示例来了解如何使用 WebExtensions API,并作为您自己的 WebExtensions 的起点
资源推荐
资源详情
资源评论
收起资源包目录
使用 WebExtensions API 创建的 Firefox 附加组件示例 (383个子文件)
.babelrc 158B
ping_pong_win.bat 47B
bootstrap.min.css 118KB
bootstrap.min.css 118KB
quicknote.css 1KB
style.css 997B
bgpicker.css 498B
panel.css 481B
options.css 464B
history.css 451B
choose_ua.css 332B
choose_beast.css 316B
options.css 256B
context.css 186B
options.css 185B
tabs.css 184B
window.css 106B
cookies.css 89B
popup.css 81B
page.css 62B
.gitignore 90B
.gitignore 60B
.gitignore 14B
left-pad.html 1KB
tabs.html 1KB
options.html 1KB
page.html 1KB
window.html 1KB
popup.html 688B
latest_download.html 633B
bgpicker.html 614B
sites.html 582B
quicknote.html 495B
options.html 425B
history.html 418B
cookies.html 384B
choose_ua.html 354B
choose_beast.html 350B
preview.html 345B
options.html 333B
panel.html 271B
options.html 270B
options.html 270B
context.html 254B
popup.html 244B
popup.html 209B
options.html 202B
popup.html 180B
popup.html 168B
popup.html 168B
popup.html 168B
popup.html 168B
popup.html 168B
sidebar.html 160B
my-page.html 120B
snake.jpg 233KB
frog.jpg 229KB
turtle.jpg 138KB
browser-polyfill.min.js 8KB
tabs.js 6KB
quicknote.js 5KB
emojiMap.js 4KB
background.js 4KB
substitute.js 3KB
background.js 3KB
history.js 2KB
window.js 2KB
background.js 2KB
background.js 2KB
authorize.js 2KB
background.js 2KB
background.js 2KB
latest_download.js 2KB
bgpicker.js 2KB
karma.conf.js 2KB
background.js 2KB
proxy-handler.js 2KB
context.js 2KB
options.js 2KB
panel.js 1KB
webpack.config.js 1KB
choose_beast.js 1KB
page.js 1KB
background.js 1KB
cookies.js 1KB
auth.js 1KB
options.js 1KB
beastify.js 975B
background.js 935B
popup.js 926B
addon-ui.js 913B
background.js 876B
options.js 851B
background.js 834B
popup.js 801B
content-script.js 799B
bootstrap.js 799B
left-pad.js 794B
clipboard-helper.js 736B
user-data-storage.js 716B
共 383 条
- 1
- 2
- 3
- 4
资源评论
Java程序员-张凯
- 粉丝: 1w+
- 资源: 6834
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Numpy数组和矩阵运算(2.数组运算)
- 基于Matlab 实现粒子滤波的多雷达多目标检测前跟踪算法
- Numpy数组和矩阵运算(1.创建数组)
- 基于C++实现多目标跟踪系统
- 基于单片机的压力流量报警器(附代码+proteus仿真+论文)
- 基于 Flask 的请假审批管理系统设计与实现
- Test Report TC-24-37 MQ012K0VPY 25.764-28.476MHz.SchDoc
- Java项目-基于Springboot+Vue的校园博客系统的设计与实现(源码+万字LW+部署视频+代码讲解视频+全套软件)
- 服务器虚拟化工具VMware vSphere Client for windows(VMware-viclient-all-6)
- 文件批量改名工具,用于替换/更改字符,更改文件后缀等
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功