Using the PlayerEmbed Protocol

Embed Protocol

The messages between a page and a framed PanelWave player, protocol 1 to 4: boot parameters, the MessagePort handshake, config, live options, state, progress, privacy mode and the purchase UI policy.

A framed PanelWave player talks to the page around it with postMessage — or, from protocol 4, over a MessagePort. The host SDK speaks this protocol for you; this page is the reference for hosts that build the frame themselves and for anyone who wants to know what crosses the frame.

Three player pages speak it:

PageWhereWho drives it
Demo appThe CMS preview and the demo appThe host sends the manifest in config and controls everything
Readerread.panelwave.orgThe page owns its manifest; the host controls options, autoplay, navigation
Standalone pageSelf-hosted packagesAs the reader; never from file://

The bridge lives in the library (PlayerEmbedBridge, EmbedStateService and the protocol types in @panelwave/player); see Services → Embed bridge.

Versions

ProtocolPlayerAdds
11.7.0Two-way bridge: live navigate, setVariable, setLocale, setEntitlements, setOptions, getState, restart; pw:hello, pw:ready, pw:event, pw:state. Control changes no longer restart the story
21.9.0Chapter embeds: chapterScope, showToolbar, hostGesture, the chapterComplete and autoplayChange events
31.10.0setTheme and the widgetEvent event for content widgets
42.4.0Channels and apps: the MessagePort handshake, the channel context, privacy mode, progress, restore, resize, fullscreenRequest and the purchase UI policy

Every version is backward compatible: a host written for an older protocol keeps working. From protocol 4 on, pw:hello lists the page's capabilities — read those rather than the number. The demo app (the CMS preview) reports protocol: 4 with capabilities: []: it speaks the protocol 3 set.

Loading the frame

https://read.panelwave.org/<team>/<work>?embed=1&origin=<host origin>&chapter=<id>&autoplay=0
./course/index.html?embed=1&origin=<host origin>&chapter=<id>&autoplay=0
https://panelwave.github.io/player/?embed=1&origin=<host origin>
ParameterMeaning
embed=1Embed mode (also on when the page is framed): no demo chrome; the demo app waits for config
originThe host page's origin, URL-encoded. The page posts only there and ignores messages from any other origin. Without it, the page assumes a same-origin host
chapterReader and standalone: show one chapter (manifest chapter id or CMS chapter id)
autoplay, toolbar, cover1 / 0
sppSeconds per panel for autoplay, 0.5–120
bridgeProtocol 4: a random nonce, 16–128 URL-safe characters, new for every mount. Enables the port handshake
trackProtocol 4: 0 = privacy mode, 1 = analytics on. Absent: the work's own consent setting
puiProtocol 4: purchase UI policy — in_place, link_out or hidden
ch, lidProtocol 4, reader only: the channel and listing the frame runs in. See Channel context

From the player to the host

MessageWhen
{ type: 'pw:hello', protocol, channel, listing, capabilities }On load, before any config — and again over the port after the handshake. channel and listing are the channel context or null; capabilities lists port, progress, restore, resize, privacy, purchaseUi, fullscreenRequest. Pages before protocol 4 send { type, protocol } only
{ type: 'pw:ready' }The work is loaded and positioned
{ type: 'pw:event', name, data }Every player output: ready, panelChange, chapterChange, chapterComplete, autoplayChange, widgetEvent, fullscreenRequest, locationChange, variableChange, localeChange, navigationAttempt, cameraChange, paywallAction, ageVerified, likeChange, bookmarkChange, error — and from the bridge progress and resize
{ type: 'pw:state', data }In reply to getState, and about 100 ms after ready, every navigation or event (except cameraChange), every inbound change and every error

Payloads are the player's outputs, except where those carry whole manifest objects: panelChange sends { panelId, previousPanelId, chapterId }, chapterChange { chapterId, title }, error { message }.

pw:state carries:

{
  chapterId: string | null,
  pageId: string | null,            // page view only
  panelId: string | null,
  viewMode: 'cover' | 'panel' | 'page' | 'canvas' | null,
  locale: string,
  entitlements: string[] | null,    // the host's tokens as last given
  variables: { [key: string]: unknown },
  history: string[],                // visited panels, last 50, oldest first
  nextPanels: { panelId: string, title?: string }[],
  paywallGate: object | null,       // the gate the overlay shows
  preloadStatus: { queued, loading, loaded, maxConcurrent } | null,
  errors: string[],                 // last 20 since the last (re)start
  loadTimeMs: number | null,
  chapterScope: string | null,
  chapterComplete: boolean,
  autoplayActive: boolean
}

From the host to the player

