diff options
| author | Romeo Fragomeli <rfr@odoo.com> | 2020-04-28 13:17:57 +0000 |
|---|---|---|
| committer | Romeo Fragomeli <rfr@odoo.com> | 2020-05-18 15:12:34 +0000 |
| commit | ee7e75d74b0bd0eb51c6c41b400a8b6ec3e0ff6e (patch) | |
| tree | 7e3e031b7adab2eb1c876b69e01ac7188aca3fa5 /addons/bus/static | |
| parent | 3f299f237a7731e1f81ecc5cd68a9b22fc1d3cf9 (diff) | |
[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>
Diffstat (limited to 'addons/bus/static')
| -rw-r--r-- | addons/bus/static/src/js/services/bus_service.js | 14 |
1 files changed, 13 insertions, 1 deletions
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); |
