WebsiteBeaver / capacitor-document-scanner

A Capacitor document scanner plugin for Android and iOS
https://document-scanner.js.org
66 stars 24 forks source link

iOS 15.6.1 - Ionic 6 - Webkit Crashes sometimes in the Background #9

Open urshofer opened 1 year ago

urshofer commented 1 year ago

Hi -

Thanks for your great Work.

In my case, when opening the scanner, the App in the background sometimes crashes and restarts. Therefore not listening to any callbacks and the scanned input is lost. I don't know when exactly it happens. Not depending of the size of the scan.

It might be related to a webkit bug: https://github.com/ionic-team/capacitor/issues/5491

Anyway, here's the log:

⚡️  [log] - start scan
⚡️  To Native ->  DocumentScanner scanDocument 67361918
2022-09-09 14:14:59.176340+0200 App[16404:767529] [XPC] Handle connection with error: Connection interrupted
2022-09-09 14:14:59.176974+0200 App[16404:766008] [Process] 0x113001230 - [PID=16415] WebProcessProxy::didClose: (web process 0 crash)
2022-09-09 14:14:59.177008+0200 App[16404:766008] [Process] 0x113001230 - [PID=16415] WebProcessProxy::processDidTerminateOrFailedToLaunch: reason=4
2022-09-09 14:14:59.177119+0200 App[16404:766008] [ProcessSuspension] 0x111018120 - ProcessAssertion: Failed to acquire RBS Background assertion 'ConnectionTerminationWatchdog' for process because PID 0 is invalid
2022-09-09 14:14:59.177285+0200 App[16404:767530] [ProcessSuspension] 0x111018120 - ProcessAssertion::acquireSync Failed to acquire RBS assertion 'ConnectionTerminationWatchdog' for process with PID=0, error: (null)
2022-09-09 14:14:59.179592+0200 App[16404:766008] [Process] 0x10301d018 - [pageProxyID=7, webPageID=8, PID=16415] WebPageProxy::processDidTerminate: (pid 16415), reason 4
2022-09-09 14:14:59.198168+0200 App[16404:766008] [Loading] 0x10301d018 - [pageProxyID=7, webPageID=8, PID=16415] WebPageProxy::dispatchProcessDidTerminate: reason=Crash
⚡️  [log] - onscript loading complete

Maybe somebody can point me in the right direction for a fix.

Best, hofer

dmarcs commented 1 year ago

Try uninstalling this plugin, and see if the error keeps happening.

urshofer commented 1 year ago

Without plugin the error does not happen. It seems like while the scanner is active, the webview in the background is restarted due to a crash. Saving the scan is not possible since the new webview has no connection to the callback from the scanner.

mattbenson247 commented 1 year ago

Any updates here? Having the same issues here with the logs below:

2023-02-21 11:03:58.215457-0600 App[2090:277065] [XPC] Handle connection with error: Connection interrupted
2023-02-21 11:03:58.368162-0600 App[2090:272383] [Process] 0x111000b90 - [PID=2223] WebProcessProxy::didClose: (web process 0 crash)
2023-02-21 11:03:58.368530-0600 App[2090:272383] [Process] 0x111000b90 - [PID=2223] WebProcessProxy::processDidTerminateOrFailedToLaunch: reason=Crash
2023-02-21 11:03:58.369847-0600 App[2090:272383] [ProcessSuspension] 0x1100201e0 - ProcessAssertion: Failed to acquire RBS Background assertion 'ConnectionTerminationWatchdog' for process because PID 0 is invalid
2023-02-21 11:03:58.370038-0600 App[2090:277065] [ProcessSuspension] 0x1100201e0 - ProcessAssertion::acquireSync Failed to acquire RBS assertion 'ConnectionTerminationWatchdog' for process with PID=0, error: (null)
2023-02-21 11:03:58.373799-0600 App[2090:272383] [Process] 0x102010018 - [pageProxyID=8, webPageID=9, PID=2223] WebPageProxy::processDidTerminate: (pid 2223), reason=Crash
urshofer commented 1 year ago

No - no solution found so far. I tried to install the newest dependencies, but the Webview just crashes sometimes in the background and does a clean restart. So it looks like the app is still running but the PID changed and there's no possibility for the plugin to pass the data back to the app. It happens on all iOS Devices I have, iPhone SE 2022 and two different iPads with latest iOS installed. The crash happens not regularly, sometimes i feel it happens less often if there are no other apps running. Maybe there's a possibility for a (nasty?) workaround. Someting like: Passing a filename to the plugin, store this name persistently, and check on every startup for a filename entry in the persistent store. In case of a crash the webview could watch for this filename and restore the scan even after a crash.

urshofer commented 1 year ago

Just waking up an old thread: After upgrades (capacitor, iOS) the bug still exists. I'm not even sure if it's a problem of capacitor-document-scanner or capacitor/ionic itself, or even a webkit bug. Anyway, If somebody knows more or has a workaround, glad to know :)

urshofer commented 1 year ago

Since I'm stuck here, I cross posted the issue in the ionic forum as well.

coolaydalena commented 6 months ago

Anybody can fix this issue? 😢

urshofer commented 6 months ago

No - I've switched my codebase to flutter, but even there using the iOS built in document scanner is wonky. Sometimes it just crashes without further notice due to memory pressure. My setup now is using not the native scanner, but the one from Wetransfer (https://github.com/WeTransfer/WeScan), which looks more stable.

Luuckyy commented 4 months ago

@urshofer Hey I was wondering if by chance you made a capacitor plugin for WeScan ? I don't really know much of Swift so it would help a lot

camilocalvo commented 1 month ago

I've come upon the same issue. It's not much help solution-wise, but it does appear to be that the crash is caused by occasional spikes in the memory while the camera scanner is active. See the attached image, with the spike where a crash occurred circled in red.

Screenshot 2024-07-11 at 3 05 26 PM

Here's someone else also describing the same issue and diagnosing it as being caused by a memory spike: https://github.com/ionic-team/capacitor/issues/6549#issuecomment-1529816229

Since this is an issue with the plugin from Apple, there may not be much to do. In any case, from the lack of customization options, it seems as if Apple hasn't put much effort into making VNDocumentCameraViewController usable by third-party applications.

@urshofer @dmarcs