javascriptpush-notificationgoogle-cloud-messagingfirebase-cloud-messagingservice-worker

Change service worker subscribe endpoint


So I'm trying to get into the Push API and I set up a very basic example with an empty service-worker.js and an index.js that just triggers the subscription for now:

function subscribeUserToPush() {
    return navigator.serviceWorker.register('service worker.js').then(function(registration) {
        var subscribeOptions = {
            userVisibleOnly: true,
            applicationServerKey: urlBase64ToUint8Array(
            'foobarkeyoffoobarness'
            )
        };

        return registration.pushManager.subscribe(subscribeOptions);
    }).then(function(pushSubscription) {
        console.log('PushSubscription: ', pushSubscription);
        return pushSubscription;
    });
}

and the subscription endpoint I get send back is something like "fcm.googleapis.com/fcm/send/dfyodk6jd3c:APA91bETwSnoOpagCulOlD11XJu7savlJXp4hwEqKeqldHJxW6_WQTfjNTKjsT9JpY1auK...."

Now my question is: is it actually possible (even if it is a bad idea) to have a custom push-service endpoint, a self hosted solution?

Does Google firebase actually have the monopoly on this?


Solution

  • As the offered link states, Each browser can use any push service they want, it's something developers have no control over

    I needed to use Push Notification in an organization which uses local network and it has no access to internet, but turns out service worker push notification doesn't fit for intranet at least for now, maybe in near future there will be some solutions, there is an alternative named SignalR technology, but as you might know it doesn't work when browser tab is closed and therefore SignalR on the contrary to WbPush can't wake up closed web browser.

    Maybe the only hope is dom.push.serverURL which you can read more about it in here. I also learned that Firefox uses Autopush as Push Service. Here are some links which says you can't: WebPush without third party - Change Push provider