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

323
Views
chrome.local.storage get set: guarde el estado y la funcionalidad marcados de la casilla de verificación cuando se cierre la ventana emergente

Este es el último paso en la construcción de mi extensión y estoy seriamente atascado. Investigué chrome.local.storage, pero no puedo hacerlo funcionar.

 I have the following in mypopup.js let a = document.getElementById("option01"); a.addEventListener("click", async () => { let [tab] = await chrome.tabs.query({ active: true, currentWindow: true }); a.setAttribute('aria-checked', a.getAttribute('aria-checked') === 'true' ? 'false' : 'true'); if (a.getAttribute('aria-checked') === 'true') { try { await chrome.scripting.insertCSS({ target: { tabId: tab.id, }, files: ["css/option01.css"], }); } catch (err) { console.error(`failed to insert roles CSS: ${err}`); } } else if (a.getAttribute('aria-checked') === 'false') { try { await chrome.scripting.removeCSS({ target: { tabId: tab.id, }, files: ["css/option01.css"], }); } catch (err) { console.error(`failed to remove roles CSS: ${err}`); } } });

He probado todas las diferentes variaciones de set y get para el almacenamiento de cromo, y aunque entiendo el concepto, hacer que funcione como quiero me tiene tirando de los pelos. Realmente agradecería algo de ayuda.

Esto es todo lo que llegué tratando de guardar el estado de la casilla de verificación (marcada/sin marcar) y para probar agregar y eliminar una clase.

Guardar el estado marcado y agregar/eliminar las hojas de estilo del código anterior, esto es lo que quiero lograr.

 document.addEventListener('DOMContentLoaded', function () { chrome.storage.local.get('enabled', function (result) { if (result.enabled != null) { a.checked = result.enabled; } }); chrome.storage.local.set({ 'enabled': a.getAttribute('aria-checked') === 'true' }, function () { }); });
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Encuentro esto enla documentación de almacenamiento de Chrome . Debe declarar el permiso de "almacenamiento" en el manifiesto de la extensión para usar la API de almacenamiento. Por ejemplo:

 { "name": "My extension", ... "permissions": [ "storage" ], ... }
about 4 years ago · Juan Pablo Isaza Report

0

chrome.storage.local.set({key: value}, function() { console.log('Value is set to ' + value); }); chrome.storage.local.get(['key'], function(result) { console.log('Value currently is ' + result.key); });

como ves en el código cuando usas una clave de cadena no usas "" y si usas una variable la pones en [] así ['clave'] Espero que este sea el problema

 document.addEventListener('DOMContentLoaded', function () { chrome.storage.local.get(['enabled'], function (result) { if (result.enabled != null) { a.checked = result.enabled; } }); chrome.storage.local.set({ enabled: a.getAttribute('aria-checked') === 'true' }, function () { }); });
about 4 years ago · Juan Pablo Isaza Report
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!