2

To replicate:

  1. Open two github tabs on which you're both logged in
  2. Log out of one tab.
  3. At the top of the 2nd tab you almost immediately get notification that you logged out on another tab

I've been trying to figure out how this works. Since the notification is almost immediate I considered 3 possibilities:

  1. Each tab makes XHR/AJAX requests on a schedule to check session validity with the server (or uses long polling)
  2. Each tab registers an event listener to Server Sent Events, and receives notification from the server upon logout.
  3. Each tab has a websocket connection to the server, and receives a similar notification.

For reference, these technologies are discussed here. I am stumped though because when I open the web browser's (Firefox 48 beta) network requests dev tool, I see no communication on the tab that shows the notification between the time I log out of the other tab, and the time the notification appears.

By the way, the notification works in the opposite direction as well. If you have two tabs logged out, and you log into one of them, a notification immediately pops up on the other tab that you logged in. What's going on?

Community
  • 1
  • 1
BeetleJuice
  • 39,516
  • 19
  • 105
  • 165

1 Answers1

3

Github uses Local Storage for this trick. It uses entry with key 'logged-in'. This key is either true or false and is set each time user logs in/out. Each tab constantly check (as I know there is no event on Local Storage modification) Local Storage.

  • 3
    One more clarification: actually there is event for local storage modification https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API and GitHub most probably uses it. – jcdenton Jul 12 '16 at 07:01
  • Interesting; I hadn't thought of that. If I manually (using dev tools in Firefox) change the local storage value from "true" to "false", the pop up does not appear. How come? – BeetleJuice Jul 12 '16 at 07:04
  • Probably Firefox does not fire appropriate event to focused tab, when altering Local Storage. Or GitHub uses some dedicated for Firefox mechanics. Anyway, works fine if you open 2 or more tabs. – Anton Onipko Jul 12 '16 at 07:28
  • @AntonOnipko Thanks for answering my question. I can confirm that if I turn off Local Storage in Firefox (by disabling `dom.storage.enabled` in `about:config`), Github no longer fires a notification when I log in/out on another tab. – BeetleJuice Jul 12 '16 at 07:43