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

200
Views
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
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!