Open Prezi inside the android app - javascript

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.

Related

htmlunit - Get new page after excuting a JavaScript function

I have an HtmlPage by WebClient. This page (HtmlPage) has a button, I want to click that button to get a new page (another page). But when I clicked that button, the result returned the same page with the original page. Below is my code:
import com.gargoylesoftware.htmlunit.*;
import com.gargoylesoftware.htmlunit.html.*;
import java.net.URL;
public class GetLink2 {
public static void main(String[] args) throws Exception {
URL url = new URL("https://fptshop.com.vn/");
String userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:58.0) Gecko/20100101 Firefox/58.0";
WebRequest request = new WebRequest(url);
request.setAdditionalHeader("User-Agent", userAgent);
//request.setAdditionalHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:57.0) Gecko/20100101 Firefox/57.0");
WebClient webClient = new WebClient(BrowserVersion.FIREFOX_52);
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.setJavaScriptTimeout(20000);
webClient.getOptions().setJavaScriptEnabled(true);
webClient.getOptions().setCssEnabled(true);
webClient.getOptions().setUseInsecureSSL(true);
webClient.waitForBackgroundJavaScript(5000);
HtmlPage page = webClient.getPage(request);
for (DomElement input : page.getElementsByTagName("input")) {
if (input.getAttribute("placeholder").contains("tìm") ||
input.getAttribute("placeholder").contains("Tìm")) {
System.out.println(input.asXml());
System.out.println("Set element focused: " + page.setFocusedElement(input));
input.setAttribute("id", "my_input_search");
System.out.println("Element focused: " + page.getFocusedElement());
//pageResult = page.pressAccessKey((char) DOM_VK_RETURN).getHtmlPageOrNull().getUrl();
//System.out.println("Result: " + pageResult.toString());
//System.out.printf("Result: %s%n", input.fireEvent(String.valueOf(KeyboardEvent.DOM_VK_RETURN)).getJavaScriptResult().toString());
break;
}
//System.out.println(htmlElement.asXml());
//result.getNewPage();
//System.out.println("result: "+ result.getNewPage().getUrl());
}
System.out.println("Input search: " + page.getElementById("my_input_search"));
String jsScript = "var element = document.getElementById('my_input_search');" +
"element.value = 'iphone 7';" +
"element.addEventListener('keypress', function (e) {" +
"console.log(e.key, e.char, e.keyCode)});" +
"var e = new KeyboardEvent('keypress', {" +
"bubbles: true, cancelable: true, char: 'Enter',key: 'enter', keyCode: 13});" +
"element.dispatchEvent(e);";
System.out.println("Input Search After Set Value: " + page.getElementById("my_input_search"));
page.executeJavaScript(jsScript);
Thread.sleep(20000);
page.getPage();
System.out.println("Result " + page.getPage());
}
}
Can everyone help me please, thanks for reading my question.
You are loosing your result, because
page.executeJavaScript(jsScript);
returns a ScriptResult, you should do
Page newPage = page.executeJavaScript(jsScript).getNewPage();
System.out.println("Result " + newPage);

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

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.

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();
}

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.

JWPlayer Javascript API for Android Webview

