[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
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
- Add webview 2 to the form with the source attribute being empty
- Create textbox to input pdf and button to open pdf. Use Source assignment for webview 2 (you can also use Nagigate)
- 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
@thanhbao1996 Can you share a simple sample app with the repro for us to start investigating the issue.
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.