相关疑难解决方法(0)

serviceworkers focus选项卡:在notificationclick上客户端为空

我有一个共同的serviceworker escenario,我想要点击通知点击并关注通知来自的选项卡.但是,clients变量始终为空,其长度为0

console.log("sw startup");
self.addEventListener('install', function (event) {
    console.log("SW installed");
});

self.addEventListener('activate', function (event) {
    console.log("SW activated");
});
self.addEventListener("notificationclick", function (e) {
    // Android doesn't automatically close notifications on click 
    console.log(e);
    e.notification.close();
  
    // Focus tab if open
    e.waitUntil(clients.matchAll({
        type: 'window'
    }).then(function (clientList) {
        console.log("clients:" + clientList.length);
        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('/');
        }
    })); …
Run Code Online (Sandbox Code Playgroud)

google-chrome service-worker

17
推荐指数
2
解决办法
4681
查看次数

标签 统计

google-chrome ×1

service-worker ×1