fix(android): grant WebView capture permissions for getUserMedia#145
Open
philippspeck wants to merge 1 commit into
Open
fix(android): grant WebView capture permissions for getUserMedia#145philippspeck wants to merge 1 commit into
philippspeck wants to merge 1 commit into
Conversation
Implement WebChromeClient.onPermissionRequest so RESOURCE_AUDIO_CAPTURE (and VIDEO_CAPTURE when CAMERA is granted) are passed through to web content. Without this handler, getUserMedia() always fails with NotAllowedError even when RECORD_AUDIO is granted at the OS level. Also inject MODIFY_AUDIO_SETTINGS whenever RECORD_AUDIO is present in the merged manifest. Chromium logs "Unable to select communication device!" and getUserMedia() fails with NotReadableError without it. Closes NativePHP#144 Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #144
Problem
navigator.mediaDevices.getUserMedia()fails on Android in NativePHP Mobile apps even whenRECORD_AUDIOis granted in system settings.Two gaps in the stock Android WebView setup:
WebChromeClient.onPermissionRequestis missing — the WebView never grantsRESOURCE_AUDIO_CAPTUREto web content →NotAllowedError: Permission denied.MODIFY_AUDIO_SETTINGSis not merged withRECORD_AUDIO— after (1), Chromium logsUnable to select communication device!→NotReadableError: Could not start audio source.Reproduced on Pixel 7 / Android 16 / WebView 148 with Livewire + Web Audio API voice recording.
Fix
WebViewManager.ktImplement
onPermissionRequestand grant capture resources when the matching Android runtime permission is already held:RESOURCE_AUDIO_CAPTURE→ requiresRECORD_AUDIORESOURCE_VIDEO_CAPTURE→ requiresCAMERAAndroidPluginCompiler.phpWhen merging plugin manifest permissions, also inject
android.permission.MODIFY_AUDIO_SETTINGSwheneverRECORD_AUDIOis present (in the plugin permission list or already in the manifest). Chromium needs this for WebView audio routing / communication device selection.Test plan
getUserMedia({ audio: true })succeeds on Pixel 7 (Android 16) after OS mic permission is grantedonPermissionRequest: android.webkit.resource.AUDIO_CAPTUREfollowed by grantUnable to select communication device!/NotReadableErrorwhenRECORD_AUDIOis in manifestgetUserMedia({ video: true })still respects CAMERA runtime permissionRECORD_AUDIOin manifest do not receiveMODIFY_AUDIO_SETTINGSunless they already declare microphone captureMade with Cursor