DEV Community

loading...
Cover image for How I Hacked Cookie Clicker Game with Inspect Element

How I Hacked Cookie Clicker Game with Inspect Element

trulyfurqan profile image Muhammad Furqan Ul Haq ・3 min read

How I Hacked Cookie Clicker Game with Inspect Element

Cookie Clicker is a very popular browser-based game. It revolves around producing cookies for the world. This game gets more interesting over time which keeps the player engaged.

Basically, there are a few ways to get cookies. These cookies can then be used to create new buildings or purchase upgrades. At first, I’m going to mention a few genuine ways to earn cookies.

  • By clicking the big “Cookie” shown on the user interface.
  • By creating new buildings. There are different types of buildings and each type can only produce a specified number of cookies per second. Initially, all buildings are locked, but they will get unlocked over time as the game progresses.
  • By enhancing the efficiency of your cookie store through upgrades.

Now, here comes the actual hacking stuff you’re waiting for.

Getting Started

As I mentioned earlier, this is a browser-based game. Meaning that it is developed using HTML5, CSS3, and JavaScript. All of these are client-side languages that can be modified through programs like Chrome DevTools.

Let’s open this game in Google Chrome.

Now to open Chrome DevTools, right-click anywhere on the game and select “Inspect” from the context menu. For now, we will only be focusing on its functionality that is written in JavaScript. So, open the “Console” tab.

Another way is to press Ctrl+Shift+J on Windows or ⌘+⌥Option+J on Mac.

You’ve to execute the below-mentioned codes here.

It’s time to hack different features of this Cookie Clicker game.

Hack Cookies

As everything in this game depends on cookies, so I hacked them!

Basically, after analyzing its source code, I found that the functionality of this game is written inside a file called “main.js”.

This file initializes an object Game through which we can easily access different features of Cookie Clicker. For example, we can modify the number of cookies we have using the Game.cookies property.

Let’s do that now!

Simply copy the below code and paste it inside the “Console” tab of Chrome DevTools. Press “Enter” to execute it.

Game.cookies = 57000
Enter fullscreen mode Exit fullscreen mode

Once executed, you will get 57000 cookies absolutely FREE. You can add any number here.

For example, the below code will give you “Infinity Cookies”.

Game.cookies = 999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
Enter fullscreen mode Exit fullscreen mode

Keep Getting Cookies

This game also has the functionality of earning cookies per second. Game.cookiesPs property will give us a specified number of cookies for one second.

So, why not wrap it inside a setInterval of one second to continuously get more and more cookies?

Here’s the code snippet to do so.

setInterval(function(){
    Game.cookiesPs = 50
}, 1000);
Enter fullscreen mode Exit fullscreen mode

This code will add 50 cookies to your account every second.

Unlock All Upgrades and Purchase Them

Finally, the developers of Cookie Clicker have also provided a cheat to get all upgrades for free.

Basically, the below method will give you all upgrades as well as unlocks all types of buildings. Additionally, you will get 1.000 nonillion cookies.

Game.RuinTheFun();
Enter fullscreen mode Exit fullscreen mode

Now you might be wondering can we hack other browser-based games too?

And the answer is "Yes, definitely!"

You can hack any game no matter whether it is browser-based, Android, or even PC.

I would like to mention that I learned game hacking from guidedhacking.com. It is the best community forum that helps us understand all the concepts of game hacking in a step-by-step manner.

Spend some time there!

You'll find game hacking tutorials and guides right from their main menu. If you find something difficult then you can always ask questions from fellow hackers.

At last, I would say that game hacking is not very difficult. It just depends on how much time you can dedicate to learn it.

Discussion (9)

pic
Editor guide
Collapse
kirilllive profile image
Kirill Live

It was interesting, I didn’t know that Cookie Clicker works like that.

Collapse
trulyfurqan profile image
Muhammad Furqan Ul Haq Author

Yeah. It is a very engaging game. I really like the way it progresses.

A few years ago, I hacked Google Chrome's Dinosaur Game and published a blog post on it. That article got really popular. So, today I decided to try hacking this Cookie Clicker. 😉

Here's a link to the "Dinosaur Game Hacked" article if you're interested.

link: JavaScript Code Plays Google Dinosaur/T-Rex Game Automatically

Collapse
patthememestealer profile image
patthememestealer

dont say you hacked it you because you didn't

Collapse
the_lusquitas profile image
Lucas Silva

But, is It a Win, If you sacrifice the Fun?

Collapse
trulyfurqan profile image
Muhammad Furqan Ul Haq Author

You are right. But, sometimes analyzing others code and finding vulnerabilities in it is also fun and interesting.

I think it's a way to improve our programming skills.

Collapse
devfranpr profile image
DevFranPR

Man I don't even finished a complete run but now I feel stupid for not trying first.

Collapse
trulyfurqan profile image
Collapse
dbillio profile image
DBillio

Hahah, amazing! I wish you good luck in your future hacks

Collapse
trulyfurqan profile image