访问cookie ||来自内容脚本的localSorage - Chrome扩展程序

时间:2010-08-12 15:47:22

标签: scripting cookies google-chrome-extension local-storage

有没有办法访问 cookies ||来自内容脚本 localSorage

例如我有 localStorage.shBox ='true'

我希望从内容脚本访问此内容..我该怎么做?

1 个答案:

答案 0 :(得分:4)

要访问扩展程序的localStorage,您需要向后台页面发送请求:

在script.js中:

chrome.extension.sendRequest("getStorageData", function(response) {
    console.log("response:", response);
}

在background.html中:

chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
    if(request === "getStorageData") {
        sendResponse(localStorage["data"]);
    }
});

Cookie API详细介绍here