2

我在 content.js 中使用以下代码,它工作正常。

window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
var fs = null;

function initFS(grantedBytes) {
    window.requestFileSystem(window.PERSISTENT, grantedBytes, function(filesystem) {
        fs = filesystem;
    }, errorHandler);
}
function askStorage(){
    console.log("askStorage");
    window.webkitStorageInfo.requestQuota(PERSISTENT, 500*1024*1024, function(grantedBytes) {
        initFS(grantedBytes);
    }, function(e) {
        console.log('Error', e);
    });
}

function errorHandler(e) {
}

function saveFileSystem(files){
    for (var i = 0, file; file = files[i]; ++i) {
        console.log("file.name:"+file.name);
        if (!fs) alertFileError();

        (function(f) {
            fs.root.getFile((file.name), {create: true, exclusive: true}, function(fileEntry) {

                fileEntry.createWriter(function(fileWriter) {
                    fileWriter.write(f); 
                    console.log("toURL:"+fileEntry.toURL());
                }, errorHandler);

            }, errorHandler);
        })(file);

    }


}
askStorage();

但是,当我在 background.js 中使用这些代码时,我收到一个错误“未捕获的错误:TYPE_MISMATCH_ERR:DOM 文件异常 11”。任何想法?谢谢!!

4

0 回答 0