Skip to main content
added 59 characters in body
Source Link
orschiro
  • 22.2k
  • 23
  • 70
  • 98

The problem is with chrome.storage.sync.set({key: testPrefs}

Your data is stored as

{ key: "{"val":10}" } 

So, your code chrome.storage.sync.get('myKey') return undefined\empty object.

Solution I

Use string "key" as your key

chrome.storage.sync.get("key", function (obj) { console.log(obj); }); 

or

Solution II

Set data through "myKey" Key.

chrome.storage.sync.set({"myKey": testPrefs}) 

P.S : Don't forget chrome.storage.sync is permanent storage API, Use chrome.storage.sync.clear before any further testing to see changes

References

EDIT 1

Use this code to set variable value in Chrome.storage

function storeUserPrefs() { var key = "myKey", testPrefs = JSON.stringify({ 'val': 10 }); var jsonfile = {}; jsonfile[key] = testPrefs; chrome.storage.sync.set(jsonfile, function () { console.log('Saved', key, testPrefs); }); } 

It generates following Output

Object{ myKey: "{"val":10}" } 

The problem is with chrome.storage.sync.set({key: testPrefs}

Your data is stored as

{ key: "{"val":10}" } 

So, your code chrome.storage.sync.get('myKey') return undefined\empty object.

Solution I

Use string "key" as your key

chrome.storage.sync.get("key", function (obj) { console.log(obj); }); 

or

Solution II

Set data through "myKey" Key.

chrome.storage.sync.set({"myKey": testPrefs} 

P.S : Don't forget chrome.storage.sync is permanent storage API, Use chrome.storage.sync.clear before any further testing to see changes

References

EDIT 1

Use this code to set variable value in Chrome.storage

function storeUserPrefs() { var key = "myKey", testPrefs = JSON.stringify({ 'val': 10 }); var jsonfile = {}; jsonfile[key] = testPrefs; chrome.storage.sync.set(jsonfile, function () { console.log('Saved', key, testPrefs); }); } 

It generates following Output

Object{ myKey: "{"val":10}" } 

The problem is with chrome.storage.sync.set({key: testPrefs}

Your data is stored as

{ key: "{"val":10}" } 

So, your code chrome.storage.sync.get('myKey') return undefined\empty object.

Solution I

Use string "key" as your key

chrome.storage.sync.get("key", function (obj) { console.log(obj); }); 

or

Solution II

Set data through "myKey" Key.

chrome.storage.sync.set({"myKey": testPrefs}) 

P.S : Don't forget chrome.storage.sync is permanent storage API, Use chrome.storage.sync.clear before any further testing to see changes

References

EDIT 1

Use this code to set variable value in Chrome.storage

function storeUserPrefs() { var key = "myKey", testPrefs = JSON.stringify({ 'val': 10 }); var jsonfile = {}; jsonfile[key] = testPrefs; chrome.storage.sync.set(jsonfile, function () { console.log('Saved', key, testPrefs); }); } 

It generates following Output

Object{ myKey: "{"val":10}" } 
Commonmark migration
Source Link

The problem is with chrome.storage.sync.set({key: testPrefs}

Your data is stored as

{ key: "{"val":10}" } 

So, your code chrome.storage.sync.get('myKey') return undefined\empty object.

#Solution I

Solution I

Use string "key" as your key

chrome.storage.sync.get("key", function (obj) { console.log(obj); }); 

or

#Solution II

Solution II

Set data through "myKey" Key.

chrome.storage.sync.set({"myKey": testPrefs} 

P.S : Don't forget chrome.storage.sync is permanent storage API, Use chrome.storage.sync.clear before any further testing to see changes

#References

References

#EDIT 1

EDIT 1

Use this code to set variable value in Chrome.storage

function storeUserPrefs() { var key = "myKey", testPrefs = JSON.stringify({ 'val': 10 }); var jsonfile = {}; jsonfile[key] = testPrefs; chrome.storage.sync.set(jsonfile, function () { console.log('Saved', key, testPrefs); }); } 

It generates following Output

Object{ myKey: "{"val":10}" } 

The problem is with chrome.storage.sync.set({key: testPrefs}

Your data is stored as

{ key: "{"val":10}" } 

So, your code chrome.storage.sync.get('myKey') return undefined\empty object.

#Solution I

Use string "key" as your key

chrome.storage.sync.get("key", function (obj) { console.log(obj); }); 

or

#Solution II

Set data through "myKey" Key.

chrome.storage.sync.set({"myKey": testPrefs} 

P.S : Don't forget chrome.storage.sync is permanent storage API, Use chrome.storage.sync.clear before any further testing to see changes

#References

#EDIT 1

Use this code to set variable value in Chrome.storage

function storeUserPrefs() { var key = "myKey", testPrefs = JSON.stringify({ 'val': 10 }); var jsonfile = {}; jsonfile[key] = testPrefs; chrome.storage.sync.set(jsonfile, function () { console.log('Saved', key, testPrefs); }); } 

It generates following Output

Object{ myKey: "{"val":10}" } 

The problem is with chrome.storage.sync.set({key: testPrefs}

Your data is stored as

{ key: "{"val":10}" } 

So, your code chrome.storage.sync.get('myKey') return undefined\empty object.

Solution I

Use string "key" as your key

chrome.storage.sync.get("key", function (obj) { console.log(obj); }); 

or

Solution II

Set data through "myKey" Key.

chrome.storage.sync.set({"myKey": testPrefs} 

P.S : Don't forget chrome.storage.sync is permanent storage API, Use chrome.storage.sync.clear before any further testing to see changes

References

EDIT 1

Use this code to set variable value in Chrome.storage

function storeUserPrefs() { var key = "myKey", testPrefs = JSON.stringify({ 'val': 10 }); var jsonfile = {}; jsonfile[key] = testPrefs; chrome.storage.sync.set(jsonfile, function () { console.log('Saved', key, testPrefs); }); } 

It generates following Output

Object{ myKey: "{"val":10}" } 
added 413 characters in body
Source Link
Sudarshan
  • 18.6k
  • 7
  • 56
  • 62

The problem is with chrome.storage.sync.set({key: testPrefs}

Your data is stored as

{ key: "{"val":10}" } 

So, your code chrome.storage.sync.get('myKey') return undefined\empty object.

#Solution I

Use string "key" as your key

chrome.storage.sync.get("key", function (obj) { console.log(obj); }); 

or

#Solution II

Set data through "myKey" Key.

chrome.storage.sync.set({"myKey": testPrefs} 

P.S : Don't forget chrome.storage.sync is permanent storage API, Use chrome.storage.sync.clear before any further testing to see changes

#References

#EDIT 1

Use this code to set variable value in Chrome.storage

function storeUserPrefs() { var key = "myKey", testPrefs = JSON.stringify({ 'val': 10 }); var jsonfile = {}; jsonfile[key] = testPrefs; chrome.storage.sync.set(jsonfile, function () { console.log('Saved', key, testPrefs); }); } 

It generates following Output

Object{ myKey: "{"val":10}" } 

The problem is with chrome.storage.sync.set({key: testPrefs}

Your data is stored as

{ key: "{"val":10}" } 

So, your code chrome.storage.sync.get('myKey') return undefined\empty object.

#Solution I

Use string "key" as your key

chrome.storage.sync.get("key", function (obj) { console.log(obj); }); 

or

#Solution II

Set data through "myKey" Key.

chrome.storage.sync.set({"myKey": testPrefs} 

P.S : Don't forget chrome.storage.sync is permanent storage API, Use chrome.storage.sync.clear before any further testing to see changes

#References

The problem is with chrome.storage.sync.set({key: testPrefs}

Your data is stored as

{ key: "{"val":10}" } 

So, your code chrome.storage.sync.get('myKey') return undefined\empty object.

#Solution I

Use string "key" as your key

chrome.storage.sync.get("key", function (obj) { console.log(obj); }); 

or

#Solution II

Set data through "myKey" Key.

chrome.storage.sync.set({"myKey": testPrefs} 

P.S : Don't forget chrome.storage.sync is permanent storage API, Use chrome.storage.sync.clear before any further testing to see changes

#References

#EDIT 1

Use this code to set variable value in Chrome.storage

function storeUserPrefs() { var key = "myKey", testPrefs = JSON.stringify({ 'val': 10 }); var jsonfile = {}; jsonfile[key] = testPrefs; chrome.storage.sync.set(jsonfile, function () { console.log('Saved', key, testPrefs); }); } 

It generates following Output

Object{ myKey: "{"val":10}" } 
Source Link
Sudarshan
  • 18.6k
  • 7
  • 56
  • 62
Loading