无论互联网连接如何,服务工作进程同步都会立即触发



我在服务工作线程中具有用于同步的侦听器:

self.addEventListener('sync', function(event) {
    if (event.tag === 'button-click') {
        console.log('SYNC for button-click triggered!');
        console.log(event);
        event.waitUntil(
            fetch('https://localhost/')
                .then(function(response) {
                    return response;
                })
                .then(function(html) {
                    console.log('Fetching successful');
                    console.log(html);
                })
                .catch(function(err) {
                    console.log('Fetching failed');
                    console.log(err);
                })
        );
    }
});

因此,当我单击按钮时 - console.logs 和获取工作正常。

问题是,当我关闭连接并单击按钮时 - console.logs 和获取会立即触发again.他们不应该等待页面再次连接并then执行console.logs和获取吗?

巨型跛脚问题:D

我在Chrome中使用了offline复选框...这似乎是NOT WORKING.

因此,当我开始断开并将整个笔记本电脑重新连接到wifi时-然后我得到了正确的行为。

结论:Always doubt the browser!!!

最新更新