Native Messaging works fine for me, and then it doesn't

I’m trying to build an extension which will get a pdf upload from a specific webpage and, through native messaging, will send to a java application, responsible for digital signing the ‘uploaded’ file using a USB token (PKCS#11) and saving it locally.

Everything seems to work fine at the beginning, but the application just shuts down out of the blue, in the middle of some code execution without exception being thrown.

I think the problem might be with some Firefox specificity I’m missing, as the application runs OK when tested on Chrome.

Here are my manifest file, background and content scripts for scrutiny:

MANIFEST FILE

{
  "name": "docsigner",
  "version": "1.0",
  "manifest_version": 2,
  "description": "Extension interacting with Native Messaging and localhost.",
  "browser_specific_settings": {
    "gecko": {
      "id": "docsigner@devir.app",
      "strict_min_version": "50.0"
    }
  },
  "content_scripts": [
    {
      "matches": [
        "*://devir.app/*"
      ],
      "js": [
        "content.js"
      ]
    }
  ],
  "background": {
    "scripts": [
      "background.js"
    ]
  },
  "permissions": [
    "nativeMessaging",
    "*://devir.app/*"
  ]
}

BACKGROUND SCRIPT

function onResponse(response) {
    console.log("Received " + JSON.stringify(response));
}

function onError(error) {
    console.log("Error: " + JSON.stringify(error));
}

function processOperation(data) {
    port = chrome.runtime.connectNative("docsigner");
    port.postMessage(data);
    port.onMessage.addListener(onResponse);
    port.onDisconnect.addListener(onError);
}

function processAnotherOperation(data) {
    var sending = chrome.runtime.sendNativeMessage("docsigner", data);
    sending.then(onResponse, onError);
}

browser.runtime.onMessage.addListener(processOperation);

CONTENT SCRIPT

    var extId = "docsigner@devir.app";

    function upload() {

        var file = document.getElementById("file").files[0];

        var reader = new FileReader();

        reader.onload = function (e) {

            console.log("enviando: " + e.target.result);

            chrome.runtime.sendMessage(extId, { content: e.target.result }, function (response) {

                console.log(JSON.stringify(response));

            });

        };

        reader.readAsDataURL(file);

    }

    document.getElementById("upload-button").addEventListener("click", upload);

Ok, so I managed to log the error on Firefox Debug:

Native application tried to send a message of 808595506 bytes, which exceeds the limit of 1048576 bytes.

It’s weird, because analyzing the native application log, it didn’t even get to the point where it was supposed to send back a response.

It must have written something to its stdout, which lead to Firefox trying to parse it as a native message and the length magic bits turned out to that number above?

I guess you’re right. It looks like one of my dependencies logs to stdout. I’ll do some tests. Thank you!