I am testing in Chrome Version 42.0.2311.152m, and I want to implement to open a window on a notification, as in this example: (source: https://developer.mozilla.org/en-US/docs/Web/API/WindowClient )
self.addEventListener('notificationclick', function(event) { console.log('On notification click: ', event.notification.tag); event.notification.close(); // This looks to see if the current is already open and // focuses if it is event.waitUntil(clients.matchAll({ type: "window" }).then(function(clientList) { for (var i = 0; i < clientList.length; i++) { var client = clientList[i]; if (client.url == '/' && 'focus' in client) return client.focus(); } if (clients.openWindow) return clients.openWindow('/'); })); });
My philology is similar:
https://myurl.no-ip.org/app/index.html
https://myurl.no-ip.org/app/manifest.json
https://myurl.no-ip.org/app/service-worker.js
I have a problem that I always get
InvalidAccessError
when calling clients.openWindow ('/') or clients.openWindow (' https://myurl.no-ip.org/app/index.html ') in service-worker.js, I get an error message:
{code: 15, message: "Not allowed to open a window.", name: "InvalidAccessError"}
The line "return client.focus ()" is never reached, because client.url is never "/". Looking at
clients.matchAll({type: "window"}) .then(function (clientList) { console.log(clientList[0])});
I see my current WindowClient:
{focused: false, frameType: "top-level", url: "https://myurl.no-ip.org/app/index.html", visibilityState: "hidden" }
The "focused" and "visibility" properties are correct and correct. When making a manual focus call
clients.matchAll({type: "window"}) .then(function (clientList) { clientList[0].focus()});
I get an error message:
{code: 15, message: "Not allowed to focus a window.", name: "InvalidAccessError"}
I think the problem is that the URL is not just "/". Do you have any ideas for this?
Many thanks!
Regards, Andi