Skip to content

Commit

Permalink
Silence failures to trigger notifications when not available
Browse files Browse the repository at this point in the history
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
  • Loading branch information
astorije committed Nov 8, 2016
1 parent 837f78f commit e21ec8b
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions client/js/lounge.js
Original file line number Diff line number Diff line change
Expand Up @@ -1031,19 +1031,24 @@ $(function() {
body = msg.text.replace(/\x02|\x1D|\x1F|\x16|\x0F|\x03(?:[0-9]{1,2}(?:,[0-9]{1,2})?)?/g, "").trim();
}

var notify = new Notification(title, {
body: body,
icon: "img/logo-64.png",
tag: target
});
notify.onclick = function() {
window.focus();
button.click();
this.close();
};
window.setTimeout(function() {
notify.close();
}, 5 * 1000);
try {
var notify = new Notification(title, {
body: body,
icon: "img/logo-64.png",
tag: target
});
notify.onclick = function() {
window.focus();
button.click();
this.close();
};
window.setTimeout(function() {
notify.close();
}, 5 * 1000);
} catch (exception) {
// `new Notification(...)` is not supported and should be silenced.
}

}
}
}
Expand Down

0 comments on commit e21ec8b

Please sign in to comment.