What I want to do:
I want to create a Chrome extension for testing. And this extension should have access to directories and files on the local hard drive .
How I did it:
I requested permissions for file:///* in my manifest.json file. Then I made sure Allow access to file URLs is checked. Then I created XHR for the file:
var xhr = new XMLHttpRequest(); xhr.open("GET", 'file://c:/dir/file.name', true); xhr.onload = function(e) { console.log('response: ', xhr.response); } xhr.send();
... and XHR for the whole directory:
var xhr = new XMLHttpRequest(); xhr.open("GET", 'file://c:/dir/', true); xhr.onload = function(e) { console.log('response: ', xhr.response); } xhr.send();
... and for a common file system:
var xhr = new XMLHttpRequest(); xhr.open("GET", 'file:///', true); xhr.onload = function(e) { console.log('response: ', xhr.response); } xhr.send();
What happened:
- I managed to get the correct answer for my file request.
- When I requested the directory, I got the Chrome source code overview of the default public directory:
.
<html> <head> <script>
[...]
</script> <style>
[...]
</style> <title id="title"></title> </head> <body> <div id="listingParsingErrorBox" i18n-values=".innerHTML:listingParsingErrorBoxText"></div> <span id="parentDirText" style="display:none" i18n-content="parentDirText"></span> <h1 id="header" i18n-content="header"></h1> <table id="table"> <tr class="header"> <td i18n-content="headerName"></td> <td class="detailsColumn" i18n-content="headerSize"></td> <td class="detailsColumn" i18n-content="headerDateModified"></td> </tr> </table> </body> </html>
[...]
<script>start("C:\\dir\\");</script> <script>addRow("..","..",1,"0 B","11/11/11 11:11:11 AM");</script> <script>addRow("file.name","file.name",0,"4.9 kB","11/11/11 11:11:11 PM");</script>
- And when I asked the whole file system, I got an error message.
My question is:
I can read simple files. But how will my extension get a good machine-readable overview of a directory or shared file system? Thanks.
EDIT: I know that the FileSystem API is designed to access the filesystem:// sandboxed software, but maybe Chrome allows extensions to also access file:// . I could not find the documentation on accessing file:// to Chrome extensions, so I can just guess.