logo
down
shadow

chrome.storage.sync.set variable key


chrome.storage.sync.set variable key

By : user2950245
Date : November 17 2020, 11:52 AM
this will help It's expected behavior in JavaScript. It is how you define keys in Objects.
If you want to set a variable value as an object key you can do something like:
code :
var item = $("#item").val();
var save = {};
save[item] = null;
chrome.storage.sync.set(save)
//...


Share : facebook icon twitter icon
Chrome.storage.sync.get not storing value in local variable

Chrome.storage.sync.get not storing value in local variable


By : wangping
Date : March 29 2020, 07:55 AM
This might help you Yep. That's how async code works. You'll have to use callbacks. Something like this would probably work.
code :
function workWithBugVal(val) {
    // Do stuff
}

function getBugVal(callback) {
    var bugVal = "";

    chrome.storage.sync.get('bugId', function (obj) {
        console.log(obj.bugId);
        bugVal = obj.bugId;
        callback(bugVal);
    });
}

getBugVal(workWithBugVal);
How to set variable key and value in Google Chrome local storage sync?

How to set variable key and value in Google Chrome local storage sync?


By : abhaivir
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , See Computed property names in ES6, you could use
code :
chrome.storage.sync.set({ [user]: id }, callback);
How can I sync localStorage across Chrome instances (or use chrome.storage.sync without a published extension)?

How can I sync localStorage across Chrome instances (or use chrome.storage.sync without a published extension)?


By : pHorp
Date : March 29 2020, 07:55 AM
may help you . This doesn't really answer the question as I originally asked it, but this is what I ended up doing to solve the problem described above, so whatever.
In the end, I abandoned the idea of using chrome.storage (the space restrictions on chrome.storage.sync were untenable) and instead wrote my extension using PouchDB, which is a Javascript implementation of CouchDB. PouchDB uses IndexedDB internally, which does have a per-extension limit by default (I think 5 MB? I didn't bother to test), but can be granted unlimited storage by setting the "unlimitedStorage" permission in the extension manifest. PouchDB's storage model is significantly superior to the chrome.storage storage model in basically every way (free revision tracking, a documented sync protocol rather than whatever voodoo chrome.storage.sync does, etc.), and the downsides (an extra dependency, need for a separate remote server [see below], etc.) were not a huge issue for me. I spun up a free EC2 micro instance and installed a CouchDB server on it. CouchDB is a little bit finicky to configure, but works well once that's taken care of. My EC2 instance stopped being free after a year, so I switched to Cloudant, which offers CouchDB-compatible hosting that's free if you use less than $50 worth of storage + bandwidth per month, which I do. I set my extension to point at my Cloudant instance, have it authenticate using plain old HTTP basic authentication (which is fine here, since I'm the only person using this extension, which means I'm free to put my password in plaintext in the extension), and have it sync with the remote instance when requested by the user. The authentication approach I took here (in conjunction with the deployment strategy [see below], etc.) probably has a bunch of holes, but I don't really care; it seems sufficient to stop casual intrusions, which is good enough (I'm not dealing with important or privileged data). Rather than deploying my extension via the Chrome store, which seems complicated and costs money, I now have a rather more ghetto solution whereby I move my extension from my development machine to my other machines by copying the unpacked extension folder into my Dropbox folder and waiting for Dropbox to sync it to my other machines. I then load (or reload) the unpacked extension on my other machines. (This was easier than a Bitbucket-based solution [or any other Git-based solution] because my Windows machines all throw fits when I try to get anything done with Git.) One downside of using Dropbox (or any other solution that involves unpublished unpacked extensions) rather than the Chrome store - Chrome pesters you about disabling non-store extensions every time you open Chrome, even if you're on the Chrome dev channel. In light of Xan's comments below, I'm probably going to take a second look at using the Chrome store as a means of deploying the extension.
how can i pass variable to chrome.storage.sync.get()

how can i pass variable to chrome.storage.sync.get()


