这里的问题是我正在写的东西popup.js
可以window.webkitRequestFileSystem
从那里读取,但我不能从content.js
.
PS:两个文件的代码是一样的
清单.json
{
"manifest_version": 2,
"browser_action": {
"default_popup": "action.html"
},
"content_scripts": [
{
"js": ["content.js"]
}
],
"background": {
"scripts": ["background.js"]
},
"permissions": [
"unlimitedStorage",
]
}
动作.html
// Here is the popup.js file included
popup.js
window.webkitRequestFileSystem(window.PERSISTENT, 0, readFromFileStorage, errorHandler);
function readFromFileStorage(fs) {
fs.root.getFile('file.txt', {}, function(fileEntry) {
fileEntry.file(function(file) {
var reader = new FileReader();
reader.onloadend = function(e) {
console.log(this.result);
};
reader.readAsText(file);
}, errorHandler);
}, errorHandler);
}
内容.js
window.webkitRequestFileSystem(window.PERSISTENT, 0, readFromFileStorage, errorHandler);
// the function 'readFromFileStorage' is the same as in "popup.js"