nativemessaging-ng
A Python package for interfacing with Native Messaging in WebExtensions. Based on the apparently unmaintained version of Rayquaza01, which is in turn based on Native Messaging on MDN and native-messaging on mdn/webextension-examples.
Native Messaging documentation
Installation
pip install nativemessaging-ng
Usage
Methods
The nativemessaging module exposes following methods:
-
log_browser_console(message)adds the given message to the browser log (accessible via ctrl-shift-J) -
get_message_raw()polls for a message from the browser and returns the result as string. If runtime.connectNative is used,get_message()must be called repeatedly in a loop to poll for messages; if runtime.sendNativeMessage is used,get_message()only needs to be called once. -
send_message_raw(message)sends the given string message to the browser. -
get_message()polls for a message from the browser and returns the message as a json structure. -
send_message(json_message)sends the given json structured message to the browser. -
install(browsers, manifest_filename)takes a list of browsers to install the manifest and a manifest filename, to install the given manifest in the browser configuration. Supported browsers are 'chrome' and 'firefox'. -
is_installed(application_name)returns the list of browsers for which the manifest of application_name is installed. -
uninstall(browsers, application_name)uninstalls the manifest of application_name for all given browsers.
Example
Browser side:
function 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("application_name", "hello").then(onReceived);
Python application side:
import nativemessaging
while True:
message = nativemessaging.get_message()
if message == "hello":
nativemessaging.send_message("world")
nativemessaging-ng
nativemessaging-ng is a command line script to install a manifest in the browser configuration.
usage: nativemessaging-ng [-h] [--version] [--manifest MANIFEST]
[--appname NAME]
{install,verify,uninstall} BROWSER [BROWSER ...]
positional arguments:
{install,verify,uninstall}
action to take, can be install, verify or uninstall
BROWSER browser(s) for which the manifest will be installed,
valid values are chrome, chromium or firefox.
options:
-h, --help show this help message and exit
--version show program's version number and exit
--manifest MANIFEST path to the manifest file to install (default: native-
manifest.json)
--appname NAME application name to be verified or uninstalled
Manifest file
The format of the manifest file must be similar to the native manifest format for Chrome or Firefox, with two main differences:
pathmust be a relative path to the native app in relation to your current working directory.- Both
allowed_extensionsandallowed_originsmust be in the manifest to work with both Chrome and Firefox.
{
"name": "application_name",
"description": "description",
"path": "application_name.py",
"type": "stdio",
"allowed_extensions": ["extension@id"],
"allowed_origins": ["chrome-extension://extension-id"]
}
Installed files
-
Windows:
<application_name>_firefox.jsonand<application_name>_chrome.jsonwill be created in<path>- A batch file will also be created to run the python application on Windows
- A registry key is created at
HKEY_CURRENT_USER\Software\Google\Chrome\NativeMessagingHosts\<application_name>orHKEY_CURRENT_USER\Software\Mozilla\NativeMessagingHosts\<application_name>
-
Linux:
<application_name>.jsonwill be installed in~/.config/google-chrome/NativeMessagingHosts/,.config/chromium/NativeMessagingHosts/or~/.mozilla/native-messaging-hosts/
-
OS/X:
<application_name>.jsonwill be installed in~/Library/Application Support/Google/Chrome/NativeMessagingHosts/,~/Library/Application Support/Chromium/NativeMessagingHosts/or~/Library/Application Support/Mozilla/NativeMessagingHosts/
Metadata
Release files for nativemessaging-ng 1.3.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| nativemessaging_ng-1.3.3.tar.gz | 13.6 kB | Without provenance | Details for nativemessaging_ng-1.3.3.tar.gz |
Release files / nativemessaging_ng-1.3.3.tar.gz
| Download URL | nativemessaging_ng-1.3.3.tar.gz |
|---|---|
| Size | 13.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6eb0a7968cd1571bcf7470ed95242f68216de4a1c96438622af74f128a1c99b4
|
|
BLAKE2b-256 checksum How to use checksums |
6b55ff9039fc51317b9d3f3bfdeb3dc13970023a080519c35fe7778f18a8f771
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.13.1
|
Security for nativemessaging-ng 1.3.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.