mirror of
https://github.com/mdn/webextensions-examples.git
synced 2026-04-17 23:08:33 +02:00
Update native-messaging to use python3, clarify instructions
Fixes #560
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "ping_pong",
|
||||
"description": "Example host for native messaging",
|
||||
"path": "/path/to/native-messaging/app/ping_pong.py",
|
||||
"path": "/Users/svincent/dev/webextensions-examples/native-messaging/app/ping_pong.py",
|
||||
"type": "stdio",
|
||||
"allowed_extensions": [ "ping_pong@example.org" ]
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
import json
|
||||
@@ -19,7 +19,7 @@ try:
|
||||
# given its content.
|
||||
def encodeMessage(messageContent):
|
||||
# https://docs.python.org/3/library/json.html#basic-usage
|
||||
# To get the most compact JSON representation, you should specify
|
||||
# To get the most compact JSON representation, you should specify
|
||||
# (',', ':') to eliminate whitespace.
|
||||
# We want the most compact representation because the browser rejects
|
||||
# messages that exceed 1 MB.
|
||||
@@ -37,6 +37,7 @@ try:
|
||||
receivedMessage = getMessage()
|
||||
if receivedMessage == "ping":
|
||||
sendMessage(encodeMessage("pong3"))
|
||||
|
||||
except AttributeError:
|
||||
# Python 2.x version (if sys.stdin.buffer is not defined)
|
||||
# Read a message from stdin and decode it.
|
||||
@@ -52,7 +53,7 @@ except AttributeError:
|
||||
# given its content.
|
||||
def encodeMessage(messageContent):
|
||||
# https://docs.python.org/3/library/json.html#basic-usage
|
||||
# To get the most compact JSON representation, you should specify
|
||||
# To get the most compact JSON representation, you should specify
|
||||
# (',', ':') to eliminate whitespace.
|
||||
# We want the most compact representation because the browser rejects
|
||||
# messages that exceed 1 MB.
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
@echo off
|
||||
|
||||
call python C:\path\to\ping_pong.py
|
||||
call python3 C:\path\to\ping_pong.py
|
||||
|
||||
Reference in New Issue
Block a user