Javascript-在Android设备上单击服务人员通知后打开浏览器选项卡

Javascript-在Android设备上单击服务人员通知后打开浏览器选项卡,javascript,android,notifications,service-worker,Javascript,Android,Notifications,Service Worker,我正在为一家餐厅制作一个web应用程序,当我收到新订单时,我的通知会通知我。该应用程序的工作流程是: 1) 服务员通过Android Chrome登录,查看待处理的机票 2) 客户端使用其他设备注册票据 3) 服务员的设备上会显示通知 到目前为止,一切正常。我想知道的是:在使用另一个应用程序时(或在查看主屏幕时)点击通知是否会打开相应选项卡(服务员登录的位置)上的Chrome 这是我的密码: App.js var n = _registration.showNotification('Menú'

我正在为一家餐厅制作一个web应用程序,当我收到新订单时,我的通知会通知我。该应用程序的工作流程是:

1) 服务员通过Android Chrome登录,查看待处理的机票
2) 客户端使用其他设备注册票据
3) 服务员的设备上会显示通知

到目前为止,一切正常。我想知道的是:在使用另一个应用程序时(或在查看主屏幕时)点击通知是否会打开相应选项卡(服务员登录的位置)上的Chrome

这是我的密码:

App.js

var n = _registration.showNotification('Menú',{
     body: 'Tienes un nuevo pedido',
     requireInteration: true,
});
服务人员

self.addEventListener('notificationclick', function(event) {
    let url = 'https://example.com/some-path/';
    event.preventDefault();

    event.notification.close(); // Android needs explicit close.
    event.waitUntil(
        clients.matchAll({type: 'window'}).then( windowClients => {
            // Check if there is already a window/tab open with the target URL
            for (var i = 0; i < windowClients.length; i++) {
                var client = windowClients[i];
                // If so, just focus it.
                if (client.url === url && 'focus' in client) {
                    return client.focus();
                }
            }
            // If not, then open the target URL in a new window/tab.
            if (clients.openWindow) {
                return clients.openWindow(url);
            }
        })
    );
});
self.addEventListener('notificationclick',函数(事件){
让url为空https://example.com/some-path/';
event.preventDefault();
event.notification.close();//Android需要显式关闭。
event.waitill(
matchAll({type:'window'})。然后(windowClients=>{
//检查是否已打开带有目标URL的窗口/选项卡
对于(var i=0;i
这在桌面浏览器上运行得非常好,但由于服务员使用的是安卓手机,这还不够。谢谢。

对我来说,
client.focus()
也不起作用,但当我点击通知时,它实际上会聚焦我的应用程序。
我的代码的不同之处在于我没有
event.preventDefault()

您找到解决方案了吗?注意:有一个小的输入错误“requireInteraction”