2

My existing C# Winforms project earlier had the default WebBrowser control. As it fails to load modern websites, I have started using the Webview2 control.

The earlier WebBrowser control used to offer the Document property; which is missing from WebView2 control. How do we go about accessing the Document and subsequently DOM of the webview2 loaded page?

Currently I am getting compilation errors on the below line:

var _document = webBrowser.Document;

Error Message:

Error CS1061 WebView2 does not contain a definition for 'Document' and no accessible extension method 'Document' accepting a first argument of type 'WebView2' could be found (are you missing a using directive or an assembly reference?)

Any pointers on how to go about this would be helpful.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Kim Smith
  • 105
  • 8
  • 1
    Why not read the [documentation about WebView2](https://learn.microsoft.com/en-us/microsoft-edge/webview2/)? – Uwe Keim Jul 15 '22 at 11:44
  • @UweKeim I did read them along with other many sites and could not find any references to my issue. – Kim Smith Jul 15 '22 at 11:55
  • 3
    You should most probably describe what you're going to do with the DOM object. Don't think you can just replace a WebBrowser Control object with a WebView2 object and then keep the same code you have -- If you're using an `ObjectForScripting`, that could turn out to be useful. – Jimi Jul 15 '22 at 12:04
  • How do you access the DOM? Javascript. – Tu deschizi eu inchid Jul 15 '22 at 13:25
  • Since I assume WebView2 to be similar to [CefSharp](https://cefsharp.github.io/), I would expect the [examples/Q&A for CefSharp](https://stackoverflow.com/q/55441574/107625) also apply to a high degree for WebView2. In the other hand, there is [the documentation that explicitly talks about Interop](https://learn.microsoft.com/en-us/microsoft-edge/webview2/concepts/overview-features-apis?tabs=dotnetcsharp#webnative-interop). – Uwe Keim Jul 15 '22 at 14:02
  • 1
    Does this answer your question? [WebView2 (2020/06) -> Where's the DOM?](https://stackoverflow.com/questions/62328943/webview2-2020-06-wheres-the-dom) – amaitland Jul 15 '22 at 21:09

0 Answers0