I want to create a Chrome extension for test purposes. And that extension should be able to access the directories and files on the local hard drive.
I requested permissions for file:///*
in my manifest.json
file. Then I made sure that the checkbox Allow access to file URLs
was checked. Then I made a XHR for a 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 a XHR for a 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 the total file system:
var xhr = new XMLHttpRequest();
xhr.open("GET", 'file:///', true);
xhr.onload = function(e) {
console.log('response: ', xhr.response);
}
xhr.send();
.
<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>
I'm able to read simple files. But how can my extension get a nice machine-readable overview of a directory or of the total filesystem? Thanks.
EDIT: I know that the FileSystem API is intended to access the sandboxed filesystem://
, but maybe Chrome allows extensions to also access file://
. I couldn't find any documentation concerning file://
access from Chrome extensions, so I'm just able to guess.
For security reasons, by default the Chrome browser does not allow extensions to access local files. If you want the accelerator to access local files (locations of "file:///...", instead of "http://" or "https://"), you must configure Chrome to allow the access.
When extensions are installed into Chrome they are extracted into the C:\Users\[login_name]\AppData\Local\Google\Chrome\User Data\Default\Extensions folder. Each extension will be stored in its own folder named after the ID of the extension.
Save the image object locally One way to share data between a background script and the other scripts that make up the extension is to save the data to a location which is accessible to all the scripts in the extension. We can use the browser localStorage API or chrome. storage which is specific to Chrome extensions.
There's no built-in feature in stand-alone Chrome.
Alternatives to parsing the directory listing page:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With