0

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?

0x11111
  • 55
  • 3
  • You've invented a non-existent API browser.runtime.getDirectory, which is why it doesn't work. The only solution is to use `nativeMessaging` API and a separate external utility. See also [How to open the correct devtools console to see output from an extension script?](https://stackoverflow.com/q/38913799) – wOxxOm Apr 04 '23 at 15:03
  • @wOxxOm Could you please give more details on the use of nativeMessaging and what is the external utility? – 0x11111 Apr 04 '23 at 15:57

0 Answers0