{"record":{"id":"439d54fed825997d","repo":"cefsharp/CefSharp","slug":"frame","errorCode":null,"errorMessage":"frame","messagePattern":"frame","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"CefSharp.Core/WebBrowserExtensionsEx.cs","lineNumber":108,"sourceCode":"                    .Build();\n\n                var urlRequest = frame.CreateUrlRequest(request, urlRequestClient);\n            });\n        }\n\n        /// <summary>\n        /// Downloads the specified <paramref name=\"url\"/> as a <see cref=\"T:byte[]\"/>.\n        /// Makes a GET Request.\n        /// </summary>\n        /// <param name=\"frame\">valid frame</param>\n        /// <param name=\"url\">url to download</param>\n        /// <param name=\"urlRequestFlags\">control caching policy</param>\n        /// <returns>A task that can be awaited to get the <see cref=\"T:byte[]\"/> representing the Url</returns>\n        public static Task<byte[]> DownloadUrlAsync(this IFrame frame, string url, UrlRequestFlags urlRequestFlags = UrlRequestFlags.None)\n        {\n            if (frame == null)\n            {\n                throw new ArgumentNullException(nameof(frame));\n            }\n\n            if (!frame.IsValid)\n            {\n                throw new Exception(\"Frame is invalid, unable to continue.\");\n            }\n\n            var taskCompletionSource = new TaskCompletionSource<byte[]>(TaskCreationOptions.RunContinuationsAsynchronously);\n\n            //Can be created on any valid CEF Thread, here we'll use the CEF UI Thread\n            Cef.UIThreadTaskFactory.StartNew(delegate\n            {\n                var request = frame.CreateRequest(false);\n\n                request.Method = \"GET\";\n                request.Url = url;\n                request.Flags = urlRequestFlags;\n","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/cefsharp/CefSharp/blob/16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec/CefSharp.Core/WebBrowserExtensionsEx.cs#L90-L126","documentation":"Thrown by DownloadUrlAsync when the frame argument is null. The method needs a valid frame to create the GET request on the CEF UI thread, so it guards up front with ArgumentNullException. This is distinct from the IsValid check that follows — null means the caller never obtained or passed a frame reference at all.","triggerScenarios":"Calling frame.DownloadUrlAsync(url) where frame is null — e.g. browser.MainFrame accessed before browser initialization completed, or a variable that was never assigned.","commonSituations":"Calling MainFrame on a ChromiumWebBrowser whose IsBrowserInitialized is still false. Disposing the browser and then awaiting a pending async operation that captured the now-null frame reference.","solutions":["Ensure the browser is initialized (await browserInitialized task / WaitForInitializationAsync) before accessing MainFrame.","Guard for null before calling: if (frame != null) await frame.DownloadUrlAsync(url);","Use WebBrowserExtensions.ThrowExceptionIfFrameNull for consistent validation in your own code."],"exampleFix":"// before\nvar bytes = await frame.DownloadUrlAsync(url);\n\n// after\nawait browser.WaitForInitializationAsync(); // or check IsBrowserInitialized\nvar frame = browser.GetMainFrame();\nvar bytes = await frame.DownloadUrlAsync(url);","handlingStrategy":"validation","validationCode":"await browser.WaitForInitializationAsync();\nvar frame = browser.GetMainFrame();\nif (frame == null) return Array.Empty<byte>();\nvar data = await frame.DownloadUrlAsync(url);","typeGuard":"public static bool IsFramePresent(IFrame f) => f != null;","tryCatchPattern":"try { return await frame.DownloadUrlAsync(url); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"frame\") { /* browser not ready */ }","preventionTips":["Await browser initialization before accessing MainFrame.","Null-check frame before calling DownloadUrlAsync.","Do not hold frame references after disposal."],"tags":["argument-null","frame","download","async"],"backgroundTag":null,"analyzedSha":"16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec","analyzedAt":"2026-08-13T19:57:05.828Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}