In my content script, I set a a couple chrome.storage
values, and in my popup script, I read and get those values.
I've tried everything, but it keeps returning "undefined" which doesn't make sense because the value is certainly not undefined.
My content.js script:
imgs=["test.png","othertest.png"]
for (i = 0; i < imgs.length; i++){
var key = "image"+i
var value = imgs[i]
chrome.storage.sync.set({key: value}, function() {
console.log('Value is set to ' + value + ' and key is set to '+key);
})
}
chrome.storage.sync.set({"count": imgs.length}, function() {
console.log('Saved count value. Current count: '+imgs.length)
});
My popup.js script:
document.addEventListener('DOMContentLoaded',function(){
chrome.storage.sync.get(['count'], function(result) {
console.log(result.value)
for (i = 0; i < result.value; i++){
chrome.storage.sync.get(['image'+i], function(result) {
var img = document.createElement("img")
img.src = result.value
document.body.appendChild(img)
})
}
})
})
My popup.html file:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<h1>Images</h1>
<script src="popup.js"></script>
</body>
</html>
The popup.js
script is supposed to get every image from chrome.storage and display them on the popup. Any help would be greatly appreciated.