When will the WPF webbrowser\'s LoadCompleted event fires? Is this event waits for any ajax calls to complete in the aspx page.
i have a wpf app in which a webbrowser co
I have been able to solve such issue.
You will need some 3rd party assemblies :
The idea, as you guess, is to create an in-memory proxy server, and redirect your web browser control to this proxy.
Then, FiddlerCore publishes some events where you can analyse the request/response, especially the body.
As it acts a proxy, all communications, including Ajax calls, Flash calls, etc, are routed by the proxy.
If it can help, a small code that help me to prototype this behavior:
App.cs :
///
/// Interaction logic for App.xaml
///
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
BootStrap();
base.OnStartup(e);
}
private void BootStrap()
{
SetupInternalProxy();
SetupBrowser();
}
private static void SetupBrowser()
{
// We may be a new window in the same process.
if (!WebCore.IsRunning)
{
// Setup WebCore with plugins enabled.
WebCoreConfig config = new WebCoreConfig
{
ProxyServer = "http://127.0.0.1:" + FiddlerApplication.oProxy.ListenPort.ToString(),
EnablePlugins = true,
SaveCacheAndCookies = true
};
WebCore.Initialize(config);
}
else
{
throw new InvalidOperationException("WebCore should be already running");
}
}
private void SetupInternalProxy()
{
FiddlerApplication.AfterSessionComplete += FiddlerApplication_AfterSessionComplete;
FiddlerApplication.Log.OnLogString += (o, s) => Debug.WriteLine(s);
FiddlerCoreStartupFlags oFCSF = FiddlerCoreStartupFlags.Default;
//this line is important as it will avoid changing the proxy for the whole system.
oFCSF = (oFCSF & ~FiddlerCoreStartupFlags.RegisterAsSystemProxy);
FiddlerApplication.Startup(
0,
oFCSF
);
}
private void FiddlerApplication_AfterSessionComplete(Session oSession)
{
Debug.WriteLine(oSession.GetResponseBodyAsString());
}
}
MainWindow.xaml :
And finally, MainWindow.xaml.cs :
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
browser.LoadURL("http://google.fr");
}
}
You will have to add some plumbing to this application, in order to route and analyse the requestion from the app to the business class, but that's beyond the scope of this question.