You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This would be very convenient to execute custom code when users subscribe or unsubscribe to notifications.
I suggest implementing a callback mechanism, for instance by adding a callback parameter in to the subscribe and unsubscribe functions, and execute the callbacks in or instead of reg.pushManager.subscribe(options).then and subscription.unsubscribe().then for instance.
What do you think?
The text was updated successfully, but these errors were encountered:
I worked around this by adding the following to my template's js:
const targetNode = document.getElementById('webpush-subscribe-button');
// Create a callback function that executes when mutations are observed
const callback = function(mutationsList) {
for (let mutation of mutationsList) {
if (mutation.type === 'childList') {
if (targetNode.textContent == "Subscribe to Push Messaging") {
// do something here
console.log('subscribed');
} else {
// do something different here
console.log(targetNode.textContent);
}
}
}
};
// Create an observer instance linked to the callback function
const observer = new MutationObserver(callback);
// Define the configuration for the observer
const config = { childList: true, subtree: true };
// Start observing the target node for configured mutations
observer.observe(targetNode, config);
This does not take into account i18n, but it works in my app. It would be much cleaner to have this built in as you suggest, but it does not seem like this repo is very maintained.
This would be very convenient to execute custom code when users subscribe or unsubscribe to notifications.
I suggest implementing a callback mechanism, for instance by adding a
callback
parameter in to thesubscribe
andunsubscribe
functions, and execute the callbacks in or instead ofreg.pushManager.subscribe(options).then
andsubscription.unsubscribe().then
for instance.What do you think?
The text was updated successfully, but these errors were encountered: