Service Worker. Troubleshooting

The eSputnik's web push script is loaded via a Service Worker file called sw.js and placed in the site's root. The problem can occur if the site code already uses files with the same name or uses a different Service Worker.

1. Changing the name of Service Worker sw.js

Some builders (GoDaddy, Wix, etc.) place the sw.js file in the site root by default. Since the eSputnik's file has the same name, errors may occur.

To avoid problems, you can rename the file and, if necessary, specify the path to it in the eSputnik's script.

To do this, find the initialization function in the eSputnik's script code

es("pushOn");

and add parameters to this entry in the following format:

es("pushOn", {'service-worker': {'relUrl': '/push-worker.js'} });

where the 'relUrl' parameter is the path to the file and its arbitrary name.

Install the script on your website instructions with the es(pushOn) code line boxed and an arrow to a version with a custom relUrl parameter

2. Merging Service Workers from eSputnik and PWA

Sites with PWA (progressive web app) already use Service Worker, i.e., they contain a JavaScript file with a specific set of functions. To enable the ability to subscribe and send web pushes via eSputnik to your site, you need to add the line at the end of the JavaScript code of your Service Worker

importScripts('https://push.esputnik.com/service-worker.js');

Note

The names of functions, variables or handlers in your Service Worker and Service Worker from eSputnik may be the same. In this case, conflicts leading to failures in your PWA and the eSputnik's script are possible.

Below is a list of methods’ (functions’) names in the eSputnik's file:

  • onPushNotification
  • getNotificationContent
  • showNotification
  • getNotificationData
  • determineClickedLink
  • collectActionLinks
  • trackNewServiceWorkerActivation

If the names in your Service Worker and the eSputnik's Service Worker match, the function located last in the code will be called. For example, if the code according to this instruction ends with the line

importScripts('https://push.esputnik.com/service-worker.js');

then the functionality related to web pushes will work correctly.

3. Manifest.json Requirements for PWA Sites

eSputnik's web push script does not create or manage your PWA's manifest.json — it only merges with a Service Worker that already exists on the site (see section 2 above). If you're setting up a Progressive Web App and need a manifest.json, that file is a standard part of the PWA specification and is unrelated to eSputnik's script.

A couple of points that are relevant for sites combining PWA and eSputnik web push:

  • Fields like display and start_url affect how the installed app behaves but don't affect eSputnik's push subscription itself.
  • gcm_sender_id is no longer required for push notifications in Chrome — it has been replaced by VAPID keys, which eSputnik's script handles automatically.

4. The "None of providers responded with success" Error

This error indicates "phantom" subscribers — tokens in your contact base that have no browser type associated with them. Without the browser type, the system can't determine which push provider to send the notification to.

To clean such subscribers from your base, use the option to automatically delete tokens with no reads during the selected number of days.

5. The WEB_PUSH_GENERAL_ERROR Status

GENERAL_ERROR for Web Push is a fallback result of the sender — it appears when no more specific provider reason was captured. Only the channel, the error code and a generic "General error" message are stored; the provider's HTTP code and raw response are not.

Two consequences to keep in mind:

  • This error does not cause the token to be deleted automatically.
  • The same top-level code can hide different underlying causes, so it is not sufficient on its own to build a table of causes or to justify bulk-removing tokens. Remove tokens only after checking a specific group of them.

Did this page help you?