Changing the UserAgent

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

Changing the UserAgent

Postby mnmccarry » Tue Sep 29, 2009 9:08 am

Hi.

I'm using CEF to embed a browser pane inside a wxWidgets app, replacing an IEHtmlWin ActiveX component. I've managed to get most of the functionality that IE was used for set up and working within CEF and I have really enjoyed using this component.

One of the last things that I need to get working is to modify the user agent to add the name of the app onto the end of the user agent string.

I thought that I would be able to do this in the Request Object before a navigation is made via the HandleBeforeBrowse method of the handler but I've not found a way to make this change within the request object.

I'm sure that there is something simple that I am overlooking but any pointers in the correct direction to modify the User Agent string would be very much appreciated. Ideally I would like to modify the string from :

Mozilla/5.0 (Windows; U; Windows NT 5.1;en-US) AppleWebKit/530.10 (KHTML, like Gecko)/1, 0, 0, 1 Safari/530.10

to:

Mozilla/5.0 (Windows; U; Windows NT 5.1;en-US) AppleWebKit/530.10 (KHTML, like Gecko)/1, 0, 0, 1 Safari/530.10 (MyApplicationName)

Any suggestions will be very much appreciated.

Many thanks in advance,

Martin McCarry
mnmccarry
Newbie
 
Posts: 4
Joined: Tue Sep 29, 2009 8:55 am

Re: Changing the UserAgent

Postby magreenblatt » Tue Sep 29, 2009 9:36 am

Hi Martin,

Setting the UserAgent is not currently exposed by the CEF API. You can, however, modify the BrowserRequestContext::GetUserAgent() method in browser_request_context.cc to return your custom string.

Regards,
Marshall
magreenblatt
Site Admin
 
Posts: 12408
Joined: Fri May 29, 2009 6:57 pm

Re: Changing the UserAgent

Postby mnmccarry » Tue Sep 29, 2009 9:49 am

Thanks Marshall.

I had hoped to create a roll in replacement for the IE component using the prebuilt cef dll, but I guess there's no escaping having to build the framework to add this string in, hehe that would have been too easy!

You've done a great job with this component and many thanks for pointing me in the right direction! :)

Martin
mnmccarry
Newbie
 
Posts: 4
Joined: Tue Sep 29, 2009 8:55 am

Re: Changing the UserAgent

Postby joshuaanderson » Thu Dec 05, 2013 9:55 pm

Hello. I was wondering if this advice is still the same, as I can't find the browser_request_context.cc file.
joshuaanderson
Techie
 
Posts: 19
Joined: Thu Sep 26, 2013 8:55 pm

Re: Changing the UserAgent

Postby magreenblatt » Thu Dec 05, 2013 10:28 pm

joshuaanderson wrote:Hello. I was wondering if this advice is still the same, as I can't find the browser_request_context.cc file.

These days you can set the user agent string via CefSettings.user_agent. For example:
Code: Select all
CefString(&settings.user_agent) = "MyBrowser/1.0";
magreenblatt
Site Admin
 
Posts: 12408
Joined: Fri May 29, 2009 6:57 pm

Re: Changing the UserAgent

Postby asarchit65 » Wed Mar 26, 2014 1:36 am

magreenblatt wrote:
joshuaanderson wrote:Hello. I was wondering if this advice is still the same, as I can't find the browser_request_context.cc file.

These days you can set the user agent string via CefSettings.user_agent. For example:
Code: Select all
CefString(&settings.user_agent) = "MyBrowser/1.0";





In which file have i to make changes to change useragent?
asarchit65
Techie
 
Posts: 11
Joined: Fri Jul 12, 2013 9:13 pm

Re: Changing the UserAgent

Postby TheoR74 » Tue Apr 15, 2014 1:13 pm

Is there a way to Just Append to the current user agent information?
TheoR74
Techie
 
Posts: 15
Joined: Wed Apr 09, 2014 11:22 am

Re: Changing the UserAgent

Postby magreenblatt » Tue Apr 15, 2014 1:16 pm

TheoR74 wrote:Is there a way to Just Append to the current user agent information?

No.
magreenblatt
Site Admin
 
Posts: 12408
Joined: Fri May 29, 2009 6:57 pm

Re: Changing the UserAgent

Postby magreenblatt » Tue Apr 15, 2014 1:17 pm

asarchit65 wrote:In which file have i to make changes to change useragent?

Wherever your application is calling CefInitialize.
magreenblatt
Site Admin
 
Posts: 12408
Joined: Fri May 29, 2009 6:57 pm

Re: Changing the UserAgent

Postby TheoR74 » Tue Apr 15, 2014 1:35 pm

magreenblatt wrote:
TheoR74 wrote:Is there a way to Just Append to the current user agent information?

No.


Then, is there a away to get the current value before making a change? Or is it not really set at that point? Basically, all I want to do is append to the browser cap, the name of my custom browser along with the other information.
TheoR74
Techie
 
Posts: 15
Joined: Wed Apr 09, 2014 11:22 am

Next

Return to Support Forum

Who is online

Users browsing this forum: No registered users and 70 guests