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 ¶
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 ¶
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 ¶
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 ¶
Manifest is the host manifest a browser reads; firefox picks that browser's allow-list field.
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" )