Skip to content

fix(CodeWebView): guard external-link launch with try/catch#446

Open
jim-daf wants to merge 1 commit into
ThirtyDegreesRay:masterfrom
jim-daf:fix-codewebview-startactivity
Open

fix(CodeWebView): guard external-link launch with try/catch#446
jim-daf wants to merge 1 commit into
ThirtyDegreesRay:masterfrom
jim-daf:fix-codewebview-startactivity

Conversation

@jim-daf
Copy link
Copy Markdown

@jim-daf jim-daf commented May 15, 2026

Closes #445.

CodeWebView.startActivity(Uri) routes any tapped link out of the code-preview WebView through AppOpener.launchUrl, which on the Custom Tabs path calls customTabsIntent.launchUrl(context, Uri.parse(url)). If the chosen custom-tabs package is uninstalled between CustomTabsHelper.INSTANCE.getBestPackageName(context) and this launchUrl, the latter raises ActivityNotFoundException. The exception propagates all the way back through shouldOverrideUrlLoading and the WebView's host activity crashes mid-tap.

openInBrowser (the non-Custom-Tabs path) already shows a fallback Toast, so the equivalent guard belongs at the helper:

private void startActivity(Uri uri){
    if(uri == null) return;
    try {
        AppOpener.launchUrl(getContext(), uri);
    } catch (android.content.ActivityNotFoundException e) {
        // chosen custom-tabs / browser package disappeared between
        // selection and launch
    }
}

The happy path (URL with a viewer installed) is unchanged.

CodeWebView.shouldOverrideUrlLoading routes tapped links out via the
startActivity helper, which delegates to AppOpener.launchUrl. The
Custom Tabs path inside AppOpener calls customTabsIntent.launchUrl
without a try/catch, so if the chosen custom-tabs package is
uninstalled between CustomTabsHelper.getBestPackageName and that
launchUrl, the exception propagates back through
shouldOverrideUrlLoading and the WebView's host activity crashes
mid-tap.

The non-Custom-Tabs path (openInBrowser) already shows a fallback
Toast, so the matching guard belongs at the helper that fans both
paths out.
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 this pull request may close these issues.

CodeWebView can crash mid-tap if the chosen Custom Tabs browser is uninstalled

1 participant