我有一个带有 Web 推送通知的 PWA,它在 TWA 中被扭曲了。如果 TWA 在后台打开,则点击通知不会执行任何操作。如果我关闭 TWA,然后点击通知会打开一个新的 chrome 标签或按预期聚焦一个预期的标签。
这是我的服务人员代码
self.addEventListener('notificationclick', function(event) {
event.notification.close();
event.waitUntil(
clients
.matchAll({
type: 'window',
includeUncontrolled: true,
})
.then(function(clientList) {
for (let i = 0; i < clientList.length; i++) {
const client = clientList[i];
const isChatAppUrl =
client.url.includes('.com/messages') ||
client.url.includes('.co/messages');
if (isChatAppUrl && 'focus' in client) {
client.postMessage({
type: 'NOTIFICATION_CLICK',
payload: event.notification.data.link,
});
return client.focus();
}
}
if (clients.openWindow) {
return clients.openWindow(event.notification.data.link);
}
}),
);
});
当调试在后台打开的 TWA 的问题时,我注意到client.focus()
失败了Not allowed to open a window