Chromedriver Offline Network Conditions seems to not block Service Worker fetches

风格不统一 提交于 2021-02-08 03:42:30

问题


I have a site with a Service Worker that caches some static resources on install. Some other resources are not cached, like data requests. So if you test the site using offline mode in Chrome, most of the page is properly displayed, but data is not there, and some errors appear in the console because of those failed requests. All right so far. But then I've created a test with Selenium and Chromedriver. I load that site, I visit the home page, Service Worker is properly installed, and then I try to simulate offline using:

chromeDriver.NetworkConditions = new ChromeNetworkConditions() { Latency = TimeSpan.FromSeconds(1000), DownloadThroughput = 1, UploadThroughput = 1, IsOffline = true };

That seems to be working fine, as if in the test I try to navigate to any page after that, it fails and shows the "no internet available" message. Also, as expected, my site loads fine due to the Service Worker, and their cached resources.

But the weird thing is the following, the site is able to load everything, even the non-cached things like data. All the site fetches are being intercepted by the Service Worker, so it seems that Offline mode is not affecting to Service Worker fetches, that is able to keep fetching resources to the server in offline.

(Note: Even though testing google chrome seems to be offline (it can't navigate to www.google.com, for instance), if I open Network or Application tabs I can't see that option as checked. If I manually check them all behaves as expected: non-cached resources can't be fetched by the Service Worker)

Update 1: I've tried to directly interact with Chrome Dev Tools via Web Sockets (I've used this library: https://github.com/MasterDevs/ChromeDevTools) and result was the same, Service Worker requests were working fine in offline)

来源:https://stackoverflow.com/questions/58513156/chromedriver-offline-network-conditions-seems-to-not-block-service-worker-fetche

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!