Epub.js - Phonegap not working because of blob URI

有些话、适合烂在心里 提交于 2019-12-10 10:36:02

问题


I'm using Epub.js library to render a .epub file in a Phonegap project.

The file gets fetched and unzipped correctly, but then the screen is displayed blank if running in WebView (Works perfect in Desktop and in android browser (Chrome app)).

Debugging, I see that the iframe where the epub should be loaded doesn't work, as iframe.onload never gets called. The URL he's trying to access is blob:file%3A///85a6ce73-2b5f-430e-a908-26a7d3d830e4, so I'm guessing that could be the reason... Cordova doesn't accept blob URI schemes.

However, I don't know any workaround... I'm completely stuck there.


回答1:


I got the solution. The answer to all "Cordova doesn't accept URI" is always "Whitelist"

With the whitelist plugin I had in my config file:

<access origin="*" />

However, debugging i saw that the blob:/file://...uri was getting blocked in shouldAllowNavigation. Then I tried with:

<access origin="*" />
<allow-navigation origin="*" />

But! it still didn't work. Debugging a bit more, I saw that the WhitelistPlugin if you add a *it doesn't allow everything, but only http://, https://and data:. Finally, adding:

<access origin="*" />
<allow-navigation href="*" />
<allow-navigation href="blob:*" />

Fixed the issue for me.

Also, just in case it's helpful for someone, while I was testing, I tried downloading the .epub file from a server and extracting it in the filesystem (/data/data/package/...) and accessing it from there. For some reason, accessing local files with XHR Requests returns status: 0, like it failed, but the response is there. I had to edit epub.js file EPUBJS.core.requestmethod to accept responses if this.response is set (instead of expecting this.statusto be 200).



来源:https://stackoverflow.com/questions/31941634/epub-js-phonegap-not-working-because-of-blob-uri

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