Environment: Windows 10 Pro - ver. 1903, VS2019 latest version, WPF Core
When I have a manual control on an HTML page displayed inside WebView2 control, I can disable the context menu by simply adding oncontextmunu={return false;} as an attribute to <body> tag. But in most cases the web page is displayed based on user interaction (what page user navigates to etc.).
Question: How can we disable to context menu of a webpage displayed in WebView2 control?
Remarks:
I have noticed that in some cases where a JavaScript is loaded along with a webpage, the oncontextmunu={return false;} does not disable the context menu even if I add this attribute programmatically to the body tag of loaded page. I see AreDefaultContextMenusEnabled property of Microsoft.Web.WebView2.Core.CoreWebView2Settings class but VS2019 does not recognize any such property for WebView2.
There was a similar issue on the old WebBrowser control of WPF as described here and here, and I have the similar situation for WebView2.
According to bullet 5 of this Microsoft link the issue was resolved. But the solution there seems to be related to C++ while I'm using C#. Maybe, there is an alternative.
Mostly, the reason for disabling the Context Menu is for preventing the End-User from inspecting the page source. Thus, we should also disable the accelerator keys using both instructions:
webView.CoreWebView2.Settings.AreBrowserAcceleratorKeysEnabled = false;
webView.CoreWebView2.Settings.AreDefaultContextMenusEnabled = false;
since the End-User can use Ctrl+Shift-C and F12 for DevTools
check Accelerator Keys
Related
I am working on a project that involves using a WPF WebBrowser to load a form created using Bootstrap JS framework. However, it appears that parts of the form (specifically drop-down select options buttons) do not function within the WebBrowser, despite working normally in IE11. The form does not retain drop-down selected values (on submit, the default value is recorded) and on change commands (e.g. loading specified data) do not work. I have searched extensively but have not found a solution that works. Drop down menus on non-Bootstrap forms seem to work when loaded, but Bootstrap forms on any site I load in the WebBrowser seem to fail.
Steps I have taken already that have not resolved the issue:
I have changed the FEATURE_BROWSER_EMULATION registry keys (among other keys suggested online) to change the default IE of the WebBrowser to IE11, and I have tested to make sure this is working, but it does not resolve the issue.
I have checked drop down boxes on other websites within the WebBrowser, which seem to be working fine.
I have ensured JavaScript is functional within the WebBrowser interface.
I have checked that the website works in IE11 outside of the WebBrowser interface.
I have tried the WebBrowser in both a Window and within a Form
I appreciate any help!
I made a program that use the new google maps in c# but when opened, I get a notification concerning the compatibility of IE. (See image)
Any idea to fix it?
Please see this answer
In general, WebBrowser control always runs in compatibility mode and the only way to disable it is to edit registry.
Another option is to use other control (not based on IE), like http://sourceforge.net/projects/webkitdotnet/
I am using rad editor for editing html of one of the module in my project. Everything works perfectly in all browser except IE10(as well as IE9). In IE, i can not insert table object which is given in rad control. also addition of symbol,undo doesn't work.if i click on any of these menus, then editor in design mode is not editable. i need to switch to html mode and then design mode to maker it work again. also the UI seems to be shaking in right side and bottom of editor.
Any help guys.....!!!!
Try their latest version. If yours is old it may not support these browsers.
A workaround for that may be adding an x-ua compatible meta tag to your page to put IE in IE8 mode
I'm in a trouble trying to fix some problem.. I have a program with Webbrowser control inside it.
It automates crawling process from some website. The problem is that I cannot fix webbrowser after recent website changes.
They have changed page navigation on website. And when I do actions MANUALLY in webbrowser (in my app) it doesn't go to the next/previous page on website. It does nothing... Whereas it works properly in IE 7/8/9 (only scripting errors thrown this time).
So does it mean that Webbrowser is not fully similar to IE??
I'm sorry for not showing source codes here, I think it wouldn't help here. Which way should I go to troubleshoot it? Why page navigation is not working in Webbrowser control?
I tried to simply put Webbrowser on a Window Form in new project and tried to navigate page 2/3/../10 in the website catalog, but it simply changes page number and doesn't navigate to it...
EDIT: Website doesn't work propely even if I do actions manually in webbrowser using mouse clicks.. but works in IE.
EDIT2: I might be not clear in my question. The problem is that I cannot use website even Manually with mouseclicks via my Webbrowser control in app. It changes page number after I click on it, but it doesn't navigate to that page. It stays silent. I'm sure that AllowNavigation property is true. It worked just yesterday and stopped after website changes today... Please tell me which way should I go to troubleshoot it.. I thought that Webbrowser control acts the same way as Internet Explorer.. Any help from you highly appreciated! Thanks
EDIT3: Strange thing... i just loaded Extended Webbrowser and navigated to that website. Page navigation panel doesn't work there also.. Is it a bug on their side or some type of guard from crawlers? What do you think?
(http://www.codeproject.com/KB/cpp/ExtendedWebBrowser.aspx)
I'm sure this isn't the answer your want but using the webbrowser control to scrape websites is very painful to maintain.
Instead use the HttpWebRequest and HttpWebRepsonse objects to recreate the calls to the webserver.
You can use Fiddler (http://www.fiddler2.com/fiddler2) and your browser to record your web sessions and recreate them in code.
You can setup your webbrowser control to disable a number of features including navigation.
I.e. to disable nav in the C# WebBrowser control:
webBrowser1.AllowNavigation = false;
I'd double check that you're not doing anything like this.
I had the same issue with a certain web site that recently changed its format. It has to do with the version of IE used by the control.
Simply force the IE version used to the latest (in my case 9). Setting the appropriate registry item to 9999 for my application worked; see: Webbrowser control behaving different than IE
I am currently testing a menu in ASP.NET I've recently made using asp:menu control.
The menu is just as I want it to be right now, but whenever there is a postback that updates the whole page, it moves a little downwards (only once, a second postback won't move it a little bit more).
It's not CSS - > I've removed all CSS from this menu)
It's not any property -> I've commented out everything related to customizing the menu
It's not any other element above it enlarging -> I've specially put it inside a table, in which the only content is the asp:menu control
It moves a lot downwards in IE6, a little in IE8, and it doesn't move at all in Firefox 4.
What could I do ? Are there any alternatives ? Is there any property I can use, or any outer element I could put it inside in order for it to stay still ?
And yes, every single machine this is going to run in is using Internet Explorer. The nightmare of any web developer.
---[update]-----
I've built a menu in a separate project, and the effect wasn't there! I've copied the exact same files into my project, and ran it, and the issue was there.
Could it be a difference in the asp.net version ?
Did you check using IE web developer toolbar to see what's the html looks like in that area before and after the postback? It seems more like a browser issue so the toolbar would give you details as what is coming in the gap or may be what's pushing it down.
If the app is in asp.net 4.0, look at the source code of the page after it renders the first time, and then after the postback. Make sure it renders as divs on both or tables on both.
I currently have a similar issue where my menu "spreads out" on the postback. Before the postback, it renders divs. After the postback, it renders tables.
There is specifically a property on the menu "RenderingMode" which is suppose to control this, but it is not working for me.
I had the same problem. My navigation menu sits in an UpdatePanel, and I changed the UpdateMode from Always to Conditional - problem solved. This was in my master page.