I'm developing an application which will allow users to sign in with their Facebook account. Currently, I'm using Eclipse SWT browser to display the login-browsing window, which works great. However, I'd prefer if this web-browsing window got treated (and therefore styled) as an iPhone. I've tried to force the HTTP-headers to mimic the iPhone's; without any change.
My current code looks somewhat like this:
String[] headers = { "Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3" };
browser.setUrl("https://m.facebook.com/dialog/oauth?client_id=appId&redirect_uri=url&state=state", "", headers);
However, the Facebook website STILL realizes that I'm not an iPhone, which makes the output looks like this:
Whilist I'm looking for this design:
Related
Is there any way to exactly implement a "desktop mode" function into my mobile app when loading website content? I'm making a android app, and I want to have a page just with static website content just like in a web browser, I really like how mobile opera implemented this feature, So I just want to know if there is a way to do that. And if there is, then How?
(I'm making this project in Java and viewing the website using WebView from the library "WebKit")
I've also tried changing the User Agent, which didn't work on a static website.
This method helps you to set DesktopMode on webview
public void setDesktopMode(WebView webView,boolean enabled) {
String newUserAgent = webView.getSettings().getUserAgentString();
if (enabled) {
newUserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5)\nAppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/85\nVersion/11.1.1 Safari/605.1.15";
}
webView.getSettings().setUserAgentString(newUserAgent);
webView.getSettings().setUseWideViewPort(enabled);
webView.getSettings().setLoadWithOverviewMode(enabled);
webView.reload();
}
Call it like that
Mobile mode : setDesktopMode(webView, false);
Desktop mode : setDesktopMode(webView, true);
For Kotlin:
fun setDesktopMode(webView: WebView, enabled: Boolean) {
var newUserAgent: String? = webView.settings.userAgentString
if (enabled) {
newUserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5)\nAppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/85\nVersion/11.1.1 Safari/605.1.15"
}
webView.settings.apply {
userAgentString = newUserAgent
useWideViewPort = enabled
loadWithOverviewMode = enabled
}
webView.reload()
}
I set the user agent in webView
mWebview.getSettings().setUserAgentString(getString(R.string.str_user_agent));
String : Mozilla/5.0 (iPad; CPU OS 11_0 like Mac OS X) AppleWebKit/604.1.34 (KHTML, like Gecko) Version/11.0 Mobile/15A5341f Safari/604.1
When i set the user agent it fails to load some images. If anyone knows the reason or the answer please mention.
I have a query regarding the HTTP request.If i have one server side service which caters requests from different types of devices.How can i know from the HTTP request(user-agent) what type of device (android,IOS) is sending the request.
Thanks in advance.
Learner.
The user agent String will contain Strings such as iPhone, Android, etc...
You can search for such Strings in the user agent using, for example, userAgent.contains("Android").
Here are some sample user agent Strings :
For Android :
Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.133 Mobile Safari/535.19
For iPhone :
Mozilla/5.0(iPhone;U;CPUiPhoneOS4_0likeMacOSX;en-us)AppleWebKit/532.9(KHTML,likeGecko)Version/4.0.5Mobile/8A293Safari/6531.22.7
For iPad :
Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5355d Safari/8536.25
I would like to write java application using jcef3 and emulate that as mobile browser.
I do somethink like that:
#Override
public boolean onBeforeResourceLoad(CefBrowser cefBrowser, CefRequest cefRequest) {
Map<String, String> headerMap = new HashMap<String, String>();
Map<String, String> newHeaderMap = new HashMap<String, String>();
cefRequest.getHeaderMap(headerMap);
for (Map.Entry<String, String> entry : headerMap.entrySet())
{
if (entry.getKey().equals("User-Agent")) {
newHeaderMap.put(entry.getKey(), "Mozilla/5.0 (Linux; Android 4.3; GT-I9300 Build/JSS15J) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.114 Mobile Safari/537.36");
} else {
newHeaderMap.put(entry.getKey(), entry.getValue());
}
}
cefRequest.setHeaderMap(newHeaderMap);
return false;
}
Problem is with that one page that I would like browse like mobile detect that is some strange OS :) and I don't know why. If I download some plugin form chrome like user agent switcher and use the same UA then everything is ok, so I'm sure that that page use user agent verification.
Any idea?
Well, I solved that problem.
Generaly there are two ways to detect browser.
First one is request headers. My sample code show how to do that.
The secound one is javascript navigator property. That was the problem. Requests were sended with correct userAgent but javascript navigator.userAgent show bad user agent version that was different with that sended in request headers.
To do that correctly You should override javascript navigator.userAgent variable.
In CEF3 there is no problem with that to inject some javascript code that override that.
I want to search the following in Google query box:
http://www.cmu.edu/silicon-valley/ faculty directory
Unfortunately, the following code does not work:
Jsoup.connect("http://www.google.com/search?hl=en&q=http%3A%%2F%%2F%www.cmu.edu%2F%silicon-valley%2F%20faculty20directory").get();
nor does this one:
Jsoup.connect("http://www.google.com/search?hl=en&q=http%3A%%2F%%2F%www.cmu.edu%2F%silicon-valley%2F%20faculty20or20directory").get();
What am I missing here?
Edit: not working means Google didn't return any result as we see from browser.
Jsoup.connect("http://www.google.com/search?hl=en&q=http%3A%"%2F%%2F%www.cmu.edu%2F%silicon-valley%2F%20faculty").get();
The code above works though. It's equivalent to Googling "http://www.cmu.edu/silicon-valley/ faculty".
Edit: I have the following trick in my program, so bot-rule is not an issue:
.userAgent("Mozilla")
Jsoup.connect("http://www.google.com/search?hl=en&q=http%3A%2F%2Fwww.cmu.edu%2Fsilicon-valley%2F+faculty+directory") leads to a 403 error (Forbidden) as google forbis robots to access its results
You'll have to change the User Agent String if you want to do that
doc = Jsoup.connect("http://www.google.com/search?hl=en&q=http%3A%2F%2Fwww.cmu.edu%2Fsilicon-valley%2F+faculty+directory").header("User-Agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.52 Safari/537.17").get() should work as expected, but could be against Google's Terms of Use.