Claim client on Service worker Activation


#1

Hi,

Why doesn’t clevertap claim my hostname as client for scope as my default service worker does…?

Regards,
Arbaaz Dossani


#2

@Arbaaz_Dossani1 Can you please elaborate a bit?


#3

Hi Apurva,

Thanks for your prompt response.

I am facing an issue where I want to integrate clevertap service-worker with my custom-service-worker before it requests for user notification permission (with the pop-up).

After the user allows notification request, Clevertap will again register its service-worker but its scope is not defined for my particular website, i.e. it does not claim my hostname as client, which is essential for offline plugins like sw-toolbox, etc

Best.
Arbaaz


#4

when you have to include two service worker files:

  1. Request you to import CleverTap’s server worker in your service worker file. importScripts(‘https://s3-eu-west-1.amazonaws.com/static.wizrocket.com/js/sw_webpush.js’);

  2. When asking for notification permission, you have to add an additional key-value pair to specify your serviceWorkerPath.

clevertap.notifications.push({
“titleText”:popupTitleText,
“bodyText”:popupBodyText,
“okButtonText”:okButtonText,
“rejectButtonText”:rejectButtonText,
“okButtonColor”:okButtonColorInHex, “serviceWorkerPath”:“/your-serviceworker.js”});

This should work for you!


#5

Hi Apurva,

I need to include only one service worker.
The above is my current implementation. However when user accepts notification permission, it re-registers the service worker again, but without scope and therefore does not work when user is offline.

Please help!


#6

Hello apurva
service worker file… can we set service-worker.js file in my project root folder ya where to put.
actually i an confuse about that where to add this file


#7

Hey Amar,

You have to upload the service worker file to your root directory to make this work.