We're writing a spotify app which uses the showAuthenticationDialog-Dialog for inviting users facebook friends.
Inviting works, but the Popup-Windows doesn't close on Windows (on a Mac it does!).
The Code looks like that:
var redir = "https://server/services/callback/facebook/apprequest/?source=spotify&user_id=" + uID;
var data = "user_id=" + session.otheruser.id;
var url = "http://www.facebook.com/dialog/apprequests?app_id=" + FB_APP_ID + "&message=" + encodeURIComponent( msg ) + "&redirect_uri=" + encodeURIComponent( redir ) + "&display=popup&data=" + encodeURIComponent( data );
auth.showAuthenticationDialog(url, 'http://moosify.com', {
onSuccess : function(response) {
console.log("Success! Here's the response URL: " + response);
},
onFailure : function(error) {
console.log("Authentication failed with error: " + error);
},
onComplete : function() { }
});
Server is acutally our server URL. (Which is in the manifest.json)
Related
I am writing a script that does a lookup for a domain, then will iterate through each IP for reachability.
For instance, if you look up google.com, there are 6 IPs. I want to go to google.com, but force it to use each IP, returning 6 different results.
I have everything, except how do I use the IP? If I just specify the IP, it fails as the servers don't respond to the IP - site is bound to the domain.
I am using npm & electron if that helps...
function checkConnection(myIP, myPort, myDomain) {
var isAccessible = null;
var url = "https://" + myDomain + ":" + myPort;
console.log(myDomain + " check at "+ url);
$.ajax({
url: url,
type: "get",
cache: false,
dataType: 'text',
timeout : 1500,
complete : function(xhr, responseText, thrownError) {
if(xhr.status != "404") {
isAccessible = true;
console.log(myDomain + " check at "+ url + " passed");
console.log(xhr);
return true;
}
else {
isAccessible = false;
console.log(myDomain + " check at "+ url + " failed");
console.log(xhr);
return false;
}
}
});
}
I am developing a SAPUI5-App. Is there a way to show all errors directly to the customer without having to put a try-catch-block into every callback of sapui5? He will use my app in a mobile device and wouldn´t be able to see the log.
I tried already the following code:
<script type="text/javascript">
window.onerror = function(msg, url, line, col, error) {
var extra = !col ? '' : '\ncolumn: ' + col;
extra += !error ? '' : '\nerror: ' + error;
alert("Error: " + msg + "\nurl: " + url + "\nline: " + line + extra);
return false; //true = suppress error alert
};
window.addEventListener("error", handleError, true);
function handleError(evt) {
if (evt.message) {
alert("error: "+evt.message +" at linenumber: "+evt.lineno+" of file: "+evt.filename);
} else {
alert("error: "+evt.type+" from element: "+(evt.srcElement || evt.target));
}
}
jQuery.sap.log.addLogListener({
onLogEntry : function(oLogEntry) {
if(oLogEntry.level == '1'){
alert(oLogEntry.details + ' - '+oLogEntry.message);
}
}});
</script>
But I like to actually copy the error-message from the log into an alert for the customer, so he can send me screenshots of the error in his device.
All my attempts did not show enough information or didn´t fire on every error in the console-log.
I've been trying to get Android push notifications working for my app for a little while now (iOS already completed) and have everything sorted out besides just getting the notification to actually show up on the Android device.
Registering the device id's, and pushing to the GCM server all seem to be working fine, but when I test what the message in the response back from GCM is returning I keep getting undefined.
All responses when pushing the message to GCM are success, correct device id's, a message id associated with it etc. Anyone able to point me in the right direction? Below you will see the code snippet with just a sample "alert" being used to display what is coming back that will end up being used as the notification in the "push".
This alert
alert('message = ' + e.message + ' payload message: ' + e.payload.message +
' e payload msgcnt: ' + e.payload.msgcnt + ' e.msg: ' + e.msg);
doesn't seem to be getting anything back to display the push.
function onDeviceReady() {
console.log('deviceready');
try {
pushNotification = window.plugins.pushNotification;
if (device.platform == 'android' || device.platform == 'Android' || device.platform == 'amazon-fireos') {
console.log('PN register');
pushNotification.register(successHandler, errorHandler, {
"senderID": "177718756870",
"ecb": "onNotification"
}); // required!
console.log('after PN register');
} else {
console.log('PN register');
pushNotification.register(tokenHandler, errorHandler, {
"badge": "true",
"sound": "true",
"alert": "true",
"ecb": "onNotificationAPN"
}); // required!
console.log('after PN register');
}
}
catch (err) {
txt = "There was an error on this page.\n\n";
txt += "Error description: " + err.message + "\n\n";
console.log("ERROR", txt);
}
}
var pushNotification;
// handle GCM notifications for Android
window.onNotification = function(e) {
console.log('EVENT RECEIVED ' + e.event)
console.log("regID BEFORE CHECKS = " + e.regid);
switch( e.event )
{
case 'registered':
if ( e.regid.length > 0)
{
console.log("regID = " + e.regid);
var data =
{
'device_id': e.regid,
'platform': device.platform,
'os_version': device.version,
'app_version': lawnmowerConfig.versionString,
'device_model': device.model
};
localStorage.setItem('push_data', JSON.stringify(data));
}
break;
case 'message':
console.log('Inside case message: ' + e.regid)
if (e.foreground)
{
// Add something to play a sound once working
}
else
{
if (e.coldstart) {
console.log("coldstart");
}
else {
console.log("not coldstart");
}
}
alert('message = ' + e.message + ' payload message: ' + e.payload.message + ' e payload msgcnt: ' + e.payload.msgcnt + ' e.msg: ' + e.msg);
break;
case 'error':
alert('GCM error = ' + e.msg);
break;
default:
// Testing using these alerts instead
alert('An unknown GCM event has occurred');
break;
}
};
function tokenHandler (result) {
console.log('push token handler');
console.log(result);
var data =
{
'device_id': result,
'platform': device.platform,
'os_version': device.version,
'app_version': lawnmowerConfig.versionString,
'device_model': device.model
};
localStorage.setItem('push_data', JSON.stringify(data));
}
function successHandler (result) {
console.log('success handler push success');
console.log("result: " + result);
}
function errorHandler (error) {
console.log('push error');
}
document.addEventListener('deviceready', onDeviceReady, true);
Registering the device id's, and pushing to the GCM server all seem to be working fine, but when I test what the message in the response back from GCM is returning I keep getting undefined.
It means that when you are testing "what the message .... is" you are referencing a variable not yet defined. In this line:
alert('message = ' + e.message + ' payload message: ' + e.payload.message +
' e payload msgcnt: ' + e.payload.msgcnt + ' e.msg: ' + e.msg);
there is no variable e.message. The data that you send from your server is attached to e.payload and value of e.event is set to message. I think your problem can be solved if you remove e.message. Something like:
alert('event = ' + e.event + ' payload message: ' + e.payload.message +
' e payload msgcnt: ' + e.payload.msgcnt + ' e.msg: ' + e.msg);
Note To detect variable issues (scope and/or declaration), debug one variable at a time. This will help you to precisely identify a problem and trace it to its origin.
I would advise you to use
alert("Payload message: " + e.payload.message);
How can i see javascript errors from within a Phonegap App?
Currently I am trying to use this:
window.onerror = function(msg, url, linenumber) {
console.error('Type: ' + typeof msg + '\nError message: ' + msg + '\nURL: ' + url + '\nLine Number: ' + linenumber);
return true;
};
But nothing shows up on screen or in weinre I am using.
I am developing a browser extension using crossrider.
I have added a context menu (background.js)
var ContextData;
appAPI.contextMenu.add("key1", "Send Data To Server", function (data) {
var ContextData = 'pageUrl: ' + data.pageUrl + '\r\n' +
'linkUrl: ' + data.linkUrl + '\r\n' +
'selectedText:' + data.selectedText + '\r\n' +
'srcUrl:' + data.srcUrl;
}, ["all"]);
On user click I want to send ContextData to extension.js. At extension.js some function will receive the data and send it to my server (A Rest API which will accept the data).
To send data to the server I have tested this and it works fine (code sample in extension.js)
appAPI.ready(function($) {
var dataToSend =="test data";
appAPI.request.post({
url: 'REST API URL',
postData: dataToSend,
onSuccess: function(response, additionalInfo) {
var details = {};
details.response = response;
},
onFailure: function(httpCode) {
// alert('POST:: Request failed. HTTP Code: ' + httpCode);
}
});
});
How can I write a function to accept ContextData from background.js and assign it to dataToSend in extension.js?
#Neel If I understand your requirements correctly, #Rob is essentially correct though a little clarification may help
By design/architecture, the extension.js code runs on each HTML page i.e. a separate extension.js instance is run for each URL that loads. In contrast, the context menu runs at the browser level (not HTML page) and is hence correctly coded in background.js file. However, the background.js code does not have direct access to the extension.js instance code running on the HTML page in the active tab and must therefore communicate the data via messaging. (For more information about scopes, see Scopes Overview)
Obviously, a user clicks the context menu item on the active tab (i.e. the page showing the HTML page being viewed); hence, once the ContextData string is created, you can use appAPI.message.toActiveTab to send the string to the extension.js instance running on the page/tab where the the context menu item was clicked.
This being the case, using your code example you can achieve this goal as follows:
background.js:
appAPI.ready(function($) {
var ContextData;
appAPI.contextMenu.add("key1", "Send Data To Server", function (data) {
var ContextData = 'pageUrl: ' + data.pageUrl + '\r\n' +
'linkUrl: ' + data.linkUrl + '\r\n' +
'selectedText:' + data.selectedText + '\r\n' +
'srcUrl:' + data.srcUrl;
appAPI.message.toActiveTab({type:'dataToSend', data: ContextData});
}, ["all"]);
});
extension.js:
appAPI.ready(function($) {
var dataToSend =="test data";
appAPI.message.addListener(function(msg) {
if (msg.type === 'dataToSend') {
appAPI.request.post({
url: 'REST API URL',
postData: dataToSend,
onSuccess: function(response, additionalInfo) {
var details = {};
details.response = response;
},
onFailure: function(httpCode) {
// alert('POST:: Request failed. HTTP Code: ' + httpCode);
}
});
}
});
});
[Disclaimer: I am a Crossrider employee]