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.
§Arguments
overrides- Optional modifications to apply to the request
See: https://playwright.dev/docs/api/class-route#route-continue
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.56.1.
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 and 1.56.1 (latest as of 2025-11-10).
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