pub struct ContextRouteRegistry { /* private fields */ }Expand description
Context-level route handler registry.
Routes registered here apply to all pages in the context. New pages automatically inherit these routes.
Implementations§
Source§impl ContextRouteRegistry
impl ContextRouteRegistry
Sourcepub fn new(connection: Arc<CdpConnection>, context_id: String) -> Self
pub fn new(connection: Arc<CdpConnection>, context_id: String) -> Self
Create a new context route registry.
Sourcepub async fn register_page_registry(&self, registry: &Arc<RouteHandlerRegistry>)
pub async fn register_page_registry(&self, registry: &Arc<RouteHandlerRegistry>)
Register a page’s route registry with this context.
When a new route is added to the context, Fetch will be enabled on all
registered page registries before the route() call returns.
Sourcepub fn subscribe_route_changes(&self) -> Receiver<RouteChangeNotification>
pub fn subscribe_route_changes(&self) -> Receiver<RouteChangeNotification>
Subscribe to route change notifications.
Pages use this to know when they need to enable Fetch domain for newly added context routes.
Sourcepub async fn route<M, H, Fut>(
&self,
pattern: M,
handler: H,
) -> Result<(), NetworkError>
pub async fn route<M, H, Fut>( &self, pattern: M, handler: H, ) -> Result<(), NetworkError>
Register a route handler for the given pattern.
The handler will be applied to all pages in the context.
§Errors
Returns an error if registering the route handler fails.
Sourcepub async fn route_predicate<P, H, Fut>(
&self,
predicate: P,
handler: H,
) -> Result<(), NetworkError>
pub async fn route_predicate<P, H, Fut>( &self, predicate: P, handler: H, ) -> Result<(), NetworkError>
Register a route handler with a predicate function.
§Errors
Returns an error if registering the route handler fails.
Sourcepub async fn unroute_all(&self)
pub async fn unroute_all(&self)
Unregister all handlers.
Sourcepub async fn has_routes(&self) -> bool
pub async fn has_routes(&self) -> bool
Check if there are any registered routes.
Sourcepub async fn route_count(&self) -> usize
pub async fn route_count(&self) -> usize
Get the number of registered routes.
Sourcepub async fn apply_to_page(
&self,
page_registry: &RouteHandlerRegistry,
) -> Result<(), NetworkError>
👎Deprecated: Use set_context_routes on RouteHandlerRegistry instead
pub async fn apply_to_page( &self, page_registry: &RouteHandlerRegistry, ) -> Result<(), NetworkError>
Apply context routes to a page’s route registry.
This should be called when a new page is created to copy context routes to the page.
§Errors
Returns an error if applying routes to the page fails.
Sourcepub async fn find_handler(
&self,
url: &str,
) -> Option<Arc<dyn Fn(Route) -> Pin<Box<dyn Future<Output = Result<(), NetworkError>> + Send>> + Send + Sync>>
pub async fn find_handler( &self, url: &str, ) -> Option<Arc<dyn Fn(Route) -> Pin<Box<dyn Future<Output = Result<(), NetworkError>> + Send>> + Send + Sync>>
Try to handle a request with context routes.
Returns Some(handler) if a matching handler is found, None otherwise.
This is called by page route registries as a fallback.
Sourcepub async fn find_all_handlers(
&self,
url: &str,
) -> Vec<Arc<dyn Fn(Route) -> Pin<Box<dyn Future<Output = Result<(), NetworkError>> + Send>> + Send + Sync>>
pub async fn find_all_handlers( &self, url: &str, ) -> Vec<Arc<dyn Fn(Route) -> Pin<Box<dyn Future<Output = Result<(), NetworkError>> + Send>> + Send + Sync>>
Find all matching handlers for a URL.
Returns all handlers that match the URL in reverse order (LIFO). This is used for fallback chaining - handlers are tried in order until one handles the request.