Quantcast
Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

New Post: Callbacks for some host objects are not executing

$
0
0
I obtain the window object in DWebBrowserEvents2_Event.NavigateComplete2 event. Following is some stripped down code snippets:
public void OnNavigateComplete(object pDisp, ref object URL)
{
    var browser = pDisp as IWebBrowser2;
    var document2 = browser?.Document as IHTMLDocument2;
    var window = document2?.parentWindow as IHTMLWindow2;

    var engine = new JScriptEngine("{16d51579-a30b-4c8b-a276-0ff4dc41e755}", null, WindowsScriptEngineFlags.EnableStandardsMode | WindowsScriptEngineFlags.MarshalNullAsDispatch | WindowsScriptEngineFlags.MarshalArraysByValue);
    engine.AddHostObject("window", HostItemFlags.GlobalMembers, window);
}
And the JavaScript snippet:

global is the window object.

contentPort is a private host object.
contentPort.addMessageListener(function (msg) {

    if (global.document.readyState !== "complete") {
        global.addEventListener('load', function () {
            console.log('message document load');
        }, false);
        console.log("Message received - waiting for document load");
    } else {
        setTimeout(function () {
            console.log('message timeout');
        });
        console.log("Message received");
    }
}
The console output displays either "Message received" or "Message received - waiting for document load" but never "message document load" or "message timeout"

The private host object callback works but the window callbacks do not.

Viewing all articles
Browse latest Browse all 2297

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>