Unfortunately, you cannot call object methods from the box using WebBrowser.Document.InvokeScript.
The solution is to provide a global function on the JavaScript side that can redirect your call. In its simplest form, it will look like this:
function invoke(method, args) {
In your .NET code, you should use this as follows:
var parameters = new object[] { "obj.method", yourArgument }; var resultJson = WebBrowser.Document.InvokeScript("invoke", parameters);
As you mentioned that you cannot change anything in your existing JavaScript code, you will need to somehow introduce the above JavaScript method. Fortunately, the WebBrowser control can also do for you by calling the eval () method:
WebBrowser.Document.InvokeScript("eval", javaScriptString);
For a more reliable and complete implementation, see the WebBrowser tools I wrote and an article explaining ScriptingBridge , which is specifically designed to solve the problem you are describing.
Christ a
source share