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.