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.
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:
However, debugging i saw that the
blob:/file://...
uri was getting blocked in shouldAllowNavigation. Then I tried with: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 onlyhttp://
,https://
anddata:
. Finally, adding: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 fileEPUBJS.core.request
method to accept responses ifthis.response
is set (instead of expectingthis.status
to be200
).