16
  1. Go to facebook and allow HTML5 Desktop Notification for it.
  2. Close facebook tab.
  3. Ask somebody to write you message on facebook.

Now u see the notification from facebook while facebook site isn't open. HOW?

CBroe
  • 91,630
  • 14
  • 92
  • 150
Ximik
  • 2,435
  • 3
  • 27
  • 53

2 Answers2

5

Facebook uses the Push Notifications API: https://www.w3.org/TR/push-api/

More information:

andyrandy
  • 72,880
  • 8
  • 113
  • 130
  • 1
    This answer is incomplete. "The Push API will also ensure reliable delivery of push messages while a user agent is actively using a webapp, for instance if a user is actively using the webapp or the webapp is in active communication with an application server through an **active worker, frame, or background window.**" But how is "active worker, frame, or background window" defined? – moi Sep 30 '17 at 20:30
  • @moi i am not sure what you mean, is your question what a worker is, for example? > https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API – andyrandy Sep 30 '17 at 20:56
  • it would be weird to explain every word in an answer (especially in the link of an answer). workers, frames, or background windows are well known terms imho, and youj can always google for those. or did i not understand what you wanted to say? – andyrandy Sep 30 '17 at 20:57
  • 1
    I read the entry on developer.mozilla.org, but I did not find an explicit statement, that a worker keeps running even when the parent is closed. This behavior would be required to explain what the questioner observed (i.e. close tab, receive notification nevertheless). – moi Sep 30 '17 at 21:23
  • don´t just read the article on mozilla, there is a lot more to find out with google. for example: https://developers.google.com/web/ilt/pwa/introduction-to-push-notifications – andyrandy Sep 30 '17 at 22:15
  • This answer is very bad. It doesn't answer the question at all. – sgon00 Nov 29 '18 at 13:36
  • why not? what´s missing in your opinion? the question was "how does facebook send notifications without an open tab", that´s been answered perfectly fine imho. information about the push notifications api (tutorials and whatnot) can be found with google, we´re not here to do the whole work for people but to help them solve things on their own - because that´s how you learn stuff :) - the question is very broad though. – andyrandy Nov 29 '18 at 14:27
0

They use the Push API - https://developer.mozilla.org/en-US/docs/Web/API/Push_API Quoting from there:

The Push API gives web applications the ability to receive messages pushed to them from a server, whether or not the web app is in the
foreground, or even currently loaded, on a user agent.

Segevz
  • 1