You can use @sitespeed.io/throttle - an npm package.
Example:
# simulate slow 3g connection on localhost
npx @sitespeed.io/throttle 3gslow --localhost
# throttle localhost with roundtrip time of 200ms
npx @sitespeed.io/throttle --rtt 200 --localhost
# later when you are done,... stop throttling
npx @sitespeed.io/throttle --stop --localhost
Note that throttle
requires sudo, and will prompt for user login.
Alternatively, throttle
can be used programmatically in NodeJS.
Example (copied from docs):
const throttle = require('@sitespeed.io/throttle');
// Returns a promise
const options = {up: 360, down: 780, rtt: 200};
await throttle.start(options);
// Do your thing and then stop
await throttle.stop();
See the documentation for more options.