I faced the same problem but the above solution could no longer be used since the interface IMenuHandler
(renamed to IContextMenuHandler
) has had a few changes and there no longer exists
bool OnBeforeContextMenu(IWebBrowser browser);
which has the following signature now:
void OnBeforeContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model);
The SO question linked in the question (Disable context menu in Chromium Embedded 3 (DCEF3)) has to do with pascal and inno setup script but the accepted answer adjusted for C# and ChromiumWebBrowser
worked for me. The solution is to clear the model parameter in the implementation of OnBeforeContextMenu
. The implementation of IContextMenuHandler
can look like this:
public class CustomContextHandler : IContextMenuHandler
{
public void OnBeforeContextMenu(IWebBrowser browserControl, CefSharp.IBrowser browser, IFrame frame, IContextMenuParams parameters,
IMenuModel model)
{
model.Clear();
}
public bool OnContextMenuCommand(IWebBrowser browserControl, CefSharp.IBrowser browser, IFrame frame, IContextMenuParams parameters,
CefMenuCommand commandId, CefEventFlags eventFlags)
{
return false;
}
public void OnContextMenuDismissed(IWebBrowser browserControl, CefSharp.IBrowser browser, IFrame frame)
{
}
}
Then in the code that creates an object of the chromium web browser:
browser = new ChromiumWebBrowser(url);
browser.MenuHandler = new CustomContextHandler();