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 ¶
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 ¶
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 ¶
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.
Types ¶
This section is empty.