-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PDF blobs no longer load in v5.0.0 on iOS 14.4.2 #863
Comments
Have you found a reliable way of using createObjectUrl on ios? |
got this error too on ios 12.x and had to downgrade to v.4.1 |
This is also now a problem for iOS 17.2.x with inappbrowser version v4.1. v4.1 works until iOS 17.1.X so can we assume this is cordova-ios issue rather than inappbrowser? I'm currently on cordova-ios@7.0.1 but it doesn't seem to have the support yet. |
I think the main issue is trying to share blob urls across different WKWebView instances. These are browser/webview implementation details but by specification, the browser is suppose t have a blob store, which when you create an object url from a blob, a blob store entry will be created and for as long as that entry exists, so will the blob. These blob store entries are the mapping from a blob url to the location of stored memory for that blob. In this case, we have 2 wkwebview instances, the main "cordova" app instance, and the in-app browser instance. I feel like they will probably have their own blob store entries and attempting to share a URL created from one instance is not usable. I think the reason why it seems to "sometimes" work is because both the in-app-browser and the main webview does used a shared process pool which states:
I suspect that if that process limit is reached and the webview instances starts sharing the same web content process, then blobs works across webview instances (assuming that the web content process is what contains the aforementioned blob store entries). Despite the use of "By default", I see no public API to adjust this behaviour (and ChatGPT claims there is no such API either, for what that's worth). We also don't know what that process limit means or how it can be reached since that is also not documented. Potential Workarouds?Base64 Data URLsIf you're dealing with small files, reading the blobs as base64 data urls could be a valid and simple workaround. Using base64 will expand memory consumption by approximately 33% of the original size, making it slow and risky to use on larger data files potentially loading to OOM (Out of Memory) errors See FileReader.readAsDataURL for more details. For larger file sizesBecomes much more tricky to remain efficient. This would be experimental but I would try reading the blob as a 8int typed array and then slicing the array in chunks. You'll need to create a special HTML document for the in-app-browser to load which will accept these chunks in sequence so that the uint8 array can be rebuilt in the inapp browser instance. Once re-created, the in-app-browser can create its own blob to create blob urls, and maybe navigate to a blob url that it creates? Reading as a 8int typed array is asynchronous and allows you to create slices and handle the data in a chunk fashion. When sending the chunks via executeScript, you can loop breaks by awaiting on the callback, making that process asynchronous, allowing your UI to render loading progresses or give user feedback. To keep the memory footprint low, it would be beneficial to discard slices on the cordova webview side once they are "sent" to the in-app-browser, allowing the slices to be garbage collected once they are no longer needed. |
Bug Report
Problem
I'm not sure if this should have worked to begin with but I was hoping to use the in app browser to display in memory PDFs. In v4.1.0 this seemed to work just fine however in v5.0.0 this no longer renders the PDF. I verified this by switching the plugin between versions and noticing the change in behaviour.
What is expected to happen?
In v4.1.0 the PDF would render in the in app browser window.
Stack trace:
What does actually happen?
In v5.0.0 displays a blank in app browser window. From reading the stack trace what jumps out at me is WebKitBlobResource (code 1).
Stack trace:
Information
I think the below code should be all thats needed. You'll need to grab the contents of a PDF and initialise
pdf
with that.Command or Code
From reading around mozilla/pdf.js#8152 (comment) it seems that using blobs is unreliable in iOS safari and I guess the in app browser was using wkwebview before which is why this wasn't exhibited before?
Hopefully thats enough info to go on but if you need any more info let me know. I did try and find what was going on myself but I'm a bit out of my depth here 😓
Environment, Platform, Device
iOS 14.4.2
Version information
cordova-plugin-inappbrowser: 5.0.0
Checklist
The text was updated successfully, but these errors were encountered: