Skip to content

Conversation

@jkadamczyk
Copy link
Collaborator

@jkadamczyk jkadamczyk commented Feb 9, 2026

This PR ensures that we are not showing native alerts whenever someone tries to do so with the beforeunload event. With this change, the browser will always navigate to the new website.

Summary by CodeRabbit

  • Bug Fixes
    • Suppressed beforeunload event alerts on Android to prevent unnecessary confirmation prompts when navigating away from pages, enabling seamless user navigation.

@coderabbitai
Copy link

coderabbitai bot commented Feb 9, 2026

📝 Walkthrough

Walkthrough

A patch release for @phantom/react-native-webview that adds beforeunload event handling on Android. The new implementation automatically confirms beforeunload events without displaying alerts to users.

Changes

Cohort / File(s) Summary
Release Configuration
.changeset/happy-snails-sleep.md
New changeset file documenting patch version bump for preventing beforeunload event alerts in WebView.
Android Implementation
android/src/main/java/com/reactnativecommunity/webview/RNCWebChromeClient.java
Added onJsBeforeUnload method override that automatically confirms the result and returns true, suppressing the default beforeunload prompt behavior.
🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: overriding onJsBeforeUnload in the Android webview to prevent beforeunload alerts.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch kuba/wp-7128-address-bar-spoofing-in-the-phantom-wallet-app-via/webview

No actionable comments were generated in the recent review. 🎉

🧹 Recent nitpick comments
android/src/main/java/com/reactnativecommunity/webview/RNCWebChromeClient.java (1)

515-519: Consider adding isActive() check for consistency with other JS dialog handlers.

The existing onJsAlert, onJsConfirm, and onJsPrompt methods (lines 489-513) check mWebView.isActive() and cancel the result when inactive. This new handler unconditionally confirms.

If the intent is to always allow beforeunload without any dialog (as stated in the changeset), the current implementation is correct. However, for an inactive webview, you might want to call result.cancel() instead of result.confirm() to be consistent with the security pattern established by the other handlers.

If this is intentional (always proceed regardless of active state), a brief comment explaining the rationale would help future maintainers understand the design decision.

     `@Override`
     public boolean onJsBeforeUnload(WebView view, String url, String message, JsResult result) {
+        // Always confirm beforeunload to prevent blocking navigation with dialogs
         result.confirm();
         return true;  // Consumed - don't show default dialog
     }

Comment @coderabbitai help to get the list of available commands and usage tips.

@jkadamczyk jkadamczyk merged commit 2e73d19 into master Feb 9, 2026
19 checks passed
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