I'm trying to capture click event from a WPF Browser Control webpage. I've created an ObjectForScriptingHelper class:
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
[ComVisible(true)]
public class ObjectForScriptingHelper
{
    public void Invoke()
    {
        MessageBox.Show("Hello");
    }
}
And in the constructor of the WPF Window hosting the Web Browser control I'm using this helper class as the ObjectForScripting:
public MainWindow()
{
    InitializeComponent();
    StandardWpfBrowser.ObjectForScripting = new ObjectForScriptingHelper();    
}
I then have a Uri variable ViewPageUri which I navigate to:
StandardWpfBrowser.Navigate(ViewPageUri);
Then in the page displayed by the browser control I have referenced jquery, added a button the html page and added javascript:
$('button').click(function () {
    if (window.external === null)
        alert('ObjectForScripting is not set');
    else
    {
        alert('ObjectForScripting is set');
        window.external.Invoke();
    }
})
The else branch is being executed but error message object doesn't support property or method 'Invoke' is thrown.
All the tutorials and MSDN docs follow the approach above. Am I missing something?
In case anyone else has this same issue. It turned out that naming the method Invoke was the problem. Once I changed the method name it all worked as expected.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With