MSHTML: Call a function when DOM is ready, but before javascript is evaluated

313 views Asked by At

I'm working on a cross-platform webview library that uses webkit (macos/linux) and mshtml (windows). I am now trying to give users a callback that would allow them to "inject" custom javascript code into the page once it is loaded (e.g. to wrap console.log, to pass initial data to the web page and so on).

My current problem is with MSHTML. If I try evaluating javascript right after I call Navigate2 - I get errors, e.g. GetIDsOfNames method on script object fails, which is understandable because it's probably too early. I try to listen to other events, such as DISPID_DOCUMENTCOMPLETE or DISPID_NAVIGATECOMPLETE2, but that arrive too late (e.g. after the scripts on the page are executed, although before window.onload).

I wonder if there is any way to get notified when the page is loaded and DOM is parsed and scripts can be evaluated, but before they are actually evaluated?

0

There are 0 answers