Re-Hacking Wordle

Ante Barić
5 min readJul 15, 2022

--

You all know about that game that flooded Twitter and the rest of the internet a few weeks ago. Like many others, I also started playing but my streak was longer than the Golden Gate Bridge and each day I would guess the word on the first try. Wanna know how? Read on…

DISCLAIMER: This is a follow-up to my original article Hacking Wordle. Since then Wordle changed its source code quite a bit. Due to this the old method no longer works.. but worry not we can crack it again…

Wordle highscore. Max streak is 78. 100% win rate.
Not bad, right?

When I first looked at the game I thought it was really smart and interesting. My mind would just immediately start working on so many words that I know and want to try. Also choosing a word for your first guess is really hard because there are so many options.

As I am Software Developer (primarily using JavaScript) I was interested to open up Chrome DevTools and look at the Wordle code and maybe find the way to help myself working out the solution for each day.

The first thing I did was open the game in Incognito window and started playing. I was expecting to see network requests that would check if solution/word was correct on the server-side. But to my surprise there were none. I said ok, maybe when you win the final answer is sent to the server, and validation is somehow encrypted/obfuscated in client-side (JavaScript) code — but no, even when I won there were no network requests so now it was clear that solutions actually had to be embedded and available on the client-side and all those JavaScript files.

Now that I knew the control flow of the game I found out that after the page loads there is a “solutions” variable that gets initialised. It was pulling the value from a single function that would get the current day index and then would look at the specific array for word. Yes, I found all the words that were available and will be available in further days for the Wordle game.

Screenshot showing Wordle source code and the available words.
All of the words above were already in the past days so do not worry about the spoilers 😉

So nice, success… just by knowing the word for the next day ahead of time I could even now win every day on the first try. But I wanted more…

So the last time I was doing this the solution variable was actually stored on the game-app HTML element (web component). I could just do document.querySelector('game-app').solution and that would print out the solution for the current day to the JavaScript console.

But due to changes made to the Wordle codebase this was no longer the case so I had to employ some new methods.

As I still knew that all of the solutions are contained in the JavaScript file that gets loaded when the website loads – my first step was to get the contents of that file through the JavaScript console. The file is called wordle.{hash}.js . I tried querying the script tag through document.querySelector but it looks like that the script tag is removed after JavaScript loads. Not an issue, I used fetch to get the initial HTML contents of the page by fetch(window.location.href) — after that querying the script was just a matter of parsing the HTML string with DOMParser and doing query select on that new document.

The next step was to actually load the JavaScript file from the script src . I fetched the contents of wordle.{hash}.js file. I first tried executing the code with eval but as the code is wrapped inside the IIFE (Immediately Invoked Function Expression) I could not get the variable with solutions as it was private inside that expression. I decided to go another route. Just load up the JavaScript file text content and search the part of the code with Regex.

So with this we are actually back at the point where we have all the solutions inside the array. The tricky part is that we need to actually pick which solution is the right one for the current day. Fortunately from the last time I knew exactly where is the function inside the JavaScript file that actually picks the right solution based on the offset. This is the slightly modified function from the original Wordle codebase:

So this function accepts two arguments. First one e is the initial Wordle date (I call it Wordle Magic Number). And it is Sat Jun 19 2021 00:00:00 GMT+0200. The second argument t is just the current day.

And that’s it, the above function gets us the index that we put inside the solutions array solutions[offset] and voilà.. this prints out the solution for the current day.

As I practically had the solution (like the last time) I was thinking.. what if I could actually automate the pressing of keys and solution submission? Short answer, I just copied the original code that was pressing the keys…

My Wordle “auto hack”. You can find the full code with comments at the bottom of the article

Nice, right? That is about it for this article. Feel free to use it on days when you are having a hard time guessing the word or just need a mental break and wish to continue your streak. That is what cheats are for 😉. Also, I know that this takes all the fun out of the game. I personally did not care and had more fun re-reverse engineering and working on this hack (again). But that is me. I would like to say kudos to the Wordle creator for the fun game, and also a fun challenge for us who like to tinker with the code 😄. Cheers!

If you wish to take a closer look at the final script here is a pretty version with comments below 👇, and if you want to check out my original article here it is Hacking Wordle.

Below script has different logic then what was referenced above in the article because Wordle changed its codebase again.

Feel free to use it by just copy pasting the code inside the JavaScript console on the Wordle website

P.S. There is also a minified version 😉

P.S. I also added a catch block to warn you if Wordle changes the codebase again so you can contact me and I can create a new hack ✅

FYI: I also re-hacked https://www.lewdlegame.com/ so if you want to see that leave a clap or let me know on Twitter. 👋

--

--

Ante Barić

I am experienced software developer, probably not that much freaky movie freak and passionate runner hailing from Croatia.