app hang while showing alert when select dropdown box is actively showing
See original GitHub issueBug Report
app hang while showing alert when select dropdown box is actively showing
Problem
cordova app went hang when calling javascript executing alert() when user has clicked the select box and the select box dropdown box is showing on screen
What is expected to happen?
alert box should show on top of the page, the app shouldn’t hang
What does actually happen?
Information
Please refer to the code below, there are one select box and one button, first, please click the button, the alert box will show after 2 seconds. After the button is clicked, do click the “select” box immediately, after that, wait for 2 seconds. Dismiss the dropdown box, the app will go hang and nothing is responding anymore.
Command or Code
Code snippet:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<meta name="viewport" content="initial-scale=1, width=device-width, viewport-fit=cover">
<meta name="color-scheme" content="light dark">
<link rel="stylesheet" href="css/index.css">
<title>Hello World</title>
<script>
function test() {
setTimeout(function(){ alert("Hello"); }, 2000);
}
</script>
</head>
<body>
<div class="app">
<h1>Apache Cordova</h1>
<div id="deviceready" class="blink">
<p class="event listening">Connecting to Device</p>
<p class="event received">Device is Ready</p>
</div>
<select><option>sdfsdf</option>
<option>sdfsdf</option>
<option>sdfsdf</option>
</select>
<button type="button" onclick="test()">Click Me!</button>
</div>
<script src="cordova.js"></script>
<script src="js/index.js"></script>
</body>
</html>
Environment, Platform, Device
iOS device (iphone or ipad), tested in iOS 13 and 14
Version information
What are relevant versions you are using? For example: Cordova CLI 10.0.0 Cordova iOS: 6.1.0
Checklist
- [x ] I searched for existing GitHub issues
- [ x] I updated all Cordova tooling to most recent version
- [x ] I included all the necessary information above
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (2 by maintainers)
Top GitHub Comments
Yah, you might be right here. I’m not too familiar with objective-c or the ios code base for that matter but Cordova has a `CDVWebViewUIDelegate class that looks like it handles how to display the alert box among other native modals like confirm and prompt.
https://github.com/apache/cordova-ios/blob/7e3402c565c2e34eae2bb954c65c989f71e20df1/CordovaLib/Classes/Private/Plugins/CDVWebViewEngine/CDVWebViewUIDelegate.m#L35-L55
This is where my expertise kinda ends. I’m not sure if there is a way to ensure that the alert modal is always displayed on top or if there is any other potential solutions but I think this method is the method of interest.
Yes it is not visible but it doesn’t show under select modal too. It is just not showing and the whole page is not responding, any click to the button or input element are not receivable.
I have tried just now, it doesn’t happen in Safari in my ipad.
What my guess is, Cordova using WebView implementation and also implement its own alert modal, which is not the same as the native browser. The alert modal (guess it is UIAlertController) doesn’t work well while there is select modal (not sure this, might be other UIViewController) showing.
I will try to look into “dialogs plugin”, although that is not convenient, because the usage of “alert()” is everywhere in my project.