MessagePort the frame’s bootstrap relays to the host. This page is version 1 of the bridge protocol as the host speaks
it: what a widget’s entry exports, the messages on the port, every call, event and refusal, and the rules the host
applies to them. BlobHub builds its own widgets with a kit;
everything here is what a widget needs without the kit, and A widget without the kit is a
complete one in plain JavaScript.
The entry
The definition’sentry names an ES module that exports mount(element, port). The frame’s bootstrap page imports the
module and calls mount once: element is the frame’s root element, and port is the widget’s end of the bridge, a
MessagePort the bootstrap relays to the host. mount may return a promise, which the bootstrap waits for. A mount
that throws, or whose promise rejects, stops the widget: the playground shows This widget failed to start: <message>,
with the error’s message clipped to 300 characters, in place of the frame. A frame whose bootstrap page does not answer
within 10 seconds of its creation, before the widget’s code loads, shows This widget did not start.
A widget listens on the port with addEventListener("message", …) and then calls port.start(). Everything the widget
sends and receives travels on this one port. The bootstrap’s own messages travel on the host’s side and are never passed
either way: a widget neither receives one nor can post one. No bridge message carries type, so a widget may still
ignore every message with a type.
Messages
Messages are plain objects posted on the port withpostMessage, not JSON text. There are three kinds:
- Request, widget to host:
{id, method, params, session}.idis a positive integer, starting at 1 and never reused on one port;methodnames a call;paramsis a plain object, and may be left out when a call takes none;sessionis optional, a field of the request besideparamsand notui.open’s param of that name; the bullet The session a call names below says what it holds. - Reply, host to widget:
{id, result}, or{id, error: {code, message, data}}when the host refuses the call.messageanddatamay be absent. - Push, host to widget:
{event, data}, an event the widget did not ask for by id.
- Replies come in the order calls finish, not the order they were sent: match each reply to its request by
id. A reply is a refusal when itserroris notnull. A widget acts on itscode, one of the Refusals; a refusal without a stringcodereads asapi_error, and a code the widget does not know is still a refusal.messageis for people. - Params are JSON values:
null, booleans, finite numbers, strings, and arrays and plain objects of them. A member set toundefinedcounts as absent, as JSON writes it. Binary, anArrayBufferor a typed array, is accepted only asfiles.upload’sbytes. Any other value aMessagePortcan carry, such as aBlob,File,Map,Set,Date, a non-finite number, anundefinedarray element or binary anywhere else, is refused withinvalid_paramsand{param}naming the top-level param that holds it, since the API would receive it altered. - The size cap. A request is at most 4 MiB + 64 KiB (4,259,840 bytes). Its size is the UTF-8 byte length of its
JSON, where each
ArrayBufferor typed array is written asnulland adds itsbyteLength. A larger request is refused withinvalid_paramsand{bytes, limit}, and so is a request JSON cannot encode, such as one holding a cycle or aBigInt. A file up toworkflow.session_file_bytesfits in one upload. - The schema. The host checks every request: a plain object carrying
idormethodis a request, checked against the call’s params as the tables below list them; any other message is ignored. The host evaluates nothing a widget sends. - Pinned. Every call is pinned by the host to the playground’s revision and its selected session at the moment of
the call, and the host takes neither from params: the id
session.selectcarries is the session to switch to, and adebuggerlink’s must be the selected session. When the session changes says what happens when the viewer switches sessions while a call is under way. - The session a call names. On a call marked Session,
sessionis the id of the session the widget last heard of, fromhelloorsession.changed, ornullwhen it heard of none; the kit’s client sets it on every such call. Any value but the selected session’s id,nullincluded while one is selected, is refused withsession_changedand nothing runs, so a write sent before the widget heard of a switch never lands in the session the viewer just picked. A call withoutsessionis pinned on arrival, and asessionset toundefinedcounts as absent. On any call, asessionthat is neither a string nornullis refused withinvalid_params; on a call not marked Session, the host checks nothing more of it.
Handshake
A widget’s first call ishello:
bridge is the major version the widget speaks, 1. The result:
bridgeis the version the host answers in. A widget built for bridge 1 refuses any other value and stops.aliasis the widget definition’s alias in the playground’s revision.portsmaps each port route the widget declares, and any other route the placed widget stores, to its value: the value set in the details pane, else the value the pane gives a new port, elsenull. A new port takes its declareddefault, anullone counting as none, else a value such as0,""orfalse, and amessageport’s value gets freshattributes. Acomponent_aliasorworkflow_aliasport starts at""and acredentialport atnull, whatever theirdefault, and a type the pane has no editor for readsnull. Editing a port pushesports.changedwith the whole map; the frame is not reloaded.vieweris{id, name, avatar, canWrite, anonymous}: the person viewing the playground,avatarpossiblynull.canWriteistruewhen the viewer may edit the playground’s revision and the selected session is open; while it isfalse, the host refuses every write, withno_sessionwhen no session is selected,session_changedwhen the write carries asessionother than the selected session’s id,nullincluded, andforbiddenotherwise.anonymousistruefor a viewer who is not signed in.sessionis the selected session’s summary, ornullwhen none is selected. A summary is{id, alias, status}:aliasisnullfor a session without one, andstatusisnullfor a session that has none, which is not open.phaseis the revision’s phase,draftorcommit.orgis the revision’s organization,{alias, name}, and no other field.themeis"light"or"dark", which the bootstrap has already set on<html data-theme>. Libraries and Theme covers the theme.
hello, so a widget that sends it first misses no event. It is
answered within 10 seconds, or the widget gives up; see Timeouts.
The playground loads a widget only when its definition’s bridge is one the page speaks, today 1; for any other it
shows This widget was built for bridge <n>; this page speaks bridge 1. instead of a frame. Within a major version,
additions never break a widget: a host answering bridge 1 also answers calls added to bridge 1 later, and its new events
and refusal codes reach widgets built before them unchanged. So a widget ignores an event it does not know, and treats a
code it does not know as a refusal.
Calls
Each table lists a call’s params, its result, and the permission it needs from the widget’s permissions, where a level aboveread implies read.
A call runs when the widget makes it, with nothing asked of the viewer: besides its params and its session, the host
checks what the widget declared, the viewer’s own rights and the rate budgets below. Whoever installs the widget
confirms what it declares (Trust at install).
Session marks a call that needs a selected session, refused with no_session without one, a write included. A write
(objects.write, objects.delete, threads.post, graph.mutate, files.upload or executions.start) also needs a
viewer who can write in the selected session, or it answers forbidden with {can_write: false, session_status}, the
selected session’s status when the host refused the write. A write naming another session is refused session_changed
first, so for a write that names a session, session_status is the status of the session it named. A session_status
of open means the viewer is a reader; any other value, null included, means the session closed under the call, and a
widget shows The session has closed. rather than the host’s message. — means none or no, and a ? marks an
optional param. A call that looks up something that does not exist answers not_found, with what it looked for as its
data. A write never answers not_found: the API’s refusal of a write is api_error.
Each placed widget has two rate budgets. Its writes, a workflow start among them, share one budget of 50 calls in any 10
seconds with its copies, opens, saves and session moves (ui.copy, ui.open, files.save, session.select and
session.follow), and ui.notify has its own of 10 calls in any 60 seconds. A call over its budget is refused with
rate_limited. A call refused earlier in the order spends nothing; one that passes spends one before it
runs, whatever it then answers.
The browser’s own rules still apply: it may refuse a new tab, a clipboard write or a notification prompt that no click
preceded. That is a result, never a refusal: ui.open answers {opened: false}, ui.copy {copied: false} and
ui.notify {shown: false}.
Session
sessions.listlists the revision’s sessions, metadata only.- A session’s summary is
{id, alias, status}, ashello’ssessionis.session.get,sessions.listandsession.changedcarry it. session.selectasks the host to switch the playground to the sessionid. An id the revision does not hold isnot_foundwith{id}. The selected session’s own id changes nothing, and any other is selected; either way the reply isnull, and the host pushessession.changedbefore it for another session.session.followturns the playground’s Sync back on.
Objects
objects.rowslists the selected session’s objects whose alias starts withprefix, or all of them. Each row is{alias, type, updated_at, size}:typeis the object’s type once the playground has read it, written it or heard it written, andnulluntil then, as for an object it has only listed;updated_atis the time of the object’s last write, ornull; andsizeis its size in bytes from the session’s object list, ornull. A value is read withobjects.read, which also answers the type a row lacks.objects.readanswers the object’stypeandvalue, andnot_foundwith{alias}when the session holds no such object.fresh: trueasks for a read from the API rather than a copy the page already holds.objects.writestoresvalue, a JSON object, as the object’s whole value, creating the object when the alias is new, as Upload Session Object does. Since a write replaces the whole value, a widget that changes part of a value reads the objectfreshfirst. The API’s refusals, such as an alias outside the grammar or a value over the size limit, answerapi_error.objects.deletedeletes the object and answersnull, also when the session holds no such object; either way a widget watching the alias hearsobject.changed. The API’s refusals answerapi_error, asobjects.write’s do.objects.watchandobjects.unwatch: see Watches and events.objects.watch_rowswatches the rows whose alias starts withprefix, andobjects.unwatch_rowsstops;prefixis required, and""is every row. A row watch is held as an alias watch is, across session switches: see Watches and events.
Threads
threads.listpages back from the newest item.pageis{cursor, limit}, both optional. Without acursorit answers the newest page; each page’sitemsare oldest first, and itscursor, passed back unchanged, answers the page before it.cursorisnullonce the thread’s start is reached.- Items are the thread items the API stores.
threads.liston a thread the session does not hold isnot_foundwith{alias}, andthreads.getisnot_foundwith{alias, item_id}when the thread or the item is missing. A read of an alias that holds another kind of object isnot_foundtoo, and a post onto one answers the API’s refusal,api_error. threads.postposts as the viewer:contentis a list of content blocks, andparent_idandmetadataare optional, as Post Session Thread Item takes them. The reply is the item posted, with itsid. A post to an alias that holds nothing creates the thread, as the operation does.
Graphs
A session’s graphs are among its objects, soobjects.rows lists them. Each graph.* call is one of the graph’s operations on the selected session, and answers
that operation’s result unchanged:
idsis one element id or a list of them;fromthe vertex ids whose neighbors to fetch;querythe traversal query;operationsthe list of mutations;optionsthe operation’s optional fields.- A graph the session does not hold is
not_foundwith{alias}on a read, and so is an alias that holds another kind of object. Ongraph.mutateeither is the API’s refusal,api_error, as any write’s refusal is.
Files
files.readanswers the file’s bytes, the one result that is not JSON.files.savehas the host save the file to the viewer’s downloads under its stored name, and answersnullonce the host has handed the file to the browser. A browser may still block or ask about repeated downloads, which the host cannot see. It writes nothing to the session, so it needs onlyfiles: read, and a viewer who cannot write may save.files.uploadcreates or replaces a file object:nameis the file’s name,typeits MIME type, which must be on the content-type allow-list, andbytesanArrayBufferor typed array, the one binary param.- A file the session does not hold is
not_foundwith{alias}onfiles.readandfiles.save.files.uploadcreates it, and answers the API’s refusal, such as an alias that holds an object other than a file, withapi_error.
Executions
workflowis a workflow reference object, andinput_datathe run’s input as Create Execution takes it. The workflow runs in the selected session, as the viewer. The run’s writes do not carry the page’s client tag, so they reach the page through the playground’s event stream, as any other writer’s change does, and may bring a watching widget no push until Sync is on again.- The permission. The reference must equal, key for key, one the widget lists under
executions; otherwise the call isforbiddenwith{permission: ["executions"]}. Only an entry that is a well-formed workflow reference, in one of its three shapes, counts: BlobHub neither starts nor shows any other entry of a stored document. A workflow that aworkflow_aliasport of the widget names starts only if the list names it too. Such a port holds its workflow in the path form, asportsshows it, and the widget passes the object that path names:approve-orderis{definition: "approve-order"},<blob id>/<revision>/<definition>is{blob, revision, definition}, andorg/blob/revision/definitionis{org, blob, revision, definition}.
People
people.getanswers a person’s display name and avatar and nothing more of them, as a thread already shows them. A person the platform does not know isnot_foundwith{user_id}.
Interface
-
ui.headersets what the host draws in the widget’s header beside its name:alias, the text of its alias chip, a string of at most 128 characters; andactions, required, at most 4, each{id, label, icon}.idandlabelare strings of at most 64 characters, andiconis optional and, when given, a string of at most 64 characters naming a react-icons icon, resolved aswidget.yaml’siconis. Analiasoriconofnullis refused. A call whoseactionsis missing, or is not an array of at most 4 actions within these bounds, is refused whole, not only the action at fault, withinvalid_paramsand{param: "actions"}; one whosealiasis out of bounds is refused with{param: "alias"}. Each call replaces the chip and the actions: analiasleft out or""draws no chip, andactions: []clears the actions. The host draws each action as an icon button, as the built-in widgets draw theirs, withlabelas its tooltip and accessible name and never as text, so a label never widens the header. A missingicon, or one the page cannot find, drawsLuMousePointerClick. When the viewer presses an action, with a click, Enter or Space, the host only pushesui.actionwith itsid; Space also presses it on a free-form layout’s canvas. The header starts empty each time the widget loads and empties when the host stops the widget and shows a status in its place, so a widget callsui.headereach time it starts. -
ui.copycopiestextto the viewer’s clipboard and answers{copied},trueonly when the browser copied it. -
ui.notifyshows a desktop notification titled<widget name>: <title>, withbodyas its text, under blobhub.io’s own notification permission, and answers{shown},trueonly when the browser showed it. Where the permission is granted it shows; where it is denied the call answers{shown: false}without asking. While it is undecided, blobhub.io asks the browser at most once per page load, one ask shared by every widget on the page, and only from a call made while the page holds the browser’s transient activation, which a click or key press on the page gives for a short time. Such a call asks, or waits for the ask already open; a call without activation answers{shown: false}and leaves the ask for a later call that has it. So a widget makes its firstui.notifyfrom the viewer’s click. A call after an ask that left the permission undecided, and any failure to ask or show, answers{shown: false}, neverapi_error.
ui.open opens a new tab, at one of three targets:
url is an absolute https address with no user or password that reads the same with and without a base, and each
of session, execution and user is an id, a string matching ^[A-Za-z0-9_-]{1,128}$. Any other key, route or value
is invalid_params: another scheme, http included; a URL carrying a user or password, since
https://docs.example.com@evil.example/ reads as one host and opens another; and a URL such as https:a.com/x, whose
host alone is a.com but which a browser would resolve against the page as a path on blobhub.io. The host opens exactly
the URL it checked, as it parsed it, never the widget’s string: https://a.com\@b.com opens https://a.com/@b.com.
A debugger link to a session other than the selected one is forbidden with {param: "session"}, and a {url} on a
host the widget’s links does not name is forbidden with {permission: ["links"]}. A named route needs no
permission, since the host builds the link. The host never opens a javascript:, data: or blob: address, and never
builds a link from a path the widget chose.
links is either ["*"] alone, which lets a widget open any https host, or a list of hosts, declared as
Permissions says. An entry matches the URL’s
host when the two are equal, case aside; *.example.com matches every host under example.com, at any depth, as
a.example.com and a.b.example.com, and never example.com itself. Matching reads the host alone, so any port
passes. An entry is never an IP address, so a URL whose host is one opens only under ["*"].
Watches and events
objects.watch, threads.watch and graph.watch register the widget’s interest in an alias, and the matching
unwatch drops it. A watch needs no session, and the alias need not exist yet. The interest survives session
switches, so a widget watches an alias once, not once per session. It is one mark per alias, not a count: one
unwatch drops it, however many watch calls came before.
The host pushes object.changed, thread.item_posted and graph.changed for a watched alias only while a session is
selected, only for that session, and only to a widget whose permissions let it read that kind. An event names what
changed and carries no value: a widget re-reads.
A data write a widget makes, with objects.write, objects.delete, files.upload, threads.post or graph.mutate,
carries the page’s client tag, so the stream does not echo it
back to the page. The page announces the write itself, once, as it does a built-in widget’s, so a widget watching that
alias hears its own write once, like anyone else’s:
object.changedwith{alias}afterobjects.write,objects.deleteorfiles.upload: a file is a session object, watched withobjects.watch.thread.item_postedwith{alias, item_id}afterthreads.post.graph.changedwith{alias}aftergraph.mutate.
threads.post’s reply is the item posted,
whose id the push’s item_id matches. An object or graph push names only the alias, so a widget re-reads either way.
Any other writer’s change reaches the page through the playground’s own event
stream, filtered for the widget, not a second connection, so it brings a
push only while the playground’s Sync is on. With Sync off, the host still
pushes for a data write any custom widget on the page makes, its own or another’s; any other change may bring none
until Sync is on again and the playground catches up, whether the viewer turns Sync on or the widget does with
session.follow.
objects.watch_rows watches every row whose alias starts with its prefix, and is held as an alias watch is: it needs no
session, survives session switches and is one mark per prefix. The host pushes object.rows_changed with that prefix
when an object under it is written or deleted in the selected session, the widget’s own objects.write,
objects.delete and files.upload included. It pushes at once, then at most once per 250 ms for each prefix, so a
burst of changes ends in one last push. The event carries no rows, so a widget calls objects.rows again.
It may come when no object changed. After a session switch, once the new session’s objects are listed, a push comes for
each prefix that has rows there. With Sync off, the host still pushes for an object any custom widget on the page
writes or deletes; any other change may bring none until Sync is on again and the playground catches up, or until the
playground next lists the session’s objects.
On
session.changed and on stream.gap, a widget re-reads everything it shows. On theme.changed, it sets
<html data-theme> itself; the bootstrap set it only before the entry loaded.
Refusals
A refused call answers{id, error: {code, message, data}}. The host checks a call in this order and answers the
first check that fails, so a widget can predict the code:
unknown_method.invalid_params: theid, the size cap,paramsbeing an object,sessiona string ornull, then each param.forbidden: an undeclared permission, anexecutions.startworkflow the widget’sexecutionsdoes not list, a{url}on a host itslinksdoes not list, or adebuggerlink to another session.no_session, a write included.session_changed, when a Session call carries asessionother than the selected session’s id,nullincluded.forbidden: a write by a viewer who cannot write in the selected session.rate_limited.session_changed, when the selected session changed before the call runs.- The call itself:
not_foundorapi_error. session_changed, when a read ran but its session changed before the reply.
When the session changes
- With no session selected, the widget’s frame stays loaded and live, whereas a built-in widget shows a status asking
for one. A call marked Session answers
no_session, a write included. The other calls work, and watches stay registered. A widget draws its own empty state, and one that declaressessions: selectmay offer its own picker:sessions.list, which needs no session, lists the revision’s sessions, andsession.selectselects one. - The host pins a Session call to the session selected when it arrives. A call whose
sessionis not that session’s id, as when the widget sent it before it heard of a switch, answerssession_changedon arrival, and nothing runs. The host checks again just before the call runs. If the selection changed, nothing runs and the call answerssession_changed. For this second check the host compares session ids, so a session selected again by then counts as unchanged. - A read that ran, whose session changed before its reply, answers
session_changedwith its data withheld, so a widget never shows one session’s data under another. - A call with an effect, a write or
files.save, that ran answers with what it did, its real result or its real error, whatever is selected by then. So a widget does not repeat a write that answered, and asession_changedfrom a write means nothing was written. session.changedis pushed when another session or none is selected, and again for the same session whenever its summary changes, a close included. A close that ends the viewer’s write rights pushessession.changed, thenviewer.changedwithcanWrite: false. A widget re-reads onsession.changedand onstream.gap; a re-read of a thread starts again from its newest page.
Timeouts
hello is answered within 10 seconds; a widget with no answer by then gives up. No other call times out.
A widget without the kit
One complete widget in plain JavaScript, with no library and no build step. It shows the session object itsorders
port names, follows it as it changes, and at a click records a review beside it, in the object <alias>/review. Its
widget.yaml:
index.js:
- The port.
mountlistens before it sends anything, ignores every message with atype, settles a pending call by its reply’sid, and hands each push to the handler for itsevent; an event without one is ignored. Its requests carry nosession, so the host pins each call to the session selected when it arrives. - The handshake.
hellogoes first, with{bridge: 1}; the widget stops on any otherbridge, and says so if no answer comes within 10 seconds. - The reads. It watches the alias its
ordersport names, once, and reads it onhello, onobject.changedfor that alias, onsession.changed, onstream.gapand when the port changes. A counter drops a reply that a newer read has overtaken. - The write.
objects.writeis called from the click handler. Itssession_changedsays nothing was written, and itsforbidden, whensession_statusis anything butopen, says the session has closed. It writes<alias>/review, an alias it does not watch, so no push follows its write, and it says itself that the write landed. The button stays disabled untilhellohas answered and the object is shown, and while the viewer cannot write. - The theme. It sets
<html data-theme>fromhello’stheme, which is current even if the page switched while the entry loaded, and again on eachtheme.changed, for a stylesheet to key its light and dark colors on.
See also
- Custom Widgets:
widget.yaml, the definition, permissions and trust at install, and deploying. - Libraries and Theme: the library catalog, building one module, and BlobHub’s light and dark look.
- Security Model: the frame and its origin, the rules the platform enforces, and the risks that remain.

