I have a problem: javascript can't close tabs it has not created itself, so the mandatory requirement becomes impossible: exit key and screen. I can close down the application and quit from game sessions properly, but the last part is impossible
You just need to assign a key the responsibility of exiting the game and showing a screen that indicates that you've exited the game. It doesn't have to close the tab or browser.