Note that there are some explanatory texts on larger screens.

plurals
  1. POweb workers behave differently in webkit than Firefox
    primarykey
    data
    text
    <p>I have a web application that works just fine in modern webkit-based browsers (<a href="http://montecarlo-tester.appspot.com" rel="nofollow">http://montecarlo-tester.appspot.com/</a>). Basically it uses a webworker to fetch data from a server, and then sends it back after performing some computations.</p> <p>It works just fine in Chrome/Safari (no errors in console), but when I try to use it in Firefox, it doesn't. I've deduced that somehow the variable 'iterations' is not set properly in Firefox. Unfortunately, Firefox lacks a debugger (for web workers), and javascript has functional scoping, so it's really hard to pinpoint where the problem is. I've posted the javascript code for my web worker, and I was wondering if anybody could point out where I went wrong:</p> <pre><code>importScripts('/static/js/mylibs/jquery.hive.pollen-mod.js'); $(function (data) { main(); //while(main()); close(); }); function main() { //make an ajax call to get a param var iterations//value will be set by server response var key//key of the datastore object var continueloop = true; p.ajax.post({ url:'/getdataurl', dataType: "json", success: function(responseText){ if (responseText === null) { var workermessage = { "log":"responseText is null. Either the server has issues or we have run out of stuff to compute." }; $.send(workermessage); continueloop = false; } iterations = responseText.iterationsjob; key = responseText.key; } }); if (continueloop === false) { return false; } //here is where I think the problems begin. In chrome/safari, iterations = 1000. //In Firefox however, iterations = null. As a result, everything after that does not work. var i,x,y,z; var count = 0; var pi; start = new Date(); for (i=0;i&lt;iterations;i++) { x = Math.random(); y = Math.random(); z = x*x+y*y; if(z&lt;=1.0){ count++; } }//end for loop pi = count/(iterations)*4.0; end = new Date(); result = { "estimated_pi":pi, "num_iter":iterations, "duration_ms":end.valueOf()-start.valueOf(), "key":key }; //send results to the server p.ajax.post({ url: "/resultshandler", dataType:'json', data: result, success: function() { //do nothing! } }); $.send(result); return true;//persists the loop } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload