Closed andrewvy closed 7 years ago
From looking at other implementations, the API should maybe look like this:
iex(1)> {:ok, server} = ChromeRemoteInterface.Session.start_link()
{:ok, #PID<0.226.0>}
iex(2)> {:ok, page_pid} = ChromeRemoteInterface.Session.checkout_page(server)
{:ok, #PID<0.229.0>}
iex(3)> ChromeRemoteInterface.RPC.Page.enable(page_pid)
{:ok, %{"id" => 1, "result" => %{}}}
ChromeRemoteInterface.Page.subscribe(page_pid, "Page.frameStoppedLoading", subscriber_pid \\ self())
ChromeRemoteInterface.RPC.Page.navigate(page_pid, %{url: "http://google.com"})
flush()
{:chrome_remote_interface, "Page.frameStoppedLoading", %{"method" => "Page.frameStoppedLoading", "params" => %{"frameId" => "98300.1"}}}
That would add a callback for that event to be forwarded to the subscriber pid (defaulting to whoever called subscribe
)
We could also provide a blocking call, more akin to GenServer.call
with timeout functionality if an event hasn't fired after X
seconds, for synchronous use-cases. (This is what we do for regular RPC calls anyways.)
{:ok, response} = ChromeRemoteInterface.Page.await(page_pid, "Page.frameStoppedLoading", timeout // 5000)
Closing now. Moving synchronous event handling to #11.
Right now, you can run
Page.enable
to subscribe to events from thePage
domain, but that won't forward any events to the requesting process.We should add a wrapping function that will allow consumers to subscribe to different domain events.