pub struct Route { /* private fields */ }Expand description
Route represents a network route handler.
Routes allow intercepting, aborting, continuing, or fulfilling network requests.
Implementations§
Source§impl Route
impl Route
Sourcepub fn new(
parent: Arc<dyn ChannelOwner>,
type_name: String,
guid: Arc<str>,
initializer: Value,
) -> Result<Self>
pub fn new( parent: Arc<dyn ChannelOwner>, type_name: String, guid: Arc<str>, initializer: Value, ) -> Result<Self>
Creates a new Route from protocol initialization
This is called by the object factory when the server sends a __create__ message
for a Route object.
Sourcepub fn request(&self) -> Request
pub fn request(&self) -> Request
Returns the request that is being routed.
See: https://playwright.dev/docs/api/class-route#route-request
Sourcepub async fn abort(&self, error_code: Option<&str>) -> Result<()>
pub async fn abort(&self, error_code: Option<&str>) -> Result<()>
Aborts the route’s request.
§Arguments
error_code- Optional error code (default: “failed”)
Available error codes:
- “aborted” - User-initiated cancellation
- “accessdenied” - Permission denied
- “addressunreachable” - Host unreachable
- “blockedbyclient” - Client blocked request
- “connectionaborted”, “connectionclosed”, “connectionfailed”, “connectionrefused”, “connectionreset”
- “internetdisconnected”
- “namenotresolved”
- “timedout”
- “failed” - Generic error (default)
See: https://playwright.dev/docs/api/class-route#route-abort
Sourcepub async fn continue_(&self, overrides: Option<ContinueOptions>) -> Result<()>
pub async fn continue_(&self, overrides: Option<ContinueOptions>) -> Result<()>
Continues the route’s request with optional modifications.
This is a final action — no other route handlers will run for this request.
Use fallback() instead if you want subsequent handlers to have a chance.
§Arguments
overrides- Optional modifications to apply to the request
See: https://playwright.dev/docs/api/class-route#route-continue
Sourcepub async fn fallback(&self, overrides: Option<ContinueOptions>) -> Result<()>
pub async fn fallback(&self, overrides: Option<ContinueOptions>) -> Result<()>
Continues the route’s request, allowing subsequent handlers to run.
Unlike continue_(), fallback() yields to the next matching handler in the
chain before the request reaches the network. This enables middleware-like
handler composition where multiple handlers can inspect and modify a request.
§Arguments
overrides- Optional modifications to apply to the request
See: https://playwright.dev/docs/api/class-route#route-fallback
Sourcepub async fn fulfill(
&self,
options: impl Into<Option<FulfillOptions>>,
) -> Result<()>
pub async fn fulfill( &self, options: impl Into<Option<FulfillOptions>>, ) -> Result<()>
Fulfills the route’s request with a custom response.
§Arguments
options- Response configuration (status, headers, body, etc.)
§Errors
Returns an error if the driver rejects the command, for example when the route has already been handled or the page has closed.
See: https://playwright.dev/docs/api/class-route#route-fulfill
Sourcepub async fn fetch(
&self,
options: impl Into<Option<FetchOptions>>,
) -> Result<FetchResponse>
pub async fn fetch( &self, options: impl Into<Option<FetchOptions>>, ) -> Result<FetchResponse>
Performs the request and fetches result without fulfilling it, so that the response can be modified and then fulfilled.
Delegates to APIRequestContext.inner_fetch() using the request’s URL and
any provided overrides.
§Arguments
options- Optional overrides for the fetch request
See: https://playwright.dev/docs/api/class-route#route-fetch