8

Please help me changing user agent of chromium embedded framework in visual c#. It uses default chromium agent but i want to change it to use my browser name instead.

user3463182
  • 81
  • 1
  • 1
  • 2
  • Just for information, I found the current default to be "User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36" for CefSharp 51.0.0 – CRice Sep 07 '16 at 06:46

4 Answers4

11

Use CefSettings.UserAgent. Also it can be configured via "user-agent" command-line switch.

Dmitry Azaraev
  • 1,093
  • 6
  • 9
  • Please explain me in detail, step by step. – user3463182 Mar 26 '14 at 14:50
  • 3
    CefSettings is class what instance passed at initialization step. Look into samples. You can't initialize CEF without it, so, i'm did not see what should be explained step-by-step. Read samples. Both, C++ and C#. There is easy, and almost same. – Dmitry Azaraev Mar 26 '14 at 23:22
  • i mean what tag, namespace, etc should i use in my project? – user3463182 Mar 27 '14 at 04:05
  • I'm did not understand what additional details you want. If you are CEF user, you should know about CefSettings class. – Dmitry Azaraev Mar 27 '14 at 18:30
  • I have done the following changes....... in cef web browser [DefaultValue("Mozilla/5.0 (Windows NT 6.2; rv:13.0) Gecko/20100101 Fire/1.0")] public string UserAgent { get; set; }----------------------------- and my form---------------- browser.UserAgent = "Mozilla/5.0 (Windows NT 6.2; rv:13.0) Gecko/20100101 Fire/1.0"; yet it does not work – user3463182 Mar 28 '14 at 03:13
  • Did you found CefSettings class? It has UserAgent property. It should pass into CefRuntime.Initalize method. – Dmitry Azaraev Mar 28 '14 at 17:34
  • This dialog is non-constructive. User agent can be changed, as i'm say in my answer. – Dmitry Azaraev Apr 02 '14 at 21:55
  • "In detail, step by step" instructions are dependent on your local environment and skillset and are therefore chargeable service you have to seek privately. Good luck. – Piotr Farbiszewski Aug 09 '22 at 11:03
7

i know its an old question but this might help someone, use the following code to change user-agent of cef-sharp 3x

ChromiumWebBrowser chromiumBrowser;

public Form1()
{

    InitializeComponent();

     CefSettings cfsettings=new CefSettings();
     cfsettings.UserAgent = "My/Custom/User-Agent-AndStuff";
     Cef.Initialize(cfsettings);

     chromiumBrowser = new CefSharp.WinForms.ChromiumWebBrowser("http://whatsmyuseragent.com/")
     {
        Dock = DockStyle.Fill,

     };


     this.Controls.Add(chromiumBrowser);

}
Beep.exe
  • 1,368
  • 12
  • 21
2

you can use by this code change the user agent in chromium

CefSettings settings = new CefSettings();
settings.UserAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1";
abbas derafshi
  • 307
  • 1
  • 11
1

Step by step:

  • Download XIlium cefglue and update the dlls. If you need any help in that use http://umaranis.com/2013/10/16/how-to-embed-chrome-browser-in-net-application/
  • Open your xilium cefglue application.
  • In solution explorer open CefRuntime.cs
  • There will be a public static void Initialize(CefMainArgs args, CefSettings settings, CefApp application, IntPtr windowsSandboxInfo) method, inside that method write settings.UserAgent = "Sonal";
  • Rebuild and run the application.
  • In the browser give the the following url: http://whatsmyuseragent.com/
  • You can find the Useragent as Sonal

Hope this helps

Sonal
  • 1,188
  • 2
  • 8
  • 10