postMessage reference
The embed SDK implements this protocol for you. Read on if you integrate
without the SDK, or want to know exactly what crosses the frame boundary.
TypeScript definitions ship in @bookmaker/embed-sdk/protocol.
Envelope
Section titled “Envelope”Every message is a plain object:
// iframe -> your page (events){ source: 'bookmaker-sportsbook', v: 1, type: 'balance_changed', payload: { balance: 49500, currency: 'USD' } }
// your page -> iframe (commands){ source: 'bookmaker-host', v: 1, type: 'navigate', payload: { path: '/live' } }payload is always an object ({} when there is nothing to say). Amounts are
integers in minor units of the currency that comes with them (see
Currencies): divide by 10decimals of that
currency to display them.
Origin rules
Section titled “Origin rules”| Direction | Rule |
|---|---|
| iframe → page | Events are posted only to the parent’s origin, after it has been checked against the tenant’s embedOrigins (or is the sportsbook’s own origin). Never '*'. Nothing is posted before that check, not even ready. |
| page → iframe | Commands are accepted only from the parent window (event.source === window.parent) at that verified origin, with source: 'bookmaker-host'. Anything else is ignored silently. |
| Your listener | Accept a message only if event.source is the sportsbook iframe’s contentWindow, event.origin is exactly the sportsbook origin, source is 'bookmaker-sportsbook' and v is 1. |
| Your commands | iframe.contentWindow.postMessage(message, '<sportsbook origin>'), with the exact origin as targetOrigin. |
How the iframe knows its parent: location.ancestorOrigins where the browser
provides it (Chromium, Safari); otherwise the origin launch parameter the
SDK adds, or the origin in document.referrer. A page that lies about its
origin gains nothing: the browser only delivers events to a parent that really
has the claimed origin, and frame-ancestors already refuses to render the
sportsbook in a page that is not allowed.
Events
Section titled “Events”Sent by the iframe. ready is always first; events that happen before it
(for example a refused launch token) are queued and sent right after it.
| Event | Payload | When |
|---|---|---|
ready |
{ version: 1, tenant, locale, loggedIn: boolean, path, features? } |
The sportsbook verified your origin and listens for commands. Once per page load. features (optional) lists the optional commands this build understands, e.g. ['set_bottom_inset']; an older build leaves it out. |
resize |
{ height } |
The document height in CSS pixels changed. The SDK sizes the iframe from it in auto mode. |
route |
{ path, title, url? } |
The player navigated. title is localised, e.g. Flamengo x Palmeiras, In-Play. An event page reports again once its title is known. url is the same page on your site (host_url?link=<path>&<share params>), when a host URL is set. |
login_required |
{ reason: 'place_bet' | 'my_bets' | 'login' } |
An anonymous player pressed Log in to bet, opened My Bets, or pressed Log in. Open your login, then send set_launch_token. |
session_expired |
{ reason } |
The session ended on the server: idle_timeout, expired, mfa_stale, logout (ended elsewhere), account_blocked or self_exclusion; or a launch token from the URL was refused (launch_token_used, launch_token_expired, launch_token_invalid, launch_failed). The player is anonymous until you send a new launch token. |
balance_changed |
{ balance, currency } |
The wallet balance is known or changed: after login, after every debit and credit the platform makes, and in answer to refresh_balance. currency is the session’s wallet currency. |
bet_placed |
{ betId, stake, potentialPayout, currency } |
A bet was accepted. One event per bet when a slip places several. currency is the bet’s (the session’s) currency. |
bet_settled |
{ betId, status, payout, currency } |
A bet reached a final status while the iframe was open: won, lost, void, cashed_out or cancelled. Sent again if a resettlement changes it. currency is the bet’s currency. |
deposit_requested |
{} |
The player pressed Deposit. Open your cashier, then send refresh_balance. |
error |
{ code, message } |
See error codes. |
open_sportsbook |
{ path, selections, eventId?, odds?, url? } |
Widget only: the player clicked a price, a match or See all. Open your sportsbook page at path with selections on the slip; url is that page with ob_path and ob_select when the widget knows it. |
widget_count |
{ count } |
Widget only: how many matches it shows, once loaded and on every change. |
version_available |
{} |
Optional, once per new build. A newer sportsbook build is out while your page keeps the frame open. The sportsbook shows its own notice (“close and open the sportsbook again”) and never reloads itself in your frame (a launch token is single-use): reload the frame when it suits the player, e.g. after the current bet, with a fresh launch token. Ignoring it breaks nothing. onVersionAvailable in the SDK. |
share |
{ code, url, channel } |
The player shared a bet: created once the booking code exists, then one event per way it was sent (copy_code, copy_link, whatsapp, telegram, native, image). url is the link the player got (see dynamic integration). |
Commands
Section titled “Commands”Sent by your page. Commands that arrive before ready are not processed: wait
for it (the SDK queues them for you).
| Command | Payload | Effect |
|---|---|---|
set_launch_token |
{ launchToken } |
Exchanges the token and logs the player in, or replaces an expired session, without a reload. The bet slip is kept. |
navigate |
{ path } |
Goes to a deep link: /, /live, /live/{sportId}, /sport/{sportId}, /competition/{id} (or a stable alias such as brasileirao-serie-a), /event/{eventId} (optionally ?market={marketId}), /my-bets, /share/{code}. |
set_locale |
{ locale } |
en, pt-BR or es (BCP 47, case-insensitive, base-language fallback: es-MX is es). Re-renders in place. |
refresh_balance |
{} |
Re-reads the balance from your wallet and answers with balance_changed. |
logout |
{} |
Ends the sportsbook session on the server and in the iframe. No session_expired follows (unless the session had already ended). |
set_display_currency |
{ code, rate }, or { code: null } |
Shows amounts converted into code (a registry code) at rate (units of code per 1 unit of the session currency, a number from 1e-9 to 1e9 with at most 12 significant digits). Send it again to update the rate. { code: null } or {} goes back to the session currency. Presentation only, see display currency. |
set_overrides |
{ overrides }, or { overrides: null } |
Presentation overrides over the brand’s configuration: theme, colorScheme and visual content sections, checked with the back office’s rules. Replaces the previous ones; null clears them (the launch’s stay). |
set_bottom_inset |
{ px } |
Px (a whole number from 0 to 200) of the iframe’s bottom covered by your fixed bar, applied live: the same as the bottomInset launch parameter, without a reload. The SDK sends it with bottomInset: 'auto', only when ready.features has 'set_bottom_inset'. Any other value answers invalid_command. |
update_context |
{ hostUrl?, shareParams? } |
Replaces the share context without a reload: the page shared links and route.url point at, and the public parameters they carry. A field left out keeps its value, null clears it. A host URL outside your origins answers invalid_host_url; private keys are dropped. |
open_bet_slip |
{ code } |
Opens a shared bet by its booking code (any case, with a dash or spaces): the same as navigate to /share/{code}. Not a code: invalid_share_code. |
There is no command to change the currency: a session holds one wallet
currency for its lifetime. To switch, create a new session and remount (see
Embedding). set_display_currency
changes only how amounts are shown: stakes are debited, and every event keeps
reporting amounts, in the session currency.
Error codes
Section titled “Error codes”code |
Meaning |
|---|---|
launch_token_invalid |
Unknown, malformed or for another tenant. |
launch_token_used |
Already exchanged: launch tokens are single use. |
launch_token_expired |
Older than 120 seconds. |
launch_failed |
The token could not be exchanged (network or server error). |
invalid_command |
Unknown command type, or a missing or invalid payload field. |
invalid_path |
Not a sportsbook deep link (from navigate or the path parameter). |
unsupported_locale |
Not en, pt-BR or es (from set_locale or the locale / lang parameter). |
unsupported_currency |
The currency launch parameter is not enabled for the tenant (or unknown). The sportsbook shows the tenant’s default currency. |
currency_mismatch |
The currency launch parameter differs from the currency of the session that was just exchanged. The session’s currency applies. |
unsupported_display_currency |
A display currency (from set_display_currency or the launch exchange) has a code outside the registry or an invalid rate, or the session currency changed under it (the rate was for the old currency). The sportsbook shows the session currency. |
invalid_override |
A set_overrides value fails the back office’s rules (unknown key or token, contrast, trade dress, an image outside the brand’s media library, a protected text…); message says which. Nothing changes. |
override_requires_launch_token |
set_overrides tried to set catalog curation, languages or the display policy, which affect betting or money: only your server may, in POST /integration/sessions overrides. Nothing changes. |
unsupported_version |
The command’s v is not a version this sportsbook speaks. |
command_failed |
A command could not be completed, e.g. the language pack for set_locale failed to load. |
invalid_host_url |
host_url (launch parameter or update_context) is not an https address of the framing page, one of your embed origins or your Share URL’s origin. A refused host never replaces the valid one in use: links keep the last valid host (or the default page when there was none). |
invalid_share_code |
open_bet_slip got something that is not a booking code. |
competition_unavailable |
A competition page (an id or an alias such as brasileirao-serie-c) opened with no matches on offer right now. The page says so and links to the sport; hide or grey out your menu entry. |
The currency codes use the usual error payload, for example
{ code: 'currency_mismatch', message: '…' }. They are informational: the
sportsbook keeps working in the currency it shows.
Versioning
Section titled “Versioning”vis the protocol’s major version. It only changes for breaking changes, and a new major version comes with a new SDK URL (/embed/v2.js);v1keeps working.- Within v1, new events, new commands and new optional payload fields can appear. Ignore event types and fields you do not know. The SDK does.
- Payload fields are never removed or retyped within v1.
- Changes are listed in the changelog.