download file in offScreen browser

58 views
Skip to first unread message

Sergey Sahon

unread,
Jun 25, 2016, 2:56:56 PM6/25/16
to CefSharp
I'm trying to download file in offScreen browser using cefSharp. My code is based on offscreen.example. JS opens new tab in browser which downloads file. I added new DownloadHelper:

public class DownloadHandler2 : IDownloadHandler
        {
            public void OnBeforeDownload(IBrowser browser, DownloadItem downloadItem, IBeforeDownloadCallback callback)
            {
                downloadItem.SuggestedFileName = @"c:\temp\temp.csv";
                if (!callback.IsDisposed)
                {
                    using (callback)
                    {
                        callback.Continue(downloadItem.SuggestedFileName, showDialog: false);
                    }
                }
            }

            public void OnDownloadUpdated(IBrowser browser, DownloadItem downloadItem, IDownloadItemCallback callback)
            {
                if (!downloadItem.IsInProgress && browser.IsPopup && !browser.HasDocument)
                {
                    browser.GetHost().CloseBrowser(false);
                }
                
            }
        }

the only problem that new blank Window is created. I do not want any windows created because this code will be part of server code.

if I add return false to ILifeSpanHandler.OnBeforePopup program download is not happening.

Is it possible to fix the issue with blank windows?
Reply all
Reply to author
Forward
0 new messages