I have been handling window.open() requests from Javascript by implementing WebChromeClient
myWebView.webChromeClient = MyChromeClient()
And, MyChromeClient looks like:
inner class MyChromeClient : WebChromeClient() {
override fun onCreateWindow(
view: WebView?,
isDialog: Boolean,
isUserGesture: Boolean,
resultMsg: Message?
): Boolean {
showNewWindowDialog(resultMsg)
return true
}
}
For any new window, I am showing a dialog which has a WebView.
The code works perfectly fine when the new windows are open one at time. The DialogFragment, I implemented opens up the URL from new window as expected. If there are multiple window, the code is able to show multiple dialogs stacked.
However, if multiple window.open() are triggered in Javascript simultaneously, only the first dialog loads the url, the remaining dialogs remain blank.
The following JS code opens multiple windows in a for loop. WebChromeClient's onCreateWindow is called multiple times. Two dialogs are presented in the screen(stacked) but the second dialog's webview does not load any url.
var urls = ["https://facebook.com", "https://google.com"]
urls.forEach((url) => {
window.open(url)
})
However, with some delay in JS, let's say, 500ms it works fine. Both the dialogs load the respective url.
urls.forEach((url, i) => {
setTimeout(()=>{
window.open(url)
}, 500 * i)
})
Since, I cannot add delay in the original code, how do I solve the issue? Is this a limitation in Android's WebView and WebChromeClient?