{"record":{"id":"7837a8d104d5d438","repo":"cefsharp/CefSharp","slug":"timeout-greater-than-maximum-allowable-value-of-42","errorCode":null,"errorMessage":"Timeout greater than Maximum allowable value of 4294967295","messagePattern":"Timeout greater than Maximum allowable value of 4294967295","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"CefSharp/WebBrowserExtensions.cs","lineNumber":1762,"sourceCode":"        /// Evaluate some Javascript code in the context of the MainFrame of the ChromiumWebBrowser. The script will be executed\n        /// asynchronously and the method returns a Task encapsulating the response from the Javascript\n        /// </summary>\n        /// <exception cref=\"ArgumentOutOfRangeException\">Thrown when one or more arguments are outside the required range.</exception>\n        /// <param name=\"browser\">The IBrowser instance this method extends.</param>\n        /// <param name=\"script\">The Javascript code that should be executed.</param>\n        /// <param name=\"timeout\">(Optional) The timeout after which the Javascript code execution should be aborted.</param>\n        /// <param name=\"useImmediatelyInvokedFuncExpression\">When true the script is wrapped in a self executing function.\n        /// Make sure to use a return statement in your javascript. e.g. (function () { return 42; })();\n        /// When false don't include a return statement e.g. 42;\n        /// </param>\n        /// <returns>\n        /// <see cref=\"Task{JavascriptResponse}\"/> that can be awaited to obtain the result of the script execution.\n        /// </returns>\n        public static Task<JavascriptResponse> EvaluateScriptAsync(this IBrowser browser, string script, TimeSpan? timeout = null, bool useImmediatelyInvokedFuncExpression = false)\n        {\n            if (timeout.HasValue && timeout.Value.TotalMilliseconds > UInt32.MaxValue)\n            {\n                throw new ArgumentOutOfRangeException(\"timeout\", \"Timeout greater than Maximum allowable value of \" + UInt32.MaxValue);\n            }\n\n            ThrowExceptionIfBrowserNull(browser);\n\n            using (var frame = browser.MainFrame)\n            {\n                ThrowExceptionIfFrameNull(frame);\n\n                return frame.EvaluateScriptAsync(script, timeout: timeout, useImmediatelyInvokedFuncExpression: useImmediatelyInvokedFuncExpression);\n            }\n        }\n\n        /// <summary>\n        /// Evaluate some Javascript code in the context of this WebBrowser. The script will be executed asynchronously and the method\n        /// returns a Task encapsulating the response from the Javascript This simple helper extension will encapsulate params in single\n        /// quotes (unless int, uint, etc)\n        /// </summary>\n        /// <param name=\"browser\">The ChromiumWebBrowser instance this method extends.</param>","sourceCodeStart":1744,"sourceCodeEnd":1780,"githubUrl":"https://github.com/cefsharp/CefSharp/blob/16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec/CefSharp/WebBrowserExtensions.cs#L1744-L1780","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nawait browser.EvaluateScriptAsync(script, TimeSpan.MaxValue); // throws\n\n// after\nawait browser.EvaluateScriptAsync(script, timeout: null); // default\n// or\nvar timeout = TimeSpan.FromMilliseconds(Math.Min((long)myTimeout.TotalMilliseconds, UInt32.MaxValue));","handlingStrategy":"validation","validationCode":"TimeSpan? safe = timeout.HasValue && timeout.Value.TotalMilliseconds > UInt32.MaxValue\n    ? TimeSpan.FromMilliseconds(UInt32.MaxValue)\n    : timeout;\nawait browser.EvaluateScriptAsync(script, safe);","typeGuard":"static bool IsValidTimeout(TimeSpan? timeout) =>\n    !timeout.HasValue || timeout.Value.TotalMilliseconds <= UInt32.MaxValue;","tryCatchPattern":"try { await browser.EvaluateScriptAsync(script, timeout); }\ncatch (ArgumentOutOfRangeException) { /* clamp and retry, or use default */ }","preventionTips":["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."],"tags":["cefsharp","javascript","argument-validation","timeout"],"backgroundTag":null,"analyzedSha":"16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec","analyzedAt":"2026-08-13T19:57:05.828Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}