Elixir foundationSort Order

Elixir: Retrieving HTML Result - [024]

Now that we know when the rendering process completes we can retrieve the completed html correctly. In this episode we will implement the call that will allow us to retrieve the html result from our GenServer

HTML Retrieval

def html(pid) do  GenServer.call(pid, :html, 20_000)end

Next we need to implement the callback

def handle_call(:html, _from, state) do  cond do    state.completed && state.valid ->      {:ok, %{ "result" => %{ "result" => %{ "value" => html }}}} =         RPC.Runtime.evaluate(state.conn, %{          expression: "document.documentElement.outerHTML"        })           {:reply, html, state}    state.completed ->      {:reply, "", state}    true ->      {:reply, :incomplete, state}  endend

We can now try this out.

{:ok, pid} = Botiful.Render.Engine.start_link("https://www.artellectual.com")Botiful.Render.Engine.html(pid)

Next we will implement a wrapper function that simplifies this process of retrieving the html.