Closing a browser window doesn’t kill your session - it remains alive for 120 (maybe 60?) seconds by default, which can be configured here, in the Session Timeout section:
So you won’t see the “end_session” message sent from the Perspective Session for at least one minute, maybe two.
I’ll look into the device_id being empty, but I just tested it myself and it worked as expected…