プッシュ通知を受け取るサービスワーカーがあり、Chrome用デスクトップではうまく動作しますが、Android用Chromeではうまく動作しません。Service Worker clients.openWindowは、要求されたURLの代わりにマニフェストからstart_urlを開きます。
期待どおりに動作することもありますが、場合によってはnotificationURL変数の値ではなく、manifest.jsonのstart_url値を開き始めます。
通知URLは次のようになります。通知場合は、いくつかのケースで
のでself.addEventListener('notificationclick', function(event) {
var notificationURL = event.notification.data.url;
event.notification.close();
event.waitUntil(clients.matchAll({
type: 'window'
}).then(function(clientList) {
for (var i = 0; i < clientList.length; i++) {
var client = clientList[i];
if (client.url === notificationURL && 'focus' in client) {
return client.focus();
}
}
if ('openWindow' in clients) {
// This prints "notificationURL: https://www.example.com/abc/123/?source=notification".
console.log('notificationURL:', notificationURL);
// But this opens "https://www.example.com/?source=manifest".
return clients.openWindow(notificationURL);
}
}));
});
、何らかの理由: https://www.example.com/?source=manifest
サンプルコード: https://www.example.com/abc/123/?source=notification
マニフェストSTART_URL値は次のように見えますURLは「https://www.example.com」で始まり、上記コードは常にhttps://www.example.com/?source=manifestとなります。
これは、ホーム画面にサイトを追加したことに関連していますか?
これは予期された現象ですか?
注:マニフェストのstart_urlを開きますが、スタンドアロンモードでは開きません。
別の回避策が見つかりました。開こうとしているURLが同じスキーマとstart_urlのホストを持っている場合は、start_urlが開きます。しかし、私がスキーマ(https)をhttpに変更すると、正しいURLが開き、私のサーバーはhttpsにリダイレクトします。しかし、これにはいくつかのセキュリティ上の問題があります... – RockoDev