From ee7e75d74b0bd0eb51c6c41b400a8b6ec3e0ff6e Mon Sep 17 00:00:00 2001 From: Romeo Fragomeli Date: Tue, 28 Apr 2020 13:17:57 +0000 Subject: [PATCH] [FIX] bus: Notification not usable in Chrome Android MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) Signed-off-by: rfr-odoo --- addons/bus/static/src/js/services/bus_service.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/addons/bus/static/src/js/services/bus_service.js b/addons/bus/static/src/js/services/bus_service.js index ba0abbf87c9..7dc932d4575 100644 --- a/addons/bus/static/src/js/services/bus_service.js +++ b/addons/bus/static/src/js/services/bus_service.js @@ -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);