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

210
Visualizações
How to connect background.js with content.js to execute action in content.js after pressing the button

I have a problem with connecting content.js to background.js so that after pressing the "switch" the action with background.js in content.js was triggered. I don't know if I should use popup.js additionally and how use it. I want to enable and disable the theme using "switch". I'm trying do this a few days.

My manifest.json:

{
"manifest_version": 3,
"name": "moonext",
"description": "Change UserAgent, Language, Background",
"version": "1.0",
"permissions": ["storage", "declarativeContent", "activeTab", "scripting"],
"action":{
    "default_popup": "Popup.html",
    "default_title": "moonext"
},
"icons": {
    "16": "/images/moon.png",
    "48": "/images/moontwo.png"
},
"content_scripts": [
    {
    "matches": ["https://synergia.librus.pl/*"],
    "js": ["content.js"],
    "css": ["main.css"],
    "run_at": "document_end"
    }
],
"background":{
    "service_worker": "background.js"
}}

My content.js:

console.log("content.js is working");
var style = document.createElement('style');
style.innerHTML = `
// my styles
`;
document.head.appendChild(style);

My Popup.html (cut code):

<script src="popup.js" type="text/javascript"></script>
    </head>
     <body>
      <div>
       <h1>MOONEXT</h1>
       <table>
       <tr>
       <td>
       <p>Switch</p>
       </td>
       <td>
       <label class="switch">
       <input type="checkbox" id="switch1">
       <span class="slider round">
       </span>
       </label>
       </td>
       </tr>
       </table>
       </div>
      </div>
     </body>

My background.js:

console.log("background.js is working");
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