My problem
I am looking to test how a script handles a loss of internet connection part way through execution. At a lower level I simply need to cause a number of network request to fail after certain point in the script.
I am attempting to keep this test as end to end as possible without mocking any javascript units.
My thoughts on how I might achieve this
Chrome has a useful toggle in it's dev tools under the network tab which simulates a loss of internet connection. I would like to toggle this from the script I am executing (in a similar manner to how debugger
triggers a breakpoint under the sources tab).
I suspect this won't be easy as it would create a significant security hole if web pages could trigger this. However, if there is anyway to hack Chrome into a state where it is possible, possibly using an extension or Chromium I'm all ears.
Is there a way to toggle the Chrome 'offline' dev tool from javascript?
Failing this is there any other way to simulate a loss of connection / cause network requests to fail from javascript? (By the way I'm not married to Chrome)