Using the viewer from pdf.js I successfully managed to open a local pdf file with the InAppBrowser. The following code works without flaws on iOS: the InAppBrowser opens and displays the pdf with the viewer!
window.resolveLocalFileSystemURL(fileURL, function (file) {
window.open('lib/pdf.js-master/web/viewer.html?file=' + file.toURL(), '_blank', 'location=no')
}, fail);
file.toURL()
renders to something like file:///blabla/bla
.
However, on Android the pdf fails to load, giving the console error
"XMLHttpRequest cannot load file:///android_asset/www/lib/pdf.js-master/web/locale/locale.properties. Cross origin requests are only supported for HTTP.", source: file:///android_asset/www/lib/pdf.js-master/web/viewer.html?file=file:///storage/emulated/0/Android/data/xxxxxxxxx/cache/677.pdf
and there isn't even a www/lib/pdf.js-master/web/locale/locale.properties
file... I don't know if this has anything to do with the problem, but I'm including it here.
But this is followed by the error
"XMLHttpRequest cannot load file:///storage/emulated/0/Android/data/xxxxxxxxx/cache/677.pdf. Cross origin requests are only supported for HTTP.", source: file:///android_asset/www/lib/pdf.js-master/web/viewer.html?file=file:///storage/emulated/0/Android/data/xxxxxxxxx/cache/677.pdf
which absolutely has something to do with the problem.
Resulting in the following screen.
I don't know how to fix the error. And once again, it works flawlessly on iOS! What can I do to make it work on android? How can I enable cross origin requests for file:///
? Is this the problem?
Thanks for any help.