Skip to content

WebView 2 does not render anything after resolution scale change and opening a new browser window #2611

Closed

Description

@markFleischmann

I was able to reproduce this issue using the WebView2Samples code.

  1. run the WebView2WpfBrowser project
  2. see the browser open and render correctly
  3. leave the app open and in the Windows 10 display settings, change the scale factor for your monitor (I changed mine from 100% to 125%)
  4. in the app, to go scenario -> new browser version -> click yes in dialog window
  5. new window opens with a Webview2 browser

result: the new window does not render the WebView2 browser
image

I only see this happen if I change the screen scaling factor before opening a new window/webview2 browser

Activity

  1. bradp0721 commented on Jul 22, 2022

    @bradp0721
    Member

    Following the repro steps, I am not able to repro the issue. I was able to reproduce the blank window using these steps.

    1. Run WebView2WpfBrowser project. (Creates Window A)
    2. Go to File -> New Window (Creates Window B)
    3. In Window A, go to File -> Close.
    4. 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?

  2. markFleischmann commented on Jul 22, 2022

    @markFleischmann
    Author

    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

  3. bradp0721 commented on Jul 22, 2022

    @bradp0721
    Member

    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?

  4. markFleischmann commented on Jul 26, 2022

    @markFleischmann
    Author

    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

  5. bradp0721 commented on Apr 13, 2023

    @bradp0721
    Member

    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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions