Setting offline=true via Network.emulateNetworkConditions does not stop serviceworkers from going online
See original GitHub issueWhen using the Network.emulateNetworkConditions to make the browser simulate offline mode, web applications that use serviceworkers are still able to bypass this setting and connect online. Therefore, this offline setting is not suitable to test the offline behaviour of these serviceworkers.
I am using the PyChromeDevTools:
import PyChromeDevTools
chrome = PyChromeDevTools.ChromeInterface()
chrome.Network.emulateNetworkConditions(offline=True, latency=250, downloadThroughput=270, uploadThroughput=300)
I tried Puppeteer and WebDriverJS as well, using setNetworkConditions(), however the outcome is the same - serviceworkers bypass the offline setting and connects online.
The only thing that works is when you manually open Chrome DevTools, go to Network and tick the Offline box - this definitely stops all serviceworkers from connecting online.
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Selenium and Service Workers offline mode - Stack Overflow
Run WebDriver with the reference to running proxy server created in step 1. 3. Perform online steps 4. Stop ProxyServer 5.
Read more >Direct control over online/offline status - Bitbucket
This is controlled by the "Offline mode" context menu option and the --offline command-line switch which will launch cefclient in offline mode.
Read more >Using Service Workers - Web APIs | MDN
Using a service worker you can set an app up to use cached assets first, thus providing a default experience even when offline,...
Read more >Testing an Application in Offline Network Mode - Cypress
Let's see how we can go offline during a Cypress test. ... Once we enable Network control, we need to actually go offline...
Read more >Going Offline With Service Workers - Webtips
Reaching users when connections are non-existent. Ferenc Almasi • 2020 December 11 • 7 min read. The average global internet speed is getting...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It’s in Canary and probably beta, though probably not stable. Have to turn on DevTools experiments first. https://hackernoon.com/hidden-experimental-features-in-chrome-devtools-2ae93b11b628
See: https://umaar.com/dev-tips/166-protocol-monitor/
there’s two options:
Target.setAutoAttach({autoAttach:true})
like the wiki page says. you’ll then get an event of related targets. and in there is a session ID. service workers are usually considered “related”, but it’s possible that this won’t fire, based on the SW process model.Target.getTargets()
response, you can then callTarget.attachToTarget
with the targetID you have. In the response you get a session ID. https://chromedevtools.github.io/devtools-protocol/tot/Target#method-attachToTargetGood luck!
Thanks a lot for all the help! I finally managed to simulate offline mode for serviceworkers. https://github.com/ldiary/marigoso/blob/master/notebooks/how-to-simulate-offline-browsing-for-serviceworker-testing-using-selenium-webdriver-and-chrome-devtools.ipynb