Native message On firefox

{

"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

Two things stand out at a quick glance:

  1. manifest.json does not include an ID. See browser_specific_settings for additional details.

  2. The allowed_extensions field in your native host’s JSON manifest looks wrong. This should contain a list of add-on IDs (the value mentioned in 1). The value you have right now starts with moz-extension:// which is the scheme Firefox uses for extension resources.

Rather than jumping straight into trying to write a native messaging extension from scratch, I’d recommend that you start with the native-messaging example in the webextensions-examples repo. That should help you get a solid foundation before you start working on your extension’s business logic.

Now I fixed the issue. but now it’s show other error like Native application tried to send a message of 1701978747 bytes, which exceeds the limit of 1048576 bytes. what to do because i’m a newbie here.