I'm following this example at: http://www.whatwg.org/specs/web-workers/current-work/
page.html
<!DOCTYPE HTML>
<html>
<head>
<title>Worker example: One-core computation</title>
</head>
<body>
<p>The highest prime number discovered so far is: <output id="result"></output></p>
<script>
var worker = new Worker('worker.js');
worker.onmessage = function (event) {
document.getElementById('result').textContent = event.data;
};
</script>
</body>
</html>
worker.js
var n = 1;
search: while (true) {
n += 1;
for (var i = 2; i <= Math.sqrt(n); i += 1)
if (n % i == 0)
continue search;
// found a prime!
postMessage(n);
}
This example works fine in firefox and Safari Version 5.0.2 (6533.18.5) on Mac OSX but doesn't work in chrome. When I debug it, worker.js is not even listed as one of the sources. What is bizarre is that the example page link on the same website works fine in chrome, which is the same code as my local code. But my local code doesn't work in chrome.
When I try to manually run code in Javascript debugger like this
var w = new Worker('worker.js')
I get an error saying:
Error: SECURITY_ERR: DOM Exception 18
Did anyone else have this experience? Can anyone suggest a solution?
Thanks