0

I'm currently attempting to save something to a local json file in an extension, but it's obviously not possible to require modules in this case. Is there any way I can save data to a JSON file without the fs module?

Thanks for reading!

MadMisty
  • 1
  • 4
  • Does this answer your question? [How to trigger a file download when clicking an HTML button or JavaScript](https://stackoverflow.com/questions/11620698/how-to-trigger-a-file-download-when-clicking-an-html-button-or-javascript) – Sean Sep 20 '21 at 12:37
  • @Sean I'm actually wanting to save data to an existing local JSON file, so that the specific user can find it back, or let the extension use it later again, thanks for the link but it sadly doesn't help with my issue. – MadMisty Sep 20 '21 at 12:45
  • I would use the new File System API via `showSaveFilePicker`. – wOxxOm Sep 20 '21 at 13:03
  • @wOxxOm is there no other way? Cause your reply is pretty much what Sean said above. – MadMisty Sep 20 '21 at 13:12
  • Due to security issues the user is going have to get involved at some point. Whether it's a) to give permission to upload the file at which point you can ask them to save the file again after the changes or, perhaps b) pass the changed data to the background script and use the downloads API to save it for which you don't need permission iirc. But that will always be sent to your downloads folder. You can of course keep a copy in localStorage. – Andy Sep 20 '21 at 13:13
  • The only other method is to write an external utility and call it via NativeMessaging. The utility will write the file directly. – wOxxOm Sep 20 '21 at 13:22
  • @Andy I've taken a look at the chrome.downloads documentation, but I can't figure out how I'd place something as a json and download it? – MadMisty Sep 20 '21 at 13:37

0 Answers0