Behaviour for browser automation adapters.
Adapters implement the low-level browser control protocol, allowing Jido.Browser to work with different browser automation backends.
Return Value Contract
All operations (except start_session and end_session) return a consistent
3-tuple on success:
{:ok, session, result_map}This ensures:
- Callers always receive the potentially-updated session
- Consistent API regardless of whether the operation modifies state
- Session can be threaded through operation chains
Implementing an Adapter
defmodule MyAdapter do
@behaviour Jido.Browser.Adapter
@impl true
def start_session(opts) do
# Start browser, return {:ok, session} or {:error, reason}
end
@impl true
def end_session(session) do
# Clean up resources, return :ok or {:error, reason}
end
@impl true
def navigate(session, url, opts) do
# Navigate and return session + result
{:ok, updated_session, %{url: url}}
end
@impl true
def screenshot(session, opts) do
# Even read-only ops return the session for consistency
{:ok, session, %{bytes: png_data, mime: "image/png"}}
end
# ... implement other callbacks
endOptional Callbacks
evaluate/3- JavaScript evaluation (not all backends support this)- pooling is modeled separately through
Jido.Browser.PoolAdapter
Built-in Adapters
Jido.Browser.Adapters.Vibium- Uses Vibium Go binary (WebDriver BiDi)Jido.Browser.Adapters.Web- Uses chrismccord/web CLI
Summary
Callbacks
Clicks an element matching the selector.
Executes adapter-native operations that are not part of the base behaviour.
Ends a browser session and cleans up resources.
Executes JavaScript in the browser context.
Extracts content from the current page.
Navigates to a URL.
Takes a screenshot of the current page.
Starts a new browser session.
Types text into an element matching the selector.
Callbacks
@callback click( session :: Jido.Browser.Session.t(), selector :: String.t(), opts :: keyword() ) :: {:ok, Jido.Browser.Session.t(), map()} | {:error, term()}
Clicks an element matching the selector.
Returns the updated session plus a result map.
@callback command( session :: Jido.Browser.Session.t(), action :: atom(), opts :: keyword() ) :: {:ok, Jido.Browser.Session.t(), map()} | {:error, term()}
Executes adapter-native operations that are not part of the base behaviour.
@callback end_session(session :: Jido.Browser.Session.t()) :: :ok | {:error, term()}
Ends a browser session and cleans up resources.
@callback evaluate( session :: Jido.Browser.Session.t(), script :: String.t(), opts :: keyword() ) :: {:ok, Jido.Browser.Session.t(), %{result: term()}} | {:error, term()}
Executes JavaScript in the browser context.
@callback extract_content(session :: Jido.Browser.Session.t(), opts :: keyword()) :: {:ok, Jido.Browser.Session.t(), %{content: String.t(), format: atom()}} | {:error, term()}
Extracts content from the current page.
@callback screenshot(session :: Jido.Browser.Session.t(), opts :: keyword()) :: {:ok, Jido.Browser.Session.t(), %{bytes: binary(), mime: String.t()}} | {:error, term()}
Takes a screenshot of the current page.
@callback start_session(opts :: keyword()) :: Jido.Browser.Session.t() | {:error, term()}
Starts a new browser session.
@callback type( session :: Jido.Browser.Session.t(), selector :: String.t(), text :: String.t(), opts :: keyword() ) :: {:ok, Jido.Browser.Session.t(), map()} | {:error, term()}
Types text into an element matching the selector.
Returns the updated session plus a result map.