flienteen
flienteen

Reputation: 234

Access cookies || localSorage from content script - Chrome extension

Is there any way to access cookies || localSorage from content script?

for example i have localStorage.shBox='true'

and I want to access this from content script.. how can I make this?

Upvotes: 3

Views: 2482

Answers (1)

serg
serg

Reputation: 111335

In order to access extension's localStorage you need to send a request to your background page:

In script.js:

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

In background.html:

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

Cookies API is described in details here.

Upvotes: 4

Related Questions