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が渡される」という現象でした。「これは不具合なんじゃないか」という意見をいくつか頂いたので報告をしたところ、やっぱりバグ認定されました。

Issue 175116: chrome.runtime.getBackgroundPage returns null if the event page has started but hasn’t finished loading

すでにコードの修正も済んでいて、コードレビューも通ったみたいです。

Diff of /trunk/src/chrome/browser/extensions/api/runtime/runtime_api.cc

これで将来のChromeのバージョンでは、getBackgroundPage()関数の呼び出しは特に何も気にすることなく使えるようになるでしょう。良かった良かった。

このエントリーをはてなブックマークに追加

関連記事

2023年のRemap

Remapにファームウェアビルド機能を追加しました

Google I/O 2023でのウェブ関連のトピック

2022年を振り返って

現在のRemapと今後のRemapについて