2017-01-22 29 views
0

我在服務人員這個監聽器同步:服務工作者同步火災,無論互聯網連接

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和獲取?

回答

0

兆跛腳問題:d

我用在Chromeoffline複選框...這似乎是NOT WORKING

因此,當我開始斷開連接並將整個筆記本電腦重新連接到無線網絡 - 那麼我得到了正確的行爲。

結論:Always doubt the browser!!!