Set userAgent at runtime.

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.

Set userAgent at runtime.

Postby devpo » Wed Oct 12, 2016 7:48 am

I am trying to change userAgent for specific browser instance, but i can't find any information about it. Only found how to setup userAgent at CefInitialize.

Maybe someone can help me?

Thnx
devpo
Newbie
 
Posts: 1
Joined: Thu Oct 06, 2016 2:50 pm

Re: Set userAgent at runtime.

Postby GoodGuySoft » Fri Mar 10, 2017 9:42 am

I have the same issue, it looks like CEF lacks this important feature. It is easy to change `User-Agent` header at runtime, however, JavaScript value for user agent will leave unchanged. Browser recreation just to change user agent doesn't look like good idea.
GoodGuySoft
Newbie
 
Posts: 9
Joined: Fri Sep 30, 2016 7:19 am

Re: Set userAgent at runtime.

Postby fddima » Fri Mar 10, 2017 9:51 am

Each CEF user can has own vision of usefullness of some features. Can you be bit more detailed about actual use case?

Also UA can be defined by providing custom CefRequestContext, but you need create new CefBrowser to utilize it.
fddima
Master
 
Posts: 788
Joined: Tue Dec 07, 2010 6:10 am

Re: Set userAgent at runtime.

Postby GoodGuySoft » Fri Mar 10, 2017 10:17 am

Can you be bit more detailed about actual use case?

When application uses CEF to simulate other browser (for example, to show mobile version of website), it needs an easy way to change user agent both in HTTP headers and JavaScript.
So, if you have application similar to Chrome device toolbar where you can enable mobile view and change your device with drop down control, you have to recreate entire browser just to change 1 string in its settings. JavaScript navigator object is read only, so it is impossible to use JavaScript injection to bypass the problem.
Actually any automated web pages test framework based on CEF may need to change user agent.
GoodGuySoft
Newbie
 
Posts: 9
Joined: Fri Sep 30, 2016 7:19 am

Re: Set userAgent at runtime.

Postby Czarek » Fri Mar 10, 2017 2:06 pm

Have you tried to delete the navigator object using C++ API in the renderer process? And then mock it using javascript or C++.
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am

Re: Set userAgent at runtime.

Postby GoodGuySoft » Fri May 12, 2017 9:18 am

BTW it is impossible to recreate browser, because CefShutdown will simply hang entire process. CEF can not reinitialize. So, the only way to change user agent is to restart entire process. It actually means that CEF doesn't support user agent change.
GoodGuySoft
Newbie
 
Posts: 9
Joined: Fri Sep 30, 2016 7:19 am


Return to Support Forum

Who is online

Users browsing this forum: salvadordf and 28 guests