native_messaging

package
v1.85.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package native_messaging speaks the browsers' native messaging protocol: each message is a little-endian uint32 length followed by that many bytes of JSON, over the process's own standard input and output.

Nothing else may be written to standard output. A stray print becomes a length prefix, and the browser then waits for a message that will never be the right size — which is why this package owns the stream, and why a native application's diagnostics belong in the journal instead.

Index

Constants

View Source
const MaximumMessageBytes = 1 << 20

MaximumMessageBytes is the largest message the browsers accept in either direction. Firefox and Chrome both stop at a megabyte, so anything longer has to be sent in pieces.

Variables

View Source
var ErrMessageTooLarge = errors.New("message is too large")

ErrMessageTooLarge is a message over the browsers' limit.

It is also what a length prefix that cannot be a real message reads as, and that is the point of checking it before allocating: the prefix is four bytes of untrusted input, a uint32 reaches four gigabytes, and a stream that has lost its framing produces exactly such a number.

Functions

func Read

func Read(reader io.Reader, message any) error

Read reads one message into message. It returns io.EOF once the browser has closed the port, which is how a native application is told to exit.

Message contents are never attached to the errors returned here. A native application carries whatever the extension sends it — a page's text, a form's contents — and an error value is written to the journal, so putting the payload in one turns a parse failure into a disclosure.

func Write

func Write(writer io.Writer, message any) error

Write writes one message.

Types

This section is empty.

Jump to

Keyboard shortcuts

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