-
-
Save IzumiSy/765cfd6dc02c79de875e to your computer and use it in GitHub Desktop.
| { | |
| "name": "SyncExtension", | |
| "version": "0.1", | |
| "manifest_version": 2, | |
| "description": "Storage Sync Extension", | |
| "permissions": [ "storage" ], | |
| "browser_action": { | |
| "default_popup": "popup.html" | |
| } | |
| } |
| <!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> |
| // 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(); | |
| } | |
Thanks! I solved my problem
window.close(); this function had using method close to sync data? I have issues when user type in textarea and must sync without close popup.html of extension. Anyone has meet same issues? @IzumiSy
@iletai No, you don't have to put window.close(). That method is only for closing popup here, not for any finalizing.
@iletai No, you don't have to put
window.close(). That method is only for closing popup here, not for any finalizing.
Yes. Thank you.
I am new in js i was trying to learn chrome storage api. I copy pasted exact your code but in console there was an error "can not read property sync of undefined" please help!.
I am new in js i was trying to learn chrome storage api. I copy pasted exact your code but in console there was an error "can not read property sync of undefined" please help!.
@maskmanlucifer I have trouble using chrome.storage, but maybe your issue comes from the fact that you didn’t write "permissions": ['storage'] in the manifest.json file
Thank u <3
@Adetona
It looks no way to do that without writing your own update logic like renaming the key of the value in updating with a new key-value pair.
No, there isn't.
Chrome.storage.synconly provides simple set/get methods. If you want to do that, you need to write your own CRUD operation logics.