react-native-webview: navigator.share (Web Share API) is not working inside a Webview
Bug description:
I have a <WebView>
in my app built using Expo and React Native.
The webview opens a page that uses the Web Share API, i.e. navigator.share({ url: 'url' })
.
However, navigator.share
is not available inside the webview.
If the same page is opened within a normal browser, sharing works as expected.
To Reproduce:
Call navigator.share
from inside a page opened in a webview and see that it’s undefined.
Expected behavior:
navigator.share
should be defined and working.
Environment:
- OS: Android
- OS version: 8
- react-native version:
"react-native": "https://github.com/expo/react-native/archive/sdk-35.0.0.tar.gz",
- react-native-webview version:
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 4
- Comments: 19
Solution by overriding navigator.share() to forward param to react native side for handling:
Still an issue in 2022. Did anyone find a solution not involving Java or Koplin?
This is still a problem in late 2021. The navigator.share() method has been around since 2017, but it’s still not supported in the Android WebView. This is not specific to React Native, so I don’t know if there is any solution that can come from this project apart from instructions on how to do it directly from java / kotlin.
Luckily, it’s easy enough to launch a share intent from native android code. All that is needed is an interface object to expose methods that can be called from javascript. @alpkahveci linked to some code that shows how to add such an interface in java.
Here’s an example on how to do it using Kotlin:
MainActivity.kt
WebAppInterface.kt
Component.jsx
It’s still driving me crazy 30-10-2020
navigator.share is not supported in Webview: https://developer.mozilla.org/en-US/docs/Web/API/Navigator/share
Guyz! I have a good news. You can do it with native and javascript. here is the solution. I hope it will work for you 😃
How do you re-open this issue? It is still a problem…
Hello 👋, this issue has been opened for more than 2 months with no activity on it. If the issue is still here, please keep in mind that we need community support and help to fix it! Just comment something like still searching for solutions and if you found one, please open a pull request! You have 7 days until this gets closed automatically
@denissb
It’s the ID of the webview component in the activity XML. In Kotlin these UI bindings are exposed automatically, but it’s the equivalent of
findViewById
.If you created your Kotlin project from Android Studio this should just work. But if not, you can check this out: https://stackoverflow.com/questions/46882421/cant-access-edittext-or-other-ui-components-with-kotlin
Does anyone have a solution?
Any updates on this?
omg why does not work in android webview? It is not normal. i am opening in mobile browser, it is working perfectly but in webview app not work! (they have completely same user agent !!)
I am facing the same issue. If in iOS working then why can’t we can run in Android webview?