I'm trying to fetch a html from an url and manipulate the html and then render it with GeckoView
I was going to use Jsoup to get the html string from an url but this said there is a problem to get a complete html using Jsoup
So i found another way to get the html using GeckoView(this and api reference)
So i succeeded to get a html string from an url and render it with only GeckoView
This is the code
private fun setupGeckoView() { // I call this in the onCreate method
geckoView = findViewById(R.id.geckoview)
val runtime = GeckoRuntime.create(this)
geckoSession.open(runtime)
geckoView.setSession(geckoSession)
val executor = GeckoWebExecutor(runtime)
val result = executor.fetch( // from here i start getting the sourcecode inputStream
WebRequest.Builder("https://google.com")
.header("Accept","Application/json")
.build())
result.then { response ->
htmlContentInStringFormat = response?.body?.bufferedReader().use { it?.readText() }
// ㄴ and i get the html string from the inputStream
geckoSession.loadData(htmlContentInStringFormat!!.toByteArray(Charsets.UTF_8),"text/html")
// ㄴ and then here i render and print the html string to my screen
result
}
urlEditText.setText(INITIAL_URL) // from here is just for setting a progressbar for web pages loading
progressView = findViewById(R.id.page_progress)
geckoSession.progressDelegate = createProgressDelegate()
}
The problem is that the web page is not printed completely like this below
And i have one more question for the above code
I found this if i wrote code like this below
result.then { response ->
htmlContentInStringFormat = response?.body?.bufferedReader().use { it?.readText() }
result
}
geckoSession.loadData(htmlContentInStringFormat!!.toByteArray(Charsets.UTF_8),"text/html")
geckoSession.loadData() method is executed first than that result.then lambda function
And i don't understand why is that like
So my questions are
- Why can't i print the web page completely?
- Why that lambda function is executed so late?