LoginSignup
2
2

More than 5 years have passed since last update.

Mac版Firefoxのバグっぽいやつとその対策

Last updated at Posted at 2012-04-29

試した環境

  • Mac OS X Lion 10.7.3
  • Firefox 12.0 or 13.0
  • Firefox 11.0 のときは観測されなかった(多分)

事象

Mac版FirefoxでWebWorkerを使っていると「応答のないスクリプト」ダイアログが表示される。

再現

下記のようなWebWorker経由のタイマー(別タブを選択しても精度が落ちなくなる)を使ったとき、特に何も処理をしていなくても「応答のないスクリプト」ダイアログが表示される。

window.js
var worker = new Worker("./timer.js");
worker.onmessage = function() {}; // 何もしていないのに..
worker.postMessage(null);    
worker.js
// timer.js
this.onmessage = function() {
  setInterval(function() {
    postMessage(null);
  }, 100);
};  

デモのページ
http://dl.dropbox.com/u/645229/webworkertest/index.html
.

対策

無駄なコードを挟むと出なくなる。
おそらくメインスレッド外からの割り込みがあれば良い?

window-with-uglypatch.js
var worker = new Worker("./timer.js");
worker.onmessage = function() {};
worker.postMessage(null);

setInterval(function() {}, 1000); // これがあれば出なくなる???

デモのページ
http://dl.dropbox.com/u/645229/webworkertest/uglypatch.html

ugly-patch

この問題は発生する環境が限られているため、スクリプト内にこういうのを書いておけば良い。

ugly-patch.js
if (/mac.*firefox/i.test(navigator.userAgent)) {
    setInterval(function() {}, 1000);
}
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2