Tuesday, May 8, 2012

Can the synchronous file system api be used in a chrome extension

I'm creating page action popup in google extensions. I need to write contents back to a file when the popup gets closed. For this I have attached the window.unload event. In the unload handler I'm trying to write to the file. But since I'm using the asynchronous api, immediately after setting the successHandler for the getFile function, the page gets closed and the successHandler does not get executed. Can I use the synchronous file api here? I read that the synchronous apis can be used only with webworkers. Can it be used in extensions? Or is there some other way to deal with this situation. I'm pasting my code for the writing to the file here



fileSystem.root.getFile(fileName, {create : true, exclusive : true}, function (fileEntry) {
file.createWriter(function() {
window.BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder;
var bb = new BlobBuilder();
bb.append(JSON.stringify(credentialsObj));
fileWriter.write(bb.getBlob('text/plain'));
}, errorHandler);
}, errorHandler);




No comments:

Post a Comment