How I Hacked Cookie Clicker Game with Inspect Element
Tags: javascript, webdev, programming, gamedev
Published: 2021-02-02 17:58:13

# How I Hacked Cookie Clicker Game with Inspect Element

 

[Cookie Clicker](https://orteil.dashnet.org/cookieclicker/) 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.

I would like to mention here that in the past I wrote a very popular article about the best open-source [HTML Games](https://www.edopedia.com/blog/open-source-html5-and-javascript-games/). I think the source code of these games will help you improve your game development/hacking skills. So, please do have a look.

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](https://developers.google.com/web/tools/chrome-devtools).

Let’s [open this game](https://orteil.dashnet.org/cookieclicker/) 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.

```javascript
Game.cookies = 57000
```



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”.

```javascript
Game.cookies = 999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
```

 

## 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.

```javascript
setInterval(function(){
    Game.cookiesPs = 50
}, 1000);
```

 

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.



```javascript
Game.RuinTheFun();
```

---

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](https://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.