By : Carter Sheehan
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further The callback of .get() expects exactly 1 parameter.
By passing a function that takes 2 parameters (i.e. function(data, e) {...}), you do the following:
How to convert chrome.storage.sync.get to browser.storage.sync.get? (or, how to use Promises)

How to convert chrome.storage.sync.get to browser.storage.sync.get? (or, how to use Promises)


By : a friend
Date : October 12 2020, 06:00 PM
fixed the issue. Will look into that further Since browser.storage.sync.get returns a Promise (and assuming the signature is the same as the chrome version), something like this should be equivalent. This returns a Promise immediately, which you can call then() and catch() on to handle success and error cases respectively
code :
var read = function(name, deflt) {
  return browser.storage.sync.get([name])
    .then(result => {
      if (browser.runtime.lastError) { // assuming this exists
        throw new Error(browser.runtime.lastError);
      }

      return result[name] || deflt
    })          
};

read('foo', 'barDefault')
  .then(doStuffWithResult)
  .catch(console.error)
Related Posts Related Posts :
  • Mocha JS: How to reuse assertions within a spec?
  • Is ember.js stable enough to use in a real world project?
  • jQuery Load() not loading within div
  • encode stream from webCam h264
  • Regex to find pattern, return subpattern
  • Why does this regex to remove empty <p></p> tags from a string fail?
  • Rails: pass data to javascript
  • Quickest way to check if a number is in a set?
  • Phonegap events online/offline not working
  • In HTML5, please explain the meaning of '?' in the statement
  • Form to use AJAX rather than a page refresh but also utilise error handling?
  • JQuery Script looping error
  • different size divs align top left
  • Image fade-in when webpage finishes loading
  • Seeking HTML5 audio element causes delay (breaks sync)
  • How can I read & write data to a new tab in Firefox?
  • jQuery or JS turn all words into italic type
  • iOS css -webkit-transform: scale doesn't offset touch events
  • Populate select list using javascript
  • Can you work out why my .js file doesn't seem to be linking to my html?
  • Make slideToggle effect only one element at a time
  • Output sound using JavaScript
  • What is the analytics.js equivalent of _trackPageview found in ga.js
  • How can I check if a JS file has been included already?
  • hasClass and condition not working
  • EDITED: I'm having issues with a button and its function
  • Importing XML in HTML with javascript
  • Create new function in contentScriptFile in Firefox extension
  • Should I build Node.js from source or download the OS X installer?
  • How to enforce integer sizes in JS? (TypeScript?)
  • How to update the JSON object without deleting old values using javascript
  • Reading a javascript variable containing a string into another file
  • Possible to prevent 403 errors from logging to the web console?
  • Jquery Accordion - Expand and collapse div on hover
  • jquery .hide() function - Hide mobile, Display Desktop
  • Holding password in javascript variable - security implications?
  • JQPlot trouble to render vertical stacked bar and horizontal legend
  • counts days inbetween then add class to those days with nested divs?
  • Marionette.js with Rails (Devise) Authentication
  • javascript anonymous function evaluation idiom
  • Why am I losing the decimal when working this equation in Javascript?
  • Site redirects to index.php after being open while making calls to an API using AJAX
  • How to determine when multiple callbacks are all done
  • How to update Yeoman dependencies?
  • How can I do a /resolve with the Soundcloud Javascript SDK?
  • I'm not able to call a named callback function
  • How to get value of Paragraph element contained in <div> in HTML using JavaScript
  • Javascript - Get value from textbox and save it on a string
  • Backbonejs collection not populated, but fetch works
  • when function's internal [[scope]] property is assigned?
  • Wrapping around the edges in a 2d array (game of life)?
  • Clone div with all nested elements along with events in pure javascript
  • How to get response text?
  • Setting and retrieving cookies in javascript
  • Passing parameter with double quotes
  • finding the meaning of the obfuscated javascript
  • Socket.io - Sending data from a pusher stream to the client
  • How to determine the visibility li's in a scrollable ul
  • How to create Scrolling Effect like Grouek website
  • How to display a state in parents template in ui-router
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org