I would like to make a firefox addon that takes scroll bar position every 10 seconds and records it into a file.
So far, I just want to write "Hello world" to a file, every 10 sec, to start with.
Below are my manifest.json and background.js files
{
"name": "My Auto-Writer Addon",
"version": "1.0",
"description": "An addon that automatically writes a string to a file every 1 second.",
"manifest_version": 2,
"icons": {
"48": "icon.png"
},
"permissions": \["file://*/*"\],
"background": {
"scripts": \["background.js"\],
"persistent": false
},
"browser_action": {
"default_icon": {
"48": "icon.png"
},
"default_title": "My Sample Addon"
}
}
browser.runtime.onStartup.addListener(() =\> {
setInterval(() =\> {
browser.runtime.getDirectory({type: "downloads"})
.then((downloadsDir) =\> {
let fileWriter = downloadsDir.createWriter("/absolute/path/my-file.txt");
console.log("filewriter",fileWriter)
let stringToWrite = "Hello, world!";
let blob = new Blob([stringToWrite], {type: "text/plain"});
fileWriter.write(blob);
})
.catch((error) => {
console.error("Error getting Downloads directory:", error);
});
}, 1000);
});
It does not work. Does not give any warnings, just does not write. And does not write to console. How do I make this work and how do I debug this?