0

I'm incredibly lost and new to browser extensions. I am making one related to dragons. Normally I would just use fs but this isn't an option since it's not node.

My browser extension folder has only three files: manifest.json, content-script.js, and dragons.json. I am making the extension in content-script.js and it's going swimmingly, but now I would like to read from and write to dragons.json. My extension will not be published or used for any other users, only me. How can I access this file? I am not trying to read the USER'S files, nor any external online files, just the files that are stored in the extension's folder.

Somna
  • 28
  • 1
  • 1
  • 8
  • Does this answer your question? [How can I save information locally in my chrome extension?](https://stackoverflow.com/questions/5364062/how-can-i-save-information-locally-in-my-chrome-extension) – Hef Jun 10 '22 at 15:54
  • @HewrChelsea The use of the word "locally" has been very confusing in trying to solve this problem. I do not want to save or read from the user's computer, I want to read from a file that's in the same folder as `content-script.js`. However, I am willing to accept that that is a poor solution and that I should just save it with the browser. But regardless, this code appears to be Google Chrome specific, and I am using Microsoft Edge. – Somna Jun 10 '22 at 16:01
  • Microsoft Edge is Chromium based, and they do support a lot of the same apis as Google. In fact you can run a chrome extension of `Microsoft Edge`, and they seem to support this `Storage Api`. Check out this link to see the supported apis. https://learn.microsoft.com/en-us/microsoft-edge/extensions-chromium/developer-guide/api-support – Hef Jun 10 '22 at 16:06
  • @HewrChelsea Interesting, I didn't know that. So you are saying that saving information via the browser is more efficient than accessing files within the extension's main folder? Or are you saying the latter is flat out impossible? – Somna Jun 10 '22 at 16:11
  • Both methods would work. I suggest you take a look at the `chrome.runtime.getURL`. https://developer.chrome.com/docs/extensions/reference/runtime/#method-getURL – Hef Jun 10 '22 at 16:29
  • @HewrChelsea Thanks, this seems to be exactly what I was looking for! I appreciate your time. – Somna Jun 10 '22 at 16:33

0 Answers0