Javascript Fun: Hacking Google Chrome’s T-rex Game


All of us like to have an extra edge while playing games (i mean cheat codes :P ). Most games have such codes that allow you to alter the gaming experience while many other games find it illegal to use such hacks.

But, have you thought about how all this works?

Let us understand it by actually ‘HACKING’ one of the simplest games out there — the T-rex runner.

For those who do not know, it is a side scrolling runner game that appears on the ‘No Internet’ screen of Google Chrome.

This 8-bit-type game features a tiny t-rex which runs through a desert. You have to avoid the t-rex from hitting the obstacles like cacti etc. Believe me, it is simple but addictive.

We will be using simple Javascript commands to tweak the game for fun!

Sounds cool? Let's do it.

1. Getting into the game’s console

First, disconnect your device from the internet and open Google Chrome. Enter any url and you will see the no internet screen with a t-rex dino.

If you want to stay online for some reason, simply enter ‘chrome://dino’ in the address bar.

Now, right click inside the window and click the Inspect option from the menu. Alternatively, you can use the shortcut key combination — Ctrl+Shift+I.

In the side panel which opens, you will be able to see the source code of the game. Next, click the console tab. This is the place where we will run our simple Javascript code to alter the game.

2. T-rex Game Speed Hack using Javascript

Normally, the game has such a logic that the speed increases gradually as you proceed further in the game. But, if you want to take on the challenge right from the start, there is a secret way to do it.
Just write the following line of code in the console tab you opened.

And hit enter.

Voila! You will see the t-rex running much faster right from the beginning. With increased speed, the game feels even more challenging.

You want more speed? No worries. Just increase the number inside the brackets in the above command. And, as soon as you hit enter, the dino would go zaaaaaappp!!!

3. Make your T-rex Immortal

The second hack for the dino game is unlimited life or simply immortality. See, the game is all about keeping the dino from dying by avoiding the hurdles. And, I understand what would be the point if the dino does not die after hitting the cacti or anything else.


It is also fun to make a high score that even your top-notch gamer friend would not be able to break.
So, here is the piece of code that will actually make your t-rex immortal.

First, paste the line below in the console tab and hit enter.
var original = Runner.prototype.gameOver

This code actually saves the original gameOver function in a static variable called original so that we can restore it when needed.

Next,paste the line of code below and hit enter again.
Runner.prototype.gameOver = function(){}

This code will replace the original gameOver function with a new function that does nothing. After whenever the gameOver function will be called in the game nothing will happen which makes your dino completely immortal!

Whenever you are done with the hack, here is what you need to do to restore the original functionality of the game.

Paste the following code in the console and hit enter.
Runner.prototype.gameOver = original

This will restore the original gameOver function and the dino game will run like normal (without immortality)

So guys, that was it! I hope you’ve realised how simple javascript can be used to alter games’ logic. If you find it cool, share it with you coding junkies.

In the end, a little disclaimer that I do not support hacking or illegal activities. This guide only tells you how Javascript can be used in fun ways. It is completely for educational purpose only.
javascript, game development, how to

You can't comment this post because its author is not yet a full member of the community. You will be able to contact the author only after he or she has been invited by someone in the community. Until then, author's username will be hidden by an alias.