mirror of
https://github.com/mdn/webextensions-examples.git
synced 2026-04-16 06:18:35 +02:00
Updated links to point to MDN, and added link to troubleshooting guide
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
This is a very simple example of how to use native messaging to exchange messages between a WebExtension and a native application.
|
||||
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".
|
||||
|
||||
@@ -12,14 +12,14 @@ To get this working, there's a little setup to do.
|
||||
|
||||
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 [Host Manifests ](https://wiki.mozilla.org/WebExtensions/Native_Messaging#Host_Manifests) to find the correct location for your OS.
|
||||
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 [Host Manifests ](https://wiki.mozilla.org/WebExtensions/Native_Messaging#Host_Manifests) to find details of the registry key to add.
|
||||
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 ##
|
||||
|
||||
@@ -29,3 +29,5 @@ You should see a new browser action icon in the toolbar. Open the console ("Tool
|
||||
|
||||
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.
|
||||
|
||||
Reference in New Issue
Block a user