Skip to content

fix(sdk): isolate WebView crash recovery callbacks - #292

Merged
e271828- merged 2 commits into
fix/webview-render-process-gonefrom
codex/fix-webview-renderer-recovery
Nov 1, 2026
Merged

e271828- merged 2 commits into
fix/webview-render-process-gonefrom
codex/fix-webview-renderer-recovery

Conversation

@e271828-

Copy link
Copy Markdown
Contributor

When a renderer exits during a retry, cleanup from an older dialog can clear the replacement dialog's shared preload reference. The replacement then displays an uninitialized WebView. Dialog cleanup now clears that reference only when it owns the WebView.

An in-flight JavaScript bridge callback can also arrive after the failure listener starts a fresh verification. Renderer failure now invalidates the old verifier's callbacks before notifying the app, so a queued token or load event cannot complete the new attempt. The renderer error still reaches the failure listener once.

Adds regressions for both callback orders and queued bridge events. This PR targets #287.

Validation: :sdk:check :compose-sdk:check passed (117 SDK and 2 Compose unit tests); five targeted API 33 Android tests passed, including real renderer termination and dialog recovery.

@github-actions

github-actions Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Diffuse report:

OLD: sdk-main.aar
NEW: sdk-pr.aar

 AAR      │ old       │ new       │ diff  
──────────┼───────────┼───────────┼───────
      jar │  99.9 KiB │   100 KiB │ +39 B 
 manifest │     411 B │     411 B │   0 B 
      res │  28.3 KiB │  28.3 KiB │   0 B 
    other │     1 KiB │     1 KiB │   0 B 
──────────┼───────────┼───────────┼───────
    total │ 129.7 KiB │ 129.7 KiB │ +39 B 

 JAR     │ old │ new │ diff          
─────────┼─────┼─────┼───────────────
 classes │  62 │  62 │   0 (+0 -0)   
 methods │ 837 │ 851 │ +14 (+26 -12) 
  fields │ 287 │ 291 │  +4 (+4 -0)
AAR
 size    │ diff  │ path          
─────────┼───────┼───────────────
 100 KiB │ +39 B │ ∆ classes.jar 
─────────┼───────┼───────────────
 100 KiB │ +39 B │ (total)
JAR
METHODS:

   old │ new │ diff          
  ─────┼─────┼───────────────
   837 │ 851 │ +14 (+26 -12) 
  
  + com.hcaptcha.sdk.HCaptcha access_000(HCaptcha) → int
  + com.hcaptcha.sdk.HCaptcha access_008(HCaptcha) → int
  + com.hcaptcha.sdk.HCaptcha access_200(HCaptcha)
  + com.hcaptcha.sdk.HCaptcha access_300(HCaptcha) → InMemorySink
  + com.hcaptcha.sdk.HCaptcha access_400(HCaptcha, long)
  + com.hcaptcha.sdk.HCaptcha access_500(HCaptcha) → Handler
  + com.hcaptcha.sdk.HCaptcha access_600(HCaptcha, Object)
  + com.hcaptcha.sdk.HCaptcha access_700(HCaptcha, HCaptchaException)
  + com.hcaptcha.sdk.HCaptcha access_802(HCaptcha, IHCaptchaVerifier) → IHCaptchaVerifier
  + com.hcaptcha.sdk.HCaptcha access_900(HCaptcha, HCaptchaException)
  + com.hcaptcha.sdk.HCaptcha setupWithLastConfig()
  + com.hcaptcha.sdk.HCaptcha_1 <init>(HCaptcha, int, HCaptchaConfig)
  + com.hcaptcha.sdk.HCaptcha_1 onWebViewGone(HCaptchaException)
  + com.hcaptcha.sdk.HCaptchaDialogFragment executePendingTransactions()
  + com.hcaptcha.sdk.HCaptchaDialogFragment onWebViewGone(HCaptchaException)
  + com.hcaptcha.sdk.HCaptchaEmbeddedView onWebViewGone(HCaptchaException)
  + com.hcaptcha.sdk.HCaptchaHeadlessWebView onWebViewGone(HCaptchaException)
  + com.hcaptcha.sdk.HCaptchaStateListener onWebViewGone(HCaptchaException)
  + com.hcaptcha.sdk.HCaptchaWebViewHelper access_200(HCaptchaWebViewHelper) → IHCaptchaVerifier
  + com.hcaptcha.sdk.HCaptchaWebViewHelper access_300(HCaptchaWebViewHelper) → HCaptchaWebView
  + com.hcaptcha.sdk.HCaptchaWebViewHelper_HCaptchaWebClient onRenderProcessGone(WebView, RenderProcessGoneDetail) → boolean
  + com.hcaptcha.sdk.IHCaptchaVerifier onWebViewGone(HCaptchaException)
  + android.view.ViewGroup addView(View, int)
  + android.webkit.RenderProcessGoneDetail didCrash() → boolean
  + androidx.fragment.app.FragmentManager executePendingTransactions() → boolean
  + java.lang.StringBuilder append(boolean) → StringBuilder
  
  - com.hcaptcha.sdk.HCaptcha access_000(HCaptcha)
  - com.hcaptcha.sdk.HCaptcha access_200(HCaptcha) → InMemorySink
  - com.hcaptcha.sdk.HCaptcha access_300(HCaptcha, long)
  - com.hcaptcha.sdk.HCaptcha access_400(HCaptcha) → Handler
  - com.hcaptcha.sdk.HCaptcha access_500(HCaptcha, Object)
  - com.hcaptcha.sdk.HCaptcha access_600(HCaptcha, HCaptchaException)
  - com.hcaptcha.sdk.HCaptcha_1 <init>(HCaptcha, HCaptchaConfig)
  - com.hcaptcha.sdk.HCaptchaWebViewHelper access_200(HCaptchaWebViewHelper) → HCaptchaWebView
  - com.hcaptcha.sdk.HCaptchaWebViewHelper access_300(HCaptchaWebViewHelper) → IHCaptchaVerifier
  - android.view.View getLayoutParams() → ViewGroup_LayoutParams
  - android.view.ViewGroup addView(View, int, ViewGroup_LayoutParams)
  - android.view.Window setLayout(int, int)
  

