nativemessaging

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package nativemessaging lets a browser extension start this program as a native-messaging host: it writes and removes the host manifests Chromium-family browsers and Firefox look for, reports whether each installed browser's manifest points at the program, and reads and writes the stdio frames the browser exchanges with the host.

Index

Constants

This section is empty.

Variables

View Source
var ErrBadName = errors.New("nativemessaging: Host.Name must be letters, digits, '.', '_' or '-', starting with a letter or digit")

ErrBadName is the error for a Host.Name a browser would not accept and that could not be one file name.

View Source
var ErrUnsupported = errors.New("nativemessaging: host manifests are not supported on this system")

ErrUnsupported is returned by Install, Uninstall and Status on a system that is neither Linux nor Windows.

Functions

func Read

func Read(r io.Reader, limit int, v any) error

Read reads one message from the browser into v: a 4-byte length in native byte order, then that many bytes of JSON. A message longer than limit is an error before any of it is read. A stream that ends cleanly between messages gives io.EOF.

func Write

func Write(w io.Writer, v any) error

Write writes v to the browser as one message, its JSON after the length prefix, in a single Write.

Types

type Host

type Host struct {
	// Name is the host name extensions connect to, such as "org.example.app".
	Name string
	// Description is the manifest's description.
	Description string
	// Path is the program the browser starts. Inside a Flatpak, Install writes a wrapper that runs Path's base name
	// with flatpak run, and the manifests name that wrapper instead.
	Path string
	// AllowedOrigins are the Chromium-family extension origins allowed to connect, "chrome-extension://<id>/".
	AllowedOrigins []string
	// AllowedExtensions are the Firefox extension ids allowed to connect.
	AllowedExtensions []string
	// ManifestDir is the folder Windows keeps the two manifest files in. Unused on Linux.
	ManifestDir string
	// Run replaces the program runner on Linux; nil runs the real program. It gets every program the host starts
	// (inside a Flatpak, "flatpak-spawn" with "--host" first and the script's arguments after) as name and args
	// exactly as exec would take them, and returns the program's standard output. A non-nil error is a failed run.
	// Windows ignores it.
	Run func(name string, args ...string) (string, error)
}

Host is one native-messaging host. On Linux its manifests go to every installed browser's own folder, through the host from inside a Flatpak; on Windows to ManifestDir, with an HKCU key per browser pointing at them.

func (Host) Install

func (h Host) Install() error

Install writes the manifest into every installed browser's folder; a browser installed later needs another call. Inside a Flatpak it first writes the wrapper the host browser starts, since the host cannot run the sandbox's Path; the browser's arguments pass through to the program.

func (Host) Manifest

func (h Host) Manifest(firefox bool) ([]byte, error)

Manifest is the host manifest a browser reads; firefox picks that browser's allow-list field.

func (Host) Status

func (h Host) Status() ([]Status, error)

Status is each installed browser's manifest, in a fixed browser order.

func (Host) Uninstall

func (h Host) Uninstall() error

Uninstall removes the manifest from every installed browser's folder.

type State

type State string

State is how one browser's manifest stands.

const (
	// OK is a manifest that names the program.
	OK State = "ok"
	// Missing is an installed browser with no manifest.
	Missing State = "missing"
	// Stale is a manifest that names another program, such as a copy that has moved.
	Stale State = "stale"
	// Unreadable is a manifest, or on Windows a registry key, that cannot be read or holds no path.
	Unreadable State = "unreadable"
)

type Status

type Status struct {
	Browser  string
	Manifest string
	State    State
}

Status is one installed browser's manifest. Manifest is the file, or on Windows the registry key when it has no file.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL