1

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:

enter image description here

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 enter yes they are still able to intercept the input.
bryanbraun
  • 3,025
  • 2
  • 26
  • 38
  • `let yes = 'no'` should break it - but a global `var` doesn't change anything. – Bergi Apr 27 '20 at 21:42
  • @Bergi `Uncaught SyntaxError: Identifier 'yes' has already been declared`. @bryanbraun They are identifier and not text or string, I think that's how they catch it. They don't read your input you call their predefined identifier. If you type `"yes"` it just prints yes" – Mickael B. Apr 27 '20 at 21:45

0 Answers0