Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Context Menu in WebView2 PDF Viewer when selecting text #1345

Closed
VijayanRamachandran opened this issue Jun 2, 2021 · 6 comments
Closed

Context Menu in WebView2 PDF Viewer when selecting text #1345

VijayanRamachandran opened this issue Jun 2, 2021 · 6 comments
Assignees
Labels
bug Something isn't working tracked We are tracking this work internally.

Comments

@VijayanRamachandran
Copy link

VijayanRamachandran commented Jun 2, 2021

UseCase:

In an sample WPF window application i hosted a single instance of WebView2 as below ( In MainWindow.xaml ) and passed source url to load a sample PDF.
In addition to that I added a settings to CoreWebView2 to disable default context menu as below ( In MainWindow.xaml.cs )

MainWindow.xaml

image

MainWindow.xaml.cs

image

Current Behavior:

Upon RMB click on selected text we could see context menu as shown in below screenshot.

Is this expected behavior ?

MiniContextMenu

Version Information

Nuget - Microsoft.Web.WebView2 => 1.0.818.41
Fixed Version: Microsoft.WebView2.FixedVersionRuntime.91.0.864.37.x64

AB#33623058

@VijayanRamachandran VijayanRamachandran added the bug Something isn't working label Jun 2, 2021
@champnic
Copy link
Member

champnic commented Jun 4, 2021

Hey @VijayanRamachandran - thanks for the report. The settings typically require a navigation to take effect. If you reload the page or try navigating somewhere else first, do you still see this behavior?

@champnic champnic self-assigned this Jun 4, 2021
@VijayanRamachandran
Copy link
Author

@champnic
Yes i still see the same behavior even after settings takes effect.

Ex:

I tried as below in MainWindow.xaml.cs ( in addition to instead of setting Source in MainWindow.xaml to pdf )

    async void InitializeAsync()
    {
        await webView.EnsureCoreWebView2Async(null);

        webView.CoreWebView2.Settings.AreDefaultScriptDialogsEnabled = false;
        webView.CoreWebView2.Settings.IsWebMessageEnabled = false;
        webView.CoreWebView2.Settings.IsStatusBarEnabled = false;
        webView.CoreWebView2.Settings.AreDefaultContextMenusEnabled = false;
        webView.CoreWebView2.Settings.AreHostObjectsAllowed = false;
        webView.CoreWebView2.Settings.IsZoomControlEnabled = false;
        webView.CoreWebView2.Settings.IsBuiltInErrorPageEnabled = false;
        webView.CoreWebView2.Settings.AreDevToolsEnabled = false;
        webView.CoreWebView2.Settings.IsScriptEnabled = false;

        webView.CoreWebView2.Navigate(@"D:\WebView2-Preview-MS-PrivateMSI\12_WebView2Preview-Pdf\WebView2Preview\SamplePdf.pdf");
    } 

@champnic
Copy link
Member

champnic commented Jun 4, 2021

I was able to repro the problem, and it looks like that menu shows up just by selecting text, not by using the right-mouse button. I don't think this is by design, so I've opened this bug on our backlog. Thanks!

@champnic champnic changed the title Context Menu in WebView2 PDF Viewer Context Menu in WebView2 PDF Viewer when selecting text Jun 4, 2021
@champnic champnic added the tracked We are tracking this work internally. label Jun 4, 2021
@champnic
Copy link
Member

champnic commented Jan 7, 2022

This should be fixed in runtimes 99.0.1112.0+. Thanks!

@champnic champnic closed this as completed Jan 7, 2022
@sergimos
Copy link

sergimos commented Mar 15, 2024

Hello @champnic

I have the same issue on a touchpanel where a webview2 element is used to display a pdf. When selecting text with the touch control I get the same context menu as shown from @VijayanRamachandran. If I select text using my mouse I dont get the context menu.

MainWindow.xaml.cs
`using System.Windows;

namespace PDFViewer
{
///


/// Interaction logic for MainWindow.xaml
///

public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
InitializeAsync();
}

    async void InitializeAsync()
    {
        await webView.EnsureCoreWebView2Async(null); // Initialize the control
        webView.CoreWebView2.Settings.AreDefaultContextMenusEnabled = false;
    }

}

}`

MainWindow.xaml
<Window x:Class="PDFViewer.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:PDFViewer" xmlns:wv2="clr-namespace:Microsoft.Web.WebView2.Wpf;assembly=Microsoft.Web.WebView2.Wpf" mc:Ignorable="d" Title="MainWindow" Height="450" Width="800"> <Grid> <wv2:WebView2 Name="webView" Source="file:///D:/test.pdf#toolbar=0"/> </Grid> </Window>

Context menu that shows when selecting text with the touch control:
ContextMenu

Webview Version:
WebView2Version

@champnic
Copy link
Member

@sergimos This is a pretty old issue. Can you open a new one for the issue you are seeing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working tracked We are tracking this work internally.
Projects
None yet
Development

No branches or pull requests

3 participants