cefsharp/CefSharp · error · ArgumentOutOfRangeException
Timeout greater than Maximum allowable value of 4294967295
Error message
Timeout greater than Maximum allowable value of 4294967295
What it means
EvaluateScriptAsync forwards the timeout to CEF as an unsigned 32-bit millisecond value, so it cannot represent a timeout larger than UInt32.MaxValue (4,294,967,295 ms, about 49.7 days). The method explicitly validates the TimeSpan before invoking the frame and throws ArgumentOutOfRangeException for any value above that ceiling.
Source
Thrown at CefSharp/WebBrowserExtensions.cs:1762
/// Evaluate some Javascript code in the context of the MainFrame of the ChromiumWebBrowser. The script will be executed
/// asynchronously and the method returns a Task encapsulating the response from the Javascript
/// </summary>
/// <exception cref="ArgumentOutOfRangeException">Thrown when one or more arguments are outside the required range.</exception>
/// <param name="browser">The IBrowser instance this method extends.</param>
/// <param name="script">The Javascript code that should be executed.</param>
/// <param name="timeout">(Optional) The timeout after which the Javascript code execution should be aborted.</param>
/// <param name="useImmediatelyInvokedFuncExpression">When true the script is wrapped in a self executing function.
/// Make sure to use a return statement in your javascript. e.g. (function () { return 42; })();
/// When false don't include a return statement e.g. 42;
/// </param>
/// <returns>
/// <see cref="Task{JavascriptResponse}"/> that can be awaited to obtain the result of the script execution.
/// </returns>
public static Task<JavascriptResponse> EvaluateScriptAsync(this IBrowser browser, string script, TimeSpan? timeout = null, bool useImmediatelyInvokedFuncExpression = false)
{
if (timeout.HasValue && timeout.Value.TotalMilliseconds > UInt32.MaxValue)
{
throw new ArgumentOutOfRangeException("timeout", "Timeout greater than Maximum allowable value of " + UInt32.MaxValue);
}
ThrowExceptionIfBrowserNull(browser);
using (var frame = browser.MainFrame)
{
ThrowExceptionIfFrameNull(frame);
return frame.EvaluateScriptAsync(script, timeout: timeout, useImmediatelyInvokedFuncExpression: useImmediatelyInvokedFuncExpression);
}
}
/// <summary>
/// Evaluate some Javascript code in the context of this WebBrowser. The script will be executed asynchronously and the method
/// returns a Task encapsulating the response from the Javascript This simple helper extension will encapsulate params in single
/// quotes (unless int, uint, etc)
/// </summary>
/// <param name="browser">The ChromiumWebBrowser instance this method extends.</param>View on GitHub (pinned to 16bc6e0711)
Solutions
- Pass timeout: null to use the default timeout instead of an arbitrarily large value.
- Clamp your timeout to <= UInt32.MaxValue milliseconds: var ms = Math.Min((long)timeout.TotalMilliseconds, UInt32.MaxValue).
- Use a realistic bounded timeout (e.g. a few seconds) appropriate for script execution.
- Review any code deriving the timeout from date arithmetic to ensure it stays within range.
Example fix
// before await browser.EvaluateScriptAsync(script, TimeSpan.MaxValue); // throws // after await browser.EvaluateScriptAsync(script, timeout: null); // default // or var timeout = TimeSpan.FromMilliseconds(Math.Min((long)myTimeout.TotalMilliseconds, UInt32.MaxValue));
Defensive patterns
Strategy: validation
Validate before calling
TimeSpan? safe = timeout.HasValue && timeout.Value.TotalMilliseconds > UInt32.MaxValue
? TimeSpan.FromMilliseconds(UInt32.MaxValue)
: timeout;
await browser.EvaluateScriptAsync(script, safe); Type guard
static bool IsValidTimeout(TimeSpan? timeout) =>
!timeout.HasValue || timeout.Value.TotalMilliseconds <= UInt32.MaxValue; Try / catch
try { await browser.EvaluateScriptAsync(script, timeout); }
catch (ArgumentOutOfRangeException) { /* clamp and retry, or use default */ } Prevention
- Never use TimeSpan.MaxValue as a sentinel; pass null for the default timeout.
- Clamp computed timeouts to UInt32.MaxValue milliseconds.
- Bound timeouts to realistic script-execution durations.
When it happens
Trigger: Passing a TimeSpan timeout to EvaluateScriptAsync whose TotalMilliseconds exceeds UInt32.MaxValue - e.g. TimeSpan.MaxValue, TimeSpan.FromDays(60), or computing a timeout from a DateTime difference that spans more than ~49 days. Also hit when 'null default' logic accidentally substitutes a huge fallback.
Common situations: Using TimeSpan.MaxValue as 'no timeout', deriving timeouts from (DateTime.MaxValue - now), or unit tests that pass large sentinel values. Migrating from an API with a larger range (e.g. Int64 ms) without clamping.
Understand the failure class
- Timeouts: ETIMEDOUT, deadlines, and hung requests — what actually expires when a request times out.
Related errors
AI-assisted analysis of cefsharp/CefSharp@16bc6e0711 (2026-08-13).
Data as JSON: /api/errors/7837a8d104d5d438.
Report an issue: GitHub.