Chrome バージョン 42.0.2311.152m でテストしており、次の例のように通知クリックでウィンドウを開くように実装したいと考えています: (ソース: https://developer.mozilla.org/en-US/docs/Web/API /ウィンドウクライアント )
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
私はいつも得るという問題があります
無効なアクセス エラー
client.openWindow('/') または client.openWindow(' https://myurl.no-ip.org/app/index.html ') を service-worker.js で呼び出すと、次のエラーが表示されます。
{code: 15,
message: "Not allowed to open a window.",
name: "InvalidAccessError"}
client.url が単なる「/」ではないため、「return client.focus()」行に到達することはありません。見つめている
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" }
プロパティ「focused」と「visibilityState」は正しく、正しく変更されます。
マニュアルフォーカスコールを行うことで
clients.matchAll({type: "window"})
.then(function (clientList) {
clientList[0].focus()});
次のエラーが表示されます。
{code: 15,
message: "Not allowed to focus a window.",
name: "InvalidAccessError"}
問題は、URL が「/」だけではないことだと思います。そのためのアイデアはありますか?
どうもありがとうございました!
よろしく
アンディ