【发布时间】:2015-01-13 22:50:33
【问题描述】:
我有一个 Chrome 打包应用程序,它要求我能够查看已保存的离线网页。这些页面在用户在线时从我的服务器下载并保存到 HTML5 文件系统,以便可以离线查看。这个 Chrome bug 票似乎表明我想做的事情是可能的:https://code.google.com/p/chromium/issues/detail?id=343382
基于 Chrome 应用程序“webview”文档 (https://developer.chrome.com/apps/tags/webview),这是我想出的。
在我的清单中:
"permissions": [
{
"fileSystem": ["write"]
},
"storage",
"unlimitedStorage",
"webview"
],
"webview": {
"partitions": [
{
"name":"contentView",
"accessible_resources":["*.html"]
}
]
}
我的网页浏览标签:
<webview id="websiteWebview" minwidth="800" minheight="600" autosize="on" partition="contentView"></webview>
然后我通过javascript添加'src'属性:
var websiteWebview = document.querySelector('#websiteWebview');
websiteWebview.setAttribute('src', decodeURIComponent(srcUrl));
这会在控制台中产生以下结果:
filesystem:chrome-extension://[appId]/[pathToFile]/index.html
Failed to load resource: net::ERR_FILE_NOT_FOUND
Not allowed to load local resource: filesystem:chrome-extension://[appId]/[pathToFile]/index.html
我不知道从这里去哪里。提前感谢您的帮助!
【问题讨论】:
-
您确定该文件存在于您期望的位置吗?
-
是的。 ERR_FILE_NOT_FOUND 错误是 webview 阻止我的本地文件的症状。 code.google.com/p/chromium/issues/detail?id=321638