Publish with the CLI
One command in your game's folder. Needs Node.js 20+.
Publish
npx juicyjuicy publishThe first time it logs you in through your browser and asks for a title to write juicy.json. It prints your game's link. Publishing again makes a new version at the same link, live within about 30 seconds.
Commands
Run each as npx juicyjuicy <command>.
publish- Upload and print the link
publish --draft- Upload without making it live
publish --replace-images- Replace the cover and screenshots set on your dashboard
check- Validate without uploading
init- Create or edit juicy.json
list- Your games and versions (--all for everyone's)
go-live- Make your newest draft live
open- Open the game's page
pull <slug>- Download your live version
remix <slug>- Start a remix of a remixable game
check-games- Check your live games after a JuicyJuicy update
setup- Install the skill for AI agents and log in
login, logout, whoami- Manage the saved login
Every command takes --json and --yes for scripts; --help lists the rest. In CI, put a token from your tokens page in JUICY_TOKEN.
juicy.json
Sits next to your game. Only slug and title are required. Schema.
{
"$schema": "https://juicyjuicy.games/schema/juicy.json",
"slug": "space-goose",
"title": "Space Goose",
"description": "Honk through an asteroid field and grab the stars.",
"buildDir": "dist",
"engine": "phaser",
"madeWith": ["Claude Opus 5.5", "Claude Code"],
"genres": ["arcade", "shooter"],
"tags": ["space"],
"ageRating": "everyone",
"languages": ["en", "pl"],
"features": ["cloud-saves"],
"input": ["keyboard", "touch"],
"thumbnail": "cover.webp",
"screenshots": ["screenshots/shot-1.webp", "screenshots/shot-2.webp", "screenshots/shot-3.webp"],
"remixable": true
}slug- The game's address, /g/<slug>: 3–40 lowercase letters, digits and dashes.
title, description- Up to 60 and 500 characters.
buildDir, entry- The folder to upload (default ".") and its HTML file (index.html).
engine- vanilla, phaser, threejs, pixi, godot, unity or other.
madeWith- The models and tools you used.
genres- Required: 1 to 3 of action, adventure, arcade, board, cards-casino, casual, idle, platformer, puzzle, racing, rhythm, roguelike, rpg, shooter, simulation, sports, strategy, story, word-trivia.
tags- Up to 3 themes, the setting or subject, e.g. space or pirates, plus multiplayer for a game people play together without JuicyJuicy's rooms.
input- keyboard, mouse, touch, gamepad.
platforms- Where it's made to be played: ["desktop"], ["mobile"] or both, the one it's made for first. Decides the Computer and Phone tabs; mobile needs touch.
ageRating- everyone, 12+ or 16+, from the game's content. Left out, the game keeps its rating.
languages- Language codes, English first. Default ["en"].
features- Required: the features your game uses, or [] for none.
orientation, aspectRatio- landscape, portrait or any; "16:9" or "fill".
thumbnail- Required: the cover, at most 1280×720 and 300 KB. Made by juicyjuicy cover.
screenshots- Required: 3 to 5 images of play, each at most 640×360 and 100 KB. Taken by juicyjuicy capture.
remixable, sourceUrl- Allow remixes on JuicyJuicy; link your source code.
Cover and screenshots
Every game needs a cover and 3 to 5 screenshots, in juicy.json or uploaded on your dashboard. The cover is a designed picture with the title, not a screenshot: design it as cover.html and run juicyjuicy cover (at most 1280×720, 300 KB). juicyjuicy capture loads the game with #jj-shot=1, #jj-shot=2, … and saves a screenshot of each (at most 640×360, 100 KB); start the game in a different moment for each number. Both use a local Chrome, Edge, Chromium or Brave, offline. The screenshots play as a slideshow when someone points at the game's tile. A cover or screenshots you upload on your dashboard stay when you publish an update; to replace them with juicy.json's, publish with --replace-images.
GitHub Actions
Publish on every push to main. Add a token as the repository secret JUICY_TOKEN (make it “Publish only, for CI”: it can publish and list your games and nothing else), then save this as .github/workflows/juicyjuicy.yml:
name: Publish to JuicyJuicy
on:
push:
branches: [main]
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: githubvoyage/juicyjuicy/packages/publish-action@v1
with:
token: ${{ secrets.JUICY_TOKEN }}
build-command: npm ci && npm run build
path: .Plain HTML games can leave out build-command.
Cloud saves
Paste this before your game's code. Signed-in players get their progress on any browser; everyone else keeps it in this one.
// JuicyJuicy cloud saves: https://juicyjuicy.games/docs/publish#saves
window.juicy = window.juicy || {};
window.juicy.save || (function (juicy) {
var KEY = "juicyjuicy:save";
var framed = window.parent !== window;
var onSite = false;
var next = 0;
var waiting = {};
window.addEventListener("message", function (event) {
var m = event.data;
if (event.source !== window.parent || !m || typeof m.id !== "string") return;
if (m.type !== "juicyjuicy:loaded" && m.type !== "juicyjuicy:saved") return;
var done = waiting[m.id];
if (!done) return;
delete waiting[m.id];
onSite = true;
done(m);
});
// The player's answer, or null when nothing answered (not on JuicyJuicy).
function ask(message) {
return new Promise(function (resolve) {
if (!framed) return resolve(null);
var id = "juicy-" + ++next;
var timer = setTimeout(function () {
delete waiting[id];
resolve(null);
}, onSite ? 30000 : 10000);
waiting[id] = function (m) {
clearTimeout(timer);
resolve(m);
};
message.id = id;
window.parent.postMessage(message, "*");
});
}
function failed(m) {
var error = new Error(m ? m.error.message : "JuicyJuicy didn't answer");
error.code = m ? m.error.code : "TIMEOUT";
return error;
}
function readLocal() {
try {
var text = localStorage.getItem(KEY);
return text === null ? null : JSON.parse(text);
} catch (e) {
return null;
}
}
function writeLocal(data) {
if (data === null) localStorage.removeItem(KEY);
else localStorage.setItem(KEY, JSON.stringify(data));
return { cloud: false };
}
function dropLocal() {
try {
localStorage.removeItem(KEY);
} catch (e) {}
}
// Resolves to the saved data, or null when there's none.
juicy.load = function () {
return ask({ type: "juicyjuicy:load" }).then(function (m) {
if (!m) {
if (onSite) throw failed(null);
return readLocal();
}
if (!m.ok) throw failed(m);
if (!m.signedIn) return readLocal();
var mine = readLocal();
if (m.data !== null || mine === null) {
dropLocal();
return m.data;
}
// Played signed out, then joined: the progress moves to the cloud.
return juicy.save(mine).then(
function () { return mine; },
function () { return mine; }
);
});
};
// Saves any JSON value (null deletes the save). Resolves to { cloud: true, savedAt } or
// { cloud: false } (kept in this browser); rejects with an error that has a code.
juicy.save = function (data) {
return ask({ type: "juicyjuicy:save", data: data }).then(function (m) {
if (!m) {
if (onSite) throw failed(null);
return writeLocal(data);
}
if (m.ok) {
dropLocal();
return { cloud: true, savedAt: m.savedAt };
}
if (m.error.code === "SIGNED_OUT") return writeLocal(data);
throw failed(m);
});
};
})(window.juicy);
const saved = await juicy.load(); // null the first time
if (saved) restoreGame(saved);
juicy.save({ level, score }).catch(() => {});- One save per game, any JSON up to 256 KB.
juicy.save(null)deletes it. - Save as often as you like: it's written at most every 10 seconds.
- Wait for
load()before starting, so a new game never saves over old progress. A failed save rejects with an errorcode.
List it in features as "cloud-saves".
Multiplayer
Rooms for playing with friends, relayed by JuicyJuicy: one player's browser runs the game, the others send it their input. Paste this before your game's code (before or after the cloud-saves snippet).
// JuicyJuicy multiplayer: https://juicyjuicy.games/docs/publish#multiplayer
window.juicy = window.juicy || {};
window.juicy.rooms || (function (juicy) {
var CLOSED = { 4001: "TICKET", 4004: "ROOM_NOT_FOUND", 4009: "ROOM_FULL", 4010: "ROOM_LOCKED",
4011: "KICKED", 4012: "REPLACED", 4029: "TOO_FAST", 4040: "GAME_GONE", 4503: "OFF" };
var onSite = window.parent !== window ? null : false;
var inviteUrl = null;
var next = 0;
var waiting = {};
window.addEventListener("message", function (event) {
var m = event.data;
if (event.source !== window.parent || !m) return;
if (m.type !== "juicyjuicy:room-ticket" && m.type !== "juicyjuicy:room-list") return;
var done = waiting[m.id];
if (!done) return;
delete waiting[m.id];
onSite = true;
done(m);
});
function fail(code, message) {
var error = new Error(message || code);
error.code = code;
return error;
}
// The player's answer to a message, or null when not on JuicyJuicy.
function ask(message) {
return new Promise(function (resolve, reject) {
if (onSite === false) return resolve(null);
var id = "juicy-room-" + ++next;
var timer = setTimeout(function () {
delete waiting[id];
if (onSite) return reject(fail("TIMEOUT", "JuicyJuicy didn't answer"));
onSite = false;
resolve(null);
}, onSite ? 30000 : 5000);
waiting[id] = function (m) {
clearTimeout(timer);
if (!m.ok) return reject(fail(m.error.code, m.error.message));
if (m.inviteUrl) inviteUrl = m.inviteUrl;
resolve(m);
};
message.id = id;
window.parent.postMessage(message, "*");
});
}
// The invite code, and a ticket when asked.
function askTicket(ticket) {
return ask({ type: "juicyjuicy:room", ticket: ticket });
}
function Room(code) {
this.code = code;
this.me = null;
this.host = null;
this.max = 0;
this.locked = false;
this.public = false;
this.label = null;
this.players = [];
this.handlers = {};
this.link = null;
this.opened = false;
this.closed = false;
this.reconnecting = false;
}
// Events: "message" (data, fromId), "join" (player), "leave" (player), "host" (id),
// "lock" (locked), "public" (isPublic), "error" (error), "close" (reason),
// "reconnecting" (attempt: 1 to 3; show "Reconnecting...", sends meanwhile are dropped) and
// "reconnected" (back in the room; "join", "leave" and "host" have told what changed).
Room.prototype.on = function (event, handler) {
(this.handlers[event] = this.handlers[event] || []).push(handler);
return this;
};
Room.prototype.emit = function (event, a, b) {
(this.handlers[event] || []).slice().forEach(function (handler) {
try {
handler(a, b);
} catch (e) {
setTimeout(function () { throw e; });
}
});
};
Room.prototype.isHost = function () {
return this.me !== null && this.me === this.host;
};
Room.prototype.player = function (id) {
for (var i = 0; i < this.players.length; i++) if (this.players[i].id === id) return this.players[i];
return null;
};
// Sends any JSON value to everyone else in the room, or only to the player whose id is "to".
Room.prototype.send = function (data, to) {
if (this.link) this.link.send({ t: "send", d: data, to: to });
};
// The host only: stop new players joining (false lets them in again).
Room.prototype.lock = function (locked) {
if (this.link) this.link.send({ t: "lock", locked: locked !== false });
};
// The host only: remove a player, who can't come back to this room.
Room.prototype.kick = function (id) {
if (this.link) this.link.send({ t: "kick", id: id });
};
// The host only: list the room in the game's public rooms (false: invite only).
Room.prototype.setPublic = function (on) {
if (this.link) this.link.send({ t: "public", public: on !== false });
};
// Shows JuicyJuicy's share sheet for the room's invite link, and returns the link.
Room.prototype.invite = function () {
if (onSite) {
window.parent.postMessage({ type: "juicyjuicy:invite", code: this.code }, "*");
return inviteUrl + this.code;
}
return location.origin + location.pathname + "?room=" + this.code;
};
Room.prototype.leave = function () {
this.end("LEFT");
};
Room.prototype.end = function (reason) {
if (this.closed) return;
this.closed = true;
this.reconnecting = false;
var link = this.link;
this.link = null;
if (link) link.close();
this.emit("close", reason);
};
Room.prototype.receive = function (m) {
var room = this;
if (m.t === "welcome") {
var before = room.players;
var host = room.host;
room.code = m.room;
room.me = m.me;
room.host = m.host;
room.max = m.max;
room.locked = m.locked;
room.public = m.public === true;
room.label = m.label || null;
room.players = m.players;
if (!room.opened) {
room.opened = true;
return room.emit("welcomed", room);
}
// Back after a dropped connection: who came and went meanwhile.
before.forEach(function (p) { if (!room.player(p.id)) room.emit("leave", p); });
m.players.forEach(function (p) {
if (!before.some(function (q) { return q.id === p.id; })) room.emit("join", p);
});
if (host !== m.host) room.emit("host", m.host);
} else if (m.t === "join") {
room.players.push(m.player);
room.emit("join", m.player);
} else if (m.t === "leave") {
var gone = room.player(m.id);
if (!gone) return;
room.players.splice(room.players.indexOf(gone), 1);
room.emit("leave", gone);
} else if (m.t === "host") {
room.host = m.id;
room.emit("host", m.id);
} else if (m.t === "lock") {
room.locked = m.locked;
room.emit("lock", m.locked);
} else if (m.t === "public") {
room.public = m.public;
room.emit("public", m.public);
} else if (m.t === "msg") {
room.emit("message", m.d, m.from);
} else if (m.t === "error") {
room.emit("error", fail(m.code, m.message));
} else if (m.t === "closed") {
room.end(m.reason);
}
};
// JuicyJuicy's relay: resolves once it has welcomed this player. "ticket" is the player's answer
// with a ticket when there is one already, else a new one is asked for.
function connect(room, query, ticket) {
return (ticket ? Promise.resolve(ticket) : askTicket(true)).then(function (m) {
return new Promise(function (resolve, reject) {
var socket = new WebSocket(m.url + "?ticket=" + encodeURIComponent(m.ticket) + query);
var welcomed = false;
var link = {
send: function (message) {
if (socket.readyState === 1) socket.send(JSON.stringify(message));
},
close: function () {
socket.close(1000);
}
};
socket.onmessage = function (event) {
var message;
try {
message = JSON.parse(event.data);
} catch (e) {
return;
}
if (message.t === "welcome" && !welcomed) {
welcomed = true;
room.link = link;
room.receive(message);
if (room.reconnecting) {
room.reconnecting = false;
room.emit("reconnected");
}
return resolve(room);
}
if (room.link === link) room.receive(message);
};
socket.onclose = function (event) {
var reason = CLOSED[event.code];
if (!welcomed) return reject(fail(reason || "DISCONNECTED", "Couldn't join the room"));
if (room.link !== link) return;
room.link = null;
if (reason) room.end(reason);
else reconnect(room, 0);
};
});
});
}
// Phones drop connections when the game is in the background: three tries to come back.
function reconnect(room, attempt) {
if (room.closed) return;
if (attempt === 3) return room.end("DISCONNECTED");
room.reconnecting = true;
room.emit("reconnecting", attempt + 1);
setTimeout(function () {
if (room.closed) return;
connect(room, "&room=" + room.code).catch(function (e) {
if (e.code === "DISCONNECTED" || e.code === "TIMEOUT" || e.code === "FAILED") {
reconnect(room, attempt + 1);
} else {
room.end(e.code);
}
});
}, 1000 * Math.pow(2, attempt));
}
// Outside JuicyJuicy: rooms between this origin's tabs. The tab that creates a room relays it,
// and the room ends when that tab leaves.
var tab = Math.random().toString(36).slice(2);
var channel = null;
var relays = {};
var mine = {};
function bus() {
if (channel) return channel;
channel = new BroadcastChannel("juicyjuicy:rooms");
channel.onmessage = function (event) {
var e = event.data;
if (e.to === "relay" && relays[e.code]) relays[e.code].handle(e.from, e.m);
else if (e.to === "list") bus().postMessage({ to: e.from, id: e.id, rooms: localRooms(e.from, e.label) });
else if (e.to === tab && e.rooms) { if (lists[e.id]) lists[e.id].push.apply(lists[e.id], e.rooms); }
else if (e.to === tab && mine[e.code]) mine[e.code].receive(e.m);
};
window.addEventListener("pagehide", function () {
Object.keys(mine).forEach(function (code) { mine[code].leave(); });
});
return channel;
}
function LocalRelay(code, max, options) {
this.code = code;
this.max = max;
this.public = options.public;
this.label = options.label;
this.locked = false;
this.players = [];
this.host = null;
this.next = 0;
this.kicked = {};
}
LocalRelay.prototype.deliver = function (to, m) {
var room = to === tab && mine[this.code];
if (room) setTimeout(function () { room.receive(m); });
else if (to !== tab) bus().postMessage({ to: to, code: this.code, m: m });
};
LocalRelay.prototype.everyone = function (m, except) {
var relay = this;
relay.players.forEach(function (p) { if (p !== except) relay.deliver(p.tab, m); });
};
LocalRelay.prototype.list = function () {
return this.players.map(function (p) { return { id: p.id, name: p.name }; });
};
// How the room shows in list() to the tab "from", or null when it isn't listed.
LocalRelay.prototype.entry = function (from) {
var relay = this;
var host = null;
relay.players.forEach(function (p) { if (p.id === relay.host) host = p; });
if (!relay.public || relay.locked || !host || relay.kicked[from]) return null;
if (relay.players.length >= relay.max) return null;
return { code: relay.code, host: host.name, players: relay.players.length, max: relay.max,
label: relay.label };
};
LocalRelay.prototype.remove = function (player) {
this.players.splice(this.players.indexOf(player), 1);
this.everyone({ t: "leave", id: player.id });
if (this.host !== player.id || !this.players.length) return;
this.host = this.players[0].id;
this.everyone({ t: "host", id: this.host });
};
LocalRelay.prototype.handle = function (from, m) {
var relay = this;
var player = null;
relay.players.forEach(function (p) { if (p.tab === from) player = p; });
if (m.t === "join") {
if (player) return;
var refused = relay.kicked[from] ? "KICKED" : relay.locked ? "ROOM_LOCKED"
: relay.players.length >= relay.max ? "ROOM_FULL" : null;
if (refused) return relay.deliver(from, { t: "closed", reason: refused });
player = { id: "p" + ++relay.next, name: "Player " + relay.next, tab: from };
relay.players.push(player);
if (!relay.host) relay.host = player.id;
relay.deliver(from, { t: "welcome", room: relay.code, me: player.id, host: relay.host,
max: relay.max, locked: relay.locked, public: relay.public, label: relay.label,
players: relay.list() });
relay.everyone({ t: "join", player: { id: player.id, name: player.name } }, player);
} else if (!player) {
return;
} else if (m.t === "send") {
relay.players.forEach(function (p) {
if (p !== player && (m.to == null || m.to === p.id)) {
relay.deliver(p.tab, { t: "msg", from: player.id, d: m.d });
}
});
} else if (m.t === "leave") {
relay.remove(player);
} else if (player.id !== relay.host) {
relay.deliver(from, { t: "error", code: "NOT_HOST", message: "Only the host can do that" });
} else if (m.t === "lock") {
relay.locked = m.locked;
relay.everyone({ t: "lock", locked: m.locked });
} else if (m.t === "public") {
relay.public = m.public;
relay.everyone({ t: "public", public: m.public });
} else if (m.t === "kick") {
relay.players.slice().forEach(function (p) {
if (p.id !== m.id || p === player) return;
relay.kicked[p.tab] = true;
relay.deliver(p.tab, { t: "closed", reason: "KICKED" });
relay.remove(p);
});
}
};
function joinLocal(room, max, options) {
return new Promise(function (resolve, reject) {
var code = room.code;
if (max) relays[code] = new LocalRelay(code, max, options);
mine[code] = room;
room.link = {
send: function (m) {
var relay = relays[code];
if (relay) setTimeout(function () { relay.handle(tab, m); });
else bus().postMessage({ to: "relay", code: code, from: tab, m: m });
},
close: function () {
delete mine[code];
var relay = relays[code];
if (!relay) return bus().postMessage({ to: "relay", code: code, from: tab, m: { t: "leave" } });
delete relays[code];
relay.players.forEach(function (p) {
if (p.tab !== tab) relay.deliver(p.tab, { t: "closed", reason: "DISCONNECTED" });
});
}
};
room.on("close", function (reason) {
if (!room.opened) reject(fail(reason, "Couldn't join the room"));
});
room.on("welcomed", resolve);
bus();
room.link.send({ t: "join" });
setTimeout(function () {
if (!room.opened) room.end("ROOM_NOT_FOUND");
}, 2000);
});
}
// The public rooms of this origin's tabs, as list() shows them: other tabs answer within 300 ms.
var lists = {};
function localRooms(from, label) {
var found = [];
Object.keys(relays).forEach(function (code) {
var entry = relays[code].entry(from);
if (entry && (!label || entry.label === label)) found.push(entry);
});
return found;
}
function listLocal(label) {
return new Promise(function (resolve) {
var id = "list-" + ++next;
var found = lists[id] = localRooms(tab, label);
bus().postMessage({ to: "list", from: tab, id: id, label: label });
setTimeout(function () {
delete lists[id];
resolve(found);
}, 300);
});
}
function newCode() {
var letters = "ABCDEFGHJKMNPQRSTUVWXYZ23456789";
var code = "";
for (var i = 0; i < 6; i++) code += letters[Math.floor(Math.random() * letters.length)];
return code;
}
// A label is the game's own id for a kind of room, never text a player typed.
function checkLabel(label) {
if (label != null && !/^[a-z0-9-]{1,24}$/.test(label)) {
throw fail("INVALID", "A room label is 1 to 24 of a-z, 0-9 and -");
}
return label || null;
}
juicy.rooms = {
// Opens a new room with this player as its host. options.max: most players, 2 to 10.
// options.public: true lists it in list() for anyone to join; options.label: the game's id for
// the kind of room (a mode, a map), shown in the list.
create: function (options) {
options = options || {};
var max = Math.max(2, Math.min(10, options.max || 10));
var label;
try {
label = checkLabel(options.label);
} catch (e) {
return Promise.reject(e);
}
var listed = options.public === true;
return askTicket(true).then(function (m) {
var room = new Room(null);
if (m) {
return connect(room, "&create=1&max=" + max + (listed ? "&public=1" : "") +
(label ? "&label=" + label : ""), m);
}
room.code = newCode();
return joinLocal(room, max, { public: listed, label: label });
});
},
// Joins the room with this code (from invited(), list(), or typed in by the player).
join: function (code) {
code = String(code || "").trim().toUpperCase();
return askTicket(true).then(function (m) {
var room = new Room(code);
return m ? connect(room, "&room=" + encodeURIComponent(code), m) : joinLocal(room, 0);
});
},
// The game's public rooms that can be joined now (not full or locked), newest first:
// [{ code, host, players, max, label }]. options.label: only rooms with that label.
list: function (options) {
var label;
try {
label = checkLabel(options && options.label);
} catch (e) {
return Promise.reject(e);
}
return ask({ type: "juicyjuicy:list-rooms", label: label }).then(function (m) {
return m ? m.rooms : listLocal(label);
});
},
// The room code of the invite link that opened the game, or null.
invited: function () {
return askTicket(false).then(function (m) {
if (m) return m.invite;
var found = /[?&]room=([A-Za-z0-9]{6})/.exec(location.search);
return found ? found[1].toUpperCase() : null;
});
}
};
})(window.juicy);
const code = await juicy.rooms.invited(); // from an invite link, or null
const room = code ? await juicy.rooms.join(code) : await juicy.rooms.create({ max: 4 });
room.invite(); // JuicyJuicy's share sheet with the link
room.on("message", (data, from) => handle(data, from));
room.send({ k: "input", left: true });
// Public rooms anyone playing can join: create({ max: 4, public: true, label: "duel" }),
// juicy.rooms.list() → [{ code, host, players, max, label }], then join(code).- Rooms are for signed-in members; JuicyJuicy offers visitors Sign in. Up to 10 players a room.
- Messages are any JSON up to 16 KB, at most 60 a second per player.
- Show player names with
textContent, and no free-text chat for now. - A public room is listed for everyone playing the game until it's full or locked. Its
labelis your game's own id for a mode or map, never text a player typed. - Outside JuicyJuicy the rooms run between tabs of the same address, so you can try it with two tabs.
List it in features as "multiplayer". The skill's recipe has the whole API.
Global highscores
A leaderboard of every signed-in player's best, kept by JuicyJuicy and shown on your game's page. Paste this before your game's code (with the other snippets in any order).
// JuicyJuicy highscores: https://juicyjuicy.games/docs/publish#highscores
window.juicy = window.juicy || {};
window.juicy.scores || (function (juicy) {
var KEY = "juicyjuicy:best";
var framed = window.parent !== window;
var onSite = false;
var next = 0;
var waiting = {};
window.addEventListener("message", function (event) {
var m = event.data;
if (event.source !== window.parent || !m || typeof m.id !== "string") return;
if (m.type !== "juicyjuicy:scored" && m.type !== "juicyjuicy:leaderboard") return;
var done = waiting[m.id];
if (!done) return;
delete waiting[m.id];
onSite = true;
done(m);
});
// The player's answer, or null when nothing answered (not on JuicyJuicy).
function ask(message) {
return new Promise(function (resolve) {
if (!framed) return resolve(null);
var id = "scores-" + ++next;
var timer = setTimeout(function () {
delete waiting[id];
resolve(null);
}, onSite ? 30000 : 10000);
waiting[id] = function (m) {
clearTimeout(timer);
resolve(m);
};
message.id = id;
window.parent.postMessage(message, "*");
});
}
function failed(m) {
var error = new Error(m ? m.error.message : "JuicyJuicy didn't answer");
error.code = m ? m.error.code : "TIMEOUT";
return error;
}
// Each board's local best; "main" keeps the key it had before boards.
function key(board) {
return board && board !== "main" ? KEY + ":" + board : KEY;
}
function readLocal(board) {
try {
var best = JSON.parse(localStorage.getItem(key(board)));
return best && typeof best.score === "number" ? best : null;
} catch (e) {
return null;
}
}
function keepLocal(board, score, order, format) {
var best = readLocal(board);
var improved = !best || (order === "low" ? score < best.score : score > best.score);
if (improved) {
best = { score: score, order: order, format: format };
try {
localStorage.setItem(key(board), JSON.stringify(best));
} catch (e) {}
}
return { cloud: false, best: best.score, rank: null, improved: improved };
}
juicy.scores = {
// Sends a finished run's score: a whole number, or milliseconds for a time. Options (pass the
// same ones every time for a board): order "high" (more is better, the default) or "low",
// format "points" (the default) or "time", board (only for a game with several, such as
// "hard": an id of lowercase letters, digits, - and _; "main" by default). Resolves to
// { cloud: true, best, rank, improved } or { cloud: false, best, rank: null, improved }
// (signed out: kept in this browser); rejects with an error that has a code.
submit: function (score, options) {
var order = (options && options.order) || "high";
var format = (options && options.format) || "points";
var board = options && options.board;
var message = { type: "juicyjuicy:score", score: score, order: order, format: format };
if (board) message.board = board;
return ask(message).then(function (m) {
if (!m) {
if (onSite) throw failed(null);
return keepLocal(board, score, order, format);
}
if (m.ok) return { cloud: true, best: m.best, rank: m.rank, improved: m.improved };
if (m.error.code === "SIGNED_OUT") return keepLocal(board, score, order, format);
throw failed(m);
});
},
// The leaderboard's top "limit" (10 by default, at most 100): { cloud, signedIn, order,
// format, entries: [{ rank, name, score, me }], me: { rank, score } or null }. Options: board
// (as for submit).
top: function (limit, options) {
var board = options && options.board;
var message = { type: "juicyjuicy:scores", limit: limit || 10 };
if (board) message.board = board;
return ask(message).then(function (m) {
if (!m) {
if (onSite) throw failed(null);
var best = readLocal(board);
return {
cloud: false,
signedIn: false,
order: best ? best.order : null,
format: best ? best.format : null,
entries: best ? [{ rank: 1, name: "You", score: best.score, me: true }] : [],
me: best ? { rank: 1, score: best.score } : null
};
}
if (!m.ok) throw failed(m);
return {
cloud: true,
signedIn: m.signedIn,
order: m.order,
format: m.format,
entries: m.entries,
me: m.me
};
});
}
};
})(window.juicy);
// When a run ends: a whole number, or milliseconds with { order: "low", format: "time" }.
const result = await juicy.scores.submit(score, { order: "high", format: "points" });
if (result.improved) showNewBest(result.best, result.rank);
const board = await juicy.scores.top(10); // { entries: [{ rank, name, score, me }], me }
// Only for a board per level or mode: juicy.scores.submit(score, { board: "hard" }), top(10, { board: "hard" })- Send every finished run; only a player's best counts. Scores are whole numbers, times are milliseconds.
- Pass the same
orderandformatevery time: the first score sets them, and you can reset the board on the game's page. top()gives up to 100 places with players' names; show them withtextContent.- One board is enough for most games. For one per level or mode, pass an id such as
board: "hard"to both calls (lowercase letters, digits,-and_; up to 10 boards). The game page shows a tab for each, labelled from its id. - Signed-out players keep their best in the browser.
List it in features as "highscores".
Features and required updates
List what your game uses in features; publish warns about one it can't find. When JuicyJuicy adds a rule every game must follow, check your live games with:
npx -y juicyjuicy@0.19.0 check-gamesA game that misses a rule past its deadline leaves the home page and search until it's updated. Its link keeps working.
Remix a game
npx juicyjuicy remix space-gooseDownloads a remixable game's web files into a new folder with its own juicy.json. Change it and publish. It's someone else's code: read it before you run anything from it.
Sandboxes
Allow juicyjuicy.games and *.r2.cloudflarestorage.com and use a JUICY_TOKEN. Otherwise the CLI stops with NETWORK_BLOCKED.
Limits and checks
- 150 MB and 3,000 files per version
- 100 MB per file
- 25 games, 2 GB per creator
- Static files only; hidden files are skipped
These stop a publish:
- API keys, tokens and private keys in the game's files (OpenAI, Anthropic, AWS, GitHub, Stripe, JuicyJuicy…). Every player can read them.
- Programs and installers (.exe, .dll, .msi, .bat, .sh, .jar, .apk, .dmg, …).
- Crypto-mining code.
- Going over the limits: 150 MB and 3,000 files per version, 100 MB per file.
A good game also:
- Runs entirely in the browser: static files only, no server code.
- One build folder with an index.html, using relative paths for its files.
- No threads or SharedArrayBuffer, and no popups or leaving the page.
- Fits the limits: 150 MB and 3,000 files per version.
- Fills its window when resized, so it plays both on the page and in fullscreen.
- Never freezes: no loop that can run forever, and a 0×0 window pauses the game instead of restarting it.
- Has the controls players need, including touch for phones when the game allows it.
- Mouse control doesn't stop at the frame's edge: drags use pointer capture, games that aim or steer with the mouse use Pointer Lock.
- Saves progress with JuicyJuicy's window.juicy snippet, if it saves at all, so it follows signed-in players to any browser (not cookies: the play domain clears them).
- A Quit or Exit button, if it has one, sends JuicyJuicy's quit message instead of calling window.close().
Engine tips
- Plain HTML
- No build needed: the project folder is the build folder.
- Vite, Phaser, Three.js, PixiJS
- Publish
dist/, with Vite'sbaseat"/"or"./". - Godot 4
- Export for Web with Thread Support off: threads can't run on JuicyJuicy.
- Unity
- WebGL with Brotli or Gzip and Decompression Fallback off. Mind the 150 MB limit.
- Mouse
- Use
setPointerCapturefor drags andrequestPointerLock()for aiming. Esc leaves fullscreen first, so pause on another key too, like P. - Quit button
window.parent.postMessage({ type: "juicyjuicy:quit" }, "*")instead ofwindow.close().- Never freeze
- In a 0×0 or hidden window, pause and wait instead of restarting, and never loop forever: a frozen game stops other games in the tab from loading.