pub struct BrowserSession { /* private fields */ }Expand description
A sandboxed headless browser controlled from outside.
The browser (Chromium via Playwright) runs inside an agentkernel sandbox. You call high-level methods; the SDK generates and executes scripts internally.
§Example
let client = agentkernel_sdk::AgentKernel::builder().build()?;
let mut browser = client.browser("my-browser", None).await?;
let page = browser.goto("https://example.com").await?;
println!("{} — {} links", page.title, page.links.len());
let png = browser.screenshot(None).await?;
browser.remove().await?;Implementations§
Source§impl BrowserSession
impl BrowserSession
Sourcepub async fn goto(&mut self, url: &str) -> Result<PageResult>
pub async fn goto(&mut self, url: &str) -> Result<PageResult>
Navigate to a URL and return page data (title, text, links).
Sourcepub async fn screenshot(&self, url: Option<&str>) -> Result<Vec<u8>>
pub async fn screenshot(&self, url: Option<&str>) -> Result<Vec<u8>>
Take a PNG screenshot. Returns the raw PNG bytes.
If url is None, re-uses the last URL from goto.
Sourcepub async fn evaluate(
&self,
expression: &str,
url: Option<&str>,
) -> Result<Value>
pub async fn evaluate( &self, expression: &str, url: Option<&str>, ) -> Result<Value>
Run a JavaScript expression on a page and return the result as JSON.
If url is None, re-uses the last URL from goto.
Sourcepub async fn open(
&mut self,
url: &str,
page: Option<&str>,
) -> Result<AriaSnapshot>
pub async fn open( &mut self, url: &str, page: Option<&str>, ) -> Result<AriaSnapshot>
Navigate to a URL and return an ARIA snapshot.
Sourcepub async fn snapshot(&mut self, page: Option<&str>) -> Result<AriaSnapshot>
pub async fn snapshot(&mut self, page: Option<&str>) -> Result<AriaSnapshot>
Get the current ARIA snapshot without navigating.
Sourcepub async fn click(
&mut self,
page: Option<&str>,
ref_id: Option<&str>,
selector: Option<&str>,
) -> Result<AriaSnapshot>
pub async fn click( &mut self, page: Option<&str>, ref_id: Option<&str>, selector: Option<&str>, ) -> Result<AriaSnapshot>
Click an element by ref ID or CSS selector. Returns a new ARIA snapshot.
Sourcepub async fn fill(
&mut self,
value: &str,
page: Option<&str>,
ref_id: Option<&str>,
selector: Option<&str>,
) -> Result<AriaSnapshot>
pub async fn fill( &mut self, value: &str, page: Option<&str>, ref_id: Option<&str>, selector: Option<&str>, ) -> Result<AriaSnapshot>
Fill an input by ref ID or CSS selector. Returns a new ARIA snapshot.
Sourcepub async fn list_pages(&mut self) -> Result<Vec<String>>
pub async fn list_pages(&mut self) -> Result<Vec<String>>
List active page names.
Auto Trait Implementations§
impl Freeze for BrowserSession
impl !RefUnwindSafe for BrowserSession
impl Send for BrowserSession
impl Sync for BrowserSession
impl Unpin for BrowserSession
impl !UnwindSafe for BrowserSession
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more