Hello,
Windows 10
Firefox 128
The extension I am developing a custom image file format (xpx) and would like to open it in Firefox. Here is the initial code:
manifest.json
{
"manifest_version": 2,
"name": "XPX Image File Opener",
"version": "1.0",
"description": "Open xpx, a zlib-compressed binary image file.",
"background": {
"scripts": ["background.js"]
},
"permissions": [
"tabs",
"activeTab",
"webNavigation"
],
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["xpx.js"],
"css": ["style.css"]
}
],
"web_accessible_resources": [
"pako.min.js"
],
"browser_action": {
"default_icon": {
"48": "icon.png"
},
"default_title": "XPX Image File Opener"
}
}
background.js
browser.browserAction.onClicked.addListener((tab) => {
browser.tabs.executeScript(tab.id, {
file: 'xpx.js'
});
});
xpx.js
console.log("Hello");
// Handle dropped files
document.addEventListener('drop', handleDrop, false);
function handleDrop(e) {
const dt = e.dataTransfer;
const files = dt.files;
if (files.length > 0) {
const file = files[0];
const fileExtension = file.name.split('.').pop().toLowerCase();
if (fileExtension === 'xpx') {
console.log(fileExtension);
//handleCustomFile(file);
}
}
}
Instead of executing the extensions files, it shows file āOpenā & āSave Asā dialog window. How do I resolve the problem?
Cheers