404/403 Service Worker Installation Error

While you attempt to integrate PushEngage into your WordPress website, you might get some errors after installation or when you subscribe to the notification. The following are common issues related to the Service Worker file during PushEngage installation and the solution that you can use to fix them –

Error 1: Incorrect Service Worker file URL

TypeError: Failed to register a ServiceWorker for scope (https://xxxx) with script (https://www). A bad HTTP response code (404) was received when fetching the script.

Solution: Verify that the Service Worker file name and location match the value from your PushEngage dashboard by navigating to Site Settings > Advanced Settings > Service Worker Settings

Error 2: The browser doesn’t have permission to read the Service Worker file

TypeError: Failed to register a ServiceWorker for scope ('https://xxx') with script ('https://xxxx'): A bad HTTP response code (403) was received when fetching the script.

Solution: Check the web server configuration with the web hosting service provider to ensure that the configuration allows reading access to the Service Worker file and that the file is publicly accessible from the internet.

Error 3: Failed to execute ‘importScripts’

Uncaught DOMException: Failed to execute 'importScripts' on 'WorkerGlobalScope'. The script at (https://xxxxxx) failed to load at (https://www).

Solution:  The Service Worker file is using an incorrect subdomain name in the importScripts (https://xxxx.pushengage.com) statement inside the Service Worker file. So, ensure that the importScript statement uses the correct PushEngage subdomain assigned to the site.

The value of the domain query parameter in the Service Worker URL is incorrect. This applies only to sites using the WordPress plugin.

Error 4: Failed to register a Service Worker

DOMException: Failed to register a Service Worker for scope (https://www) with the script (https://xxxxxxxx). The path of the provided scope ('xxx') is not under the max scope allowed ('xxxxxxx'). Adjust the scope, move the Service Worker script, or use the Service-Worker-Allowed HTTP header to allow the scope.

Solution:  Move the service worker file to the root directory and update the service worker path at Site Settings > Advanced Settings > Service Worker Settings
Turn on the switch to “Enable addition of Service Worker in another sub-folder” at Site Settings > Advanced Settings
Set the value of the HTTP header Service-Worker-Allowed to ‘/’ for requests to the Service Worker file

Points To Remember –

  • Avoid Redirections – The service-worker.js file should be publically accessible (https://www.mywebsite.com/service-worker.js). If there is any redirection when you try to visit the service-worker.js file, your installation is incorrect, and the subscription will also fail
  • If you see a 403 or 404 error after attempting to subscribe to your site, it means that something is preventing the PushEngage Serviceworker files from being openly accessible. You can check this by visiting your PushEngage Dashboard or your Browser Console. These files must be written in all capital letters, not as redirects. These pages ought to be accessible to you without any issues.
  • Merge the Service-worker Files – It is necessary to merge service workers if you are integrating PushEngage into a website that already has a service worker (such as a PWA) for PushEngage to function correctly. This happens if you have a PWA or multiple service-worker files for your website

Still stuck? How can we help?
Last updated on February 27th, 2023

Engage and Retain Visitors AfterThey’ve Left Your Website

Increase the value of every web visit with Push Notifications that are hard to miss.

  • Forever Free Plan
  • Easy Setup
  • 5 Star Support