Skip to content

Browser shows gray screen although PDF file exists #4808

Description

@abid76

Is there an existing issue for this?

  • I have searched both open/closed issues, no issue already exists.

CefSharp Version

124.3.50

Operating System

Windows 11

Architecture

x64

.Net Version

.Net 4.8

Implementation

WPF

Reproduction Steps

This happens only sometimes. I do not see any way to reproduce it.

Expected behavior

Browser displays PDF file's content.

Actual behavior

Browser shows a gray screen instead of file content.

Screenshot 2024-05-21 164357

E.g. this happened at 2024-05-21 16:37:32. But the cef-debug.log doesn't show any error except from some issue regarding an extension. I don't think this extension log message has anything to do with the issue described above as it is logged everytime you open a PDF file.

cef-debug.log

Regression?

This also happend with version 123.0.60, but never with 106.0.260.

Known Workarounds

No response

Does this problem also occur in the CEF Sample Application

No.

Other information

We're using CefSharp in a WPF TabControl to display PDF files which are located on a SMB share.

The files are processed using a ResourceHandler implementation (see below).

As this issue occurs only sometimes it may be some concurrency issue.

public override CefReturnValue ProcessRequestAsync(IRequest request, ICallback callback)
{
    string file = null;
    var uri = new Uri(request.Url);
    if (uri.Scheme == LocalSchemeHandlerFactory.SchemeName || uri.Scheme == SmbSchemeHandlerFactory.SchemeName)
    { 
        // smb://server/DMS/Dokumente/2020/03/2d18df48-04be-4b27-a141-dff5119debd3.docx.pdf
        var server = uri.Authority;
        var path = uri.LocalPath.Substring(1);
        file = Path.Combine(@"\\", server, path);
    }
    else
    {
        Log.Error($"Invalid Scheme: {uri.Scheme}");
    }

    if (file == null)
        return CefReturnValue.Cancel;

    Task.Run(() =>
    {
        using (callback)
        {
            if (!File.Exists(file))
            {
                callback.Cancel();
                return;
            }

            byte[] bytes = null;
            try
            {
                bytes = File.ReadAllBytes(file);
            }
            catch (Exception ex)
            {
                Log.Error($"Konnte Datei {file} nicht einlesen.", ex);
            }

            if (bytes == null)
            {
                Log.Debug("File is empty.");
                callback.Cancel();
            }
            else
            {
                var stream = new MemoryStream(bytes);
                stream.Position = 0;
                ResponseLength = stream.Length;

                var fileExtension = Path.GetExtension(file);
                MimeType = CefSharp.Cef.GetMimeType(fileExtension);
                StatusCode = (int)HttpStatusCode.OK;
                Stream = stream;

                callback.Continue();
            }
        }
    });

    return CefReturnValue.ContinueAsync;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions