Skip to content

fix: handle permissions for getUserMedia#1895

Merged
GitToTheHub merged 3 commits intomasterfrom
getusermedia-perm
Apr 24, 2026
Merged

fix: handle permissions for getUserMedia#1895
GitToTheHub merged 3 commits intomasterfrom
getusermedia-perm

Conversation

@jcesarmobile
Copy link
Copy Markdown
Member

closes #1888

The code is based on Capacitor's implementation.

It uses newer ActivityResultCallback/ActivityResultLauncher instead of the old requestPermissions.

This could later on be extended to request geolocation permissions as at the moment it requires the Geolocation plugin to be installed.

Comment thread framework/src/org/apache/cordova/engine/SystemWebChromeClient.java Fixed
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Feb 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 61.43%. Comparing base (6b17223) to head (63ad99c).
⚠️ Report is 17 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1895   +/-   ##
=======================================
  Coverage   61.43%   61.43%           
=======================================
  Files          24       24           
  Lines        4922     4922           
=======================================
  Hits         3024     3024           
  Misses       1898     1898           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@breautek breautek added this to the 15.0.1 milestone Feb 25, 2026
Copy link
Copy Markdown
Member

@erisu erisu left a comment

Choose a reason for hiding this comment

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

Overall, the code looks good to me.

I left a couple of change requests. Can you confirm if they're OK?

I also tested the following use case, with and without my suggested changes:

  1. Create a default Cordova application
  2. Add the following to config.xml:
<platform name="android">
    <config-file target="AndroidManifest.xml" parent="/*" xmlns:android="http://schemas.android.com/apk/res/android">
        <uses-permission android:name="android.permission.CAMERA" />
        <uses-feature
            android:name="android.hardware.camera"
            android:required="false" />
    </config-file>
</platform>
  1. Add the following to index.html:
<video id="video" autoplay playsinline></video>
<script>
navigator.mediaDevices.getUserMedia({ video: true }).then(stream => {
    const video = document.getElementById('video');
    video.srcObject = stream;
}).catch(error => {
    console.error('Camera Access Error:', error);
});
</script>
  • If uses-permission/uses-feature are not in the AndroidManifest file, nothing happens when launching the app.
  • If uses-permission/uses-feature are defined in the AndroidManifest file, a runtime permission dialog appears when the app launches.

Comment thread framework/src/org/apache/cordova/engine/SystemWebChromeClient.java Outdated
Comment thread framework/src/org/apache/cordova/engine/SystemWebChromeClient.java Outdated
Comment thread framework/src/org/apache/cordova/engine/SystemWebChromeClient.java
@jcesarmobile
Copy link
Copy Markdown
Member Author

Addressed the comments.

Where you say "If uses-permission/uses-feature are not in the AndroidManifest file, nothing happens when launching the app.", it should be going to the catch now and you should see the console.error('Camera Access Error:', error);, which is what the PR fixes, at the moment we are always "grating" the WebView permission, after this change we would grant or reject based on if the permission is present and granted (the method call will succeed), or if not present or present but not granted, it will go to the catch.

Copy link
Copy Markdown
Member

@erisu erisu left a comment

Choose a reason for hiding this comment

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

LGTM

@GitToTheHub GitToTheHub merged commit 2450217 into master Apr 24, 2026
21 checks passed
@GitToTheHub GitToTheHub deleted the getusermedia-perm branch April 24, 2026 16:53
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.

WebView permission request breaks with no native permission granted

6 participants