Skip to content
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

Reading big media files make WKWebView crash with cordova-ios-6.x #1033

Closed
3 tasks done
gerhardsletten opened this issue Nov 27, 2020 · 13 comments · Fixed by #1481
Closed
3 tasks done

Reading big media files make WKWebView crash with cordova-ios-6.x #1033

gerhardsletten opened this issue Nov 27, 2020 · 13 comments · Fixed by #1481
Milestone

Comments

@gerhardsletten
Copy link

gerhardsletten commented Nov 27, 2020

Bug Report

After migration from cordova-ios-5.x to cordova-ios-6.x we now see that the cordova no longer support reading files in chunks. Instead the whole file is loaded into memory, which will limit file access to what is available on your device.

Problem

After what I can see, it looks like CDVURLSchemeHandler is handling access of local files in a cordova app, and it does not support delivering files with range headers so WKWebView don't need to load the whole file at once.

What is expected to happen?

Earlier with UIWebView we did not experience this so I guess that cordova on UIWebView handled this by reading these files in chunks. (Or it was packed with the default file-reading that UIWebView had)

What does actually happen?

Running simulator or a device attached to xcode we see a memory spike at the same size as the file you try to access. If you are on a device that can not handle this, it will result in a restart of the webview.

Information

Think the same problem is reported here for cordova-plugin-ionic-webview

Version information

[email protected]

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above
@timbru31
Copy link
Member

timbru31 commented Dec 7, 2020

Can you share an example project that we could use to debug the issue?

@gerhardsletten
Copy link
Author

@timbru31 Will do, I was looking for examples of stream-delivery with WKURLSchemeTask, but I have not found anything yet. Would think that also for native iOS apps, there would be use cases where content would be displayed within a WKWebView for simpler formatting, but maybe they would use the native playback of locally stored video and audio-file.

In this app I work with, we both support streaming and local playback of audiobooks, and since cordova-plugin-media did not support streaming, using the build in audio-tag in html5 worked well for both cases in the previous versions of cordova-ios.

@gerhardsletten
Copy link
Author

gerhardsletten commented Dec 16, 2020

@timbru31 You can find an example here: https://www.dropbox.com/s/900pfcoouh9h9xl/mp3Player.zip?dl=0

The 700mb mp3-audio book is to big for a github-repo. Its embedded right into the app to keep the example simple.

When running the app, you can click the InitAudio button which will read the file, and insert the native url into a tag.

function initAudioPlayer() {
  const audioEl = document.getElementById('audioEl');
  const file = cordova.file.applicationDirectory + "www/audio/ulyssess-grant.mp3";
  window.resolveLocalFileSystemURL(file, function(entry) {
    audioEl.style.display = "block"
    const nativePath = entry.toURL();
    const usedPath = window.WkWebView.convertFilePath(nativePath)
    audioEl.src = usedPath;
  })
}

If you have the memory usage open, you will see a big spike.

Skjermbilde 2020-12-16 kl  20 42 51

@mlegenhausen
Copy link
Contributor

I can confirm the problem. We have an offline functionality in our app that downloads a video of roughly the same size. When using the generated path from convertFilePath in the source tag for an video element the app crashes randomly due to these memory spikes and what was previously to cordova-ios@6 an instant load of the video now takes "ages" do to the loading time of the file into memory.

@iyevpak
Copy link

iyevpak commented Dec 7, 2021

Hello,
any news about this problem?

@gerhardsletten
Copy link
Author

Did research a lot if there was some way around this, but since you have to upgrade to WKWebView to work on the latests ios-versions and since cordova with WKWebView don't support a streamed reading of files, cordova is not longer an option if your app require these things. I migrated the app over to React Native.

@iyevpak
Copy link

iyevpak commented Dec 10, 2021

Thanks for reply

@0pamama
Copy link

0pamama commented Jun 2, 2022

Hello, I am still facing this issue. Is there any solution now?

@mlegenhausen
Copy link
Contributor

You can work around this issue with the cordova-httpd Plugin. The trick is to start a local web server on your device and fetch all bigger resources from there. Be careful when you bind to a port. It could actually already be taken so you will need some fallback strategy, like trying another port until you found a free one.

@0pamama
Copy link

0pamama commented Jun 3, 2022

Thank you! I will give it a try...
Is this a WKWebView issue or is it cordova-ios related? I noticed that requests with custom scheme do not contain range header!?

@jbgtmartin
Copy link

I think that this issue is related to WKWebView itself. See this WebKit issue, that has been fixed but not landed yet in iOS. I have tried with iOS 15.4.1 and the memory usage is still huge. So I guess that it will be fixed in a future iOS release, but I don't know which one.

@dpogue
Copy link
Member

dpogue commented Apr 16, 2023

Is this fixed with iOS 16?

@dpogue dpogue added the webkit bug Bugs that originate upstream in Apple's WebKit implementation label Aug 18, 2024
@dpogue
Copy link
Member

dpogue commented Aug 25, 2024

Range headers are now included in the WKURLSchemeTask headers on recent versions of iOS, but this is still an issue because the Range headers need to actually be handled in the Scheme Handler.

There's a PR on the Ionic webview plugin (ionic-team/cordova-plugin-ionic-webview#692) that looks promising as far as implementing that logic, so we should be able to try something similar here.

@dpogue dpogue added this to the 8.0.0 milestone Aug 25, 2024
@dpogue dpogue removed the webkit bug Bugs that originate upstream in Apple's WebKit implementation label Aug 25, 2024
dpogue added a commit to dpogue/cordova-ios that referenced this issue Aug 28, 2024
dpogue added a commit to dpogue/cordova-ios that referenced this issue Aug 28, 2024
dpogue added a commit to dpogue/cordova-ios that referenced this issue Aug 28, 2024
dpogue added a commit to dpogue/cordova-ios that referenced this issue Aug 29, 2024
@dpogue dpogue closed this as completed in 2cc8678 Aug 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants