Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to get the HTML content in WebView2? #354

Closed
alexchx opened this issue Jul 24, 2020 · 8 comments
Closed

Is there a way to get the HTML content in WebView2? #354

alexchx opened this issue Jul 24, 2020 · 8 comments

Comments

@alexchx
Copy link

alexchx commented Jul 24, 2020

Is there a way to get the HTML content in WebView2? I noticed the HTTP response and the HTML content might be retrieved in this experimental event WebResourceResponseReceived, but it's not available in the WPF version yet, so could you advise if there's any other alternatives at this moment? Thank you.

@ukandrewc
Copy link

There's an extended control here that has a DocumentHTML property
https://github.com/ukandrewc/Webview2.Winforms.DOM

@alexchx
Copy link
Author

alexchx commented Jul 26, 2020

@ukandrewc Thanks a lot for sharing, I noticed your project depends on this library Aimco.DOMWebView2, however, our project has strict restrictions on third-party libraries, so that might not be a good option in our case, thanks for your advice anyway.

@ukandrewc
Copy link

This question has been asked a few times, and as yet, there doesn't seem to be a direct way.
You can get the DOM HTML, but that's after any JS has been executed.
The code behind DocumentHTML, just uses fetch to get the source from the URL.

@alexchx
Copy link
Author

alexchx commented Jul 27, 2020

This new event WebResourceResponseReceived was released in 0.9.579 days ago, we might be able to get the page content from that event, but I didn't find such event in the wpf version, not sure if I did something wrong, or it isn't available for .net version yet.

@billhenn
Copy link

I was also looking for a way to access the HTML DOM. In particular I need to find an element and scroll to that element. It's disappointing that it's not accessible in the WPF WebView2.

@ukandrewc
Copy link

It is accessible, just async and you need to execute JS to do it:
WebView2.ExcecuteScriptAsync("document.getElementById('myelem').scrollIntoView()")

@billhenn
Copy link

Ahh, thanks for the tip @ukandrewc!

@champnic
Copy link
Member

champnic commented Jun 1, 2023

Tracked in #77

@champnic champnic closed this as not planned Won't fix, can't repro, duplicate, stale Jun 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants