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.
Related
i am developing an application and loading an hosted application using the inapp browser plugin cordova-plugin-inappbrowser
I have gotten most of the functionalities to work but i am unable to get the part of loading an error message when he url does not load, it dosent just work and shows me an error message of the url where i have hosted my application instead.
Which could be embarrassing.
please i need help on this
This is what am working with below thanks for ur potential responses
// my child browser code, the main source of my app content
function fire(){
var ref = cordova.InAppBrowser.open('http://####################', '_blank', 'location=no,zoom=no,hardwareback=yes,clearsessioncache=yes,clearcache=no');
var myCallback = function(event) { alert(event.url); }
ref.addEventListener('loadstart', inAppBrowserbLoadStart);
ref.addEventListener('loadstop', inAppBrowserbLoadStop);
ref.addEventListener('loaderror', loadErrorCallBack);
ref.addEventListener('exit', inAppBrowserbClose);
}
function loadErrorCallBack(params) {
$('#status-message').text("");
var scriptErrorMesssage =
"alert('Sorry we cannot open that page. Message from the server is : "
+ params.message + "');"
inAppBrowserRef.executeScript({ code: scriptErrorMesssage }, executeScriptCallBack);
inAppBrowserRef.close();
inAppBrowserRef = undefined;
}
function executeScriptCallBack(params) {
if (params[0] == null) {
$('#status-message').text(
"Sorry we couldn't open that page. Message from the server is : '"
+ params.message + "'");
}
}
Your code is generally fine, but you have no control over the title of the alert() function. You can use some other techniques to display the error message. For example, you can use a div:
function loadErrorCallBack(params) {
$('#status-message').text("");
var scriptErrorMesssage = createMsg('Sorry we cannot open that page. Message from the server is: '
+ params.message);
inAppBrowserRef.executeScript({
code: scriptErrorMesssage
}, executeScriptCallBack);
inAppBrowserRef.close();
inAppBrowserRef = undefined;
}
function createMsg(msg) {
return 'var div = document.createElement("div");'
+ 'div.style.position = "absolute";'
+ 'div.style.top = "50%";'
+ 'div.style.left = "50%";'
+ 'div.style.width = "100px";'
+ 'div.style.height = "100px";'
+ 'div.style.color = "#f00";'
+ 'div.innerHTML = "' + msg + '";'
+ 'document.appendChild(div);'
}
When working on Selenium user-extension, how can you call a Selenium Command?
When debugging Selenium User Extension, how can you echo/console.log ?
Could find the answer on the internet so I'm posting my own answer below
To call a Selenium Command in user-extension.js, you need to use this syntax
this.doCommandName(param)
ie, to call echo
Selenium.prototype.doMyFunction = function(){
this.doEcho("This info will show on logs");
}
Perhaps this works even better. As now the debug messages of your user extension are similar as the debug and info messages of 'build-in' commands.
Selenium.prototype.doYourCommand = function(strTarget, strValue) {
LOG.debug("begin: doBaseURL | " + strTarget + " | " + strValue + " |");
LOG.info(strValue);
LOG.debug("end: doBaseURL | " + strTarget + " | " + strValue + " |");
}
I am trying to test a simple Ajax script using Javascript and I'm not receiving a response. The PHP script is placed in the htdocs folder of the local server and the HTML page that includes the Ajax calls is placed on my desktop. A readyState of 4 is received from the server but the status returned is 0, not 200.
The error generated on Firefox state:
NS_ERROR_DOM_BAD_URI: Access to restricted URI denied.
Here is the section of code responsible for calling the Ajax object:
var myRequest = getXMLHttpRequest();
function callAjax() {
var url = "localhost/clock.php";
var myRandom = parseInt(Math.random()*99999999);
myRequest. open("GET", url + "?rand=" + myRandom, true);
myRequest.onreadystatechange = responseAjax;
myRequest.send(null);
}
function responseAjax() {
if(myRequest.readyState == 4) {
if(myRequest.status == 200) {
var now = new Date();
var localTime = now.getHours() + ":" + now.getMinutes() + ":" + now.getSeconds();
var serverTime = myRequest.responseText;
document.getElementById("clock").innerHTML = "Server: " + serverTime + "<br />Local: " + localTime;
} else {
alert("An error has occurred: " + myRequest.statusText);
}
}
}
Can anyone offer insight to my problem?
OSX 10.8.5
MAMP version 2.1.3
You say your file is on the desktop. You cannot open a local file ( file:// ) and do ajax. You need to access the file through your Apache server ( http:// ).
I have a Flash app set up in a Facebook canvas and it's using ExternalInterface to call a JavaScript function, then calling a Flash function from JavaScript when the first function completes:
Flash objects & vars:
this.dBug.text += "\ngetting user albums...\n"
var usrAlbums:Array = new Array();
var pageLimit:Number = 48;
var pageOffset:Number = 0;
this.dBug.text += "\ttotal albums before call: " + usrAlbums.length + "\n";
Callback function:
this.dBug.text += "\tadding getAlbumResponse callback to ExternalInterface\n";
ExternalInterface.addCallback('getAlbumResponse', getAlbumResponse);
this.dBug.text += "\tcreating getAlbumResponse callback\n";
function getAlbumResponse(rtrn):void{
dBug.text += "\nresponding to album get...\n";
this.dBug.text += "\t\t\tresult: " + rtrn['data'] + "\n";
var album:Array = rtrn['data'];
this.dBug.text += "\t\tadding objects to usrAlbums array...\n";
for(prop in rtrn['data']){
usrAlbums.push(new Array(album[prop], new Array()));
this.dBug.text += "\t\t\tadded " + album[prop] + ", new Array() to usrAlbums array\n";
++pageOffset;
this.dBug.text += "\t\t\t\talbumCount: " + pageOffset + "\n";
}
this.dBug.text += "\tcheck for more albums\n";
if(pageOffset == pageLimit){
getAlbum(++pageOffset, pageLimit);
}else{
this.dBug.text += "\t\ttotal albums after call: " + usrAlbums.length + "\n";
}
}
ExternalInterface call function to JavaScript:
function getAlbum(offset:Number, limit:Number){
this.dBug.text += "\t\tcalling swfGetAlbum(/me/albums?offset=" + offset + "&limit=" + limit + ")...\n";
ExternalInterface.call('swfGetAlbum', '/me/albums?offset=' + offset + '&limit=' + limit);
}
Call the EI function:
getAlbum(pageOffset, pageLimit);
Javascript on hosting page:
function swfGetAlbum(graph){
console.log('swfGetAlbum(' + graph + ')');
FB.api(graph, function(response){ console.log(response); swfGetAlbumCallback(response); });
}
var swfGetAlbumCallback = function(response){
console.log(response);
console.log(document.getElementById('app-root'));
document.getElementById('app-root').getAlbumResponse(response);
}
Everything works fine on my Mac under my Facebook account on Chrome, Safari, Opera and Firefox. It also works under the same browsers on my testing PC, and additionally on Internet Explorer.
For some reason when my friend tests the app using his Facebook account, he gets an error when the Javascript code initiates the callback and attempts to run document.getElementById('app-root').getAlbumResponse(response);. He is testing on his own PC with the same browsers, all producing the same result. Under Chrome, the error reads as Uncaught Error: Error calling method on NPObject.
To make things more interesting; this error appears when he is testing the app on MY machine using his Facebook account and does not happen when I test the app on HIS machine using my Facebook account.
I've also been able to test the app with two other Facebook accounts. One of them on my Mac under Safari and another on my friend's wife's PC using Chrome. Neither of those tests had the error.
The target version for Flash for this app is at least v11 (all tested machines/browsers have the latest Flash player,) and inserted into the page using swfobject 2.
I am totally baffled by this behavior. Anyone come across something like this?
Thanks in advance!
Total shot in the dark that we even tried this...
To conform with Facebook's https, we're on a secure server. We checked under my friend's settings to discover that the https browsing setting was unchecked. Once it was checked again, everything worked.
I need help how to use correctly the javascript : "document.cookie" or
how to write cookie from javascript in Android web browser ?
I've make sure in the settings that cookie is enabled. When I checked
by using "navigator.cookieEnabled", it returns true as well.
I've a piece of javascript code as follow that has been working
everywhere
( e.g. PC browsers, iPhone ), but doesn't work in Android.
function createCookie(name) {
// cookies expired in 1 year.
var expDate = new Date();
expDate.setDate(expDate.getDate() + 365);
expDate = expDate.toGMTString();
var el = document.getElementById(name);
document.cookie = name + '=' + escape(el.value) + '; path=/ ;expires=' + expDate;
document.cookie = name + '-idx=' + escape(el.selectedIndex) + ';path=/ ; expires=' + expDate;
//alert('cookie : ' + document.cookie);
}
When I open the 'alert' comment in the last line of code, Android will
just show blank while
all other browsers show me the content of the cookie that I've just
written.
Please help.
Thanks.
I got this thing working, for Android 2.2, javascript's document.cookie works fine, just make sure that in your Webview...javascript is enabled like so:
yourWebViewVariable.getSettings().setJavaScriptEnabled(true);
for Android 3.1 just add this to your java file onLoadInit:
CookieManager.setAcceptFileSchemeCookies(true); //This is the line that specifically makes it work so the other lines is optional
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.setAcceptCookie(true);
cookieManager.acceptCookie();
Also, here's a few links that I found while I was trying to figure this error out, this could be helpful for others that wants to Send variables from Javascript to the Webview(Native Android Language) and Vise versa.
http://android-er.blogspot.com/2011/10/run-android-java-code-from-webpage.html
http://android-er.blogspot.com/2011/10/call-javascript-inside-webview-from.html
Thanks and Goodluck!
Ok, now I really got it (window.cookie, lol).
Just remove the space in the path definition. Seemed to work on my phone.
Edit: Put all the strings on one line too, I think it screwed up the parsing.
function createCookie(name) {
// cookies expired in 1 year.
var expDate = new Date();
expDate.setDate(expDate.getDate() + 365);
expDate = expDate.toGMTString();
var el = document.getElementById(name);
document.cookie = name + '=' + escape(el.value) + '; path=/; expires=' + expDate;
document.cookie = name + '-idx=' + escape(el.selectedIndex) + '; path=/; expires=' + expDate;
//alert('cookie : ' + document.cookie); }