{
"manifest_version": 2,
"name": "Mac Address",
"version": "1.0",
"description": "Mac Address",
"permissions": [
"activeTab",
"nativeMessaging",
"tabs",
"url"
],
"background": {
"scripts": ["background.js"]
},
"content_scripts": [
{
"matches": ["url"],
"js": ["content.js"]
}
],
"icons": {
"16": "icons/icon.png",
"48": "icons/icon.png",
"128": "icons/icon.png"
}
}
the above code is manifest.json
const nativeHostName = ‘com.example.macaddress’;
console.log(“Background script loaded”);
// Listen for messages from content scripts
browser.runtime.onMessage.addListener((request, sender, sendResponse) => {
console.log(“Received message:”, request);
if (request.action === “sendToNativeHost”) {
console.log("Sending message to native host:", request.data);
browser.runtime.sendNativeMessage(nativeHostName, request.data)
.then(response => {
console.log("Received response from native host:", response);
sendResponse({ success: true, response });
})
.catch(error => {
console.error("Native message error:", error.message);
sendResponse({ success: false, error: error.message });
});
return true; // Indicates that the response will be sent asynchronously
}
});
the above code is background.js
function monitorAndHandleClick() {
const targetElement = document.querySelector('label#lblLogin.mybutton.btnPadding');
if (targetElement) {
console.log("Target element found:", targetElement);
targetElement.addEventListener('click', () => {
const dataToSend = {
action: "sendToNativeHost",
data: {
url: window.location.href,
elementId: targetElement.id,
timestamp: new Date().toISOString()
}
};
console.log("Sending message to background script:", dataToSend);
browser.runtime.sendMessage(dataToSend)
.then(response => {
if (response && response.success) {
console.log("Message sent to native host successfully.");
} else {
console.error("Failed to send message to native host:", response);
}
})
.catch(error => {
console.error("Error sending message:", error);
});
});
} else {
console.error("Target element not found.");
}
}
if (window.location.href === ‘url’) { // Replace with your target URL
console.log("Target URL matched, starting click monitoring.");
monitorAndHandleClick();
}
the above code is content.js
{
"name": "com.example.macaddress",
"description": "MAC Address Sender",
"path": "C:\\Users\\<username>\\Downloads\\firefoxMacaddress\\get_mac_address.bat",
"type": "stdio",
"allowed_extensions": [
"moz-extension://69d48aa9ae7a27e3e04ab0fbba5df82a97ded53c@temporary-addon/"
]
}
the above code is hostnative json file
the above is not even console printing can i know where the error is ? and i have reg the entry in registry too in the below path.
Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Mozilla\NativeMessagingHosts\com.example.macaddress