MicrosoftEdge / WebView2Feedback

Feedback and discussions about Microsoft Edge WebView2
https://aka.ms/webview2
449 stars 53 forks source link

WebView1 (EdgeHTML) questions C# WPF #78

Closed DmitryBorodiy closed 4 years ago

DmitryBorodiy commented 4 years ago
  1. How to include a context menu in WebView (EdgeHTML) C# WPF. I mean buttons to copy, paste, cut.

2.How to get a screenshot of the site with WebView (EdgeHTML) C# WPF.

3.How to open a local file with WebView(EdgeHTML) C# WPF.

Also, if you're not having a hard time, you can take a code sample. I also want to remind you that my project is running on WPF (.NET Framework) technology and using the C# language. I am grateful to the Edge team for their support in advance😁.

The text was translated using Microsoft Bing Translator.

david-risney commented 4 years ago
  1. We have no way to programmatically control the context menu. The context menu should display with copy, cut and paste when the user right clicks on text boxes in the WebView.
  2. Use the CapturePreviewToStreamAsync method
  3. You can use NavigateToString if you have just HTML content in memory, or NavigateToLocalStreamUri to provide custom stream objects for custom URI schemes, or use WebResourceRequested to replace the response body of any http/https URI request.
DmitryBorodiy commented 4 years ago

WebView on WPF does not show contextual menus. And also, the contextual menu is not displayed when you press the right button on the text box. Please add a contextual menu like the old IE-based WebBrowser. That's a great idea. You also need to add the ability to disable and turn it on.

DmitryBorodiy commented 4 years ago

Will the contextual menu be implemented on WebView 2?

DmitryBorodiy commented 4 years ago

David Risney, can I take your contact email for support?

ukandrewc commented 4 years ago

You can prevent and show a contextmenu from script: document.documentElement.addEventListener("contextmenu", function (e) { showMyMenu(e); e.preventDefault() })

DmitryBorodiy commented 4 years ago

Can you set an example with the contextual menu in WebView? For C# WPF

ukandrewc commented 4 years ago

I don't use C# or WPF, but basic principle is create JS, then PostMessage to .Net:

Sub BrowserCreated(sender As Object, e As EventArgs)
 AddScriptToExecuteOnDocumentCreated("document.documentElement.addEventListener("contextmenu",function(e){window.chrome.webview.postMessage('contextmenu');e.preventDefault() }")
End Sub

Sub WebMessageRecieved(sender As Object, e As WebMessageReceivedEventArgs)
  If e.WebMessageAsString="contextmenu" then
    MyContextMenu.Show(WebView2, WebView2.PointToClient(Cursor.Position))
 End If  
DmitryBorodiy commented 4 years ago

How do I copy, cut, paste text from WebView through code?

ukandrewc commented 4 years ago

As you can't say 'thank you', I won't answer any more of your posts. Basic stuff from about two years old.

DmitryBorodiy commented 4 years ago

Ok, thank you😁

DmitryBorodiy commented 4 years ago

EdgeHTML (WebView) developers, please add a contextual menu to your control. I assure you this is a great idea for WebView. Many .NET developers lack this. Through JS, this is not very convenient. Methods are also needed: Copy(), Paste (), Cut (). This will make your control really convenient. I just want to help make WebView better. Thank you😁

david-risney commented 4 years ago

You can read about DOM APIs for interacting with the clipboard (and all other DOM APIs): https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Interact_with_the_clipboard

I'll move your context menu feature request out into its own issue for WebView2. We have planned to look into such an API for WebView2.

DmitryBorodiy commented 4 years ago

The ability to customize the contextual menu is present in Chromium. You can use it in your control.

Why don't you integrate the context menu from Edge to WebView (EdgeHTML)?

DmitryBorodiy commented 4 years ago

Thank you in advance

DmitryBorodiy commented 4 years ago

Please add a contextual menu to WebView EdgeHTML.

Thank you for your understanding.

I'm really looking forward to the release of WebView 2 for .NET Framework WinForms and WPF, as my app is written on C#.

DmitryBorodiy commented 4 years ago

With Chromium I had a problem. I couldn't open a few windows with a Chromium control. I could only run one window with one control. I used the CefSharp library.

Will webView 2 be able to run multiple controls at once?

Will multitasking be implemented?

Thank you😊

david-risney commented 4 years ago

Yes, you can run multiple WebView2 webviews at the same time.

DmitryBorodiy commented 4 years ago

When will WebView 2 work on the C#?

david-risney commented 4 years ago

We're working on C# support for the first half of 2020 with a dev preview sometime earlier.

DmitryBorodiy commented 4 years ago

Thank you)

Will so contextual menu with buttons copy, cut, paste?

Will there be WebView.Copy(); , WebView.Paste(); , WebView.Cut(); methods?

DmitryBorodiy commented 4 years ago

It wouldn't be bad if Microsoft.Toolkit.Wpf.UI.Controls had a new TabView control.

DmitryBorodiy commented 4 years ago

return await myWebView.InvokeScriptAsync("eval", new string[] { "document.execCommand("copy");" });

Can I use this to copy text from WebView?

Thank you in advance

david-risney commented 4 years ago

We'll likely have an API to allow customizing the context menu entries (providing your own, removing existing) and potentially also separately a mechanism to own drawing the context menu. I don't believe we will have cut/copy/paste methods on the WebView itself.

If you have feedback for Microsoft.Toolkit.Wpf.UI.Controls you may need to find their github project?

I'm not positive if you can use that to copy text in a WebView (EdgeHtml). There is an API CaptureSelectedContentToDataPackage that you might try out. Otherwise all you can do is inject script like what you're trying using MDN's description of interacting with the clipboard

DmitryBorodiy commented 4 years ago

I'll try to implement it.

How can I connect with those who work on the Microsoft.Toolkit.Wpf.UI.Controls library?

DmitryBorodiy commented 4 years ago

How do I get a screenshot of WebView (EdgeHTML) on WPF C#?

WebView.CapturePreviewToStream doesn't work on WPF.

What should I do?

Thank you in advance.

DmitryBorodiy commented 4 years ago

I also can't catch a right-click event on WebView.

david-risney commented 4 years ago

The nuget package for Microsoft.Toolkit.Wpf.UI.Controls takes you to https://github.com/windows-toolkit/Microsoft.Toolkit.Win32/releases so maybe from there you can figure it out?

If CapturePreviewToStream isn't available then I don't know how to do that.

You should be able to use JavaScript to catch the right click in WebView1. See https://developer.mozilla.org/en-US/docs/Web/API/Element/contextmenu_event

DmitryBorodiy commented 4 years ago

Thank you for helping😁.

I try it.

I solved the problem with TabView. I found a FabTab library that helped me implement the tabs.

DmitryBorodiy commented 4 years ago

Will I be able to get a screenshot of the web page in WebView 2 on C#?

DmitryBorodiy commented 4 years ago

There is also a problem with opening local files, I can't open the file with absolute path. When will I be able to open files with absolute path in WebView on WPF apps?

DmitryBorodiy commented 4 years ago

Will WebView send visitation data and other confidential information to Microsoft?

DmitryBorodiy commented 4 years ago

How to optimize WebView(EdgeHTML) control? And how to clean the WebView(EdgeHTML) cache?

Thank you in advance

pagoe-msft commented 4 years ago

You can expect the same functionality in the WPF version of WebView as the Win32 version. We tentatively plan to release WebView for C# in Q3 2020.

WebView does send data to Microsoft in-line with the data collected by the browser. You can read more about it here: https://support.microsoft.com/en-us/help/4468242/microsoft-edge-browsing-data-and-privacy-microsoft-privacy