package apps
较chrome拓展,chrome应用有更加严格的安全策略,有一些只在应用中支持的API,例如fileSystem
开发中遇到的不好查阅到的点
确认需要开发的是拓展或者应用,应用对后台脚本的申明
"app": {
"background": {
"scripts": ["background.js"]
}
},
后台脚本创建的窗口(区别于浏览器窗口)支持打断点需在manifest配置
"content_scripts": [
{
"matches": ["http://www.google.com/*"],
"css": ["popup.css"],
"js": ["jquery.js", "popup.js"]
}
],
后台脚本创建的窗口不支持command+R刷新,似乎屏蔽了刷新的机制, 只能从拓展应用页面上command+R或者手动触发
console 调用 location.reload() 无法对页面进行刷新
chrome.runtime.reload() 能实现刷新
fileSystem调用示例
this.fs = chrome.fileSystem;
this.reader = new FileReader();
//打开文件夹
this.chooseEntry = function() {
var that = this;
this.fs.chooseEntry({ type: "openDirectory" }, function(Entry) {
chrome.fileSystem.getDisplayPath(Entry, function(Path){
document.getElementById('J_qnPath').value = Path;
that.qnWorkbenchPath = Path;
})
});
};
//遍历子目录以及文件
this.getSubEntries = function(depth, Entry, parent){
var dirReader = Entry.createReader();
dirReader.readEntries(function(Entries) {
for(var i=0; i<Entries.length; i++){
var newParent = document.createElement('div');
newParent.id = Date.now();
newParent.innerText = echoEntry(depth+1, Entries[i]);
parent.appendChild(newParent);
if(Entries[i].isDirectory){
getSubEntries(depth+1, Entries[i], newParent);
}
}
}, errorHandler);
};