Search code examples
javascriptfirebase-cloud-messagingtizentizen-wearable-sdktizen-web-app

FCM for Tizen Werable Web Application


I am working on Tizen Wearable Standalone Web application and Would like to integrate Firebase to incorporate Notifications Feature. I followed all the steps provided by firebase using Javascript. But I am unable to get the Token and ended up with the below error:

Failed to register a ServiceWorker: The URL protocol of the current origin 
('file://') is not supported."
code: "messaging/failed-serviceworker-registration"
message: "Messaging: We are unable to register the default service worker. 
Failed to register a ServiceWorker: The URL protocol of the current origin 
('file://') is not supported. (messaging/failed-serviceworker-
registration)."
stack: (...)

I tried

navigator.serviceWorker.register('/sw.js').then(function(registration) {
console.log("success")
firebase.messaging().useServiceWorker(registration)
// Registration was successful
console.log('ServiceWorker registration successful with scope: ',registration.scope);
// registration.pushManager.subscribe({
console.log('Registration was successful1');
//  userVisibleOnly: true
}).then(function(sub) {
  console.log('endpoint:', sub.endpoint);
}).catch(function(e) {
    console.log('Registration Failed',e);
});

But unable to get it work. Please let me know whether FCM provides support for Tizen Web application as I have seen FCM provider has given access for Android, iOS, and Javascript. But nowhere I saw support for Tizen Web application(Hybrid application for Wearable).


Solution

  • Tizen Web application does not support service worker. The FCM JavaScript API requires service worker support.

    You can try this simple code snippet to check service worker support.

     if ('serviceWorker' in navigator) 
        alert('Service worker is Supported'); 
     else 
        alert('Service worker is not Supported'); 
    

    I've tried the code snippet on Firefox, Chrome (Shortcut: Developer tools > Console > Paste the Code > Enter).

    Both Supports service worker. But when I added this code chunk on js file of a Tizen web application it alerts 'not supported'.

    The code sample to Register a service worker on Google developers also includes this check service worker API availability first before registration.

    Register a service worker

    And about Native Mobile environment instead of Web, FCM supports Android and iOS Native environment, But not Tizen Native.