Version: Smart Feature Phone 2.5

Clients

Description#

The Clients interface of the Service Workers API represents a container for a list of Client objects.

You should include an entry in your manifest.webapp file for Service Worker API including it in a KaiOS app.

Methods:#

  • Clients.get() Gets a service worker client matching a given id and returns it in a Promise.

  • Clients.matchAll() Gets a list of service worker clients and returns them in a Promise. Include the options parameter to return all service worker clients whose origin is the same as the associated service worker's origin. If options are not included, the method returns only the service worker clients controlled by the service worker.

  • Clients.openApp()
    Launches a web app with the same origin of its service worker scope.

  • Clients.claim() Allows an active Service Worker to set itself as the active worker for a client page when the worker and the page are in the same scope.

Examples#

// When the user clicks a notification open the App if it does not exist
onotificationclick = function(event) {
var found = false;
clients.matchAll().then(function(clients) {
for (i = 0; i < clients.length; i++) {
if (clients[i].url === event.data.url) {
// do something else involving the matching client
found = true;
break;
}
}
if (!found) {
clients.openApp();
}
});
};
});

KaiOS manifest permissions#

"permissions": {
"serviceworker": {
"description": "Needed for assocating service worker"
},
"desktop-notification": {
"description": "Needed for creating system notifications."
}
},
"messages": [{"serviceworker-notification": "path/to/your/index.html"}]