Posted 04 Feb 2022
Alternate Title: “Sucking the Fun Out of Everyone’s Favorite Word Guessing Game”
Warning: This article contains Wordle spoilers for February 4th. Proceed at your own risk.
So, I found a tweet yesterday (sorry to whoever wrote it, but there is no way in hell I’ll ever find it in the endless sea of Wordle tweets) that basically said “hey, Wordle stores all its info locally! Check it out!”
This piqued my interest, and I started poking around. Lo and behold, everything was stored in window.localStorage. Some initial experimenting yielded some fun results:
However, I wanted to see if I could put this to good use. I wanted to break Wordle¹. I present to you: the Wordle Solver bookmarklet.
There are five main parts to how this code works:
- Getting the game board object (where all the current game state stuff is stored)
- Getting the solution from the game board
- Input the solution into the game
- Telling the game you inputted 5 letters
- Submitting the word
I’ll walk you through these step-by-step, but all the code is right here.
First, a note on how Wordle is actually structured. The game itself is actually contained in a <game-app> tag, which contains all the game information.
There are 3 interesting things here:
- boardState, which contains the letters on the board
- evaluations, which contains each letter’s state of correctness (absent, present, or correct)
- solution, which (you guessed it) is the solution to the day’s board
Modifying the first 2 directly is what let me make the fun boards from above.
So first, I grab the <game-app> object (which I will refer to as game), so I can access all the game state information. Next, I use game.addLetter() to input game.solution into the board.
The thing with the addLetter() method is that it’s meant to only be called with one letter. So while I do call it with the full string and it adds all five letters to the board, the game still thinks you’ve only inputted one letter. So that’s why I manually set game.tileIndex to 5, which just tells the game that you actually inputted five letters. Lastly, I simply call game.submitGuess() which I doubt I need to explain.
Every method used in this solver is straight from the game itself, no hacks. If you want the fun sucked out of this worldwide phenomenon, add this link to your bookmarks:
Update Feb 27, 2022: After the New York Times bought Wordle, the URL for the page has changed. I updated the bookmarklet to reflect this, which is above. If you still want the old URL to work, use the one below.
You should be able to right-click and add it to your bookmarks, but if you can’t, you can copy that link and paste it into an existing bookmark. If you can’t copy the link, the minified code is here. Open it on the Wordle page, and it’ll solve it for you.
- I don’t actually want to break Wordle. Love the game Josh <3