UrlLauncherIOS Safari view controller load crash#4533
Conversation
… crash Catch exceptions from launchUrl with inAppBrowserView mode and fallback to external browser. Prevents crash when Safari view controller fails to load the URL. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Code Review
This pull request addresses a crash on iOS when launching URLs in an in-app browser by adding a try-catch block and a fallback mechanism to an external browser. The change is straightforward and effectively prevents the crash. The included comment further improves the robustness of the URL launching logic by handling cases where launchUrl might fail without throwing an exception, which is a valuable enhancement.
| try { | ||
| await launchUrl( | ||
| uri, | ||
| mode: LaunchMode.inAppBrowserView, | ||
| ); | ||
| } catch (e) { | ||
| Logger.debug('Failed to launch URL: $e'); | ||
| // Fallback to external browser if in-app browser fails | ||
| try { | ||
| await launchUrl(uri, mode: LaunchMode.externalApplication); | ||
| } catch (e) { | ||
| Logger.debug('Failed to launch URL externally: $e'); | ||
| } | ||
| } |
There was a problem hiding this comment.
The current implementation correctly handles exceptions when launching the URL, which fixes the reported crash. However, launchUrl can also return false on failure without throwing an exception. In that case, the fallback to an external browser would not be triggered, leading to a silent failure.
To make the implementation more robust, we should also handle the false return value from launchUrl. The suggested change refactors the logic to catch both exceptions and false return values from the in-app launch attempt, and then proceeds to the fallback in either case.
try {
if (!await launchUrl(uri, mode: LaunchMode.inAppBrowserView)) {
throw Exception('launchUrl returned false');
}
} catch (e) {
Logger.debug('Failed to launch URL in-app, falling back: $e');
try {
if (!await launchUrl(uri, mode: LaunchMode.externalApplication)) {
Logger.debug('Failed to launch URL externally, launchUrl returned false.');
}
} catch (e2) {
Logger.debug('Failed to launch URL externally: $e2');
}
}|
closed in #4628 |
|
Hey @aaravgarg 👋 Thank you so much for taking the time to contribute to Omi! We truly appreciate you putting in the effort to submit this pull request. After careful review, we've decided not to merge this particular PR. Please don't take this personally — we genuinely try to merge as many contributions as possible, but sometimes we have to make tough calls based on:
Your contribution is still valuable to us, and we'd love to see you contribute again in the future! If you'd like feedback on how to improve this PR or want to discuss alternative approaches, please don't hesitate to reach out. Thank you for being part of the Omi community! 💜 |
Summary
launchUrlwithinAppBrowserViewmodeCrash Stats
Test plan
🤖 Generated with Claude Code