I'm developing an application for iOS, Android and Windows with React Native in which I need to show a webpage through a WebView
. That webpage accesses the camera of the device, so it uses MediaDevices.getUserMedia()
Javascript function.
It works without problems in desktop, even in the Chrome app on the smartphone. However, when I call the webpage via the React Native <WebView />
, I get a PermissionDenied
error. The problem is that no request is shown to let me accept that permission. It justs denies the request without asking.
Here is a sample of my WebView element:
<WebView
style={{flex: 1}}
mediaPlaybackRequiresUserAction={false}
domStorageEnabled={true}
allowsInlineMediaPlayback={true}
source={{uri: 'https://myurltomyapp.com/index.html'}}
startInLoadingState={true}
allowUniversalAccessFromFileURLs={true}
/>
I've got all necessary permissions set on AndroidManifest.xml
(and even some not needed for the sake of testing):
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAPTURE_AUDIO_OUTPUT" />
<uses-permission android:name="android.permission.CAPTURE_SECURE_VIDEO_OUTPUT" />
<uses-permission android:name="android.permission.CAPTURE_VIDEO_OUTPUT" />
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.RECORD_VIDEO"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
And yes, the URL where is hosted the website is SSL certified, so it goes through HTTPS. It works on Chrome app, so it should work on WebView
, too.
I've been reading through the net, and it seems that's because React Native WebView
lacks of a onPermissionRequest()
implementation, so it fails silently (and denies it).
Is there a way to implement it overriding the native WebView in React Native? Which files do I have to edit, if possible? Is there any third-party module (up to date) which has this implemented (haven't been able to find any)?
Thank you.