Я тестирую Chrome версии 42.0.2311.152m и хочу реализовать открытие окна при нажатии на уведомление, как в этом примере: (источник: 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('/');
}));
});
Моя файловая структура выглядит так:
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
У меня проблема в том, что я всегда получаю
InvalidAccessError
при вызове client.openWindow ('/') или clients.openWindow ('https://myurl.no-ip.org/app/index.html ') в service-worker.js, я получаю сообщение об ошибке:
{code: 15,
message: "Not allowed to open a window.",
name: "InvalidAccessError"}
Строка «return client.focus ()» никогда не достигается, потому что client.url никогда не бывает просто «/». Смотря на
clients.matchAll({type: "window"})
.then(function (clientList) {
console.log(clientList[0])});
Я вижу свой текущий WindowClient:
{focused: false,
frameType: "top-level",
url: "https://myurl.no-ip.org/app/index.html",
visibilityState: "hidden" }
Свойства "focus" и "visibilityState" верны и изменяются правильно.
Выполняя вызов фокуса вручную
clients.matchAll({type: "window"})
.then(function (clientList) {
clientList[0].focus()});
Я получаю сообщение об ошибке:
{code: 15,
message: "Not allowed to focus a window.",
name: "InvalidAccessError"}
Я думаю, проблема в том, что url - это не просто '/'. У вас есть идеи на этот счет?
Большое спасибо!
С уважением,
Andi