Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to change user agent in chromium embedded framework in c#?

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.

like image 872
user3463182 Avatar asked Mar 26 '14 08:03

user3463182


People also ask

What is Chromium user agent?

Yes, Chromium identifies itself as Chrome. Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.52 Safari/537.36. 'Course, the operating system and version are probably going to be different. Follow this answer to receive notifications.

How do I use CefSharp chromium?

To add CefSharp, go to the Solution Explorer on the Top Right of Visual Studio, then right click on your app (under the solution) and select Manage NuGet Packages. When the search menu appears, type cefsharp , select the WinForms distributtion and install it. Follow the installation setup (accept therms and install).


4 Answers

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

like image 166
Dmitry Azaraev Avatar answered Dec 15 '22 14:12

Dmitry Azaraev


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);

}
like image 42
Beep.exe Avatar answered Dec 15 '22 15:12

Beep.exe


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

like image 21
Sonal Avatar answered Dec 15 '22 15:12

Sonal


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";
like image 22
abbas derafshi Avatar answered Dec 15 '22 14:12

abbas derafshi