Is writing to a file on the filesystem at all possible through chrome's content_scripts or extension background scripts?

StackOverflow https://stackoverflow.com/questions/22990319

سؤال

I would like to create an extension for google chrome that periodically writes some stuff to a file in the computer's filesystem. I have been searching the docs for a while now but I can't find anything about it. Is it possible to write to a file from a google chrome or chromium extension at all?

هل كانت مفيدة؟

المحلول

Yes, and no, and "kind of".

In the context of a Chrome app it's possible with chrome.fileSystem API.

In the context of a Chrome extension it's not possible to gain access to an existing file.

However, not all hope is lost. You can maintain a sandboxed read/write filesystem using HTML5's fileSystem API, and if you need to export a file for the user, you can get the browser to "download" it.

You may want to declare unlimitedStorage permission if you have potential to go over 5Mb.

See this question for exporting the file to the user: Chrome Extension write to file system


Edit: Switching to a packaged app model means a shift in how your GUI works. If you cannot live without extension-only UI elements (like browser actions), there are two possible approaches:

  1. Have an app AND an extension talking to each other through onMessageExternal
  2. Have an extension and a Native Host talking through Native Messaging.

Big Hammer Warning, these methods are last resort ones that lead to complications if you want to widely distribute your extension and not writing it for yourself or in-house use.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top