Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set user agent in GeckoFX?

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.

like image 903
pzogr Avatar asked Feb 01 '13 19:02

pzogr


People also ask

What is user agent in HTTP header?

The User-Agent request header is a characteristic string that lets servers and network peers identify the application, operating system, vendor, and/or version of the requesting user agent.

How do I use user agent?

Just right click on any page and select your user-agent. This Chrome extension adds a toolbar button and a menu to switch between user-agents. Browse with our predefined user-agents or add your own user-agents. Changing User-Agent allows you to mimic, spoof or fake other browsers, devices or search engine spiders.

Why do all user agents start with Mozilla?

Why do so many browser user agents start with Mozilla? Mozilla was the name of the Netscape project and that was used as browser agent string. Some scripts checked that so that competing browsers used something Mozilla compatible (e.g. IE) and so all other browsers ended up using Mozilla with something.


1 Answers

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;
}
like image 108
Nikola Anusev Avatar answered Sep 23 '22 02:09

Nikola Anusev