Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

126
Views
establecer y luego obtener múltiples valores de entrada usando la API de almacenamiento de Chrome

Estoy guardando los valores de entrada de un usuario de la página de bienvenida al escuchar el evento de click en un botón que tiene id ok_btn usando Chrome Storage API usando el siguiente código:

 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.") }); });

Hacer lo anterior solo establece el valor contra CustomerApiKey . También quiero almacenar el valor de numberOfLetters . Estoy usando el siguiente código para get el valor del almacenamiento:

 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();

El siguiente es el resultado:

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

No se puede averiguar por qué no muestra la segunda clave en el almacenamiento.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!