Vereyon's Windows.WebBrowser is a helper library for controlling and enhancing the System.Windows.Forms.WebBrowser
control which embeds Microsoft Internet Explorer. It improves JavaScript interoperability and enables controlling the IE version and GPU acceleration.
The ScriptingBridge
is a utility which makes it possible to invoke JavaScript member functions in the embedded browser and to receive return values and objects. This is in contrast to the HtmlDocument.InvokeScript()
method which can only invoke global functions. It also provides enhanced error handling by for example differentiating between a not found function and a function returning void.
If you for example want to invoke myObject.myFunction
as defined in the following JavaScript snippet:
var myObject = {
memberFunction: function()
{
return "some result";
}
};
You can do so using the ScriptingBridge
as follows where webBrowser
is your System.Windows.Forms.WebBrowser
instance:
var bridge = new ScriptingBridge(webBrowser, true);
var result = bridge.InvokeFunction<string>("myObject.myFunction", parameter);
The InternetFeatureControl
is a utility class which can be used to control features of the System.Windows.Forms.WebBrowser
control.
Using InternetFeatureControl.SetBrowserEmulation()
the Internet Explorer rendering engine version can be controlled.
Using InternetFeatureControl.SetGpuRendering()
GPU acceleration for rendering can be enabled and disabled.
The WinInetCacheControl
is a utility class which can be used to controle the WinInet cache.
Using InternetFeatureControl.ClearCache()
the WinInet cache can be fully cleared.
The ScriptingBridge object provides both a property and an event for this purpose. The ScriptingBridge.IsInitialized
property will be set to true
once the scripting bridge is initialized. The ScriptingBridge.Initialized
event is invoked once initialization is completed.
Since you can set only one ScriptingObject
on the webbrowser and you are required to set it to a ScriptingBridge
instance in order for the bridge to work you are left with no direct method to expose extra services to the web page.
A straightforward solution is to extend the ScriptingObject
and to expose your services from there derived class.
This is a dreaded question for WebBrowser users and a lot has been written about controlling this version. The Scripting Bridge will magically tell you where in history you are after initialization via the ScriptingBridge.DocumentMode
property.
The design of the library is discussed in detail in the article Overcoming WebBrowser control scripting limitations with ScriptingBridge.
See the Windows.WebBrowser.Tests project for xUnit based unit tests.