-
-
Save letanure/1e2a7af77c61e007e8a652dd583dca89 to your computer and use it in GitHub Desktop.
Chrome.storage.sync example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "SyncExtension", | |
"version": "0.1", | |
"manifest_version": 2, | |
"description": "Storage Sync Extension", | |
"permissions": [ "storage" ], | |
"browser_action": { | |
"default_popup": "popup.html" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="ja"> | |
<head> | |
<meta charset="utf-8" /> | |
</head> | |
<body> | |
<div id="data"></div> | |
<input type="text" id="text"></input> | |
<button id="set">Set</button> | |
<script src="popup.js"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// popup.js | |
document.body.onload = function() { | |
chrome.storage.sync.get("data", function(items) { | |
if (!chrome.runtime.error) { | |
console.log(items); | |
document.getElementById("data").innerText = items.data; | |
} | |
}); | |
} | |
document.getElementById("set").onclick = function() { | |
var d = document.getElementById("text").value; | |
chrome.storage.sync.set({ "data" : d }, function() { | |
if (chrome.runtime.error) { | |
console.log("Runtime error."); | |
} | |
}); | |
window.close(); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hi, i am able to store data using chrome.storage.sync.set(); and retrieve using chrome.storage.sync.get();
chrome.storage.sync.set({ "key" : JSON.stringify(value) }, function() {
console.log('async success');
});
chrome.storage.sync.get("key", function (response) {
console.log(JSON.parse(Object.values(response)));
});
now on click of a plugin icon , a new tab should open showing the stored data graphically. how to achieve.?