Programatically save files to user specified location in firefox extension - javascript

I'm writing a firefox extension that writes files to a directory structure at a specified location by the user but can't seem to find documentation on how to include that in the permissions of the extension or how to access this facet in the API. I was initially trying to use a greasemonkey script to accomplish this but ran into the javascript limitation of not being able to access the user's local storage and had read I needed to write it as an extension. Any link or help on how to write a function for a mozilla extension that will save a file to a local disk location? Thanks in advance for any help!

Related

How do I access local PDF files in my Chrome Extension app?

Google Chrome allows you to preview local PDF files in the browser like pictured below:
I am working on an extension that takes whatever PDF is in the browser preview and opens it in my custom editor/markup tool.
I have been successful in loading PDFs from remote URLs because I can just send the remote URL to my server, download it there, and open the PDF in my app using PDFjs.
How can I accomplish the same functionality for local PDF files?
I have looked into possibly using javascript to create a File object from local PDF files but Chrome doesn't allow access to the local file system.
I am hoping to accomplish this functionality by the user just clicking my extension icon, similar to the popular extension, Kami.
you need to add permissions to your extension:
"permissions": ["file://*/*"]
to ensure that you have permissions for local files, use:
chrome.extension.isAllowedFileSchemeAccess
P.S. have a good day and do not use upwork for these type of questions :-D

Modifying local files embedded in a Google Chrome Extension using JS

I have been doing a lot of research and have been unable to find an answer to my exact question. I understand that having a google chrome extension that can write to local user files would be a major security breach and thankfully isn't possible. However in my extension is a .json file that is used to make a HTML webpage with links via JavaScript. The JS reads the .json file and inserts the lines of code on the html page. I am attempting to make a user interface that allows them to update and edit the .json file that is inside the extension in order to add new lines of code to the webpage, but have been unable to find anything that could make this work due to security issues. I was thinking that since the file is in the extension users should be able to modify it.
If that was confusing here is a flow of what I want to happen and where it is not working:
Works:
Users clicks on button that takes them to a webpage hosted in the extension -> when page is loaded, the javascript runs -> the JS looks at a .json file in the extension using an XMLHttpRequest, parses the data, and then inserts it into the html -> The user now see's the content that was contained in the .json file on the html page.
Doesn't work:
After this I would like to have an interface that will allow the user to edit this .json file in order to update the page as they see fit, all in the extension itself.
If it was just me using this extension I could simply use the chrome storage api's available, however this is for my team at work, who are wanting to make edits as we need. Which means we will all be editing the same .json file.
Any information regarding this would be very beneficial. Even if it's as simple as it can't be done. Either way manually editing the .json file without a simple UI is much easier than editing the html directly.
Thanks in advance!
Posts/Articles I have looked at regarding this question:
Access Local Files using a Google Chrome Extension
https://developer.chrome.com/extensions/storage
Local file access with javascript
Allow Google Chrome to use XMLHttpRequest to load a URL from a local file

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}.

How to write a configuration file for chrome extension using a local script

I have a chrome extension (intended to be used by companies internally) that needs to have user specific configurations but I want to avoid the user having to do all that and have a sysadmin configure those things for them via a script.
EDIT: Basically, I just need to read from a file that sysadmin can write.
Is this in any way possible?
You have two solutions.
First one is to ask your sysadmin to properly locate chrome's extension folder on all platforms, and edit a file in there. It might be a bit complicated if all computers at your company are not the same or use different platforms.
See: Where to find extensions installed folder for Google Chrome on Mac?
The second one, is simply to ask for the file:///* permission when you install the extension.
It will allow your extension to read files on the whole hard drive, and load the configuration file on a predetermined place.
Here is a related question:
Chrome plugin reading text file on hard drive and replacing textbox content
edit: for the second solution to work, you need your users to enable "Allow access to file URLs" in chrome's config (not sure you can do that automatically)
Assuming you have an enterprise install, you can use chrome.storage.managed (which can be easily controlled from a central location) to hold those preferences.
See Configuring Apps and Extensions by Policy for a detailed, per-OS explanation.
If an enterprise managed storage is not an option, perhaps a better one would be to have a configuration file available somewhere on an internal web server. The extension can then retrieve that pre-defined URL and configure itself accordingly.
You can differentiate between computers automatically using IP/MAC address information accessible by the server processing the request, of you can pass some query parameters yourself.

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.

Categories

Resources