I'm trying to get JWPlayer to return an alert when a few specific events happen from a flash player playing a local video. If you notice from the code below, onComplete, JWPlayer should return an alert, which can then be intercepted by onJsAlert from setWebChromeClient so I can do stuff with that information. Am I doing something wrong?
A possible reason, I can find here: JWplayer Javascript interaction not working that it's being loaded locally. Is there any way I can bypass this issue? Would it be easier to load somehow by calling localhost? Is that even possible?
For those of you curious about why I generate an HTML file instead of just having one move from the assets - after scouring the Internet to figure out how to get a local flv player working correctly, the best option was to generate the HTML file with the custom information and write the file to the same directory as the FLV (hence the FileWriter function).
HTML code for JWPlayer embed:
private void createVideoHtml(File flvDirectory, File htmlFile, String videofilename)
{
String htmlPre = "<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"utf-8\"></head><body style='margin:0; padding:0;'>";
String htmlCode =
"<script type='text/javascript' src='"+ flvDirectory.getAbsolutePath() + "/jwplayer.js'></script>" +
"<div id='mediaspace'>EZ Stream TV FLV Player</div>" +
"<script type='text/javascript'>" +
"jwplayer('mediaspace').setup({" +
"'flashplayer': '"+ flvDirectory.getAbsolutePath() + "/player.swf', 'file': '" + videofilename + "', 'backcolor': 'FFFFFF', 'frontcolor': '000000', 'lightcolor': '000000'," +
"'screencolor': '000000', 'volume': '100', 'autostart': 'true', 'mute': 'false', 'quality': 'false', 'controlbar': 'bottom', 'width': '100%', 'height': '100%'," +
"events: { " +
"onComplete: function() { alert('COMPLETED');}" +
"}});" +
"</script>";
String htmlPost = "</body></html>";
String finalHTML = htmlPre + htmlCode + htmlPost;
try {
FileWriter f = new FileWriter(htmlFile);
PrintWriter p = new PrintWriter(f);
p.print(finalHTML);
p.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Code for webview and handling the Javscript alert:
webView = (WebView)findViewById(R.id.web_player);
webView.getSettings().setBuiltInZoomControls(false);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setLoadsImagesAutomatically(true);
webView.getSettings().setPluginsEnabled(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webView.getSettings().setAllowFileAccess(true);
webView.setInitialScale(60);
webView.setBackgroundColor(Color.BLACK);
getWindow().addFlags(128);
webView.getSettings().setUserAgentString("Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 (.NET CLR 3.5.30729)");
webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
webView.setWebChromeClient(new WebChromeClient() {
#Override
public boolean onJsAlert(WebView view, String url, String message, final android.webkit.JsResult result)
{
Log.d(TAG, message);
new AlertDialog.Builder(view.getContext()).setMessage(message).setCancelable(true).show();
result.confirm();
return true;
}
});
You can refer to the code below for JWPlayer to Webview
private void createVideoHtml(File flvDirectory, File htmlFile, String videofilename)
{
String htmlPre = "<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"></head><body style='margin:0; padding:0;'>";
String htmlCode =
"<script type='text/javascript' src='"+ flvDirectory.getAbsolutePath() + "/jwplayer.js'></script>" +
"<div id='mediaspace'>EZ Stream TV FLV Player</div>" +
"<script type='text/javascript'>" +
"jwplayer('mediaspace').setup({" +
"'flashplayer': '"+ flvDirectory.getAbsolutePath() + "/player.swf', 'file': '" + videofilename + "', 'backcolor': 'FFFFFF', 'frontcolor': '000000', 'lightcolor': '000000'," +
"'screencolor': '000000', 'volume': '100', 'autostart': 'true', 'mute': 'false', 'quality': 'false', 'controlbar': 'bottom', 'width': '100%', 'height': '100%'," +
"events: { " +
"onComplete: function() { alert('COMPLETED');}" +
"}});" +
"</script>";
String htmlPost = "</body></html>";
String finalHTML = htmlPre + htmlCode + htmlPost;
try {
FileWriter f = new FileWriter(htmlFile);
PrintWriter p = new PrintWriter(f);
p.print(finalHTML);
p.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
webView = (WebView)findViewById(R.id.web_player);
webView.getSettings().setBuiltInZoomControls(false);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setLoadsImagesAutomatically(true);
webView.getSettings().setPluginsEnabled(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webView.getSettings().setAllowFileAccess(true);
webView.setInitialScale(60);
webView.setBackgroundColor(Color.BLACK);
getWindow().addFlags(128);
webView.getSettings().setUserAgentString("Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 (.NET CLR 3.5.30729)");
webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
webView.setWebChromeClient(new WebChromeClient() {
#Override
public boolean onJsAlert(WebView view, String url, String message, final android.webkit.JsResult result)
{
Log.d(TAG, message);
new AlertDialog.Builder(view.getContext()).setMessage(message).setCancelable(true).show();
result.confirm();
return true;
}
});
I had the same problem while working with jwplayer, my conclusion was that the onComplete event isn't trustable in some cases.
Can you benchmark other events does work like the onTime event ?
Otherwise use the onIdle event and measure the time left ( getDuration - getPosition ) to get a custom onComplete event.

Categories

Resources