To keep web push subscriptions working after updating the Web SDK from npm, check the following steps.
1. Update the package
The npm package is web-push-notifications:
npm install web-push-notifications@latest2. Import the widget you use
Since the SDK became modular, widgets are separate entry points and are not initialized automatically — if you rely on a built-in subscription UI you must import and run it explicitly:
import { Pushwoosh } from 'web-push-notifications';
import { PWSubscribePopupWidget } from 'web-push-notifications/widget-subscribe-popup';If you implement your own subscription UI instead, call the SDK’s subscribe() method from your own button.
3. Copy the service worker to your site root
During your build, copy node_modules/web-push-notifications/service-worker.js to the root of your website so it is publicly reachable, for example at https://yoursite.com/service-worker.js. The file must be served from the root (or a scope that covers your pages).
4. Point the SDK at it
const pushwoosh = new Pushwoosh();
pushwoosh.push(['init', {
applicationCode: 'XXXXX-XXXXX',
serviceWorkerUrl: '/service-worker.js'
}]);Set serviceWorkerUrl explicitly — the SDK default (/pushwoosh-service-worker.js) matches the CDN build, not the npm build, so a mismatch here silently breaks subscriptions.
Default prompt widget behaviour
- Reappearance: after the user ignores or declines the widget (its own buttons, not the browser prompt), it can show again after 4 hours.
- Limit: it is displayed at most 3 times without a subscription, after which it stops appearing.
Reference: Usage with npm.
Comments
0 comments
Please sign in to leave a comment.