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

fix: calling webView.loadUrl on destroyed WebView #136

Merged
merged 2 commits into from
Dec 14, 2023

Conversation

CAMOBAP
Copy link
Collaborator

@CAMOBAP CAMOBAP commented Dec 13, 2023

Problem

If HCaptcha.reset is called after verification is finished (doesn't mater successful or not) message below gets printed to logcat by the system:

Application attempted to call on a destroyed WebView
java.lang.Throwable
	at org.chromium.android_webview.AwContents.s(chromium-TrichromeWebViewGoogle6432.aab-stable-609904333:10)
	at com.android.webview.chromium.WebViewChromium.loadUrl(chromium-TrichromeWebViewGoogle6432.aab-stable-609904333:15)
	at android.webkit.WebView.loadUrl(WebView.java:743)
	at com.hcaptcha.sdk.HCaptchaWebViewHelper.reset(Unknown Source:4)
	at com.hcaptcha.sdk.HCaptchaDialogFragment.reset(Unknown Source:4)
	at com.hcaptcha.sdk.HCaptcha.reset(Unknown Source:4)
	at Hcaptcha.reset$lambda$5(Hcaptcha.kt:112)
	at Hcaptcha.$r8$lambda$Z8mwFMXoe_rKDOgMykL8R7w_6Zw(Unknown Source:0)
	at Hcaptcha$$ExternalSyntheticLambda1.run(Unknown Source:2)
	at android.os.Handler.handleCallback(Handler.java:958)
	at android.os.Handler.dispatchMessage(Handler.java:99)
	at android.os.Looper.loopOnce(Looper.java:205)
	at android.os.Looper.loop(Looper.java:294)
	at android.app.ActivityThread.main(ActivityThread.java:8177)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)

To improve dev experience make sense to handle this situation, and keep logcat less poluted

It's not a crash just logcat

@CAMOBAP CAMOBAP requested a review from DSergiu December 13, 2023 18:33
@CAMOBAP CAMOBAP self-assigned this Dec 13, 2023
Copy link

github-actions bot commented Dec 13, 2023

Diffuse report:

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

 AAR      │ old       │ new       │ diff   
──────────┼───────────┼───────────┼────────
      jar │  51.8 KiB │  51.9 KiB │ +126 B 
 manifest │     411 B │     411 B │    0 B 
      res │  78.3 KiB │  78.3 KiB │    0 B 
    other │     814 B │     814 B │    0 B 
──────────┼───────────┼───────────┼────────
    total │ 131.2 KiB │ 131.3 KiB │ +126 B 

 JAR     │ old │ new │ diff       
─────────┼─────┼─────┼────────────
 classes │  37 │  37 │  0 (+0 -0) 
 methods │ 506 │ 507 │ +1 (+5 -4) 
  fields │ 164 │ 164 │  0 (+1 -1)
AAR
 size     │ diff   │ path          
──────────┼────────┼───────────────
 51.9 KiB │ +126 B │ ∆ classes.jar 
──────────┼────────┼───────────────
 51.9 KiB │ +126 B │ (total)
JAR
METHODS:

   old │ new │ diff       
  ─────┼─────┼────────────
   506 │ 507 │ +1 (+5 -4) 
  + com.hcaptcha.sdk.HCaptchaWebView isDestroyed() → boolean
  + com.hcaptcha.sdk.HCaptchaWebViewHelper <init>(Handler, Context, HCaptchaConfig, HCaptchaInternalConfig, IHCaptchaVerifier, HCaptchaStateListener, HCaptchaWebView)
  + com.hcaptcha.sdk.HCaptchaWebViewHelper access_100(HCaptchaWebViewHelper) → HCaptchaWebView
  + com.hcaptcha.sdk.HCaptchaWebViewHelper getWebView() → HCaptchaWebView
  + android.view.View setBackgroundColor(int)
  
  - com.hcaptcha.sdk.HCaptchaWebViewHelper <init>(Handler, Context, HCaptchaConfig, HCaptchaInternalConfig, IHCaptchaVerifier, HCaptchaStateListener, WebView)
  - com.hcaptcha.sdk.HCaptchaWebViewHelper access_100(HCaptchaWebViewHelper) → WebView
  - com.hcaptcha.sdk.HCaptchaWebViewHelper getWebView() → WebView
  - android.webkit.WebView setBackgroundColor(int)
  

FIELDS:

   old │ new │ diff      
  ─────┼─────┼───────────
   164 │ 164 │ 0 (+1 -1) 
  + com.hcaptcha.sdk.HCaptchaWebViewHelper webView: HCaptchaWebView
  
  - com.hcaptcha.sdk.HCaptchaWebViewHelper webView: WebView

Copy link

Copy link

Benchmark report:

Test name Time ms. (median) Allocations (median)
com.hcaptcha.sdk.HCaptchaBenchmarkTest.EMULATOR_UNLOCKED_benchmarkInvisibleVerification +272.23 -6
com.hcaptcha.sdk.HCaptchaBenchmarkTest.EMULATOR_UNLOCKED_benchmarkInvisibleVerificationColdRun +124.13 +97
com.hcaptcha.sdk.HCaptchaBenchmarkTest.EMULATOR_UNLOCKED_benchmarkInvisibleSetup +6.32 +103
com.hcaptcha.sdk.HCaptchaDebugInfoTest.EMULATOR_UNLOCKED_benchmarkDebugInfo +30.69 +556
com.hcaptcha.sdk.HCaptchaDebugInfoTest.EMULATOR_UNLOCKED_benchmarkDebugSys +0.18 -43
com.hcaptcha.sdk.HCaptchaWebViewHelperTest.EMULATOR_UNLOCKED_benchmarkWebViewLoad +68.71 +95

@DSergiu DSergiu merged commit a6026df into main Dec 14, 2023
12 checks passed
@DSergiu DSergiu deleted the bugfix/not-call-destroyed-webview- branch December 14, 2023 13:42
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