DotNetBrowser does not have a predefined window.external object that is always accessible from JavaScript. However, it is possible to simulate its presence.


The following code injects the externalObject as window.external for each frame on the web page before any JavaScript of this frame is executed. The externalObject instance will receive all the calls made to window.external in JavaScript.


C#


browser.ScriptContextCreated += (s, e) =>
{
  var window = e.Browser.ExecuteJavaScriptAndReturnValue(e.Context.FrameId, "window").AsObject();
  window.SetProperty("external", externalObject);
};



VB.NET


AddHandler browser.ScriptContextCreated, Sub(s, e)
    Dim window = e.Browser.ExecuteJavaScriptAndReturnValue(e.Context.FrameId, "window").AsObject()
     window.SetProperty("external", externalObject)
End Sub


Note: It is recommended to attach this handler before loading the first page into the Browser instance.