Update native-messaging to use python3, clarify instructions

Fixes #560
This commit is contained in:
Simeon Vincent
2024-07-12 18:42:56 -07:00
parent 91c8d7e708
commit b5260e150a
6 changed files with 63 additions and 24 deletions

View File

@@ -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" ]
}

View File

@@ -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.

View File

@@ -1,3 +1,3 @@
@echo off
call python C:\path\to\ping_pong.py
call python3 C:\path\to\ping_pong.py