Question

I've tried the built in WPF WebBrowser (.NET ActiveX Wrapper), Awesomium.NET, and Chromium.NET.

I'm not sure if I just missed something here, but I don't know if there is any way to raise an event when the DOM changes so that my C# code can execute. I want to avoid having a timer check/compare the DOM for changes each time if I can...

So, I'm just wondering if I missed something in those controls that allows me to do what I want or if not, is there any alternatives/methods to have a DOMChanged event?

Was it helpful?

Solution

I don't believe there's any way to do that by default with those controls (though I've never used Chromium.NET).

One thing you could try doing is using JavaScript to detect DOM changes. You could have your application register a callback function and write the JavaScript itself. Here's a rough example in Awesomium syntax:

myControl.CreateObject("JSCallback");
myControl.SetObjectCallback("JSCallback", "handleDOMChange", OnDOMChange);
myControl.ExecuteJavascript(
  //this is where you would write your Javascript method that would detect DOM change and have it execute this handler method
  //Here's a post with some info on this (ignore cross-browser compatibility issues since it's all running within Awesomium): http://stackoverflow.com/questions/3219758/detect-changes-in-the-dom
  function DOMChangeDetected () 
  {
    JSCallback.handleDOMChange();
  }
);

private void OnDOMChange(object sender, JSCallbackEventArgs eventArgs)
{
  //.NET event triggered from JS DOM change detection
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top