MessageEffect
{ type: 'config', data }Settings and, for the demo app, the manifest. See below
{ type: 'navigate', panelId }Jump to any panel of the work
{ type: 'setVariable', key, value }Write one story variable; conditional content reacts at once. No restart
{ type: 'setLocale', locale }Content and interface language, live
{ type: 'setEntitlements', entitlements }Tokens such as premium, purchased:<productId>, age-verified. Gates are re-evaluated live
{ type: 'setOptions', data }Live options, see the table below
{ type: 'getState' }Replies with pw:state at once
{ type: 'restart' }Same work from the start with the current settings
{ type: 'setTheme', theme }Protocol 3: live widget theme on top of the manifest's ui.theme; null clears it
{ type: 'hostGesture' }Protocol 2: the reader interacted with the host page, so sound held back by the browser may start (the frame needs allow="autoplay")
{ type: 'setPrivacy', tracking }Protocol 4: analytics on or off, e.g. after the host's consent step
{ type: 'restore', panelId, variables? }Protocol 4: continue at a position — variables first, then the jump; waits for ready if sent earlier
{ type: 'purchaseHandled', productId? }Protocol 4: the host took over a purchase after paywallAction

config

{ type: 'config', data: {
  manifest?, locale?, variables?, entitlements?,
  autoplay?, muted?, viewMode?, pageFormat?, secondsPerPanel?, showCover?, reducedMotion?,
  initialPanelId?, initialViewMode?, restart?,
  chapterScope?, showToolbar?,           // protocol 2
  resume?, purchaseUi?, hostFullscreen?  // protocol 4
} }

The player is created on the first manifest and re-created only when the manifest changes or restart: true is set. Any other config is applied live: language, entitlements and options; variables are compared with the previous config, so only changed keys are written.

Options: live or restart

KeyApplied
autoplay, viewMode, pageFormat, secondsPerPanel, reducedMotion, showToolbarLive
mutedLive, and again on every ready: the host's flag wins over the work's default
showCoverAt (re)start; false also drops a cover that is showing
initialPanelId, initialViewMode, chapterScopeAt (re)start only (config keys, not setOptions)
purchaseUiProtocol 4, live
hostFullscreenProtocol 4, live: where the browser has no Fullscreen API, the fullscreen button stays and sends fullscreenRequest
resumeProtocol 4: { panelId, variables? }, same as restore

Protocol 4

Port handshake

Create the frame with a nonce

Load the frame with ?embed=1&bridge=<nonce>, a new random nonce for every mount.

Offer a port

After the frame's load event, post { type: 'pw:connect', nonce, protocol: 4 } with one MessagePort in the transfer list. The target origin may be *: the nonce, not the origin, binds the port.

The page adopts the first matching port

The page accepts the first pw:connect whose nonce matches its bridge parameter and that carries a port. It answers pw:hello over the port — and pw:ready if the work is already loaded.

Only the port from then on

Every message of this page flows over the port in both directions. Window messages are ignored and a second pw:connect is refused.

const nonce = crypto.randomUUID().replaceAll('-', '');
const frame = document.createElement('iframe');
frame.src = `https://read.panelwave.org/acme/night-city?embed=1&bridge=${nonce}`;
frame.allow = 'autoplay; fullscreen';
frame.addEventListener('load', () => {
  const { port1, port2 } = new MessageChannel();
  port1.onmessage = (event) => console.log('from the player', event.data);
  frame.contentWindow.postMessage({ type: 'pw:connect', nonce, protocol: 4 }, '*', [port2]);
});
document.getElementById('comic').append(frame);

Without bridge the page speaks the origin-checked window path as before. App pages on capacitor://localhost or ionic://localhost cannot be reached with postMessage, so app hosts need the port.

Channel context

ch (channel key) and lid (listing id) tell the reader which channel a frame runs in. The reader takes them only from the reader server, which first checks that the work is live on that channel; a channel in the page's own address is ignored, so nobody can attribute reads to a channel that does not list the work. The standalone page never has a channel. The reader adds channel and listing to pw:hello and to the analytics session start, which is how the creator's analytics show reads per channel.

A channel can leave analytics to the host page — roadbeat does. A frame on such a channel without track starts in privacy mode; an explicit track always wins.

Privacy mode

track=0 or { type: 'setPrivacy', tracking: false } switches the player's tracking to privacy mode: no event is queued and no request leaves the frame. The session start is kept in memory only; setPrivacy with tracking: true sends it, with the time of the opt-in. Events from before are not recovered. Autoplay stays off unless the host passes autoplay=1, and sound needs hostGesture.

progress and restore

pw:event progress arrives at most every two seconds after the position moved (panel, chapter, location, chapter end) and at once on pagehide:

{ chapterId, chapterUuid, panelId, pageId, percent, variables, completed }

percent is the share (0–100) of the chapter's reachable panels — a walk of the chapter's graph from its entry — seen on this visit; the chapter's end counts as 100. A host that keeps positions for readers without an account sends them back with restore or config.resume.

resize

pw:event resize { aspect, minHeight } after ready and whenever the view's shape changes. aspect is width / height of the current page in page view, otherwise of the active page format, otherwise 16:9; minHeight is 320 CSS pixels. Size the frame from it.

Purchase UI policy

puiWhat the paywall shows
in_place (default)Purchase options and sign-in; paywallAction reaches the host as before
link_outAvailable at … with one neutral link to the work's reader page — no prices, no buttons. Without a usable link it behaves like hidden
hiddenNot available in this app — no price, no link

For apps under store rules: hidden on iOS, link_out on Android.

Not in this version yet

setReaderToken, clearReaderToken, entitlementChange, readerTokenExpiring and checkoutReturn come with PanelWave reader accounts and checkout. pw:hello does not announce them until they work.