Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top