从chrome.storage中检索数组

时间:2017-01-13 16:23:24

标签: javascript arrays google-chrome-extension local-storage

我正在尝试使用chrome.storage来存储从 popup.js 收到的数组。

这是 background.js

chrome.runtime.onMessage.addListener(
    function (request, sender, sendResponse) {
        //obtains a unique array with all the urls the user entered to save
        var tabs = request.url; // receives array
        chrome.storage.local.set({tabs: tabs}, function () {});
    }
);
chrome.storage.onChanged.addListener(function (tabs) {
    chrome.storage.local.get("tabs", function () {
        storedInputs = tabs.tabs.newValue.concat(tabs.tabs.oldValue)
                           .filter(function (item, index, inputArray) { //removes duplicates
            return inputArray.indexOf(item) == index;
        });;
        console.log(storedInputs);
    });
});

当我查看存储的内容时,有两个名为oldValuenewValue的对象。 oldValue包含在打开扩展名之前带有术语的数组。 newValue包含新输入的字词。由于某些原因。我第一次打开弹出窗口并传递值时,它包含所有数据。下一次,仅存在从该特定实例输入的数据。

这是一个示例输出:
sample output

0 个答案:

没有答案
相关问题