{"record":{"id":"b3c6258767eb5d74","repo":"cefsharp/CefSharp","slug":"cookiemanager","errorCode":null,"errorMessage":"CookieManager","messagePattern":"CookieManager","errorType":"exception","errorClass":"ObjectDisposedException","httpStatus":null,"severity":"error","filePath":"CefSharp/AsyncExtensions.cs","lineNumber":34,"sourceCode":"        /// <summary>\n        /// Deletes all cookies that matches all the provided parameters asynchronously.\n        /// If both <paramref name=\"url\"/> and <paramref name=\"name\"/> are empty, all cookies will be deleted.\n        /// </summary>\n        /// <param name=\"cookieManager\">cookie manager</param>\n        /// <param name=\"url\">The cookie URL. If an empty string is provided, any URL will be matched.</param>\n        /// <param name=\"name\">The name of the cookie. If an empty string is provided, any URL will be matched.</param>\n        /// <returns>Returns -1 if a non-empty invalid URL is specified, or if cookies cannot be accessed;\n        /// otherwise, a task that represents the delete operation. The value of the TResult will be the number of cookies that were deleted or -1 if unknown.</returns>\n        public static Task<int> DeleteCookiesAsync(this ICookieManager cookieManager, string url = null, string name = null)\n        {\n            if (cookieManager == null)\n            {\n                throw new ArgumentNullException(nameof(cookieManager));\n            }\n\n            if (cookieManager.IsDisposed)\n            {\n                throw new ObjectDisposedException(\"CookieManager\");\n            }\n\n            var callback = new TaskDeleteCookiesCallback();\n            if (cookieManager.DeleteCookies(url, name, callback))\n            {\n                return callback.Task;\n            }\n\n            //There was a problem deleting cookies\n            return Task.FromResult(TaskDeleteCookiesCallback.InvalidNoOfCookiesDeleted);\n        }\n\n        /// <summary>\n        /// Sets a cookie given a valid URL and explicit user-provided cookie attributes.\n        /// This function expects each attribute to be well-formed. It will check for disallowed\n        /// characters (e.g. the ';' character is disallowed within the cookie value attribute) and will return false without setting\n        /// </summary>\n        /// <param name=\"cookieManager\">cookie manager</param>","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/cefsharp/CefSharp/blob/16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec/CefSharp/AsyncExtensions.cs#L16-L52","documentation":"DeleteCookiesAsync is an extension method on ICookieManager. If the manager's IsDisposed property is true — meaning the cookie manager (and typically its owning browser or context) has already been torn down — the call throws ObjectDisposedException before attempting the delete.","triggerScenarios":"Calling DeleteCookiesAsync on a cookie manager obtained from a disposed browser, a disposed RequestContext, or the global manager after Cef.Shutdown.","commonSituations":"Awaited async cookie operations completing after the browser window was closed. Using a cached ICookieManager reference that outlived its browser. Cleanup ordering: browser disposed while cookie tasks are still in-flight.","solutions":["Check cookieManager.IsDisposed before calling DeleteCookiesAsync.","Cancel in-flight cookie operations when the browser is closing (use a CancellationToken or a completion gate).","Obtain a fresh ICookieManager reference from the live browser/RequestContext rather than caching it long-term."],"exampleFix":"// before — manager may be disposed\nawait cookieManager.DeleteCookiesAsync(\"https://example.com\", null);\n\n// after — guard before call\nif (cookieManager == null || cookieManager.IsDisposed)\n    return;\nawait cookieManager.DeleteCookiesAsync(\"https://example.com\", null);","handlingStrategy":"validation","validationCode":"if (cookieManager == null || cookieManager.IsDisposed)\n{\n    return Task.FromResult(TaskDeleteCookiesCallback.InvalidNoOfCookiesDeleted);\n}\nreturn cookieManager.DeleteCookiesAsync(url, name);","typeGuard":null,"tryCatchPattern":"try\n{\n    await cookieManager.DeleteCookiesAsync(url, name);\n}\ncatch (ObjectDisposedException)\n{\n    Log.Info(\"CookieManager disposed — skipping delete\");\n}","preventionTips":["Check cookieManager.IsDisposed before every cookie operation.","Do not cache ICookieManager references beyond the browser's lifetime.","Cancel in-flight cookie tasks when the browser closes."],"tags":["cookies","disposal","async","object-disposed"],"backgroundTag":null,"analyzedSha":"16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec","analyzedAt":"2026-08-13T19:57:05.828Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}