如何在Chrome应用程序Webview中显示文件系统URL? [英] How do you display a filesystem URL in a Chrome app webview?

查看:84
本文介绍了如何在Chrome应用程序Webview中显示文件系统URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Chrome打包的应用,该应用要求我能够查看已保存的离线页面.这些页面在用户在线时从我的服务器上下载,并保存到HTML5文件系统中,以便可以脱机查看.这张Chrome浏览器故障单似乎表明我想做的事情是可能的: https ://code.google.com/p/chromium/issues/detail?id = 343382

I have a Chrome packaged app that requires me to be able to view saved, offlined web pages. These pages are downloaded from my server when the user is online and saved to the HTML5 filesystem so that they can be viewed offline. This Chrome bug ticket seems to indicate that what I want to do is possible: https://code.google.com/p/chromium/issues/detail?id=343382

基于Chrome应用程序的"webview"文档( https://developer.chrome.com/apps/tags/webview ),这就是我想出的.

Based on the Chrome app 'webview' docs (https://developer.chrome.com/apps/tags/webview), this is what I came up with.

在我的清单上

"permissions": [
    {
        "fileSystem": ["write"]
    },
    "storage",
    "unlimitedStorage",
    "webview"
],
"webview": {
    "partitions": [
        {
            "name":"contentView",
            "accessible_resources":["*.html"]
        }
    ]
}

我的webview标签:

My webview tag:

<webview id="websiteWebview" minwidth="800" minheight="600" autosize="on" partition="contentView"></webview>

然后我通过javascript添加'src'属性:

And then I'm adding the 'src' attribute through javascript:

var websiteWebview = document.querySelector('#websiteWebview');
websiteWebview.setAttribute('src', decodeURIComponent(srcUrl));

这将在控制台中显示以下内容:

This results in the following in the console:

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

我不确定从这里去哪里.预先感谢您的帮助!

I'm not sure where to go from here. Thanks in advance for your help!

推荐答案

webview标签似乎不支持文件系统URI-

It looks like the webview tag does not support filesystem URIs - Chromium Issue 321628. Bummer.

您可以尝试使用 FileReader ,然后将webviewsrc属性设置为URL.

You could try reading the file to a data URL using a FileReader, then setting the webview's src attribute to the URL.

我正在使用在NaCl中创建的一个简单的Web服务器来解决这个问题,该服务器已经嵌入到我的应用程序中(数据URL弄乱了我的文件编码).

I'm getting around it by using a simple web server I created in NaCl which I've already got embedded in my app (data URLs are messing up my file encoding).

这篇关于如何在Chrome应用程序Webview中显示文件系统URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