[FIX] bus: Notification not usable in Chrome Android

Before this commit, the Notification is used but in Chrome Mobile
we can't use it outside a ServiceWorker.

After this commit, if the Notification Object produce
an error it will fallback to the old method do_notify()

Steps to reproduce:
* Open a Odoo instance with Chrome Mobile (e.g. with Demo user)
* In Chrome Mobile, accept to receive the "Native Browser Notification"
* Put Chrome Mobile in the background of Android (don't close it)
* Open another instance of the same Odoo somewhere else with another user (e.g. Admin)
* From Admin, send a direct message to Demo
* Resume Chrome Mobile to the foreground the you will see the traceback (BUG)

GitHub issue: odoo/odoo#34714

Ref:
https://bugs.chromium.org/p/chromium/issues/detail?id=481856

closes odoo/odoo#51474

X-original-commit: ebe6731c583f9f4125272af3d8bdc4625e06de7c
Signed-off-by: Adrien Dieudonné (adr) <adr@odoo.com>
Signed-off-by: rfr-odoo <rfr-odoo@users.noreply.github.com>
This commit is contained in:
Romeo Fragomeli
2020-05-18 15:12:34 +00:00
parent 3f299f237a
commit ee7e75d74b
@@ -32,7 +32,19 @@ var BusService = CrossTab.extend(ServicesMixin, {
sendNotification: function (title, content, callback) {
if (window.Notification && Notification.permission === "granted") {
if (this.isMasterTab()) {
this._sendNativeNotification(title, content, callback);
try {
this._sendNativeNotification(title, content, callback);
} catch (error) {
// Notification without Serviceworker in Chrome Android doesn't works anymore
// So we fallback to do_notify() in this case
// https://bugs.chromium.org/p/chromium/issues/detail?id=481856
if (error.message.indexOf('ServiceWorkerRegistration') > -1) {
this.do_notify(title, content);
this._beep();
} else {
throw error;
}
}
}
} else {
this.do_notify(title, content);