How do I use local json in my browser extension? - javascript

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.

Related

Where do the files and folders created by a Chrome App reside in file system?

First I have to say I'm very new to Google Chrome App development. I'm using webkitRequestFileSystem to create folders and files dynamically from my app.
Now where can I find the folders and files in my file system, or is there any other way to see them?
It will be buried deep into your Chrome profile, with all file names and paths obfuscated and complex metadata dependencies.
Something along the lines (from the root of the profile folder):
Storage/ext/your_app_id_here/def/File System/
The filesystem is virtual: it's not expected to map to a location within a user's filesystem, and you're not expected to be able to access it outside Chrome. The fact it's actually stored as a collection of files that correspond to virtual files is but a technical implementation detail.
If you want to interact with the real filesystem, you need to request access to a folder from the user using chrome.fileSystem.chooseEntry API for Chrome Apps instead of webkitRequestFileSystem.

Read content of a local file with chrome extension

I am developing an extension for the chrome browser. I use the KangoExtensions framework. The extension is written in JavaScript. I want to read the content of a file, which is located on the local filesystem. What is the easiest way to implement this?
If you already know the file's path in the filesystem you just need to add a permission to file://*in your manifest file and make a GET XMLHttpRequest to the url file://{filepath}.

Chrome Extension Save File Dialog

Please I am new to building Chrome Extensions. After the user installs the extension, I want them to configure it by specifying a directory where the app can save files. I want to do this by opening a save file dialog so they can browse to the folder of their choice. How do I do this?
The answer is that there is no means in the Chrome Extension API to write files outside of the sandboxed file system provided by Chrome. This could theoretically be done by writing an interface in C and then call that, but so far I have not yet seen a successful implementation.

Access local files from HTML5 Desktop Application in html folder

HTML5 is great and I can replace my existing desktop application with it, but just a little security restriction prevents me to complete my job. I plan to create a simple desktop application completely with HTML5 so it can run on any mobile and desktop devices that support HTML-5.
I know about the browser security on local file and the reason behind it, but I don’t know why I couldn’t find a way to grant read-only access to a folder as sandbox. My application does not need to write a file or even does not need to read a file outside of It main html folder. It needs to read the local file just in same folder same as it do on domain.
So please let me know:
Can run browser with specific command to force it grant access to local file that exists in same folder of HTML? It should not disable all local security restriction just grant HTML access to file in same folder or subfolder.
Is it cross platform method to map a local folder as local host that work on mobile platforms?
Is there any manifest file exists to put in folder to grant read access in same HTML folder?
Is there any way to grant read-only access to a folder as sandbox?
Note: I don't want use third party solution such as XULRunner, Mozilla Prism, Adobe Air or any other third party, I need HTML-5 solution to be cross platform if there is any.
Any idea is welcome.
If you need that file so much, why not just load it dynamically inside a JS script as a json object.
So, in other words, put the contents of the file into a js script, and strucutre the file contents into JSON format, then load that script on load or when you require it.
Alternately if you need file IO use localstorage.
according to this site, launching chrome from the cmd with the parameter --allow-file-access-from-files will disable this security feature

Local file access and compiling a greasemonkey script to xpi

I want to provide some functionality through an extension. This requires (read and execute) access to some resource files (an mp3 file, a swf file and two js).
I know user scripts cannot access local files and I need an extension (add-on) to do that.
But can I start by writing a greasemonkey script and compiling it to a xpi?
How should I specify the path to the file for it to work when compiled into an xpi?
This question is close to what I'm trying to do, but does not say anything about the path.
Yet this other question discusses how to add resources to your xpi, but assumes you write the xpi from scratch not if you compile a greasmonkey user script to an xpi
I am not familiar with greasemonkey, however I have successfully written to files using a FireFox addon. Once you have a FireFox addon which you can modify, you can see the page here: File I/O - MDC for some help writing files via the API in FireFox. I use the nsiFilePicker service to select the file/path.

Categories

Resources