question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Setting offline=true via Network.emulateNetworkConditions does not stop serviceworkers from going online

See original GitHub issue

When 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:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
paulirishcommented, May 24, 2018

What version of Chrome has this Protocol Monitor?

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/


Any hint on how I can get the sessionId of the subtarget, please?

there’s two options:

  1. 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.
  2. after your Target.getTargets() response, you can then call Target.attachToTarget with the targetID you have. In the response you get a session ID. https://chromedevtools.github.io/devtools-protocol/tot/Target#method-attachToTarget

Good luck!

0reactions
ldiarycommented, May 26, 2018
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found