Skip to Content
Menu
This question has been flagged
1 Reply
3753 Views

Hello,

I'm trying to catch firebase notification in odoo14,
I tried all possible path.
navigator.serviceWorker.register('firebase-messaging-sw.js')

getting below error,

Unable to get permission to notify. FirebaseError: Messaging: We are unable to register the default service worker. Failed to register a ServiceWorker for scope ('http://localhost:8069/firebase-cloud-messaging-push-scope') with script ('http://localhost:8069/firebase-messaging-sw.js'): A bad HTTP response code (404) was received when fetching the script. (messaging/failed-service-worker-registration).
at ot. (https://www.gstatic.com/firebasejs/8.2.4/firebase-messaging.js:1:36826)
at https://www.gstatic.com/firebasejs/8.2.4/firebase-messaging.js:1:1982
at Object.throw (https://www.gstatic.com/firebasejs/8.2.4/firebase-messaging.js:1:2087)
at i (https://www.gstatic.com/firebasejs/8.2.4/firebase-messaging.js:1:884)

Avatar
Discard
Author Best Answer

Got the solution for this:

@http.route(['/firebase-messaging-sw.js'], type='http', auth="user", website=True, sitemap=False)
def firebase_messaging_sw(self, **post):
custom_js = None
url = os.path.join(os.path.dirname(os.path.dirname(__file__)), "Your javascript file path.")
mime = 'application/javascript'
with open(url,'r') as js:
custom_js = js.read()
body = json.dumps(custom_js)
return Response(
body, status=200,
headers=[('Content-Type', mime), ('Content-Length', len(body))]
)

it will resolve your problem.

Avatar
Discard
Related Posts Replies Views Activity
1
Nov 24
1485
1
Nov 24
1193
2
Sep 24
1047
1
Aug 24
2454
3
Aug 24
2687