This can happen when code is already running and you start it again from the command line: The process that is started is killed very early after sending a IPC message to the running instance and that running instance is then trying to restore/focus the last active window which often fails....
Every time a renderer process gets focus (either pragmatically, or via normal means), it needs to signal the browser process with its window ID. When someone callsfocus, they signal the browser to ask, "Can you tell whoever currently has focus to AllowSetForegroundWindow me?" ...