0

Version: CefSharp.WPF 63.0.3 from NuGet.

I have a form that post it's data to _blank.

Depending on the outcome of the process the response will be a PDF file or a html site showing an user friendly error message.

I am able to download the pdf file. Also i can produce a post request resulting in an error message.

Using the LifespanHandler I can intercept the popup an create a custom window (using the cefsharp.wpf.example) But the custom window performs a get request (showing the form again) and not a post request (showing a pdf file or the error)

How can i detect if a pdf is returned or a message?

MBU
  • 3
  • 3
  • What does your code look like for OnBeforePopup? You can potentially allow the creation of a hidden popup – amaitland Apr 19 '18 at 22:32
  • I use the Code from here: https://github.com/cefsharp/CefSharp/blob/cefsharp/63/CefSharp.Wpf.Example/Handlers/LifespanHandler.cs I uncommented everything and commented out the first return in OnBeforePopUp – MBU Apr 20 '18 at 06:30
  • In that case it's a known issue see https://github.com/cefsharp/CefSharp/issues/1267 – amaitland Apr 20 '18 at 07:33
  • Oh, ok. Thank you for your help. I will look for an other way to solve my problem – MBU Apr 20 '18 at 07:54

1 Answers1

0

Found a solution that works for me.

When submitting the form I will set a variable (_popupincoming) to true. On the OnResourceResponse of IRequesthandler I do something like this

    public bool OnResourceResponse(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IResponse response)
    {
        // Header will be set if there is a file for download
        if (_popupincoming && response.ResponseHeaders.AllKeys.Contains("content-disposition") == false)
        {
            // Popup still opens but the result will also show in mainwindow
            browserControl.GetMainFrame()?.LoadRequest(request);
            _nofiledata = true;
            // Close Popup
            browser.CloseBrowser(true);
        }

        _popupincoming = false;

        return false;
    }

Within the FrameLoadEnd Event of my mainwindow I check for _nofiledata

            if(_nofiledata)
            {
                FileLog.Error(getErrorMessage());
                Browser.Back(); // Get Back to previous page
                _nofiledata = false;
                return;
            }

This feels a bit wrong but let me get the error message from the page.

For any future reader please check if there is a proper solution for this problem.

MBU
  • 3
  • 3