1

ページをリロードするときに保存されていないように見える理由がわかりません(オブジェクトをストレージに保存しているように見えますが.

関連するコードは次のとおりです。

options.js

function saveSettings(){
 var settings = {
    "blockComments": document.querySelector("input[name='BlockComments']:checked"),
    "visualDisplay": document.getElementById("visualDisplay").options[document.getElementById("visualDisplay").selectedIndex],
    "shortcut": document.querySelectorAll("[data-shortcut-key] option:checked")
 };
 // Store options object
 chrome.storage.sync.set({"data": settings}, function() {
    // Update status to let user know options were saved.
    var status = document.getElementById('status');
    status.textContent = 'Options saved.';
    setTimeout(function() {
        status.textContent = '';
    }, 2000);
 });
}
// This is called on DOMContentReady and is triggered
function restoreSettings(){
  chrome.storage.sync.get("data", function(items) {
    console.log(items.data); // Returns empty object(s)
  });
}

console.log に表示される内容:

ここに画像の説明を入力

なぜ空なのかわからない。何か助けはありますか?

4

1 に答える 1

1

DOM ノード (JSON シリアル化できない) を保存しようとしています。

必要なプロパティを抽出し、代わりに保存します。

// Returns true or false
document.querySelector("input[name='BlockComments']).checked

それ以外の

// Returns an element or nothing depending on its state
document.querySelector("input[name='BlockComments']:checked")
于 2015-02-27T18:27:41.430 に答える