FIELDS:

   old │ new │ diff       
  ─────┼─────┼────────────
   287 │ 291 │ +4 (+4 -0) 
  
  + com.hcaptcha.sdk.HCaptcha setupGeneration: int
  + com.hcaptcha.sdk.HCaptcha_1 val_generation: int
  + com.hcaptcha.sdk.HCaptchaDialogFragment fragmentManager: FragmentManager
  + com.hcaptcha.sdk.HCaptchaDialogFragment webViewDestroyed: boolean

@e271828-
e271828- requested a review from CAMOBAP October 31, 2026 19:18
@github-actions

github-actions Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Benchmark report:

Test name Time ms. (median) Allocations (median)
com.hcaptcha.sdk.HCaptchaBenchmarkTest.EMULATOR_UNLOCKED_benchmarkInvisibleVerification +592.92 +26
com.hcaptcha.sdk.HCaptchaBenchmarkTest.EMULATOR_UNLOCKED_benchmarkInvisibleVerificationColdRun +727.18 +551
com.hcaptcha.sdk.HCaptchaBenchmarkTest.EMULATOR_UNLOCKED_benchmarkInvisibleSetup +5.40 +515
com.hcaptcha.sdk.HCaptchaDebugInfoTest.EMULATOR_UNLOCKED_benchmarkDebugInfo +19.70 -5568
com.hcaptcha.sdk.HCaptchaDebugInfoTest.EMULATOR_UNLOCKED_benchmarkDebugSys +37.98 -163

@e271828-
e271828- merged commit 339e855 into fix/webview-render-process-gone Nov 1, 2026
12 checks passed
@e271828-
e271828- deleted the codex/fix-webview-renderer-recovery branch November 1, 2026 10:59
e271828- added a commit that referenced this pull request Nov 3, 2026
* fix(sdk): handle WebView render process crash

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* test(sdk): cover WebView render process crash

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* fix(sdk): don't reuse or retry a WebView whose renderer is gone

A dead WebView went through onFailure, so a retry predicate could
silently retry on it, and HCaptcha kept the cached verifier, so the
next verifyWithHCaptcha() reused the destroyed WebView.

Route it through a dedicated onWebViewGone that tears the WebView down
and reports the failure without retrying, and let HCaptcha drop the
cached verifier. The cold start reuses the config from an earlier
setup(config) instead of falling back to the manifest site key.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(sdk): verify again after the render process is gone

End to end in headless and dialog mode: once the renderer is gone the
failure is reported, and a following verifyWithHCaptcha() gets a token
from a fresh WebView instead of reusing the dead one.

The renderer death is signalled through the WebView's own client rather
than chrome://crash: all WebViews of the app share one renderer, so a
real crash would also kill the ones other tests left behind and fire
their listeners.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(sdk): recover cleanly when the WebView is gone mid-flow

- Dialog: land queued fragment transactions before checking whether the
  dialog is already shown, and remove a dead dialog synchronously, so a
  verify from the failure listener shows a fresh dialog and a crash
  before the show commits leaves nothing on screen.
- Client: scope the WebView-gone callback to its setup generation, so a
  stale WebView sharing the renderer can't clear the replacement verifier
  or report a second failure.
- Compose: start over with a fresh WebView on the next recomposition
  after the renderer is gone; document retrying via key().

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(sdk): don't touch a destroyed client or WebView afterwards

- destroy() cancels the pending token expiration, so a replaced client
  no longer reports TOKEN_TIMEOUT for its last token.
- The dialog skips resetting its WebView in onDestroy() once destroy()
  released it, which logged "attempted to call on a destroyed WebView".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(sdk): keep the fields the render-process-gone tests reach by reflection

R8 renamed them in the minified UI test build, failing it with NoSuchFieldException.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(sdk): isolate WebView crash recovery callbacks (#292)

* fix(sdk): isolate WebView crash recovery callbacks

* fix(sdk): retire verifier before reconfiguration

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-authored-by: e271828- <e271828-@users.noreply.github.com>
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.

2 participants