WebKit.WebView has a Settings.UserAgent option, but that only has a get() method defind, so I can't set the value. I can't seem to find anywhere else that it might be.
Asked
Active
Viewed 774 times
1 Answers
0
Okay, this is how to do it...
Override the WebKit.WebSettings class and access the GLib.Object protected member SetProperty:
class ExposedWebSettings : WebKit.WebSettings {
public void g_object_set(string name, GLib.Value value) {
SetProperty(name, value);
}
}
Then you can instantiate this object and call g_object_set to set any property...
WebView webView = new WebView();
ExposedWebSettings settings = new ExposedWebSettings();
settings.g_object_set("user-agent", new GLib.Value("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20120427 Firefox/15.0a1"));
webView.Settings = settings;
webView.Open ("http://www.google.com");
This is what GLib.Object.SetProperty looks like, by the way:
protected void SetProperty (string name, Value val)
{
IntPtr intPtr = Marshaller.StringToPtrGStrdup (name);
Object.g_object_set_property (this.Raw, intPtr, ref val);
Marshaller.Free (intPtr);
}

David Mulder
- 7,595
- 11
- 45
- 61