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.