{
"manifest_version": 3,
"name": "Mac Address",
"version": "1.0",
"description": "Mac Address",
"permissions": [
"activeTab",
"nativeMessaging",
"tabs"
],
"background": {
"service_worker": "background.js"
},
"content_scripts": [
{
"matches": ["url of product"],
"js": ["content.js"]
}
],
"host_permissions": [
"url of product"
],
"icons": {
"16": "icons/icon.png",
"48": "icons/icon.png",
"128": "icons/icon.png"
}
}
the code is manifest.json
const nativeHostName = 'com.example.macaddress';
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === "sendToNativeHost") {
console.log("Sending message to native host:", request.data);
chrome.runtime.sendNativeMessage(nativeHostName, request.data, (response) => {
if (chrome.runtime.lastError) {
console.error("Native message error:", chrome.runtime.lastError.message);
sendResponse({ success: false, error: chrome.runtime.lastError.message });
} else {
console.log("Received response from native host:", response);
sendResponse({ success: true, response });
}
});
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);
chrome.runtime.sendMessage(dataToSend, (response) => {
if (response && response.success) {
console.log("Message sent to native host successfully.");
} else {
console.error("Failed to send message to native host:", response);
}
});
});
} else {
console.error("Target element not found.");
}
}
if (window.location.href === 'url of product') {
console.log("Target URL matched, starting click monitoring.");
monitorAndHandleClick();
}
the above code content.js .
All above code is working fine on chrome browser(131.0.6778.205) but not on edge (131.0.2903.112). can i now where the mistake is? and i have reg on registry in path of
ComputerHKEY_LOCAL_MACHINESOFTWAREMicrosoftEdgeNativeMessagingHostscom.example.macaddress
.
when the Above code is Working fine on chrome browser but not on Edge can i Know where the problem is?