From b718261de0e40ba52fb05a4011cbde515dbf512a Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Fri, 19 Dec 2025 22:34:58 -0800 Subject: [PATCH 1/8] Catch and log additional potential subscription failures --- styles/all/template/webpush.js | 79 ++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 38 deletions(-) diff --git a/styles/all/template/webpush.js b/styles/all/template/webpush.js index e57b5d3..6eaf49f 100644 --- a/styles/all/template/webpush.js +++ b/styles/all/template/webpush.js @@ -164,8 +164,8 @@ function PhpbbWebpush() { allowBtn.addEventListener('click', (event) => { event.stopPropagation(); popup.style.display = 'none'; - subscribeButtonHandler({ - preventDefault: () => {} + subscribeButtonHandler(event).catch(error => { + console.error('Subscription handler error:', error); }); }); } @@ -237,48 +237,51 @@ function PhpbbWebpush() { async function subscribeButtonHandler(event) { event.preventDefault(); - subscribeButton.addEventListener('click', subscribeButtonHandler); - - // Prevent the user from clicking the subscribe button multiple times. - const result = await Notification.requestPermission(); - if (result === 'denied') { - phpbb.alert(subscribeButton.getAttribute('data-l-err'), subscribeButton.getAttribute('data-l-msg')); - return; - } + try { + // Prevent the user from clicking the subscribe button multiple times. + const result = await Notification.requestPermission(); + if (result === 'denied') { + phpbb.alert(subscribeButton.getAttribute('data-l-err'), subscribeButton.getAttribute('data-l-msg')); + return; + } - const registration = await navigator.serviceWorker.getRegistration(serviceWorkerUrl); + const registration = await navigator.serviceWorker.getRegistration(serviceWorkerUrl); - // We might already have a subscription that is unknown to this instance of phpBB. - // Unsubscribe before trying to subscribe again. - if (typeof registration !== 'undefined') { - const subscribed = await registration.pushManager.getSubscription(); - if (subscribed) { - await subscribed.unsubscribe(); + // We might already have a subscription that is unknown to this instance of phpBB. + // Unsubscribe before trying to subscribe again. + if (typeof registration !== 'undefined') { + const subscribed = await registration.pushManager.getSubscription(); + if (subscribed) { + await subscribed.unsubscribe(); + } } - } - const newSubscription = await registration.pushManager.subscribe({ - userVisibleOnly: true, - applicationServerKey: urlB64ToUint8Array(vapidPublicKey), - }); + const newSubscription = await registration.pushManager.subscribe({ + userVisibleOnly: true, + applicationServerKey: urlB64ToUint8Array(vapidPublicKey), + }); - const loadingIndicator = phpbb.loadingIndicator(); - fetch(subscribeUrl, { - method: 'POST', - headers: { - 'X-Requested-With': 'XMLHttpRequest', - }, - body: getFormData(newSubscription), - }) - .then(response => { - loadingIndicator.fadeOut(phpbb.alertTime); - return response.json(); + const loadingIndicator = phpbb.loadingIndicator(); + fetch(subscribeUrl, { + method: 'POST', + headers: { + 'X-Requested-With': 'XMLHttpRequest', + }, + body: getFormData(newSubscription), }) - .then(handleSubscribe) - .catch(error => { - loadingIndicator.fadeOut(phpbb.alertTime); - phpbb.alert(ajaxErrorTitle, error); - }); + .then(response => { + loadingIndicator.fadeOut(phpbb.alertTime); + return response.json(); + }) + .then(handleSubscribe) + .catch(error => { + loadingIndicator.fadeOut(phpbb.alertTime); + phpbb.alert(ajaxErrorTitle, error); + }); + } catch (error) { + console.error('Push subscription error:', error); + phpbb.alert(subscribeButton.getAttribute('data-l-err'), subscribeButton.getAttribute('data-l-msg')); + } } /** From c7486c6f62f183753908e37d164cae8a05259a10 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Sat, 20 Dec 2025 07:39:17 -0800 Subject: [PATCH 2/8] More appropriate fallback error message from lang system --- .../all/template/event/notification_dropdown_footer_after.html | 2 +- styles/all/template/webpush.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/styles/all/template/event/notification_dropdown_footer_after.html b/styles/all/template/event/notification_dropdown_footer_after.html index 8f5c54a..d0012da 100644 --- a/styles/all/template/event/notification_dropdown_footer_after.html +++ b/styles/all/template/event/notification_dropdown_footer_after.html @@ -1,7 +1,7 @@ {% if NOTIFICATIONS_WEBPUSH_ENABLE and notification_types is not defined %}