0

I have been trying to figure out how I can capture the close-web-view and console-message signals from WebKit in webkit-sharp (unfortunately I have to use webkitsharp as available on Ubuntu 16.04 packaging).

I thought I had this working, however it seems I do not.

First, I override the WebView class:

public class MyWebView : WebKit.WebView
{
   [Signal("console-message")]
   public event ConsoleSignalHandler ConsoleMessage {
      add {
         Signal signal = Signal.Lookup(this, "console-message", typeof(ConsoleSignalArgs));
         signal.AddDelegate(value);
      }
      remove {
         Signal signal = Signal.Lookup(this, "console-message", typeof(ConsoleSignalArgs));
         signal.RemoveDelegate(value);
      }
   }
}

I also have ConsoleSignalArgs defined as:

public class ConsoleSignalArgs : SignalArgs {

    public String Source {
        get {
            return (String)base.Args [3];
        }
    }

    public Int32 Line {
        get {
            return (Int32)base.Args [2];
        }
    }

    public String Message {
        get {
            return (String)base.Args [1];
        }
    }
}

And ConsoleSignalHandler defined as:

public delegate void ConsoleSignalHandler(object o, ConsoleSignalArgs e);

I then instantiate my web view and attach to this event, however nothing happens. I can tell the console messages are being sent as I can see them on the console, however these look to be from the WebView itself not my code.

private void CreateWebView() {
    this.m_webView = new MyWebView();

    this.m_webView.Editable = false;
    this.m_webView.TitleChanged += (o, e) => {
        this.Title = "Title Changed Got Fired!";
    };
    this.m_webView.ConsoleMessage += (sender, e) => {
        Console.WriteLine("Console Message Got Here!");
                    Debug.WriteLine("Got Here!");
    };
}

What am I doing wrong?

Addendum: I also notice that when I stop the code in the debugger and inspect "signal" the property Handler throws a NullReferenceException.

Justin
  • 196
  • 1
  • 3

1 Answers1

0

Found the issue. Turns out anonymous delegates don't work with some signals. This was the correct solution FYI:

this.m_webView.ConsoleMessage += new ConsoleSignalHandler(this.ConsoleMessage);

...

[ConnectBefore]
private void ConsoleMessage(System.Object sender, ConsoleSignalArgs e) {
    Console.WriteLine("Console Message got Here!");
}
Justin
  • 196
  • 1
  • 3