Reading and writing files in chrome extensions

I am trying to write a chrome extension that initializes some parameters from a configuration file. I would like to allow the extension to modify these parameters and save them to a file so that it will use the new configuration the next time the extension is loaded.

I read the chrome.filesystem api, but it needs user interaction with the file selection. However, in this case, the process should be performed automatically without any user action.

Since this configuration file will only be available for extension, it can be marked as sand, but it must be permanent even if the chrome is closed.

I am able to read the file using XMLHttpRequest, but I could not find a way to modify the file.

Can this be done with the chrome extension?

+4
source share
2 answers

This is an old question, but unfortunately the only answer he received was incorrect.

You can definitely read and write files using HTML5 in Chrome, without the mentioned "uncertainty" issues. The HTML5 file system creates a secure sandbox in which you write and read virtual files: you can think of it as files that are written to a database based on files managed by Chrome and are not accessible to other Chrome applications or extensions, or to other applications on OS base. The user will not be able to copy or move these files using his OS file browser, since they are inside the DB file of the web browser.

You cannot read (or write) arbitrary files from (to) a disk based on any given file path. If you need a file from disk, you can allow the user to select it by himself using chrome.fileSystem.chooseEntry ()

However, you can read (and write) your own files from (to) the HTML5 file system.

So, to answer your question: no, you do not need user interaction to write your configuration file to the browser file system. An alternative to files can be chrome storage, localstorage, or even indexedDB to store your (stored) key-value configuration pairs.

Here are some useful links to start reading about it:

Playing with the HTML5 File System

HTML5 Rocks

HTML5 demos

+4
source

I assume that the chrome extension for writing to configuration files without user knowledge may be a security issue. You are probably facing a security feature. The potential work is to create a desktop application that is always on and your Chrome application interacts with it. Hell, you can do what you need (without knowing all the details) with something like an autohotkey.

0
source

All Articles