Inside Chrome Dino’s Open Source Code (Wayou Fork)

Glowing neon sign with pixelated Game Over text in a dark arcade setting.

The Chrome Dino game is one of the rare browser easter eggs you can actually open up and read. Google’s T-Rex Runner ships in Chrome’s source tree, but a community fork by GitHub user “wayou” packages just the game into a standalone HTML5 project you can clone, run, and modify in minutes. If you’ve ever wondered how the dinosaur jumps, where the cactus comes from, or what makes the speed scale, the t-rex runner code answers all of it in under 2,000 lines of JavaScript.

Key takeaways

  • The T-Rex Runner is licensed under BSD-3, allowing anyone to clone, modify, and redistribute the code.
  • The most popular standalone version is github.com/wayou/t-rex-runner, a near-direct port of Google’s Chromium source.
  • The core game logic lives in one main JavaScript file — Runner, Trex, Obstacle, Horizon, and a few helpers.
  • Sprites are packed into a single sheet; everything is drawn on an HTML5 canvas.
  • You can clone the repo and run it locally with no build step — just open index.html in a browser.

Where the code lives

Google maintains the original T-Rex Runner inside Chromium, in the offline assets directory of the browser source. That tree compiles into Chrome itself — useful if you want the absolute canonical version, less useful if you just want to read or modify the game.

The fork most developers actually use is github.com/wayou/t-rex-runner, created in 2014 shortly after the dino game first appeared in Chrome. It strips out the Chromium-specific scaffolding and leaves a clean, runnable project. Clone it, open index.html, and the game runs.

The file structure

Open the Wayou fork and you’ll see roughly this layout:

  • index.html — minimal page with a single canvas element.
  • index.js — the entire game engine: Runner, Trex, Obstacle, Horizon, HorizonLine, Cloud, NightMode, DistanceMeter, and the input handlers.
  • index.css — small stylesheet for the canvas container.
  • assets/ — the sprite sheet and audio files (jump, point, die).

The “engine” is one file. There’s no framework, no build step, no dependencies. The whole thing is vanilla JavaScript talking directly to a canvas 2D context.

The Runner class is the heart of it

The top-level Runner class kicks off the game and owns the loop. When the page loads, a single Runner() instance is created and stored on window. Its init() method sets up the canvas, loads sprites, hooks up key listeners, and starts the requestAnimationFrame loop.

From there, the loop ticks every frame and calls into the sub-components: the dinosaur (Trex) updates its position and animation frame, the Horizon scrolls the background and spawns obstacles, and the DistanceMeter increments the score. Collision detection happens inside the runner once per frame, comparing the T-Rex’s hitbox against each active obstacle.

How jumping works in code

Jumping is the most visually obvious mechanic, and the code is satisfyingly direct. The Trex class tracks a vertical velocity and applies gravity each frame. When the player presses space (or taps), startJump() sets the velocity to a fixed negative value (upward). Gravity pulls it back down at a constant rate until the dinosaur hits the floor.

A small trick: holding the jump key slightly extends the dinosaur’s airborne time. The code checks how long the input is held and reduces gravity during the hold window, which makes longer jumps feel responsive. Releasing early causes a shorter hop.

Where the cactus comes from

The Obstacle class handles cacti and pterodactyls. The horizon spawns a new obstacle whenever the previous one has moved far enough offscreen and the random gap timer has elapsed. Cactus variants (single, double, triple, large) are picked from a definition table; pterodactyl height is one of three preset bands.

The spawn frequency increases with the player’s distance, which is what makes the game feel harder over time. There’s no explicit difficulty curve — just a function that shrinks the minimum gap between obstacles as the score grows. By the time the speed plateaus, the obstacle density alone is doing the heavy lifting.

The day/night cycle

The NightMode object handles the palette flip. Every ~700 obstacles or so (the exact threshold is defined as a constant), the background and foreground colors invert. A moon sprite slides across the sky during night phases, and the cycle continues indefinitely.

This is one of the more readable pieces of the code — the constants are right at the top, and the toggle logic is a single boolean flip. If you want a permanent night mode mod, you’re literally changing one variable.

How the score is rendered

The DistanceMeter renders the score directly from a sprite atlas of digits. It tracks a running distance variable (a plain JavaScript number) and converts it to a five-character string each frame. Once the distance crosses 99,999, the string conversion clamps to five characters — that’s the source of the famous rollover. The internal number keeps growing; only the display resets.

If you want a six-digit counter, the change is genuinely tiny: a few characters in the string-format function. Modders have done it dozens of times.

How to run the t-rex runner code yourself

  1. Clone the repo: git clone https://github.com/wayou/t-rex-runner
  2. Open index.html in any modern browser. You can double-click it.
  3. The game runs locally with no server needed. To distribute it, host the folder anywhere — GitHub Pages, Vercel, an S3 bucket, your own server.

That’s it. There’s no npm install, no webpack, no compile step. The simplicity is part of why the dino game has been forked so widely.

Common mods people build from this code

  • Permanent night mode — flip the constant in NightMode.
  • Higher score ceiling — increase the digit count in the display.
  • Different dinosaur sprite — swap the sprite sheet.
  • Mouse-controlled jump — add a listener inside Runner.handleEvent().
  • Coin or power-up additions — extend the Obstacle class with a new spawn type.

None of these need any new dependencies. The code is small enough that most mods are 20-line patches.

Why “wayou” and not Google directly?

Google’s source is buried inside the Chromium repository, which is massive and not friendly to drive-by exploration. Wayou’s fork extracts just the game files into a standalone project, making it the de facto reference for anyone wanting to study or modify the dinosaur game. It’s been updated occasionally to track upstream changes, but the core game is stable and the fork rarely needs revisions.

The code is licensed under BSD-3 (Chromium’s own license), which means it’s freely available for any use — commercial, personal, modified, or otherwise — with attribution preserved.

Frequently asked questions

What language is the Chrome Dino game written in?

The T-Rex Runner is written in vanilla JavaScript using the HTML5 canvas API. There’s no framework, no build step, and no external dependencies in the standalone fork.

Can I legally use the Chrome Dino code in my own project?

Yes. The code is licensed under BSD-3, which allows modification and redistribution, including for commercial use, as long as the license text and copyright notice are preserved.

How big is the source code?

The Wayou fork’s main game file is around 2,000 lines of JavaScript. Including the HTML, CSS, and sprite/audio assets, the whole project is under 200 KB.

Is the wayou fork still maintained?

The repository is stable but not actively developed. Issues are sometimes triaged. The core game works in all modern browsers without modification, so most users don’t need updates.

Where is the high-score storage in the code?

The fork persists the local high score via browser localStorage, written when a run ends. The relevant logic lives near the bottom of the main game file, in the Runner.gameOver() method.

Read the code, then play it

Studying the t-rex runner code is one of the cleanest examples of “tiny HTML5 game, fully readable” you’ll find. Two thousand lines, one canvas, one sprite sheet, and a worldwide audience. If you want to see what the code actually produces, run the live recreation at the top of this site — and if you want to fork it yourself, the repo’s a single git clone away.