【发布时间】:2014-06-18 11:17:48
【问题描述】:
编辑:发现错误,但无法解决,见下文。
manifest.json
{
...
"offline_enabled": true,
"app": {
"background": {
"persistent": true,
"scripts": [
"/js/background.js"
]
}
},
"permissions": [
"notifications",
"storage",
{"fileSystem": ["directory"]}
]
}
background.js
chrome.app.runtime.onLaunched.addListener(function() {
window.open('/index.html');
});
index.html
<!DOCTYPE html>
<html>
<head>
<title>Achshar Player</title>
<script src="/js/index.js"></script>
</head>
<body>
<input id="input" type="button">
</body>
</html>
index.js
window.addEventListener('load', function() {
document.getElementById('input').addEventListener('click', function() {
chrome.fileSystem.chooseEntry({type: 'openFile'}, function(readOnlyEntry) {
console.log(readOnlyEntry);
});
});
});
方法被调用,回调也被调用,但是文件选择对话框永远不会出现,并且在执行回调时readOnlyEntry未定义。开发工具上没有错误,我在 35.0.1916.153 m。
我已经为 fileSystem 尝试了不同的清单声明变体,但由于该函数在脚本执行中未定义,因此清单不太可能是问题。
当我使用fileSystem API 的official example 扩展时,应用程序可以正常工作,因此 chrome 设置也不是问题。问题似乎是我的代码,但我在这里迷路了。
编辑:我添加了每个文件的内容
编辑2:发现错误,现在如何解决?
我在 canary 中尝试过,发现错误是通过 chrome.runtime.lastError 而不是普通控制台显示的。这就是我得到的错误。
调用页面无效。无法从后台页面调用此函数。
但这不在 background.js 中,这是在 index.js 中,它是从 index.html 调用的。
【问题讨论】:
-
回滚编辑:
fileSystemAPI 不可用于扩展 -
酷,不知道。
-
你在使用 jQuery 吗?
-
不,纯 ol' javascript。无论如何,我将如何在 jquery 中调用 chrome API?编辑:哦,
$函数是我自己的,而不是 jquery。只是getelementbyid和queryselectorall的简写。 -
Chrome 应用程序在 jQuery 上运行良好;它只是 JavaScript。你会像其他任何东西一样称呼他们。但是,当您的代码包含
$('input')时,看起来您正在使用 jQuery 来查找页面中的元素。
标签: javascript google-chrome google-chrome-app