6

After using the webbrowser control for some time, I decided to give gecko a try, because of the webbrowser's problems that I've experienced, low speed and degrading performance. I downloaded the latest version of geckofx (16.0.0.2) and xulrunner(16.0.2) and created a geckoWebbrowser control. When I tried to navigate to a webpage I got a javascript.alert that my web browser is not supported and that I should use firefox>2.0.0.2 which of course is ridiculous. The problem was - I assume - that the detected useragent string was "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0) Gecko/ /16.0" instead of the normal firefox string "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0". '20100101' and 'Firefox' are missing from the control's useragent string. Is there any way to change it using C#? I use C# winforms .net 4.5.

Nikola Anusev
  • 6,940
  • 1
  • 30
  • 46
pzogr
  • 424
  • 1
  • 12
  • 30
  • Please post some links or additional information on compilation. – Dennis Alexander Feb 01 '13 at 19:33
  • I'm not sure what you're looking for... I'll give you some links, hoping to answer your question. GeckoFX = "https://bitbucket.org/geckofx", XULRunner="http://ftp.mozilla.org/pub/mozilla.org/xulrunner/releases/". The question has already been answered. – pzogr Feb 02 '13 at 11:32

1 Answers1

12

From the http://www.webprogrammingblog.com/geckofx-set-user-agent/:

public Form1()
{
    InitializeComponent();
    Gecko.Xpcom.Initialize("c:\\tools\\xulrunner");
    myBrowser = new GeckoWebBrowser();
    myBrowser.Parent = this;
    myBrowser.Dock = DockStyle.Fill;

    string sUserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; pl; rv:1.9.1) Gecko/20090624 Firefox/3.5 (.NET CLR 3.5.30729)";
     Gecko.GeckoPreferences.User["general.useragent.override"] = sUserAgent;
}
Nikola Anusev
  • 6,940
  • 1
  • 30
  • 46
  • Absolutely magnificent! Thank you! I just had to replace the skybound part because it doesn't exist any more. The final command goes like this: Gecko.GeckoPreferences.User["general.useragent.override"] = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0"; – pzogr Feb 01 '13 at 19:38