Currently attempting to develop a straightforward chrome extension, however encountering challenges when trying to access the options.html's local storage from my content script "auto.js".
After researching and navigating through Chrome's convoluted documentation, it seems that this can only be achieved using:
chrome.runtime.sendMessage & chrome.runtime.onMessage.addListener
In the content script "auto.js":
var quantity = ""
var shoe_size = ""
function addToCart() {
chrome.runtime.sendMessage({localstorage: "qty"}), function(response){
var quantity = response.qty;
}
chrome.runtime.sendMessage({localstorage: "size"}), function(response){
var shoe_size = response.size;
}
...
The listener in "options.js":
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse){
if(request.localstorage == "qty")
sendResponse({qty: localStorage.qty});
else if(request.localstorage == "size")
sendResponse({size: localStorage.size});
else
sendResponse({});
});
...
The issue lies in the fact that my quantity
& shoe_size
variables never receive the values stored in the local storage of the html.
No errors are appearing in my JavaScript console and troubleshooting this problem is proving to be a challenge. Any insights or suggestions would be highly appreciated.