webview2 / EdgeSharp

Build .NET Win32/WinForms/WPF WebView2 HTML5 Desktop Apps
MIT License
255 stars 30 forks source link

AreDefaultContextMenusEnabled don't work during first load #4

Closed gaetandezeiraud closed 2 years ago

gaetandezeiraud commented 2 years ago

I have set WebView2CreationOptions.AreDefaultContextMenusEnabled = false; in SampleEdgeSharpConfig.cs to disable the right click. I am based on the Win32 sample. The problem is between the window creation and the render of the webview. During this interval the right click (so the context menu) can be trigger. But when the page is loaded and displayed by the web view, the context menu no longer works as expected.

image

mattkol commented 2 years ago

@Brouilles sorry, I have not really had bandwidth to revisit some of the flow here. When you say it no longer work as expected, you mean the context menu is not expected to show?

Does it seem related to this? https://stackoverflow.com/questions/63322779/wpf-webview2-not-able-to-disable-context-menu?

I will find sometime over the weekend to reproduce.

mattkol commented 2 years ago

@Brouilles

I made a change in SampleConfig.cs and works for me:

    internal class SampleConfig : Configuration
    {
        public SampleConfig() : base()
        {
        // ------
            WebView2CreationOptions.AreDefaultContextMenusEnabled = false;
        }
    }

EdgeSharp_win-32_Sample.zip

gaetandezeiraud commented 2 years ago

It is during the initialization of the webview, before the html render. I can open the context menu. During some ms/s.

mattkol commented 2 years ago

I am not quite sure what you are trying to do really. But my guess is it may be a threading issue. Some functions will not work if not executed on the browser thread.

Please can you see how the dispatcher is used here:

https://github.com/webview2/EdgeSharp/blob/f4c7eafdb21f356169dec6e380459a66a2b56d2a/src/EdgeSharp.Core/Defaults/ResourceRequestSchemeHandler.cs#L95

More samples here - https://github.com/webview2/EdgeSharp/search?q=Dispatcher.Browser

If that does not work, you may need to attach a skeletal sample.