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
Chrome extension - Inject code is not getting executed

I am building a chrome extension that will check if the current webpage has any malware. I have placed a button in popup.html to trigger the malware checking code. But it is not working.

manifest.json:

{
  "name": "Malware Detector",
  "version": "1.0",
  "permissions": ["activeTab", "declarativeContent", "storage"],
  "browser_action": {"default_popup": "popup.html"},
  "manifest_version": 2
}

app.js:

chrome.runtime.onInstalled.addListener(function() {
});

popup.html:

<body>
  <p>Malware Detector</p>
  <button id="populateBtn">Detect Malware</button>
  <script src="popup.js"></script>
</body>

popup.js:

const btn = document.getElementById('populateBtn');
btn.onclick = () => {
  chrome.tabs.query({active: true, currentWindow: true}, ([tab]) => {
    chrome.tabs.sendMessage(tab.id, {data}, () => {
      if (chrome.runtime.lastError) {
        chrome.tabs.executeScript({file: 'inject.js'}, () => {
          chrome.tabs.sendMessage(tab.id, {data});
        });
      }
    });
  });
};

inject.js:

chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
    // this is where malware checking code will go
    alert("test"); 
    console.log("test");
});

The test code of alert and console.log in inject.js are not getting triggered.

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