here is what I have done:
- I downloaded, installed and run the firefox extension SDK
- Created a whole new extension with ctx init
- Opened lib/main.js
- This is what I wrote there:
var Request = require("request").Request;
console.log("Here I am!");
Request({
url: "http://www.google.com",
onComplete: function (response) {
console.log(response.responseText);
}
});
Run the extension with ctx run
It perfectly prints out "Here I am!", then nothing happens. No exception is thrown, no errors, nothing. But the url doesn't seem to get loaded.
What happened? Did I do something wrong?
Thank you very much!
Matteo
Silly me. I forgot to actually submit the request using the .get() function.
Related
We have multiple marketplace Apps that use Gmail Contextual Gadgets. These have been running for years successfully.
We are now noticing the following intermittent error being thrown when calling out to an external web server using open social osapi.http.post
"{"id":"http.post","error":{"message":"Response not valid JSON","code":406}}"
We have checked and there is nothing wrong with our server. We can make the call directly to our server successfully without fail.
We can replicate the issue calling to multiple servers running different apps/gadgets. The only commonality appears to be the use of osapi.http.post.
Here is the post
osapi.http.post({
'body': postdata,
'href': serverUrl + 'iLinkStreamer.ashx?data=' + "" + setTimeStamp() + debugString,
'format': 'json',
'authz': 'signed',
'noCache': true
}).execute(displayStreamList);
which raises the 406 error as above
Has anybody else noticed this issue?? Not sure how we can address it?
I had the same issue for a while and finally found the problem. I was also invoking external resources using osapi.http.post. I read the new documentation and found that there is a new way to do the same.
Check this url for more details, but the idea is that now you'll need to use makeRequest API, it will look something like this:
var params = {};
params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.JSON;
params[gadgets.io.RequestParameters.AUTHORIZATION] = gadgets.io.AuthorizationType.SIGNED;
params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST;
gadgets.io.makeRequest("https://your.backend.com", on_response_function, params);
...
def on_response_function(response){ ... }
I hope this helps someone.
I'm not sure if I'm the only one, but I never received a notification message that the previous API will be deprecated. :(
I have an external javascript file that calls a setinterval function that checks a cfc for file transfer completion between server and a remote computer. When I call this function with standard error handler it works. Soon as I add the custom error handler it fails. Im dumb founded.
File_transfer.js
{
Function check_stream_server ()
Ajax call to query, application scoped, query-object.
Path = "ss_check.cfc"
};
// exception log and response with custom error
// I work with no custom error handler
Function send_file ()
{
Ajax to Put file in object; // I work
Same ajax call to Start stream.
thread if not running; //I work
Setinterval (check_stream_server, 5000) //I set interval
}
}
}
Index.cfm null {
Include the file_transfer.js
<button>click </button>
<script>
Button.on ('click', function (){
Send_file()
})
</script>
}
Index.cfm, check_ss.cfc, and the object_insert.cfc are all in same folder. Js is in external lib folder.
Sorry that this code sucks but I'm typing this from phone and won't be able to sleep tonight or be dreaming about it all night.
If it helps I'm also running a compiled archive.
It was a bug in setting the cf admin on update error. There was a remote clients = arrayofclients that was not removed from someone copying and pasting the example in the docs. I had a work around that worked by initializing the functions into the proper scopes in the initial cfm page, but later found out it was a bug when setting the custom error handler
I'm creating my first Firefox extension using the Addon SDK, but I can't get messages I pass with console.log() to appear in my debugger.
I created a new profile in Firefox 33 and installed the latest version of Firebug. When I launch my addon using cfx run -p <My_Profile_Directory> I can see both Firebug and my addon, and the addon does what it's supposed to do. However, I don't see anywhere messages I wrote to log using the console.log() command
Here's my main.js so far:
function loginToSite(user, password) {
var Request = require("sdk/request").Request;
var doLogin = Request(
{
url: "https://website.com/login/index.php",
contentType: "application/x-www-form-urlencoded",
content: "username=xxxx&password=xxxx&remember=1",
onComplete: function(response) {
console.log(response.text);
}
}
);
doLogin.post();
}
function checkLoginStatus(tab) {
//TODO Actually check if the tab is logged in, currently assume it's not
loginToSite(0,0);
}
// Listens for tabs and checks each loaded tab if it's the website
tabs.on("ready", function(tab) {
var tabUrl = tab.url.toLowerCase();
if(tabUrl.contains("website.com")) {
console.log("Not connected to website.com, running login procedure");
checkLoginStatus(tab);
}
});
Like I said, I'm actually being logged in automatically, but no log messages appear in either Firebug's or the Firefox Developer Tools' console.
What am I doing wrong here? Where are the log messages?
You have to change the default logging level (error) to something more verbose, like info.
The global level is controlled by the preference extensions.sdk.console.logLevel. But you can adjust the logging level of your extension only, with the preference extensions.myExtensionID.sdk.console.logLevel
When you run cfx without passing a profile directory, it takes care of setting up the temporary profile to be developer friendly.
I am trying to use object-oriented code to handle an AJAX upload. When I run the code, it sees the file, creates the XMLHttpRequest object, but I cannot seem to get the progress event to fire. The full source of my code can be found here: http://pastebin.com/89QawbS6
Here is a snippet:
var xhr = new XMLHttpRequest();
xhr.upload.addEventListener("progress", MyObj.trackProgress, false);
xhr.open("POST", url, true);
...
Then in that same object, different method:
trackProgress: function (event) {
console.log(event);
// stuff that should calculate percent
}
But that console.log(event) never fires.
Please note: I know jQuery is great, and there are a dozen awesome upload plugins that I could just use instead. I am not doing this for a class or homework, I just want to understand the process better myself. So offering a jQuery plugin as an answer is not what I'm looking for. I'm trying to make myself less dependent on jQuery.
This FF bug might be the reason for your issue. It's reported on MacOSX and another similar bug on Linux. I don't know if that matters but I tested on Windows. I still believe that your code is fine.
SlimerJS added a onAuthPrompt callback. Is it possible to get it to work with CasperJS?
I found mention that the phantomjs or slimerjs object is available as casper.page, and then the following answer said that casper.page is only available after calling casper.start(): https://stackoverflow.com/a/16629231/841830
So I tried this code. The onAuthPrompt code is taken from the documentation; I just added a log line to make sure it works.
casper.test.begin("first",function suite(test){
casper.start();
casper.page.onAuthPrompt = function (type, url, realm, credentials) {
console.log("onAuthPrompt: type="+type+",url="+url+",realm="+realm+",credentials="+credentials); //TEMP
credentials.username = "laurent";
credentials.password = "1234";
return true;
};
casper.thenOpen(url,function(){
console.log('Loaded:'+url);
test.assertSelectorHasText('#msg','');
this.capture('1.png');
});
casper.run(function(){test.done();});
});
It loads url (which does not require auth), then an XMLHttpRequest or EventSource connection is made, which is what requires authentication. I see the password prompt pop-up but my onAuthPrompt() function is not getting called.
Am I doing something wrong, or is this not what onAuthPrompt is for, or could it be a bug that I could report (but in that case, do you think the problem is in CasperJS or in SlimerJS?).
According to the documentation, the onAuthPrompt callback was added in version 0.9.0, which has yet to be released.
You can check the documentation from the master branch of the Git repo here.
There is also the latest released documentation (v0.8.3) here