MicrosoftEdge / WebView2Feedback

Feedback and discussions about Microsoft Edge WebView2
https://aka.ms/webview2
441 stars 52 forks source link

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

Open RickStrahl opened 9 months ago

RickStrahl commented 9 months ago

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

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 commented 9 months ago

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 commented 9 months ago

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 commented 8 months ago

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 commented 6 months ago

https://github.com/MicrosoftEdge/WebView2Feedback/issues/1355 btw this is the same issue here as well.

victorhuangwq commented 5 months ago

Do refer to this https://github.com/MicrosoftEdge/WebView2Feedback/issues/1355 for a solution using WebResourceRequested.

RickStrahl commented 5 months ago

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

There are two problems actually:

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.