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
- Caught opens your
index.htmlin a fullscreen iframe. - Your game (or the injected SDK) sends ready.
- Caught sends init with generic team and player labels, locale, a layout seed in
actionId, optionalinputsfrom the reviewed manifest defaults, andoutcomesAllowedfrommanifest.outcomes. - 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. - The player plays your game.
- Your game calls complete with a predefined
result(win/lose/draw) that you declared. - 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.
| Spec | Value |
|---|---|
| Close constant | HOST_CLOSE_SAFE_ZONE = 80 |
| Close zone | Top-left of the iframe viewport |
| Review settings constant | REVIEW_SETTINGS_SAFE_ZONE = 80 |
| Review settings zone | Top-right of the iframe viewport |
| Size | 80×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.
| Field | Values | Meaning |
|---|---|---|
result | win | lose | draw | Competitive 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.parentexcept through the SDK. - Do not rely on
localStoragefor 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):
localeactionIdis a stable hash of the action ID in play and a random seed in review. Use it for deterministic layouts. Setmanifest.usesActionId: trueto show a regeneratable Layout ID during review.- Use
inputsof typecolorfor packaged hex colours. team.nameis a generic team label (Teamin the player).player.displayNameis a generic player label (Playerin the player).inputs— object keyed by yourmanifest.inputs[].id(empty{}if you declared none)
Not available yet: others[] (other team names). Do not depend on it.
Packaged defaults (optional manifest.inputs):
| Type | Value shape in context.inputs[id] |
|---|---|
string | string; optional manifest format: line (default) | paragraph (admin textarea) |
boolean | boolean |
color | #rrggbb hex string |
image | string[] 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.