Simulate an individual script timeout (or slow boot) using Chrome DevTools

I am trying to figure out how to use Google Chrome DevTools to simulate a timeout in a JavaScript file on my site.

I can use "Toggle Device Mode" to introduce throttling, but this is not aimed at a specific script.

Is there a way to do this using DevTools?

I am using Chrome 38.

+6
source share
1 answer

DevTools technical writer and developer is here. As of January 2018:

  • You cannot disable individual requests in DevTools. However, you can block them, which I mean by the word "timeout". See Block Requests .
  • You can use the service worker to send individual requests over the network.

Not tested this code, but something like this might work for throttling in the workplace:

self.addEventListener('fetch', event => { const TARGET = 'example.com'; const DELAY_MS = 1000; if (event.request.url === TARGET) { setTimeout(() => { event.respondWith(caches.match(event.request)); }, DELAY_MS); } }); 
0
source

Source: https://habr.com/ru/post/977122/


All Articles