Silence failures to trigger notifications when not available

Recent Chrome versions are dropping out `new Notification` in favor of `ServiceWorkerRegistration.showNotification`.
This makes sure nothing bad happens until we have proper support for Service Workers.

See:
- https://stackoverflow.com/questions/29774836/failed-to-construct-notification-illegal-constructor
- https://stackoverflow.com/questions/31512504/html5-notification-not-working-in-mobile-chrome
This commit is contained in:
Jérémie Astori 2016-11-07 00:16:10 -05:00
parent 837f78f1ae
commit e21ec8b447

View File

@ -1031,6 +1031,7 @@ $(function() {
body = msg.text.replace(/\x02|\x1D|\x1F|\x16|\x0F|\x03(?:[0-9]{1,2}(?:,[0-9]{1,2})?)?/g, "").trim(); body = msg.text.replace(/\x02|\x1D|\x1F|\x16|\x0F|\x03(?:[0-9]{1,2}(?:,[0-9]{1,2})?)?/g, "").trim();
} }
try {
var notify = new Notification(title, { var notify = new Notification(title, {
body: body, body: body,
icon: "img/logo-64.png", icon: "img/logo-64.png",
@ -1044,6 +1045,10 @@ $(function() {
window.setTimeout(function() { window.setTimeout(function() {
notify.close(); notify.close();
}, 5 * 1000); }, 5 * 1000);
} catch (exception) {
// `new Notification(...)` is not supported and should be silenced.
}
} }
} }
} }