Hack the Chrome Dino Game: Ultimate Guide with Code Examples
Google Chrome includes an endless runner Dinosaur (T-Rex) game that appears in the absence of an internet connection. Let’s put on our hacker hats and try to mess with this game!
If you are unable to get the No Internet page, open a new tab and type chrome://dino
and press Enter.
Not too important if you’re not a programmer, but this game is written in JavaScript, and fortunately for us, the class and object are globally exposed. Due to JavaScript’s dynamic nature, we can override functions on the class to change the functionality. We can do all this from the Chrome console.
Playing the Game
Just in case this is your first time seeing this game, it is fairly straightforward to play:
- Space Bar / Up: Jump (also to start the game)
- Down: Duck (pterodactyls appear after 450 points)
- Alt: Pause
The game enters a black background mode after every multiple of 700 points for the next 100 points.
Open Chrome Console
To start hacking the game, follow these steps:
- Make sure you are on the No Internet Connection page.
- Right-click anywhere on the page and select Inspect.
- Go to the Console tab. This is where we will enter the commands to tweak the game.
After every command, press Enter. All the commands are case-sensitive. If you see undefined
after entering a command correctly, don’t worry—that is expected (for those who want to know more, it is the return type of the function we called).
Immortality (God Mode)
Follow the commands to make the Dino un-killable:
// Store the original game over function var original = Runner.prototype.gameOver; // Make the game over function empty Runner.prototype.gameOver = function(){};
How to Stop?
When you want to stop the game, revert back to the original game over function. This would only work if you had entered both commands in order for Immortality.
Runner.prototype.gameOver = original;
Tweaking Speed
Type the following command in the Console and press Enter. You can use any other speed in place of 1000.
Runner.instance_.setSpeed(1000);
To go back to normal speed:
Runner.instance_.setSpeed(10);
Setting the Current Score
Let’s set the score to 12345. You can set any other score less than 99999. The current score is reset on game over.
Runner.instance_.distanceRan = 12345 / Runner.instance_.distanceMeter.config.COEFFICIENT;
Jumping Height
You can control how high the Dino jumps by using the below function. Adjust the value as necessary.
Runner.instance_.tRex.setJumpVelocity(10);
Walk in Air
Make the Dino walk in mid-air by disabling gravity:
Runner.instance_.tRex.groundYPos = 0;
To bring the Dino back to the ground:
Runner.instance_.tRex.groundYPos = 93;
Auto-play
This code periodically checks for the closest obstacle (cactus or pterodactyl) and then jumps or ducks based on the obstacle’s position.
function dispatchKey(type, key) { document.dispatchEvent(new KeyboardEvent(type, {keyCode: key})); } setInterval(function () { const KEY_CODE_SPACE_BAR = 32; const KEY_CODE_ARROW_DOWN = 40; const CANVAS_HEIGHT = Runner.instance_.dimensions.HEIGHT; const DINO_HEIGHT = Runner.instance_.tRex.config.HEIGHT; const obstacle = Runner.instance_.horizon.obstacles[0]; const speed = Runner.instance_.currentSpeed; if (obstacle) { const w = obstacle.width; const x = obstacle.xPos; // measured from left of canvas const y = obstacle.yPos; // measured from top of canvas const yFromBottom = CANVAS_HEIGHT - y - obstacle.typeConfig.height; const isObstacleNearby = x < 25 * speed - w / 2; if (isObstacleNearby) { if (yFromBottom > DINO_HEIGHT) { // Pterodactyl going from above, do nothing } else if (y > CANVAS_HEIGHT / 2) { // Jump dispatchKey("keyup", KEY_CODE_ARROW_DOWN); dispatchKey("keydown", KEY_CODE_SPACE_BAR); } else { // Duck dispatchKey("keydown", KEY_CODE_ARROW_DOWN); } } } }, Runner.instance_.msPerFrame);
Conclusion
With these hacks, you can now take full control of the Chrome Dino game. Whether you want to make the game easier, more challenging, or just have some fun customizing it, these techniques will help you get there. Feel free to experiment with the code and see what other cool modifications you can come up with!
If you found this guide helpful, share it with your friends and let them enjoy the hacked Chrome Dino game too!