MicrosoftEdge / MicrosoftEdge/WebView2Feedback

Window gets forced into foreground on IsVisible=true

Open
#398 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug priority-low tracked
Dominant language
PowerShell
Stars
526
Forks
67
PR merge metrics
No merged PRs in 30d

Description

Setup

I am running a WPF application,
targeting .Net 4.7.2
with the 0.579-prerelease package for WebView
and Edge Dev installed.

Problem

When IsVisible changes from false to true in a WebView on an inactive window, the window will be activated and thus be forced topmost. In addition focus will be tried placed in the WebView, but instead it just comes out to null, instead of where the user left focus when they last were in the window (accessibility issue).

Code

I have created a minimum viable example which can reproduce the issue. Create a new WPF app with the following code:
MainWindow.xaml

<Window x:Class="TestWebView2App.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:wv2="clr-namespace:Microsoft.Web.WebView2.Wpf;assembly=Microsoft.Web.WebView2.Wpf"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
  
  <Grid>
    <Grid.RowDefinitions>
      <RowDefinition Height="Auto" />
      <RowDefinition Height="*" />
    </Grid.RowDefinitions>

    <Border Background="White"
            Grid.Row="1">

      <TextBlock Text="Some data is loading !"
                 VerticalAlignment="Center"
                 HorizontalAlignment="Center" />

    </Border>

    <Button Content="Refresh visibility in 2 seconds"
            Click="Button_Click" />

    <wv2:WebView2 Name="WebView"
                  Grid.Row="1"
                  Source="http://microsoft.com" />

  </Grid>
</Window>

MainWindow.xaml.cs

using System;
using System.Windows;
using System.Windows.Threading;

namespace TestWebView2App
{
  public partial class MainWindow : Window
  {
    private DispatcherTimer Timer { get; }

    public MainWindow()
    {
      InitializeComponent();

      Timer = new DispatcherTimer() { Interval = TimeSpan.FromSeconds(2) };
      Timer.Tick += Timer_Tick;
    }

    private void Timer_Tick(object sender, EventArgs e)
    {
      Timer.Stop();
      WebView.SetCurrentValue(VisibilityProperty, Visibility.Visible);
    }

    private void Button_Click(object sender, RoutedEventArgs e)
    {
      WebView.SetCurrentValue(VisibilityProperty, Visibility.Collapsed);
      Timer.Start();
    }
  }
}
How to reproduce
  1. Open a window which takes up your whole screen (could be Notepad)
  2. Open the application
  3. Press the "Refresh visibility in 2 seconds" button
  4. Shift to the other window, so that the application is covered
  5. After 2 seconds the application is forced into the foreground
Scenario

I use the WebView in conjunction with some other fields to display data to the user, data which might be changed by another user and then pushed to the first users client.
On receiving the push, I mask the fields with an overlay while updating - this causes the IsVisible property of the webview to switch to false, and when the overlay is removed back to true again.
The problem arises from the fact that the user might be sitting in another window/application when this updates happens which is not considered a feature 😅

Of Note

None of these problems are present when the user is actively working in the window, neither focus nor activeness of the window is affected in this case.

AB#28715517

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the behavior using MainWindow.xaml and MainWindow.xaml.cs with the supplied WPF example, then inspect how WebView visibility changes affect the inactive Window. Verify the result by toggling Visibility while another application is foreground and checking that the window stays inactive and focus is preserved.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
desktop
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.