Elixir foundationSort Order

Elixir: GenServer Handle Info - [017]

Chrome Dev Tools has the ability to communicate with our application via events. We can choose which events to subscribe to using chrome remote interface. In this episode we'll show you how to listen to the Page.loadEventFired event.

Let's begin with modifying our GenServer

Listening for Message

We can use handle_info to listen for messages sent to our GenServer.

defmodule Botiful.Render.Engine do  use GenServer  alias ChromeRemoteInterface.{    RPC,    PageSession  }  # ...  def init(url) do    conn = ChroxyClient.page_session!(%{ host: "localhost", port: 1330 })        {:ok, _} = RPC.Page.enable(conn)    :ok = PageSession.subscribe(conn, "Page.loadEventFired", self())    {:ok, %{conn: conn}}  end  def handle_info({:chrome_remote_interface, "Page.loadEventFired", data}, state) do    IO.inspect data       {:noreply, state}  endend

That's pretty much all we need to do we can now start this Render Engine and see the output of the data sent by Chrome.

{:ok, pid} = Botiful.Render.Engine.start_link("https://www.artellectual.com")# ...%{  "method" => "Page.loadEventFired",  "params" => %{"timestamp" => 408433.795479}}