Workbox and webpushr

Can I register my sw.js with workbox and use webpushr’s push feature properly if I follow the setup below?

CC的部落格
hexo-webpushr-notification
workbox-build.js
sw-workbox.js

Sorry for misguiding you. If you are using function, please use the following format for disabling registration of service worker:init

  • webpushr('init','YOUR_KEY_HERE','none');

The following format if you use function:setup

  • webpushr('setup',{'key':'YOUR_KEY_HERE','sw':'none'});

Both functions are supported by our JS.

Hi,

Please follow the 2 steps below if you want to use your own sw.js

  1. Replace
    Preformatted textwebpushr('setup',{'key':'YOUR_KEY_HERE'});
    with
    webpushr('setup',{'key':'YOUR_KEY_HERE','sw':'none'});
    so it stop registering Webpushr’s Service Worker.

  2. Import Webpushr’s service worker into your service worker (sw.js) by adding the following line

importScripts('https://cdn.webpushr.com/sw-server.min.js');

By implementing these two steps you can use both service workers at the same time without breaking any functionality.

1 Like

In addition to the SW: none prohibition option, is there an SW: true option? Because I want to write this configuration into the plug-in. If not, I will write a few more lines of code.

No, basically it represents the service worker path. If set to “none” no service worker will be registered. If it is not define then by default the service worker at root direcorty (/webpushr_sw.js) is register.