Skip to main content

Route

Struct Route 

Source
pub struct Route { /* private fields */ }
Expand description

Route represents a network route handler.

Routes allow intercepting, aborting, continuing, or fulfilling network requests.

See: https://playwright.dev/docs/api/class-route

Implementations§

Source§

impl Route

Source

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.

Source

pub fn request(&self) -> Request

Returns the request that is being routed.

See: https://playwright.dev/docs/api/class-route#route-request

Source

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

Source

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

Source

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

Source

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

Source

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

Trait Implementations§

Source§

impl Clone for Route

Source§

fn clone(&self) -> Route

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Route

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !Freeze for Route

§

impl !RefUnwindSafe for Route

§

impl Send for Route

§

impl Sync for Route

§

impl Unpin for Route

§

impl UnsafeUnpin for Route

§

impl !UnwindSafe for Route

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more