The embed protocol (version 1)

Every message is a plain object with protocol "athanor-embed" and v 1. Send hello first; each request with an id gets exactly one reply; the editor sends ready and change events.

On a Mac, Ctrl is Cmd.

You do not need this if you use athanor-embed.js. It is here so the editor can be driven from anything that can post a message.

Every message is a plain object with protocol: "athanor-embed" and v: 1.

Requests

From your page to the editor. Each carries an id, a positive integer you choose, and a type:

type Payload Result
hello { version: 1, readOnly }. Must come first
getSmiles SMILES text ("" for an empty page)
getMolfile Molfile text
getStructure format: smiles, molfile, molV3000, sdf, mrv, cml, cdxml, inchi or inchikey The page in that format
getSvg The page as an SVG document, at its own size, on no background
getPng scale (0.25 to 8, default 2) The page as a PNG data URL
setStructure data (at most 1,000,000 characters), format (smiles, molfile, mrv, cdxml, helm or auto, default auto) Replaces the page; resolves to its SMILES. A structure that cannot be read is refused with the reason
clear Empties the page. true
setReadOnly readOnly (boolean) The new state
setTheme theme: light, dark or system The theme now showing

Replies

Exactly one per request: { protocol, v, re: <id>, ok: true, result }, or { protocol, v, re: <id>, ok: false, error: "<a sentence>" }. A request with a version the editor does not speak is refused with both numbers in the sentence.

Events

From the editor to your page:

  • { protocol, v, event: "ready", version, smiles } after the handshake.
  • { protocol, v, event: "change", smiles, atoms } when the structure changes, debounced by 300 ms and only when the SMILES actually differs.

setStructure and clear start a fresh page with nothing to undo; edits made in the editor undo with Ctrl+Z as usual.

Versions

A change that a page written for version 1 could misread gets a new number. The editor keeps answering version 1, and refuses a number it does not know at the handshake.

Is this helpful?

Last updated Nov 12, 2026