Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Problem/Bug]: NavigateToString() fails with large content page that has embedded image (data: src) #4251

Open
RickStrahl opened this issue Dec 20, 2023 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@RickStrahl
Copy link

What happened?

I'm generating a simpe page to display output from an OpenAI generated image and using a data:image/png;b64 data stream to display the image. If I dump the HTML page with the embedded image to file and display it in any browser or in the WebView it works fine. However, if I display the same page that doesn't have external dependencies using NavigateToString() it fails.

image

Importance

Important. My app's user experience is significantly compromised.

Runtime Channel

Stable release (WebView2 Runtime)

Runtime Version

120.0.2210.77

SDK Version

1.0.2088.41

Framework

WPF

Operating System

Windows 11

OS Version

22631.2861

Repro steps

  • Load an image from file
  • Turn into b64 data string
  • Embed into an image tag in an HTML page
  • NavigateToString()

Something along the lines of this:

var sb = new StringBuilder();
sb.AppendLine("<html><body>");


//  data:image/png;base64Data
var b64 = await prompt.GetBase64DataFromImageFile(prompt.ImageFileName);
if (!string.IsNullOrEmpty(b64))
{
        sb.AppendLine("\t<div class='image-container'>");
        sb.Append($"\t\t<img src='{b64}' />");
        sb.AppendLine("\t</div>");
}

// This works fine (ie. small doc with online URL)
// sb.Append($"\t<img src='{prompt.ImageUrls.FirstOrDefault()}' />");

sb.AppendLine("</body></html>");

var html = sb.ToString();
// this fails
WebView.NavigateToString(html);

Repros in Edge Browser

No

Regression

Don't know

Last working version (if regression)

No response

@RickStrahl RickStrahl added the bug Something isn't working label Dec 20, 2023
@RickStrahl
Copy link
Author

Ugh - I guess I should look at the documentation first.

Looks like it is limited to 2mb in size.

Is there any reason why this is limited to this size?

@RickStrahl
Copy link
Author

Also it would be nice if this API could throw a better error message that actually says that the page is too large. Not exactly difficult to figure out the length of a string...

@victorhuangwq
Copy link
Collaborator

Looks like it is limited to 2mb in size.
Is there any reason why this is limited to this size?

@yildirimcagri-msft do you have any idea about this?

@victorhuangwq
Copy link
Collaborator

#1355 btw this is the same issue here as well.

@victorhuangwq
Copy link
Collaborator

Do refer to this #1355 for a solution using WebResourceRequested.

@RickStrahl
Copy link
Author

RickStrahl commented Apr 1, 2024

As far as I can tell that doesn't solve either of the problems.

There are two problems actually:

  • NavigateToString() fails on large content
  • Any embedded data: Urls even in file content fail to render

I haven't tried to fix NavigateToString() since that has a fairly easy workaround by navigating to file, but the data: urls issue is not solved by the workaround as apparently the WebResourceRequest event is not fired for the data Urls.

I'm going to open a separate issue because the data: url thing is actually much more critical than the NavigateString size issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants