Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I am trying to inject some Javascript into my web view immediately after loading data into my web view via webView.loadDataWithBaseURL() but I have no way of knowing when the data is actually finished loading. Is this method synchronous? Can I just rely on the data being immediately loaded since it comes from memory? I'm asking because it seems as if my injected Javascript is not seeing elements on the page. I'm assuming it's because the view has not loaded before injecting the JS. (I have yet to prove this.)
–
–
–
–
–
postVisualStateCallback
with custom
WebViewClient
solved my problem:
class WebViewWithCallback(private val webView: WebView, private val callback: () -> Unit): WebViewClient(){
override fun onPageFinished(view: WebView?, url: String?) {
super.onPageFinished(view, url)
webView.postVisualStateCallback(0, object: WebView.VisualStateCallback() {
override fun onComplete(p0: Long) {
callback.invoke()
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.