Outside your game window your are not in your game ... so mouse events are managed by os and not by your code. The best is not use the mouse to go in pause mode but a keyboard input for desktop computers.

is just I wanted to pause the game if accidentally the user clicks out of it, for example if click on a button that is not in my game screen... I wanted it to be a global function to always pause if this happens, trying to make it easy instead of communicating to the html of the page, but I guess is not that simple :/