Czarek wrote:ndesktop wrote:As of 4430:
- paying/G suite login just works
- free accounts (gmail.com, accounts.google.com, youtube.com etc.) do not work.
In order to make it work a patched CEF using another accepted user agent is now required.
So from what I understand seting CefSettings.user_agent is not enough, because that changes only HTTP header. You also need to change user agent in JavaScript possibly by injecting custom js code. And that resolves the issue?
As I mentioned, I solved this by patching CEF.
I am not using custom JS code (I suppose what I did is similar to what you mean by "injecting custom JS code", only I needed on C++ level because I am integrating in a C++ solution).
In short, what I have done is:
- add a new method to CefRequestHandler
- Code: Select all
///
// Gives the opportunity to override user agent before the request becomes
// readonly.
///
virtual bool GetOverrideUserAgent(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefDictionaryValue> request_info,
CefString& overrideUserAgent) {
return false;
}
If a client implements this method, it should set overrideUserAgent and return true, otherwise return false for the default behavior.
|request_info| is currently a dictionary of strings, with various keys (currently only "url" is defined) for passing data from the request handler wrapper (InterceptedRequestHandlerWrapper - see below) to the client.
- This will be overriden in cefclient's ClientHandler by combining passed |request_info| and decide using application custom logic if a certain UA should be used, for example if |requst_info| has an "url" key and the host of this url is gmail.com, then set overrideUserAgent to "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0" and return true.
- the implementation is called from InterceptedRequestHandlerWrapper::OnBeforeRequest; after
- Code: Select all
request->headers.SetHeaderIfMissing(net::HttpRequestHeaders::kUserAgent,
init_state_->user_agent_);
is called, then the last chance if offered to the client by calling CefRequestHandler::GetOverrideUserAgent.
If this returns true and the returned UA is not empty, then another call to is issued with the value returned from client (excerpt from 90 patched):
- Code: Select all
...
// Add standard headers, if currently unspecified.
request->headers.SetHeaderIfMissing(
net::HttpRequestHeaders::kAcceptLanguage,
init_state_->accept_language_);
request->headers.SetHeaderIfMissing(net::HttpRequestHeaders::kUserAgent,
init_state_->user_agent_);
+ // if browser says otherwise, override with it
+ std::string browser_user_agent =
+ GetUserAgentFromBrowser(init_state_->browser_, request->url);
+ if(!browser_user_agent.empty()) {
+ request->headers.SetHeader(net::HttpRequestHeaders::kUserAgent,
+ browser_user_agent);
+ }
+
const bool is_external = IsExternalRequest(request);
...
GetUserAgentFromBrowser is a helper function that calls GetOverrideUserAgent (it just creates a CefDictionaryValue, set "url" key to url.spec() and does the call).
Until now, it seems working.