How to use wonderPush into existing custom service worker (PWA)?

Hi ,

I want to know if it’s possible to use WonderPush featured into own service worker ? I didn’t any exemple with this case ?!

Best regards

Hi,

Yes it’s possible.
You’ll want to:

  1. Tell WonderPush to use your service worker, instead of trying to register ours, using the serviceWorkerUrl: "sw.js" init option (that’s the typical name they’re given, make sure to use the url of your service worker)

  2. Copy the content of the service worker we provide into yours, replacing the webkey:

    importScripts('https://cdn.by.wonderpush.com/sdk/1.1/wonderpush-loader.min.js');
    WonderPush.init({
        webKey: "YOUR_WEBKEY",
    });
    
    // The rest of your service worker
    

Best,

Ok thanks for your quick reply , i already use my own service worker , so i guess i must to implements required fonctions , SDK need some functions to work correctly ?

Hi Franck,

Simply adding the code Frédéric gave you to your own service worker will take care of everything that’s needed to implement the required functions in your service worker.

Best,

For future reference, we’ve created an entry in our documentation about this: https://docs.wonderpush.com/docs/service-worker-integration.