-
Notifications
You must be signed in to change notification settings - Fork 24.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Webview is not executing my JavaScript from the web page on Android? #14754
Comments
Can you reproduce this using Snack? |
Yes: https://snack.expo.io/H18CZMeVW But in WebView, when I click a button nothing happens. Same thing with my second website, where the entire page does not load, because it is all in JavaScript. |
Any chance you can write a minimal reproduction? Such as loading a very simple website with minimal JavaScript, as opposed to your actual app. |
I am using React-navigation (https://reactnavigation.org/), that's why I can't reproduce it fully. |
Anyway, a simple page with only a WebView should be displaying JavaScript with javaScriptEnabled option, right? And it is not. |
I have added a html template into react native webView, but when i run the app on IPad don't work the css files linked on html template. |
Can you help me? |
Can you show me your code? |
import React, { Component } from 'react'; export default class Products extends Component { AppRegistry.registerComponent('Products', () => Products); |
This is my index.ios, and Prova.html is a simple file liked to css file |
I am having the same issue. |
That is why I stopped using React-Native tbh |
The community does not seem to be really strong and supportive. |
Hi @andrisole92, I'm sorry that you're experiencing some issues with WebView. Let's figure it out together.
Could be related to #14834, @koenpunt ? Does anyone have an idea? If not, I'll try to take a look. Feel free to ping me if you need any assistance. |
For me the page loaded in the webview has no problem using JavaScript, but the injected JavaScript doesn't get executed without |
somehow its not working in android emulator but its working fine in my device. |
I am trying to attach html file in webview. the html file contains css and js files as in regular webpages. I am trying to open webView after navigation. Code for WebView is: const html = require( '../path/index.html')
With this code I am unable to run js on my app. I have also tried javaScriptEnabled to true, but no luck. Also when I build app, it shows me blank page instead of html content. please help me resolve conflict. |
@pankaj-ag I have tried all the possible ways. I have local html file placed in android/app/src/main/assets/folder/index/html. This html has injected js in it. I am unable to load js. the js file contains my data. app works fine when I add source url of live site, but with local file it doesnot load properly. my data is not loaded. Please provide me solution. |
@ishita-kothari can you provide the code snippet here of your web view implementation. |
this is the html file. bundle.js file contains the data. |
can anyone tell me how to include <script> tag in webview? |
Any updates to this issue? I've ran into a similar issue with inline JS - thanks! |
Same here. Even after putting the Javascript directly in the html, it's still not being executed on Android. |
Any updates on this? I'm facing the same problem now. |
Hey I'm also having a similar problem. Some of the javascript in my Android webview will fail to execute, but there seems to be no way to get debug information or error messages. Does anyone know how to read the console on the embedded webview? I have resorted to doing stuff like this:
Which obviously does not always work because sometimes javascript fails to execute in the webview and I cannot see the console output. |
@a-r-d I've done something similar sending a value from a Swift I haven't tried running this code but it shouldn't take much to get it to work. The idea is to override injectedJavaScript:
handler:
WebView:
You may always wish to add an identifier to the |
Javascript execution in webview is not working for android API version 21 and below. Anyone found any solution? |
@pankaj-ag Thank you! Why does an emulator WebView not work when same emulator's native browser does work?Try running on a real Android device.
I am not sure if anything more than javaScriptEnabled is needed.
|
Confirmed not working on android emulator but works with real device ... solution : ignore your emulator 💯 |
Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as "For Discussion" or "Good first issue" and I will leave it open. Thank you for your contributions. |
@ishita-kothari @cgathergood @abdallamohamed @ggsrivas so there are long time no activity here, did u solved this issue? I just find this and have no idea... |
In my case, it was a code error. I was using a few es6 syntaxes which were not working on webview in lower android versions (my bad). Luckily I could debug webview javascript in android Lollipop (and above) and that where I found this issue. |
@ggsrivas thx! I have tried and find this problem, too. I used |
This issue has been migrated to react-native-webview/react-native-webview#7 and can be closed here. |
To enable javascript popups in WebView its necessary to set webChromeClient and override openFileChooser methods.
And handle the onActivityResult as below:
|
@priyankahipoint Please update the issue on the other repo. Thanks! |
This issue only comes on old Android devices, It does support ES6 script(It makes sense right). |
JavaScript isn't executing at all for Android 5.0 and under (<= API 21 as ggsrivas also reported) on the app I'm building as well. Inside the script tag, all I've put is a JavaScript alert and it won't fire. 5.1 and above work (an yes you have to avoid ES6 syntax and use polyfills where necessary). |
@jayporta have u tried with |
Is it sure that it js inside the <script> tag of html file won't run on android studio for API level <=21. |
@ujjwal-sri it runs, just you need to write ES5 syntax |
I have same problem. |
@orchoban i think you have to mention this in |
I check it and Expo change the files name of the images and all the files in asset folder. |
@orchoban I think the best way is to host it and load it with URL rather than loading with local assets. |
@if4lcon also emulators with any android version not working. |
I'm running an android emulator 7.1.1 and it is working fine, but running on android device 4.4.4 does not work |
Description
When I open WebView on Android emulator or real device it does not execute JavaScript. I have run simple Android App in Android Studio and it worked there.
Reproduction Steps
Just create a new app and add this WebView to it
Sample Code
Solution
Can you please check it and say what is wrong?
Additional Information
The text was updated successfully, but these errors were encountered: