The built-in subscription prompt widget (the simple banner shown automatically while notification permission is still "default") hides itself as soon as the user clicks anywhere outside it. That behaviour is hardcoded in the widget — there is no initialization option to disable it.
This widget is not gated by the subscribePopup or subscribeWidget init parameters — those configure the separate Custom Subscription Popup and the floating Subscribe button. The main SDK script loads the prompt widget automatically whenever the browser's notification permission is still "default", and it then displays itself if your Control Panel's Subscription prompt setting is on Default widget (or unset while autoSubscribe is true, which is the SDK's own default).
To get a dialog that stays open until the user makes a choice, do not rely on the built-in widget: render your own UI and trigger the subscription yourself.
How to implement
- In the Control Panel, go to Settings → Configure Platforms → Web push notification → Subscription prompt → Settings and select My custom widget instead of Default widget, then Publish. Also set
autoSubscribe: falsein yourinitcall — either one stops the built-in widget from appearing. - Build your own modal with your own HTML/CSS/JS, so you fully control when it closes.
- When the user clicks your "Allow" button, call the SDK's
subscribe()method — this shows the native browser permission prompt and registers the subscriber.
const pushwoosh = new Pushwoosh();
pushwoosh.push(['init', {
applicationCode: 'XXXXX-XXXXX',
serviceWorkerUrl: '/service-worker.js',
autoSubscribe: false
}]);
// call from your own "Allow" button handler:
myAllowButton.addEventListener('click', () => {
pushwoosh.subscribe();
});Note: Pushwoosh.push(['subscribe']) is not a valid command and will throw Unknown command! — use the subscribe() method on the Pushwoosh instance. The subscribePopup and subscribeWidget init parameters configure the Custom Subscription Popup and the floating Subscribe button respectively; neither controls the automatic prompt widget described above, and there is no customPopup parameter.
See the documentation on Custom subscription popup for the available styling options.
Comments
0 comments
Please sign in to leave a comment.