What's Inside a .riv File? Inspect Artboards, State Machines and View Models in JS
You got a .riv file from your animator (or downloaded one from the Rive Community), and now you need to wire it up. Which artboard do you load? What is the state machine called? Which View Model properties can your code set? Guessing names is the most common reason a Rive animation "loads but does nothing". In this post I'll explain what a .riv file actually is, and then we'll build a tiny .riv file inspector in plain JavaScript that lists everything inside: artboards, state machines, View Models, properties and enums.
What is a .riv file?
A .riv file is the binary runtime format that the Rive Editor exports. According to the Rive docs, it holds your artboards, shapes, animations and state machines in a compact form that every Rive runtime can read: web, React, Flutter, Apple, Android, Unity, Unreal and others. The same exported file works across all of them.
A few things worth knowing before you ship one:
- It is not the editable source. The .riv is the "compiled" output. The editable backup format is .rev (Export for backup in the editor). If you only have the .riv, you can't open it in the editor and change the design.
- It starts with a header. The first 4 bytes are the ASCII letters
RIVE, followed by a major version, a minor version and a file ID. The current major format is 7. - Minor versions are forgiving. A runtime with the same major version can load a file exported from a newer editor. Features it doesn't understand are skipped (treated as no-ops) instead of crashing, so the rest of the file keeps working. That is also why "it works in the editor but one effect is missing in my app" usually means your runtime is out of date.
- Free plan exports show a Rive splash screen. Every plan can export for runtime, but on the Free plan the exported file plays a Rive splash; paid plans export without it. Worth checking before a client launch.
How to export a .riv file
In the Rive Editor, click the blue Publish button on the right side of the toolbar, or go to Export > For runtime from the left toolbar menu. That gives you the .riv you load in code.
If you only want someone to look at the animation (a client or a PM), you don't need a .riv at all. On Voyager and Enterprise plans you can use Generate Embed URL from the main menu to get a hosted link, an embed link or an iframe snippet. Keep in mind embeds are snapshots and don't give you access to the runtime API.
Why inspect a .riv file before writing code?
Every Rive runtime asks you for names: the artboard name, the state machine name, and the View Model property paths. A typo, an extra space or a renamed state machine fails quietly. The web FAQ even lists "How come my State Machine isn't playing?" with the answer: make sure you passed the correct state machine name and autoplay: true.
So before I wire anything up, I like to dump the file contents. I also wrote about agreeing on these names up front in The Rive Handoff Checklist, but an inspector is how you check what actually got exported.
Build a .riv file inspector in JavaScript
We'll use the official web runtime @rive-app/webgl2 (the package Rive recommends for most projects, because it uses the same Rive Renderer as the editor). Everything below is from the current web runtime docs; the latest version on npm when I wrote this was 2.57.1.
Step 1: The page
One file input, one canvas element and a pre block for the output:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <title>.riv inspector</title> <style> canvas { width: 400px; height: 400px; border: 1px solid #ddd; } pre { white-space: pre-wrap; font-size: 13px; } </style> </head> <body> <input type="file" id="file" accept=".riv" /> <canvas id="canvas"></canvas> <pre id="out">Pick a .riv file…</pre> <script src="https://unpkg.com/@rive-app/webgl2@2.57.1"></script> <script src="inspector.js"></script> </body> </html> The script tag exposes a global rive object. With npm you would npm install @rive-app/webgl2 and import * as rive from "@rive-app/webgl2" instead.
Step 2: Read the header
The format docs describe the header: 4 fingerprint bytes, then the major and minor versions as LEB128 variable-length unsigned integers (little endian). That is easy to read by hand, and it tells you right away if someone sent you a renamed file that isn't a .riv at all:
function readHeader(buffer) { const bytes = new Uint8Array(buffer); const fingerprint = String.fromCharCode(...bytes.slice(0, 4)); let offset = 4; // LEB128 variable unsigned integer function readVarUint() { let result = 0; let shift = 0; let byte; do { byte = bytes[offset++]; result |= (byte & 0x7f) << shift; shift += 7; } while (byte & 0x80); return result; } const major = readVarUint(); const minor = readVarUint(); return { fingerprint, major, minor, sizeKB: (bytes.length / 1024).toFixed(1) }; } If fingerprint isn't RIVE, stop there.
Step 3: Load the file and list its contents
Rive can load a file from a URL (src), from an ArrayBuffer (buffer) or from an already parsed RiveFile (riveFile). A file picked from disk gives us an ArrayBuffer, so we use buffer.
Once loaded, the Rive instance exposes:
-
contents: artboards, their timeline animations and their state machines -
viewModelCountandviewModelByIndex(i): every View Model in the file - on each View Model:
name,properties(each with anameandtype),instanceNames -
enums(): the enums defined in the file -
globalViewModelNames(): View Models marked global in the editor
const out = document.getElementById("out"); const canvas = document.getElementById("canvas"); let r = null; document.getElementById("file").addEventListener("change", async (e) => { const file = e.target.files[0]; if (!file) return; const buffer = await file.arrayBuffer(); const header = readHeader(buffer); if (header.fingerprint !== "RIVE") { out.textContent = "This is not a .riv file."; return; } // Free the previous file before loading a new one if (r) r.cleanup(); r = new rive.Rive({ buffer, canvas, autoplay: true, autoBind: true, onLoad: () => { r.resizeDrawingSurfaceToCanvas(); out.textContent = report(header); playFirstStateMachine(); }, onLoadError: (err) => { out.textContent = "Could not load file: " + JSON.stringify(err.data); }, }); }); function report(header) { const lines = []; lines.push(`Format ${header.major}.${header.minor} · ${header.sizeKB} KB`); lines.push("\nARTBOARDS"); for (const ab of r.contents.artboards) { lines.push(`- ${ab.name}`); lines.push(` state machines: ${ab.stateMachines.map((sm) => sm.name).join(", ") || "none"}`); lines.push(` timelines: ${ab.animations.join(", ") || "none"}`); } lines.push("\nVIEW MODELS"); for (let i = 0; i < r.viewModelCount; i++) { const vm = r.viewModelByIndex(i); lines.push(`- ${vm.name} (instances: ${vm.instanceNames.join(", ") || "none"})`); for (const p of vm.properties) { lines.push(` ${p.name}: ${p.type}`); } } const globals = r.globalViewModelNames(); if (globals.length) lines.push(`\nGLOBAL VIEW MODELS: ${globals.join(", ")}`); lines.push("\nENUMS"); lines.push(JSON.stringify(r.enums(), null, 2)); return lines.join("\n"); } Step 4: Actually play the state machine
Here is a gotcha. If you don't pass a stateMachine name, the current web runtime plays the first timeline animation it finds, not the state machine. The docs say this changes in the next major version (v3), where Rive will play the artboard's default state machine. For now, an inspector that doesn't know the names in advance can pick the first one from contents and reset:
function playFirstStateMachine() { const artboard = r.contents.artboards[0]; const sm = artboard && artboard.stateMachines[0]; if (!sm) return; r.reset({ artboard: artboard.name, stateMachine: sm.name, autoplay: true, autoBind: true, }); } reset() cleans up the current artboard and state machine instances and starts again, following autoplay and autoBind.
Version note
stateMachine (singular) was added in v2.41.0. The plural stateMachines and the animations parameter still work but log a one-time console warning and will be removed in a future major version. If you're on an older runtime, update before copying the code above.
Also note that contents still lists each state machine's inputs. State machine inputs are deprecated in favor of Data Binding, so for new files the View Model list is the part to pay attention to.
Reading the output
Here's what I look at when the inspector runs:
- Format version: major 7 is current. If loading fails with an import error, check the runtime version against the editor features used.
- Artboards and state machines: copy these names straight into your code instead of retyping them from a screenshot.
- View Model properties: these are your API. A
numberbecomesvmi.number("path"), atriggerbecomesvmi.trigger("path"), anenumbecomesvmi.enum("path"), and so on. Nested View Models are reached with slash paths like"Settings/volume". - Instances:
autoBind: truebinds the artboard's default View Model with the instance marked "Default" in the editor. If the animator made several instances (themes, characters, states),instanceByName()lets you pick one. - File size: the header function prints it. Large files are usually embedded images, fonts or audio, which can be loaded separately at runtime (see Loading Assets).
Common .riv loading problems
- CORS errors when the .riv is on a CDN or S3: set CORS headers on the host.
- Blurry animation: give the canvas element a CSS width and height, then call
resizeDrawingSurfaceToCanvas()inonLoad(and on window resize). - Content Security Policy blocks it: the runtime uses WebAssembly, so a CSP that blocks
unsafe-evalneedswasm-unsafe-eval. - Nothing animates: wrong state machine name, or
autoplaynot set. Run the inspector. - Memory grows in a SPA: call
cleanup()when the view with the animation goes away.
Wrapping up
A .riv file is a small, versioned binary that every Rive runtime can read, and the web runtime gives you everything you need to look inside it. Ten minutes spent dumping the artboards, state machines and View Models saves a lot of "why isn't it playing?" debugging later, and it gives you a ready-made list of property names to discuss with your animator.
Need a Rive animator?
I'm Maxim, a Rive animator and motion designer with 10+ years in motion and 100+ projects: interactive mascots, animated logos and icons, and UI animations, delivered with a clean developer handoff (clear names, documented View Models, no guessing).
See my work and get in touch at hireriveanimator.com
Have a .riv that refuses to load, or a question about what's inside one? Drop it in the comments.