Event pageを複数回取ろうとしたときの罠はバグでした
ちょっと前に「 Event pageを複数回取ろうとしたときの罠」というエントリをしました。これは、以下のようなコードを実行した時に、Event pageのwindowオブジェクトを最初の1回しか取得できない、っていう現象を報告したものでした。
chrome.runtime.getBackgroundPage(function(backgroundPage) {
console.log("1: " + backgroundPage);
});
chrome.runtime.getBackgroundPage(function(backgroundPage) {
console.log("2: " + backgroundPage);
});
chrome.runtime.getBackgroundPage(function(backgroundPage) {
console.log("3: " + backgroundPage);
});
chrome.runtime.getBackgroundPage(function(backgroundPage) {
console.log("4: " + backgroundPage);
});
chrome.runtime.getBackgroundPage(function(backgroundPage) {
console.log("5: " + backgroundPage);
});
chrome.runtime.getBackgroundPage(function(backgroundPage) {
console.log("6: " + backgroundPage);
});
chrome.runtime.getBackgroundPage(function(backgroundPage) {
console.log("7: " + backgroundPage);
});
厳密に言うと「Event pageの生成が完了しないうちにgetBackgroundPage()関数を呼ぶと、コールバック関数にnullが渡される」という現象でした。「これは不具合なんじゃないか」という意見をいくつか頂いたので報告をしたところ、やっぱりバグ認定されました。
すでにコードの修正も済んでいて、コードレビューも通ったみたいです。
Diff of /trunk/src/chrome/browser/extensions/api/runtime/runtime_api.cc
これで将来のChromeのバージョンでは、getBackgroundPage()関数の呼び出しは特に何も気にすることなく使えるようになるでしょう。良かった良かった。