WebWorkers をテストしようとしている次のコードがあります。次のような index.html ファイルがあります。
<html>
<head></head>
<body>
<script type='text/javascript'>
var worker = new Worker('./myworker.js');
console.log('after creation');
worker.addEventListener('message', function(msg){
console.log(msg);
});
worker.postMessage();
</script>
</body>
</html>
myworker.js (index.html と同じディレクトリにある) の内容は次のとおりです。
this.onmessage = function(){
postMessage('got the msg, thanks');
};
(Chrome 14で)index.htmlをロードすると、「作成後」のconsole.logは発生しません。他にも何もありません。Console.logs は new Worker() の作成前に発生しますが、その後は何も発生しないようです。