Can’t use PushAPI on macOS Safari, returned endpoint is an empty string

My code works fine locally and in production with Chrome.

This is my Subscribe() function running in the browser when the user wants to enable notifications (I’m not using Apple’s APN service, but standard PushAPI).

export function Subscribe(vapid: string): Promise<PushSubscription> {
    return new Promise((resolve, reject) => {
        if (!vapid) {
            reject("VAPID not declared")
        }

        navigator.serviceWorker.getRegistration()
        .then((registration) => {  
            if (!registration) {
                return
            }
            registration.pushManager.subscribe({
                userVisibleOnly: true,
                applicationServerKey: urlBase64ToUint8Array(vapid),
            }).then((subscription) => {
                console.log(subscription)
                if (!subscription) {
                    reject(new Error("Unable to subscribe (empty subscription)"))
                }
                if (subscription.endpoint === "") {
                    reject(new Error("Unable to subscribe (empty endpoint)"))
                }
                resolve(subscription)
            })
        })
        .catch((err) => {
            reject(err)
        });
    })
}

The browser asks for user’s permission, no problem there, then when trying to subscribe, the payload I’m getting is this :

PushSubscription {endpoint: "", expirationTime: null, options: PushSubscriptionOptions, getKey: function, unsubscribe: function, …}

Stringified:

{
  "keys":{
    "p256dh":"",
    "auth":""
  }
}

As you can see, there is no error, but the endpoint is empty as well as the keys.

  • It works on a different machine when I ask someone to test
  • I can use this test page without issues : https://www.bennish.net/web-notifications.html (but I couldn’t until I deleted ~/Library/Safari/RemoteNotifications/Permissions.plist), but I think it’s using a different API and those are not server-side pushed notifications.
  • I can not use the following site https://cleverpush.com/en/test-notifications/, I get an “undefined” alert when sending a notification. In debugger I see similarities with the payload being sent to their server :
{
  "endpoint":"",
  "publicKey":"",
  "authSecret":""
}

It looks like a weird issue on my system, but couldn’t figure out what is the problem.

I should add that this machine is under enterprise management, but they say they don’t have policies to block push notifications.