Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

160
Visualizações
checkbox status in chrome extension

I have a problem to safe an state from popUp to the local storage in chrome extension. I am doing a checkbox and I would like that when I click on it, changes the status on storage and informs in content. Also I would like that when I open a new tab it keeps the state of the checkbox, taking the information from the storage, and if i close the browser and i open, i would like that keep the information of the last time it was open.

this is my Popup:

const PopUp = () => {

const [checked, setchecked] = useState(false);

  chrome.storage.sync.get('checked', storage => {
    setchecked(storage.checked);
  });

  const handleChange = () => {
    setchecked(status => !status);
    chrome.storage.sync.set({ checked });
  };

  return (
    <div>
      <input type='checkbox' checked={checked} onChange={handleChange} />
    </div>
  );
};

and this is my content.js

(() => {
  chrome.storage.sync.get('checked', storage => {
    toggle(storage.checked);
  });

  chrome.storage.onChanged.addisExtensionActiveListener(storage => {
    toggle(storage.checked);
  });

  const toggle = (state) {
    if (state) {
     //do something
    }
  }
})();

in the background I have that, if can help:

const getSomethingFromContent = () => {
  const getValue = activeInfo => {
    chrome.tabs.get(activeInfo.tabId, () => {
      chrome.tabs.executeScript({ file: 'content.js' });
    });
  };

  chrome.tabs.onActivated.addListener(getValue);
  chrome.extension.onActivated.removeListener(getValue);
};

getSomethingFromContent();

thanks in advance

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda