Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
334 views
in Technique[技术] by (71.8m points)

android - First iteration of javascript with loadurl and evaluatejavascript works fine but the second time it works halfway and stops

I load URL of a website inside myWebView using this code:

myWebView?.loadUrl("url of the site")

inside this website there are many buttons with class btn for example, so I find them one by one and click on them.

Whenever I click, a new popup window (webViewPop) will open and inside that popup I click on a new button and then I close that popup using on consolemessage and sending data with console.log from javascript side

@RequiresApi(Build.VERSION_CODES.KITKAT)
override fun onConsoleMessage(consoleMessage: ConsoleMessage?): Boolean {
    if(consoleMessage?.message().toString() == "done"){
        webViewPop?.setVisibility(View.GONE);
        webViewPop?.destroy()
        myWebView?.visibility = View.VISIBLE;
        runOnUiThread {
            myWebView?.clearCache(true);
            if( flag3 != 1){
                myWebView?.loadUrl("javascript:" + Javascript)
                flag3 = 1
            }
        }
    }
    return super.onConsoleMessage(consoleMessage)
}

After console message I invisible my popup webview using code above and I will go to myWebViewand then run again my javascript file using evaluateJavascript or loadUrl to confirm my task (clicking on that button inside popup) and then continue to the next task.

Now what is the problem?

Everything works fine for first task the second task also goes to the popup then for next time when it must press on confirm button javascript is running but nothing is happening. I can confirm that page is running but javascript is running only half way and it stops to continue other methods inside my javascript file

I check that javascript is running even for second task but nothing is happening I can confirm that javascript is running by alert in my javascript file. I used evaluateJavascript and loadurl as well and both have same condition and I can't get it why. It seems like it's kinda memory problem which I don't know where to look at.

It's odd since one time is possible to do same task but second time it stops eventhough javascript is loading.

question from:https://stackoverflow.com/questions/65894325/first-iteration-of-javascript-with-loadurl-and-evaluatejavascript-works-fine-but

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...