Problem Description
I am developing a browser extension that uses OpenPGP.js to encrypt and decrypt selected text on a webpage. The extension works perfectly in Chrome, but I encounter an issue in Firefox where the openpgp
object is not defined.
Also one more error in openpgp.min.js
Error: concatUint8Array: Data must be in the form of a Uint8Array
Code Snippet
Here is the relevant part of my content script:
async function encryptSelectedText() {
const selection = window.getSelection().toString();
console.log("Selected text:", selection);
const selectionObj = window.getSelection().getRangeAt(0);
console.log("Selection object:", selectionObj);
if (selection) {
try {
// Get the selected public key from storage
browser.storage.sync.get("selectedPublicKey", async function (data) {
// console.log("Selected public key:", data.selectedPublicKey);
const publicKeyArmored = data.selectedPublicKey;
console.log("Public key:", publicKeyArmored);
if (publicKeyArmored) {
const publicKey = await openpgp.readKey({
armoredKey: publicKeyArmored,
});
// further code but i get error here
Alreadt included openpgp.js in the content scripts:
{
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["src/openpgp.min.js", "src/content.js"]
}
]
}
My file structure:
├── manifest.json
└── src
├── background.js
├── content.js
├── openpgp.min.js
├── openpgp.min.js.map
└── popup
├── popup.css
├── popup.html
└── popup.js
Expected Behavior
The openpgp
object should be defined in Firefox, just as it is in Chrome, allowing the encryption and decryption functions to work correctly.
Searched internet for related problems but no help. Also asked chatgpt but that also did’t work
The openpgp object should be defined in Firefox, just as it is in Chrome, allowing the encryption and decryption functions to work correctly but it dosen’t work i firefox.
Sukhmeet Singh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1