How to detect network state changes in a Chrome extension

前端 未结 2 1118
[愿得一人]
[愿得一人] 2021-01-25 08:59

I\'m writing a simple Chrome extension, the behavior is needed to detect if device is connect to the Internet. I\'m currently trying to connect to ping service for checking netw

2条回答
  •  遥遥无期
    2021-01-25 09:51

    On my MacBook navigator.onLine works as expected if I turn wifi on and off.

    console.log("Is the browser online? "+ navigator.onLine);
    

    With and without wifi enabled...

提交回复
热议问题