0

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

1

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?
Markus Kauppinen
  • 3,025
  • 4
  • 20
  • 30
TYFA
  • 313
  • 1
  • 10

1 Answers1

1

You can use about:debugging from Firefox Desktop to connect to your device and check the errors in the developer console.

My wild guess is that the page is trying to load images from Google and hot linking is not allowed.

If all you want to do is manipulate some html requests, what you really should be using is a built-in WebExtension in your app, you can find docs here: https://gv.dev/consumer/docs/web-extensions

Agi Sferro
  • 626
  • 3
  • 12