Google has an easter egg where if you search "text adventure" and then open the browser tools on the results page, you can start playing a text-based adventure game by entering words into the console:
My question is, how does this work?
What could they be doing that allows their JavaScript to intercept browser console input and respond accordingly?
Other possibly relevant details:
- Most console behavior appears to work like normal (defining variables, functions,
debugger
commands, etc.). It only behaves differently when a valid command is entered. - You can inspect the JavaScript that contains many of the strings and logic, but it's minified so it's hard to understand much of how it works.
- It doesn't seem to be built into the browser, since the game works on Safari and Firefox.
- They aren't just intercepting errors. If you define a variable that matches their keywords (like
var yes = 'test';
), and then enteryes
they are still able to intercept the input.