pub struct BindingManager { /* private fields */ }Expand description
Manager for exposed function bindings on a page.
Implementations§
Source§impl BindingManager
impl BindingManager
Sourcepub fn new(connection: Arc<CdpConnection>, session_id: String) -> Self
pub fn new(connection: Arc<CdpConnection>, session_id: String) -> Self
Create a new binding manager for a page.
Sourcepub async fn expose_function<F, Fut>(
&self,
name: &str,
callback: F,
) -> Result<(), PageError>
pub async fn expose_function<F, Fut>( &self, name: &str, callback: F, ) -> Result<(), PageError>
Expose a function to JavaScript.
The function will be available as window.<name>() in JavaScript.
Arguments are passed as JSON values and the return value is also JSON.
§Example
use viewpoint_core::page::binding::BindingManager;
manager.expose_function("compute", |args| async move {
let x: i64 = serde_json::from_value(args[0].clone()).map_err(|e| e.to_string())?;
let y: i64 = serde_json::from_value(args[1].clone()).map_err(|e| e.to_string())?;
serde_json::to_value(x + y).map_err(|e| e.to_string())
}).await?;Sourcepub async fn remove_function(&self, name: &str) -> Result<(), PageError>
pub async fn remove_function(&self, name: &str) -> Result<(), PageError>
Remove an exposed function.
Sourcepub async fn rebind_all(&self) -> Result<(), PageError>
pub async fn rebind_all(&self) -> Result<(), PageError>
Re-bind all functions after navigation.
This should be called after page navigation to re-inject the wrapper scripts.
Auto Trait Implementations§
impl !Freeze for BindingManager
impl !RefUnwindSafe for BindingManager
impl Send for BindingManager
impl Sync for BindingManager
impl Unpin for BindingManager
impl !UnwindSafe for BindingManager
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