My problem
I am looking to test how a script handles the loss of part of an Internet connection through execution. At a lower level, I just need to make several network requests crash after a certain point in the script.
I am trying to keep this test as close to the end as possible without mocking any javascript units.
My thoughts on how I could achieve this
Chrome has a useful tool for working with dev tools on the network tab, which simulates the loss of an Internet connection. I would like to switch this from the script I execute (similar to how it debuggerstarts a breakpoint on the sources tab).
I suspect this will not be easy, as it will create a serious security hole if web pages can cause this. However, if in any case hack Chrome in a state where it is possible, perhaps using the extension or Chromium, I’m all ears.
Is there a way to switch the "offline" tool for Chrome from javascript?
Otherwise, is there another way to simulate connection loss / network request failure with javascript? (By the way, I'm not married to Chrome)
source
share