2

Is it possible to throttle CPU in chrome's devtools via python selenium? And if so, how?

It would appear the driver has a method execute_cdp_cmd which stands for "Execute Chrome Devtools Protocol command" but I do not know what command I would give it.

Marcel Wilson
  • 3,842
  • 1
  • 26
  • 55
  • [This post](https://stackoverflow.com/questions/8521683/is-there-a-way-to-throttle-javascript-performance-to-simulate-a-slow-client) suggests it is possible in devtools. – Marcel Wilson Jul 12 '19 at 14:38

2 Answers2

1

It would appear to be possible in chromedriver 75.

## rate 1 is no throttle, 2 is 2x slower, etc. 
driver.execute_cdp_cmd("Emulation.setCPUThrottlingRate", {'rate': 10})

NOTE:

2.38 didn't seem to support execute_cdp_cmd() while 2.48 did. Chromedriver also appears to have changed their versioning scheme to keep in sync with browser releases.

I did some quick checking and was able to push the throttle rate to upwards of 200x but it started having serious issues. My guess it going beyond 100x is ill-advised.

Marcel Wilson
  • 3,842
  • 1
  • 26
  • 55
0
## rate 1 is no throttle, 2 is 2x slower, etc. 
driver.execute_cdp_cmd("Emulation.setCPUThrottlingRate", {'rate': 10})

This still works today!