WebView2Feedback icon indicating copy to clipboard operation
WebView2Feedback copied to clipboard

[Problem/Bug]: When opening a Pdf file for the first time by attaching source or nagigate, a black render appears before loading the pdf reader

Open thanhbao1996 opened this issue 1 year ago • 1 comments

What happened?

When I add webview2 to Winform, then open a pdf file path, the form's background turns black after showing the pdf reader. This phenomenon only appears the first time. If you open the pdf file next time with different pdf files, it will not appear.

Importance

Blocking. My app's basic functions are not working due to this issue.

Runtime Channel

Stable release (WebView2 Runtime), Prerelease (Edge Canary/Dev/Beta)

Runtime Version

126.0.25.92.102

SDK Version

No response

Framework

Winforms

Operating System

Windows 10

OS Version

Enterprise LTSC 1809

Repro steps

  1. Add webview 2 to the form with the source attribute being empty
  2. Create textbox to input pdf and button to open pdf. Use Source assignment for webview 2 (you can also use Nagigate)
  3. phenomenon of rendering black background and then loading pdf viewer. Note: It only appears the first time, it doesn't appear the next time

Repros in Edge Browser

No, issue does not reproduce in the corresponding Edge version

Regression

No, this never worked

Last working version (if regression)

No response

AB#53949887

thanhbao1996 avatar Aug 01 '24 02:08 thanhbao1996

@thanhbao1996 Can you share a simple sample app with the repro for us to start investigating the issue.

monica-ch avatar Sep 16 '24 15:09 monica-ch

I'm seeing the exact same problem. (Using WebView2 V137.0.3296.83 on Windows 11 24H2.)

This happens when I use Navigate('file:///C:/Users/user/AppData/Local/Temp/myfile.pdf'). And this just happens for the first call of Navigate(). Additional calls to Navigate() do not show the black background.

For additional debugging I've used "Inspect" to see the html source after the first call to Navigate('file:///C:/Users/user/AppData/Local/Temp/myfile.pdf'). The html source looks like this:

<html><head></head>
<body style="height: 100%; width: 100%; overflow: hidden; margin:0px; background-color: rgb(38, 38, 38);">
<embed name="FB4BC363702CAB36C09E55E3B1BD8739" style="position:absolute; left: 0; top: 0;" width="100%" height="100%" src="about:blank" type="application/pdf" internalid="FB4BC363702CAB36C09E55E3B1BD8739">
</body>
</html>

There is the body style attribute "background-color: rgb(38, 38, 38);". That's the black color that is seen on the first call to Navigate().

After a second call to Navigate() the html source looks like this:

<html><head></head>
<body style="height: 100%; width: 100%; overflow: hidden; margin:0px; background-color: rgb(230, 230, 230);">
<embed name="1504CE4236701D67A1E2758F551066DC" style="position:absolute; left: 0; top: 0;" width="100%" height="100%" src="about:blank" type="application/pdf" internalid="1504CE4236701D67A1E2758F551066DC">
</body>
</html>

After the second call the body style now has the attribute "background-color: rgb(230, 230, 230);".

Again: The black background only shows up when I use Navigate('file:///C:/.../myfile.pdf') to display a local pdf file.

I tried constructing html source and save this to a local .html file. When I then use Navigate('file:///C:/.../myfile.html') the black background does not show.

Firstly I thought the WebView2.DefaultBackgroundColor property could be the cause but after trying many things I'm sure that it does not change or affect this behaviour.

e-mano-e avatar Jun 17 '25 15:06 e-mano-e