Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

120
Vistas
set and then get multiple input values using chrome storage API

I am saving a user input values from welcome page upon listening click event on a button having id ok_btn using chrome Storage API by using following code:

let submit = document.getElementById("ok_btn");

submit.addEventListener("click", async () => {

    let apiKey = document.getElementById("APIkey").value;
    let letters = document.getElementById("numberOfLetters").value;

    // console.log(apiKey);
    await chrome.storage.sync.set({ 'CustomerApiKey': apiKey }, function () {
        alert("APikey is set.")
    });
    await chrome.storage.sync.set({ 'numberOfLetters': letters }, function () {
        alert("Letters value is set.")

    });
});

Doing above only sets the value against CustomerApiKey. I want to store the the value of numberOfLetters as well. I am using following code to get the value from storage:

const getCustomerApiKey = async () => {
   
    return new Promise((resolve, reject) => {
        // Asynchronously fetch all data from storage.sync.
        chrome.storage.sync.get(null, (items) => {
            // Pass any observed errors down the promise chain.
            if (chrome.runtime.lastError) {
                return reject(chrome.runtime.lastError);
            }
            resolve(items);
        });
    });
};
async function key() {
    CustomerApiKey = await getCustomerApiKey();
    // doLetters = await getCustomerApiKey('numberOfLetters');
    console.log(CustomerApiKey);
    // console.log(doLetters);

    main(CustomerApiKey);
};
key();

Following is the result:

{CustomerApiKey: 'test_abcdefghijkl'}
CustomerApiKey: "test_abcdefghijkl"
[[Prototype]]: Object

Unable to figure out why it is not showing the second key in storage.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda