I'm using vb.NET but I incorporated a C# example from here using addEventListener and DOMSubtreeModified to watch the entire DOM document:
Dim script As HtmlElement = Me.Browser.Document.CreateElement("script")
script.InnerHtml = "function listenToDOM() { document.addEventListener('DOMSubtreeModified', function(e) { window.external.DOMUpdate() }); }"
Me.Browser.Document.GetElementsByTagName("body")(0).AppendChild(script)
Me.Browser.Document.InvokeScript("listenToDOM")
...however, I'm trying to sort it out to more specific DIVs. I haven't succeeded on that front yet but the more I read the more it seems I should be using a MutationObserver which I know nothing about, and I especially don't know how to incorporate with a WebBrowser control.
Has anyone managed to do this?
Note: Yes this is WinForms WB and I did already set my BrowserEmulation to IE11 so that shouldn't be a problem.
Update: I attempted an implementation but it's not triggering:
Dim scriptEl As HtmlElement = Me.Browser.Document.CreateElement("script")
scriptEl.InnerHtml = "var targetNode = document.querySelector('.div-content');
var Config = {
attributes: true,
childList: true,
characterData: true,
subtree: true
};
function (as Observer = new MutationObserver(function (MutationRecords, MutationObserver) { window.external.DivUpdated(); });
Observer.observe(targetNode, Config);"
Me.Browser.Document.GetElementsByTagName("body")(0).AppendChild(scriptEl)