How to solve Selenium::WebDriver::Error::ScriptTimeoutError: script timeout

During your work, you may have faced various challenges while working on your projects. One such challenge is the ScriptTimeoutError that you may have encountered while debugging System Capybara tests in the non-headless browser. This error can be very frustrating. But don't worry, there is an easy solution to this problem.

The problem may have occurred after you updated your Chrome driver to the latest version. If you try to run the tests without debugging, everything may work fine. This difference in behaviour may be due to a different configuration for running the Chrome browser on your desktop versus in headless mode. The root cause of this issue is the default_max_wait_time parameter in Capybara.
This parameter is helpful for having the lowest possible latency, as it allows you to type Ruby commands and see the result without waiting for a response. However, if this value is set to zero, it will crash because there is no time given for the script to execute.

Capybara.default_max_wait_time = ENV['BROWSER'].present? ? 0 : 15
Problem with zero value

To resolve this error, you only need to set the default_max_wait_time to a value that gives enough time for the script to execute. To do this create or open your Capybara configuration file and add the following code:

Capybara.default_max_wait_time = ENV['BROWSER'].present? ? 0.1 : 15
100ms would be enough

Happy coding!