You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
WebView 2 does not render anything after resolution scale change and opening a new browser window #2611
Following the repro steps, I am not able to repro the issue. I was able to reproduce the blank window using these steps.
Run WebView2WpfBrowser project. (Creates Window A)
Go to File -> New Window (Creates Window B)
In Window A, go to File -> Close.
In Window B, go to Scenario -> New browser Version -> click Yes in dialog window.
In your repro, were you using the originally created window when you changed the DPI? Can you confirm that the issue reproes without ever calling File -> New Window?
Brad Peters (@bradp0721) In my scenario, I only have the one Window open when I change the DPI. After I change the DPI, I open a second Window using 'New Browser Version,' I don't call File -> New Window. So yes, I can confirm that the issue happens without ever calling File -> New Window
I'm not seeing a second Window created by calling 'New Browser Version'. I see one Window with a WebView when I launch the app. Clicking 'New Browser Version' causes the WebView to be destroyed and a new WebView is created in the same Window. When you say "I open a second Window using 'New Browser Version'", did you make changes to the WebView2WpfBrowser app to make a new Window in New Browser Version?
Can you also provide the WebView2 Runtime version and the WebView2 nuget version you are using?
Brad Peters (@bradp0721) I updated my code to the latest version which is using version 1.0.1305-prerelease. The latest version works slightly different than the version that I was using. Now, when I click the New Browser Version, it does not create a new window. Now it seems to reload the browser in the original window. When it reloads the browser, it does not render anything (the same problem as I originally reported in the issue). I did not modify the code from what I downloaded here: https://github.com/MicrosoftEdge/WebView2Samples
markFleischmann, I was able to get a repro and root cause the issue. The problem comes from WebView2WPFBrowser being a System DPI aware app and an OS feature to “Fix blurry apps”. Old versions of Windows had a single System DPI that was given to all System DPI aware apps. Even if the monitor scale changed, when a System aware app asked for the scale, it would be given the System DPI. The fix blurry apps feature made it so that a System aware app gets the current monitor DPI. Once the app is given this value, it never changes for that application. But if the monitor scale is changed and a different System aware app is launched, those two apps will have a different DPI value even though they are both System aware.
In the repro, WebView2WPFBrowser is being launched on a 100% monitor, so it's PerProcessSystemDPI is 100%. It then creates a WebView2. The WebView2 process are created as System DPI aware to match the application process. They are also given the PerProcessSystemDPI of 100%. Then the monitor DPI is changed from 100% to 150%. Doing New Browser Version results in closing the current WebView2 (including all the WebView2 processes) and creating a new WebView2. This new WebView2 process is launched at System DPI aware of match the application process, but the Windows OS gives this process a PerProcessSystemDPI of 150%. This does not match the WebView2WPFBrowser PerProcessSystemDPI which is still 100%. Because of this mismatch in PerProcessSystemDPI, the OS is not able to render the WebView2 child HWND as part of the application HWND tree.
We reached out to Windows team about this issue and they marked the bug as Won't Fix, but there are work-arounds.
Workaround 1)
Make the app PerMonitor DPI aware. This will completely avoid the PerProcessSystemDPI issue. The app process and WebView2 process will both be PerMonitor and will receive updates when the monitor DPI changes.
Workaround 2)
There is a registry key that you can set to opt the app process out of PerProcessSystemDPI. This does mean that the app might appear blurry if the monitor DPI is changed and then the app is launched (similar to the current behavior if you change the monitor DPI while the app is running). By opting the app out of PerProcessSystemDPI, the WebView2 process, as child processes, are also opted out. So when you recreate the WebView2 after changing the monitor DPI, the WebView2 process System DPI will match the app process System DPI.
[HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers]
"C:\WebView2Samples\SampleApps\WebView2WpfBrowser\bin\Debug\netcoreapp3.0\WebView2WpfBrowser.exe"="~ PERPROCESSSYSTEMDPIFORCEOFF"
Activity
bradp0721 commentedon Jul 22, 2022
Following the repro steps, I am not able to repro the issue. I was able to reproduce the blank window using these steps.
In your repro, were you using the originally created window when you changed the DPI? Can you confirm that the issue reproes without ever calling File -> New Window?
markFleischmann commentedon Jul 22, 2022
Brad Peters (@bradp0721) In my scenario, I only have the one Window open when I change the DPI. After I change the DPI, I open a second Window using 'New Browser Version,' I don't call File -> New Window. So yes, I can confirm that the issue happens without ever calling File -> New Window
bradp0721 commentedon Jul 22, 2022
I'm not seeing a second Window created by calling 'New Browser Version'. I see one Window with a WebView when I launch the app. Clicking 'New Browser Version' causes the WebView to be destroyed and a new WebView is created in the same Window. When you say "I open a second Window using 'New Browser Version'", did you make changes to the WebView2WpfBrowser app to make a new Window in New Browser Version?
Can you also provide the WebView2 Runtime version and the WebView2 nuget version you are using?
markFleischmann commentedon Jul 26, 2022
Brad Peters (@bradp0721) I updated my code to the latest version which is using version 1.0.1305-prerelease. The latest version works slightly different than the version that I was using. Now, when I click the New Browser Version, it does not create a new window. Now it seems to reload the browser in the original window. When it reloads the browser, it does not render anything (the same problem as I originally reported in the issue). I did not modify the code from what I downloaded here: https://github.com/MicrosoftEdge/WebView2Samples
bradp0721 commentedon Apr 13, 2023
markFleischmann, I was able to get a repro and root cause the issue. The problem comes from WebView2WPFBrowser being a System DPI aware app and an OS feature to “Fix blurry apps”. Old versions of Windows had a single System DPI that was given to all System DPI aware apps. Even if the monitor scale changed, when a System aware app asked for the scale, it would be given the System DPI. The fix blurry apps feature made it so that a System aware app gets the current monitor DPI. Once the app is given this value, it never changes for that application. But if the monitor scale is changed and a different System aware app is launched, those two apps will have a different DPI value even though they are both System aware.
In the repro, WebView2WPFBrowser is being launched on a 100% monitor, so it's PerProcessSystemDPI is 100%. It then creates a WebView2. The WebView2 process are created as System DPI aware to match the application process. They are also given the PerProcessSystemDPI of 100%. Then the monitor DPI is changed from 100% to 150%. Doing New Browser Version results in closing the current WebView2 (including all the WebView2 processes) and creating a new WebView2. This new WebView2 process is launched at System DPI aware of match the application process, but the Windows OS gives this process a PerProcessSystemDPI of 150%. This does not match the WebView2WPFBrowser PerProcessSystemDPI which is still 100%. Because of this mismatch in PerProcessSystemDPI, the OS is not able to render the WebView2 child HWND as part of the application HWND tree.
We reached out to Windows team about this issue and they marked the bug as Won't Fix, but there are work-arounds.
Workaround 1)
Make the app PerMonitor DPI aware. This will completely avoid the PerProcessSystemDPI issue. The app process and WebView2 process will both be PerMonitor and will receive updates when the monitor DPI changes.
Workaround 2)
There is a registry key that you can set to opt the app process out of PerProcessSystemDPI. This does mean that the app might appear blurry if the monitor DPI is changed and then the app is launched (similar to the current behavior if you change the monitor DPI while the app is running). By opting the app out of PerProcessSystemDPI, the WebView2 process, as child processes, are also opted out. So when you recreate the WebView2 after changing the monitor DPI, the WebView2 process System DPI will match the app process System DPI.
[HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers]
"C:\WebView2Samples\SampleApps\WebView2WpfBrowser\bin\Debug\netcoreapp3.0\WebView2WpfBrowser.exe"="~ PERPROCESSSYSTEMDPIFORCEOFF"