0

Hello everyone :)

my other post where we solved the GET. Ok, I got the base working once again - i think. Now I really don't know how the SET command of chrome storage works.

This should set/save the value that is in a box with this ID: "ts_id_js_html"

var input_id = document.getElementById("ts_id_js_html").value;
chrome.storage.local.set({"ts_id_js": input_id});

This is where it (should)get the Value from:

<form>
   <input id="ts_id_js_html" type="text" value="128856"></input>
   <button id="execButton">Save/Load</button>
</form> 
Community
  • 1
  • 1
Frizzant
  • 684
  • 1
  • 7
  • 28
  • How are you running the code? Is it in an event listener attached to the button? – Barmar Dec 08 '16 at 11:13
  • Please [edit] the question to be on-topic: include a **complete** [mcve] that duplicates the problem. Including a *manifest.json*, some of the background *and* content scripts. Questions seeking debugging help ("**why isn't this code working?**") must include: ►the desired behavior, ►a specific problem or error *and* ►the shortest code necessary to reproduce it **in the question itself**. Questions without a clear problem statement are not useful to other readers. See: "**How to create a [mcve]**", [What topics can I ask about here?](http://stackoverflow.com/help/on-topic), and [ask]. – Makyen Dec 08 '16 at 11:18
  • How do you know your code is not working? You show nothing that retrieves the value using `chrome.storage.local.get()`. Thus, there is no indication that what you have written is not functioning correctly. We need a *complete* [mcve] which duplicates the problem. – Makyen Dec 08 '16 at 11:28
  • my main question is if this is a viable way of setting a value for a variable that is stored in the browser, or if I am totally wrong. Basically everything else needed is in the other question (should i add all that stuff here too?) `chrome.storage.local.set({"ts_id_js": input_id});` – Frizzant Dec 08 '16 at 12:05
  • @frizzant: BTW: If you want a specific person to be notified of your comment, you need to include their ID in your comment with an `@` in front of it. For instance, for me it would be `@Makyen`. If you do this as the first thing in your comment the system will provide auto-complete suggestions from those who have already posted comments on that answer/question. The original poster of the answer/question on which you are commenting will always be notified. This [meta post](http://meta.stackexchange.com/a/43020/271271) has more information. – Makyen Dec 08 '16 at 18:34
  • While it can be helpful to have a link to another question for context, each question should be sufficiently complete such that it can be answered on its own. Thus, yes, this question needs a [mcve] *and* the desired behavior, *and* a specific problem (what is not working, or how it is not currently doing what you want or error). I am still unclear what your actual issue is. If you're generally wondering if [`chome.storage.local`](https://developer.chrome.com/extensions/storage) (or `chome.storage.sync`, if appropriate) is a good way to store options data, then the answer to that is "Yes". – Makyen Dec 08 '16 at 18:46
  • @Makyen ooh lovely - thank you! Even tab works like on linux :D I actually got it working with this: `chrome.storage.local.set({"ts_id_js": input_id}, function (obj) { chrome.storage.local.get("ts_id_js", function (obj) { console.log("ts_id_js INSIDE func. test (is this your ID?):" + obj.ts_id_js); //this line is for test output in console });` Only issue now is, that it fails to get the input in the chrome extension for some reason. Whenever I try to GET the I need to first add `chrome.storage.local.get("ts_id_js", function (obj) {` infront of the code, anf close `});` – Frizzant Dec 09 '16 at 08:20

1 Answers1

0

I actually got it working with this:

chrome.storage.local.set({"ts_id_js": input_id}, function (obj) { chrome.storage.local.get("ts_id_js", function (obj) { console.log("ts_id_js INSIDE func. test (is this your ID?):" + obj.ts_id_js); //this line is for test output in console });

Only issue now is, that it fails to get the input in the chrome extension popup for some reason. Whenever I try to GET the ID I need to first add

chrome.storage.local.get("ts_id_js", function (obj) {

infront of the code, and then close it at the end

});

(if someone else uses this code, DON'T forget to change all parts that are necessary! (ts_id_js, input_id, obj (obj.ts_id_js))

Frizzant
  • 684
  • 1
  • 7
  • 28