Skip to main content

Minigames SDK overview

Build small HTML/CSS/JavaScript games that run fullscreen inside Caught. Your game is loaded in a sandboxed iframe on a dedicated games origin. Caught injects the SDK at publish time and talks to your game with a simple message protocol.

Lifecycle​

  1. Caught opens your index.html in a fullscreen iframe.
  2. Your game (or the injected SDK) sends ready.
  3. Caught sends init with generic team and player labels, locale, a layout seed in actionId, optional inputs from the reviewed manifest defaults, and outcomesAllowed from manifest.outcomes.
  4. Your game preloads images (CaughtGame.preloadImages), then reveals UI (e.g. document.documentElement.classList.add('cg-ready')). Keep the body hidden until then — no loading splash.
  5. The player plays your game.
  6. Your game calls complete with a predefined result (win / lose / draw) that you declared.
  7. The game displays its result. The player can dismiss the game and reopen the optional activity later.

You can also receive pause / resume / terminate from Caught (app background, host Close).

Host Close / review chrome (do not re-implement)​

Caught draws a round X in the top-left and (in review preview) a settings control in the top-right. Your game must not send a close/abort signal and should not place interactive or critical UI in either corner.

SpecValue
Close constantHOST_CLOSE_SAFE_ZONE = 80
Close zoneTop-left of the iframe viewport
Review settings constantREVIEW_SETTINGS_SAFE_ZONE = 80
Review settings zoneTop-right of the iframe viewport
Size80×80 CSS px each (plus host safe-area insets outside the game)

Abort is host-owned. Author modes after confirm: fail (fail step), skip (advance without competitive result), reset (restart session in place — no step submit). In-game “give up” must use CaughtGame.complete with a declared lose (or other declared result) — that is not abort.

Predefined outcomes​

The SDK supports this fixed set (not custom scores or property names). Rank/place is deferred.

FieldValuesMeaning
resultwin | lose | drawCompetitive result for this team/session

Your manifest.outcomes must declare a non-empty result subset. Runtime rejects anything outside that declaration.

Constants: CaughtGame.RESULTS.WIN, .LOSE, .DRAW.

The declared outcomes describe the game and appear in the review flow.

SDK API​

The publish pipeline injects caught-game-sdk.js. You do not need to bundle it yourself.

CaughtGame.onInit((ctx) => {
// ctx.context.team.name, ctx.context.locale, ctx.context.actionId, ...
// ctx.context.inputs contains defaults keyed by manifest.inputs[].id
// ctx.outcomesAllowed — e.g. { result: ['win', 'lose'] }
const urls = collectImageUrls(ctx); // packaged assets and generated placeholders
CaughtGame.preloadImages(urls).then(() => {
document.documentElement.classList.add('cg-ready');
startMyGame(ctx);
});
});

CaughtGame.onPause(() => pauseMyGame());
CaughtGame.onResume(() => resumeMyGame());
CaughtGame.onTerminate(() => cleanupMyGame());

// Finished as winner (solo win/lose game):
CaughtGame.complete({
status: 'success',
result: CaughtGame.RESULTS.WIN,
});

Boot / images: Hide the body until assets are ready, e.g. in CSS html:not(.cg-ready) body { visibility: hidden; }. Call CaughtGame.preloadImages(urls) after onInit (author URLs are only known then). Settles on load or error so a broken URL never hangs. Empty list is fine for canvas-only games.

CaughtGame.complete may only be accepted once per session.

The game reports success or fail. The host handles aborts. The result field carries the game outcome.

Runtime constraints​

  • Browser / Cordova WebView only — no Node, no Cordova plugins, no Caught Meteor APIs.
  • Do not touch window.parent except through the SDK.
  • Do not rely on localStorage for secrets (games may share an origin).
  • External network is denied in phase 1 (connect-src 'none'). Ship all assets in the ZIP.
  • Prefer relative asset URLs under your bundle folder.

Context (phase 1)​

Always available after onInit (on ctx.context / mirrored fields):

  • locale
  • actionId is a stable hash of the action ID in play and a random seed in review. Use it for deterministic layouts. Set manifest.usesActionId: true to show a regeneratable Layout ID during review.
  • Use inputs of type color for packaged hex colours.
  • team.name is a generic team label (Team in the player).
  • player.displayName is a generic player label (Player in the player).
  • inputs — object keyed by your manifest.inputs[].id (empty {} if you declared none)

Not available yet: others[] (other team names). Do not depend on it.

Packaged defaults (optional manifest.inputs):

TypeValue shape in context.inputs[id]
stringstring; optional manifest format: line (default) | paragraph (admin textarea)
booleanboolean
color#rrggbb hex string
imagestring[] of generated placeholder data URLs
stringTranslateable{ [lang]: string } (Caught multilang map); same optional format
imageTranslateable{ [lang]: string[] }
stringImageList{ text: string, image: string }[] (itemMode: either | both)
stringImageListTranslateable{ [lang]: { text, image }[] }

Every field needs a mock, which the SDK receives in both live play and review. Use { placeholder: true, … } for image mocks and ship any gameplay artwork in the ZIP. For translated values, pick the entry for context.locale with a fallback language.

Scoring model​

Report one of the declared outcomes. Caught authors map those to Properties on the playminigame action; the step engine applies matching maps and advances (or fails) accordingly. Games never send Property names or award points directly.

Minimal example​

Declare in manifest.json:

{
"name": "Tap Race",
"version": "1.0.0",
"sdkVersion": "1",
"entry": "index.html",
"mode": "solo",
"outcomes": { "result": ["win", "lose"] }
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Tap Race</title>
<style>
body { font-family: system-ui; text-align: center; margin-top: 20vh; }
button { font-size: 1.5rem; padding: 1rem 2rem; margin: 0.5rem; }
</style>
</head>
<body>
<h1>Tap Race</h1>
<button id="win" type="button">I won</button>
<button id="lose" type="button">I lost</button>
<script>
CaughtGame.onInit(() => {
document.getElementById('win').onclick = () => {
CaughtGame.complete({ status: 'success', result: CaughtGame.RESULTS.WIN });
};
document.getElementById('lose').onclick = () => {
CaughtGame.complete({ status: 'success', result: CaughtGame.RESULTS.LOSE });
};
});
</script>
</body>
</html>

A fuller reference implementation is Pong (best-of-5 vs AI → win/lose only). See Examples and Bundle & manifest.

Next​