WPF WebBrowser fails to load rendered HTML of an Angular JS website

限于喜欢 提交于 2019-12-08 04:42:49

问题


I am working on a WPF aplication and I want to get the rendered HTML of a website that uses Angular JS technology. Here is what I've tried:

First, I create a WPF Web Browser control:

private WebBrowser webBrowser;

Then I navigate it to my target web page:

var uri = new Uri("http://my-angualrjs-site.com", UriKind.RelativeOrAbsolute);
webBrowser.Navigate(uri);

In the LoadCompleted event handler of my WebBrowser instance I cast the retrieved document to mshtml.HTMLDocument:

var doc = (mshtml.HTMLDocument) webb.Document;

And all I get is the raw HTML of the page, not the HTML processed and rendered by Angular JS from the server. Am I missing something?


回答1:


I had a similar issue with not being able to get an angular page to render properly in the control. After following Noseratios answer it was rendering and working good. Maybe this would help you too: C# webbrowser Ajax call

In short, you need to add features to the control to make the behavior closer to IE.

With his solution you'll be able to use code such as:

SetBrowserFeatureControlKey("FEATURE_AJAX_CONNECTIONEVENTS", fileName, 1);


来源:https://stackoverflow.com/questions/28449755/wpf-webbrowser-fails-to-load-rendered-html-of-an-angular-js-website

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!