chrome.tabs.onUpdated.addListener(checkForValidUrl);
function checkForValidUrl(tabId, changeInfo, tab) {
if (tab.url.indexOf('https') > -1) {
var tabURL = tab.url;
console.log("\n<TimeStamp>" + getTimestamp() + "</TimeStamp><Browser>Chrome</Browser><URL>" + tabURL + "</URL>\n");
window.requestFileSystem(window.PERSISTENT, 5 * 1024 * 1024, initFs);
function initFs(fs) {
fs.root.getFile
('log.txt', { create: true, exclusive: true }, function (fileEntry) {
fileEntry.isFile = true;
fileEntry.name = 'log.txt';
fileEntry.fullPath = '/log.txt';
fileEntry.createWriter(function (fileWriter) {
fileWriter.seek(fileWriter.length);
var bb = new BlobBuilder();
bb.append("\n<TimeStamp>" + getTimestamp() + "</TimeStamp><Browser>Chrome</Browser><URL>" + tabURL + "</URL>\n");
fileWriter.write(bb.getBlob('text/plain'));
});
});
}
}
}

- 398,270
- 210
- 566
- 880

- 2,185
- 4
- 20
- 24
-
1Are you writing a Chrome extension? If so, please specify that (in a tag and/or in the question). – Martijn Mar 25 '11 at 07:56
-
Try adding an error callback to the requestFileSystem call to display any errors. – HBP Mar 25 '11 at 12:14
-
I have edited changes to my question,previous problem have been solved & I have been faced with a new problem. Do guide me along,thank you in advance. – Derek Mar 26 '11 at 07:37
-
If your question was answered you should close it and open a new one. In any case I see your code, what is the question. – HBP Mar 26 '11 at 09:58
3 Answers
Based on this:
At the time of writing this article, Google Chrome 9+ has the only working implementation of the FileSystem API. Since a dedicated browser UI does not yet exist for file/quota management, the API cannot be used without running Chrome with the --unlimited-quota-for-files flag (Note: if you're building an app or extension for the Chrome Web Store, the unlimitedStorage manifest file permission will suffice).
found at http://www.html5rocks.com/tutorials/file/filesystem/#toc-support
I assume you are using Chrome and that you have not set the --unlimited-quota-for-files flag

- 15,685
- 6
- 28
- 34
-
If I were to add the permission "unlimitedStorage" in the manifest file,it would prompt me " Manifest is not valid JSON, syntex error. Whats the problem ? – Derek Mar 26 '11 at 05:13
-
The manifest file must be valid JSON syntax. See here : http://code.google.com/chrome/extensions/manifest.html#permissions – HBP Mar 26 '11 at 05:42
-
I have edited changes to my question,previous problem have been solved & I have been faced with a new problem. Do guide me along,thank you in advance. – Derek Mar 26 '11 at 07:38
This filesystem API does not appear to actually write a true "file" to your hard disk.
It seems to store a file within a sandboxed safe zone in the browser.
You'll have to write a quick and dirty little file manager (or find one out there) to manage the files for a given web app. You can also try visiting filesystem://<your URL here>/temporary/
to see all the files that your app has created.
-
-
1can the written file be accessed from outside the browser? Let's say I write a text file, can I open it in an external text editor somehow? – ycomp May 20 '16 at 23:56
What about just using localStorage?

- 27,922
- 9
- 70
- 85
-
I have seen the tutorial on the HTML5 fileSystem API on writing the file to the local system,I believed I followed every step but I havent been able to see my log file inside my local system. Any advice ? – Derek Mar 25 '11 at 07:46
-
I have edited changes to my question,previous problem have been solved & I have been faced with a new problem. Do guide me along,thank you in advance. – Derek Mar 26 '11 at 07:37
-
localStorage is probably the easiest option. Only disadvantage is that is limited to 5 MB, even after specifying the `"unlimitedStorage"` permission. Use it like this: `localStorage["log"] = "Hello World!"` to write, and `log = localStorage["log"]` to read. – Maxime Kjaer Jul 30 '12 at 21:11