In DotNetBrowser 1.8.2 the JavaScript context events have been added:

  • ScriptContextCreated - indicates that JavaScript context has been created.
  • ScriptContextDestroyed - indicates that JavaScript context has been destroyed.

The ScriptContextCreated event can be used to execute any JavaScript code before the web page JavaScript is executed:

browser.ScriptContextCreated += (sender, args) =>
  browser.ExecuteJavaScriptAndReturnValue(args.Context.FrameId, @"
    screen = new function() {
    this.width = 100;

Both events are processed synchronously, blocking JavaScript execution on the web page. It is not recommended to put the long-running code in the corresponding event handler, because this will affect web page loading and displaying performance.