我正在尝试使用 chrome.fileSystem api 将从 Chrome 地理定位 api 收集的数据保存到一个 txt 文件中,但是虽然我能够为此目的创建一个文件,但该文件在过程结束时仍然是空的。为简单起见,我首先尝试在文件中添加一个字符串 (1234567890)。正如您在代码中看到的那样,我添加了几个 console.log 来调查代码中的哪些行不执行,并且似乎代码没有从 writableFileEntry.creatrwriter() 向下执行。
chrome.fileSystem.chooseEntry({type: 'saveFile'}, function(writableFileEntry) {
console.log('writableFileEntry - here');
writableFileEntry.createWriter(function(writer) {
console.log('After writableFileEntry - here');
writer.onerror = errorHandler;
writer.onwriteend = function(e) {
console.log('write complete');
};
console.log('before Blob - here');
writer.write(new Blob(['1234567890'], {type: 'text/plain'}));
}, errorHandler);
});
manifest.json 文件如下所示:
"permissions": ["location","geolocation", "storage", "unlimitedStorage", "fileSystem", "syncFileSystem", {"fileSystem": ["write"]}
],
"app": {
"background": {
"scripts": ["background.js"]
}
},
"sockets": {
"tcp": {
"connect": "localhost:80"
},
"udp": {
"send": "localhost:80"
}
}
任何指导或建议都会很棒!谢谢奥弗