我有一个 Chrome 打包应用程序,要求我能够查看已保存的离线网页。当用户在线时,这些页面会从我的服务器下载并保存到 HTML5 文件系统,以便可以离线查看。这个 Chrome bug 似乎表明我想做的事情是可能的:https://code.google.com/p/chromium/issues/detail?id=343382 https://code.google.com/p/chromium/issues/detail?id=343382
基于 Chrome 应用程序“webview”文档(https://developer.chrome.com/apps/tags/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
我不知道从这里该去哪里。在此先感谢您的帮助!