I've been having trouble with my html5 web worker. The web worker postMessage()'s a JSON object to the document-level javascript that invoked the worker, which comes with an onmessage() function.
Apparently the "iterationsjob" key can be accessed as the worker can process the associated number value, but this seems to only work in Google Chrome and it still raises the error:
18Uncaught TypeError: Cannot read property 'iterationsjob' of null
In Firefox, the web worker does not work at all and doesn't seem to be able to access the numbers either, I'm getting a successful ajax call but it seems to bypass the logging steps and raise another error with a separate ajax call.
So I hacked together a basic way for workers to log() messages back to the console, and invoked them from within the worker:
var iterations
//get iteration data from the server
p.ajax.post({
url:'/getdataurl',
dataType: "json",
success: function(responseText){
log("test");
log("responseText is "+responseText);
iterations = responseText.iterationsjob;
log("iterations is "+iterations);
}
});
I expected to see the following:
test
responseText is [object Object]
iterations is 3993547
Instead, I see:
test
responseText is [object Object]
iterations is 3993547
test
responseText is null
Uncaught TypeError: Cannot read property 'iterationsjob' of null
Could anybody explain what the problem is and how to fix it?
EDIT: I've uploaded a zip of the source code here. Runs on Google App Engine.
Thanks! any help much appreciated.
Ah, turns out that I needed to add an empty success callback function to the second ajax call. for some reason it calls the first success callback by default if there is none defined...
Related
When a Google App Engine endpoint API is called immediately once the page is loaded, the following error is thrown. I need to wait for few seconds to call the API.
Then is same when the page is reloaded by some other means, say called from an other page etc.
I have tried adding a callback to call the API after few milliseconds $timeout(queryCallback, 100, false); The results are the same.
Is this a AngularJS error or resource load error? How to solve the error, please share your comments.
angular-1.2.16.min.js:89 TypeError: Cannot read property 'queryInfo' of undefined
at h.$scope.queryInfoAll (controllers.js:641)
at $scope.queryInfo (controllers.js:616)
at angular-1.2.16.min.js:119
at e (angular-1.2.16.min.js:37)
at angular-1.2.16.min.js:40
controllers.js:641
gapi.client.database.queryInfo().execute(function (resp) {
}
In looking at the Java endpoints example here, you use endpoints in javascript by initializing via a call to
<script src="https://apis.google.com/js/client.js?onload=init"></script>
...which calls the JS method named "init", which is a method name of your choosing. This is, however, a plain ole JS method that is unaware of the AngularJS lifecycle. In your init method, it seems you explicitly init your specific endpoint library, as in:
gapi.client.load(apiName, apiVersion, callback, apiRoot);
So, in your "run()", you may have to ask if "gapi" exists and defer until it is. You would then call "gapi.client.load()" with the callback function set.
I'm playing around with implementing a JavaScript server ping tool based on the accepted answer given on this question: Is it possible to ping a server from Javascript?. This essentially works by assuming the pinged server is down if no response has been given after n milliseconds.
That's great, and it's a pretty cool way of doing it, however there are two rather large pitfalls:
Not all servers do respond within the allocated time.
Sometimes an ERR_CONNECTION_TIMED_OUT error is thrown before our timeout timer has finished.
Both of these things cause incorrect results. The former suggests that the server is offline when it's possibly online and responding slowly, and the latter suggests the server is online when it's (likely) offline.
In an ideal world this code would capture what type of error thrown was thrown and handle this appropriately. After all, if the error thrown is a 404 Not Found error, this counter-intuitively means the server is online and has responded.
If we log the image error event, the only thing we see surrounding the error is:
Event {
...
type: "error"
}
There's no message or anything hinting at what the error thrown was, and both the 404 and ERR_CONNECTION_TIMED_OUT errors give identical information.
What can I do to capture the ERR_CONNECTION_TIMED_OUT error I see in Chrome's JavaScript console, rather than relying on a fixed-speed timer?
Update
The best way I can replicate this issue is by altering Trante's JSFiddle demo (as linked to in the question I've linked above) to use a 30000ms timer rather than a 1500ms timer:
this.timer = setTimeout(function () {
if (_that.inUse) {
_that.inUse = false;
_that.callback('timeout');
}
}, 30000);
The 'unknown' server should obviously not respond, but instead we see this:
In Chrome's console, the following error has been thrown:
Failed to load resource: net::ERR_NAME_NOT_RESOLVED
As the Image's onerror function has been fired with the generic error as given above, the function believes this to mean that 1. 'unknown' exists, and 2. it's online. The ERR_NAME_NOT_RESOLVED error appears to be something which only Chrome is aware of, and isn't passed through to the error event at all.
Update 2
Today I tried doing this with web sockets instead of images and unfortunately these suffer from the same problem. The only data surrounding the error returned is type: "error" - no information about what the error actually was.
From the Chrome console window of my Chrome app, I'm making these calls:
window.navigator.appVersion.match(/Chrome\/(.*?) /)[1];
"37.0.2062.120"
chrome.identity.getProfileUserInfo(console.log)
undefined
Why is the callback (console.log) never called? It should print a userInfo object returned w/o needing network IO. I'm getting no callback in the console, or in the code run in my app.
The API is here: https://developer.chrome.com/apps/identity#method-getProfileUserInfo
What did I miss?
Thanks!
console.log is not a JavaScript function. Pass a function (an anonymous function will do) with an argument to the API call, and see if you get something then. Also, this API requires that the manifest.json file have "identity" permission, and (1) you may not have that in the manifest, or (2) you do, but somehow the API call isn't permitted when typing directly to the console (something I personally have never done). If your tests indicate that #2 is a possibility, put the API call into a JavaScript file and try it that way.
I am using chrome.extension.onRequest.addListener, I see that I am calling sendResponse with no arguments (=> sendResponse(); ), Sometimes I get an error like this:
Error: Attempting to use a disconnected port object
Must I call sendResponse, or I can remove this function if I am not expecting to get a response from the background?
The documentation says:
Function to call (at most once) when you have a response.
This "at most once" sort of indicates that sending a response is optional. While I won't be able to get you an official confirmation, I checked the source code of my extension and there are several messages where sendResponse isn't being called - so far (after a year of heavy use) no issues.
I'm developing this extension https://builder.addons.mozilla.org/addon/1022928/latest/
The code central to this question is in Data/panel.js
And it's working pretty well, except that whenever I hit "Gem" to post a jquery call, it just hangs at the loading icon, I don't get any feedback in the console as to why the call is not going through and being processed as it should.
So how do I debug that with the new firefox add-on sdk builder beta. I've tried writing to console.log(), and I've read that it's supposed to work for others, but I really can't see any of my log messages, just errors that are synchronous in code, and hence not ajax errors.
Returning to my question: How do I debug a hanging ajax call in my firefox extension's panel?
HTTPFox extension shows that your request was sent successfully and result is a 500 Internal Error response. So jQuery would have called an error callback - but you didn't give it any (see jQuery.post() documentation, the third parameter is the success callback). To define an error callback you should ideally use jQuery.ajax() method directly:
$.ajax({
type: "POST"
url: url,
data {title:$("#txtTitle").val(), url:encodeURIComponent(taburl)},
success: function(data, textStatus) {
...
},
error: function(data, textStatus) {
...
}
});
Or you could use the request package of the Add-on SDK that provides similar API.
To sum up: you don't see an error message because there was no error. In case of errors you should indeed expect an exception that will be visible in Error Console if not caught.