Skip to content

fix: Android In-App Browser Crash#22212

Merged
weitingsun merged 6 commits intomainfrom
wsun/fix-android-in-app-browser-crash
Nov 5, 2025
Merged

fix: Android In-App Browser Crash#22212
weitingsun merged 6 commits intomainfrom
wsun/fix-android-in-app-browser-crash

Conversation

@weitingsun
Copy link
Contributor

@weitingsun weitingsun commented Nov 5, 2025

Description

The app crashes on Android when users grant camera + microphone permissions through the in-app browser (e.g., visiting https://permission.site/).

Root Cause:
The WebView permission handling code had a fundamental architectural flaw when multiple permissions (camera + microphone) were requested simultaneously:
Old behavior: Showed separate dialogs for each permission (one for camera, one for microphone)
Each dialog's "Allow" button independently called request.grant()
Android's WebView API only allows calling grant() or deny() once per permission request
When the user clicked "Allow" on the second dialog → CRASH: "Either grant() or deny() has been already called"

Solution:
Rewrote the permission handling logic in RNCWebChromeClient.java:
Changed permission handling to show ONE dialog for all permissions:

  • "Allow example.com to use your camera and microphone?"
  • Call grant() only once with all permissions together
  • Added error handling to prevent crashes in edge cases

Android build for this PR: https://app.bitrise.io/build/560c02e8-611e-4bfd-a24c-34e69751c86b?tab=artifacts

PR to browser: MetaMask/react-native-webview-mm#72

Changelog

CHANGELOG entry:null

Related issues

Fixes: #22162

Manual testing steps

Feature: Fix Android double permission bug on webview

  Scenario: App does not crash when user grant/deny camera + microphone permission
    Given user navigates to website https://permission.site in website

    When user select Camera + Microphone 
    Then user is able give/deny permission to Camera and Microphone without app crashing

Screenshots/Recordings

Before

Android Before
Android Before

After

Android After
Android After

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Note

Consolidates Android WebView permission flow into a single dialog with a single grant call for multiple resources, adds error handling, and delivers via a Yarn patch of @metamask/react-native-webview.

  • Android WebView (RNCWebChromeClient.java):
    • Show a single confirmation dialog for multiple already-OS-granted permissions with a combined message.
    • Aggregate requested resources and call request.grant() once; map CAMERARESOURCE_VIDEO_CAPTURE, RECORD_AUDIORESOURCE_AUDIO_CAPTURE, handle RESOURCE_PROTECTED_MEDIA_ID.
    • Reset state before handling requests; manage permissionRequest/grantedPermissions lifecycle; only set permissionRequest when system permissions must be requested.
    • Wrap grant() with try/catch to ignore IllegalStateException and prevent duplicate grant/deny errors.
    • Minor UX: delay enabling the "Allow" button to avoid accidental taps.
  • Dependencies:
    • Use Yarn patch for @metamask/react-native-webview@14.5.0 via .yarn/patches/...; update package.json and yarn.lock.

Written by Cursor Bugbot for commit 7396b7f. This will update automatically on new commits. Configure here.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 5, 2025

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@metamaskbot metamaskbot added the team-mobile-platform Mobile Platform team label Nov 5, 2025
@github-actions github-actions bot added the size-M label Nov 5, 2025
@weitingsun weitingsun changed the title fix Android In-App Browser Crash fix: Android In-App Browser Crash Nov 5, 2025
@weitingsun weitingsun marked this pull request as ready for review November 5, 2025 20:28
@weitingsun weitingsun requested a review from a team as a code owner November 5, 2025 20:28
Copy link
Contributor

@smilingkylan smilingkylan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM ✅

Copy link
Contributor

@sethkfman sethkfman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sonarqubecloud
Copy link

sonarqubecloud bot commented Nov 5, 2025

@weitingsun weitingsun enabled auto-merge November 5, 2025 22:57
@weitingsun weitingsun added this pull request to the merge queue Nov 5, 2025
Merged via the queue into main with commit 5c63946 Nov 5, 2025
150 of 152 checks passed
@weitingsun weitingsun deleted the wsun/fix-android-in-app-browser-crash branch November 5, 2025 23:16
@github-actions github-actions bot locked and limited conversation to collaborators Nov 5, 2025
@metamaskbot metamaskbot added the release-7.59.0 Issue or pull request that will be included in release 7.59.0 label Nov 5, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.59.0 Issue or pull request that will be included in release 7.59.0 size-M team-mobile-platform Mobile Platform team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Android In-App Browser Crash

5 participants