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);