Skip to content

IsUserInitiated on navigation event does not work for backwards/forwards #402

@cbra-caa

Description

@cbra-caa

Setup

  • WPF application
  • .Net 4.7.2
  • 0.9.579-prerelease package for WebView
  • Edge Dev installed

Problem

When a user navigates inside the browser we can subscribe to the NavigationStarted event which holds the property IsUserInitiated. When the user moves forwards/backwards in th browser this property is expected to be true, but this is not the case.

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="800" Width="1000">
  
  <Grid>
    <Grid.RowDefinitions>
      <RowDefinition Height="*" />
      <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>

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

    <ScrollViewer Height="150"
                  Grid.Row="1">
      <TextBox x:Name="WebViewEvents" 
               Text="*** EVENT OVERVIEW ***"
               Foreground="OrangeRed"
               Background="Black"
               IsReadOnly="True" />
    </ScrollViewer>

  </Grid>
</Window>

MainWindow.xaml.cs

using System;
using System.Windows;

namespace TestWebView2App
{
  public partial class MainWindow : Window
  {
    public MainWindow()
    {
      InitializeComponent();

      WebView.CoreWebView2Ready += WebView_CoreWebView2Ready;
    }

    private void WebView_CoreWebView2Ready(object sender, EventArgs e)
    {
      WebView.CoreWebView2.NavigationStarting += CoreWebView2_WebView_NavigationStarting;
    }

    private void CoreWebView2_WebView_NavigationStarting(object sender, Microsoft.Web.WebView2.Core.CoreWebView2NavigationStartingEventArgs e)
    {
      WebViewEvents.Text += Environment.NewLine + $"Navigation to '{e.Uri}', is from user: '{e.IsUserInitiated}'";
    }
  }
}

How to reproduce

  1. Open the app
  2. Press any link on the site
  3. Go back using either Alt+Left, a dedicated mouse button or the contextmenu
  4. Go forward again using the same measures
  5. See in the event overview that IsUserInitiated is not correctly reported
    image

AB#28898249

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpriority-lowWe have considered this issue and decided that we will not be able to address it in the near future.trackedWe are tracking this work internally.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions