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: Option<FulfillOptions>) -> Result<()>
pub async fn fulfill(&self, options: Option<FulfillOptions>) -> Result<()>
Fulfills the route’s request with a custom response.
§Arguments
options- Response configuration (status, headers, body, etc.)
§Known Limitations
Response body fulfillment is not supported in Playwright 1.49.0 - 1.58.2.
The route.fulfill() method can successfully send requests for status codes and headers, but the response body is not transmitted to the browser JavaScript layer. This applies to ALL request types (main document, fetch, XHR, etc.), not just document navigation.
Investigation Findings:
- The protocol message is correctly formatted and accepted by the Playwright server
- The body bytes are present in the fulfill() call
- The Playwright server creates a Response object
- But the body content does not reach the browser’s fetch/network API
This appears to be a limitation or bug in the Playwright server implementation. Tested with versions 1.49.0, 1.56.1, and 1.58.2 (latest as of 2026-03-22).
TODO: Periodically test with newer Playwright versions for fix. Workaround: Mock responses at the HTTP server level rather than using network interception, or wait for a newer Playwright version that supports response body fulfillment.
See: https://playwright.dev/docs/api/class-route#route-fulfill
Sourcepub async fn fetch(
&self,
options: Option<FetchOptions>,
) -> Result<FetchResponse>
pub async fn fetch( &self, options: 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