How do you display a filesystem URL in a Chrome app webview?

喜你入骨 提交于 2020-01-01 05:45:08

问题


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

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

In my manifest:

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

My webview tag:

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

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!


回答1:


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

You could try reading the file to a data URL using a FileReader, then setting the webview's src attribute to the 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).




回答2:


You could work around this by including the web server for chorme library within your application. There are examples on the site for how to include it in your own chrome app. It would require you to use extra permissions in your manifest, namely some chrome.sockets permissions.



来源:https://stackoverflow.com/questions/27932960/how-do-you-display-a-filesystem-url-in-a-chrome-app-webview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!