Route

Struct Route 

Source
pub struct Route {
    inner: Weak<Route>,
}
Expand description

Whenever a network route is set up with [method: Page.route] or [method: BrowserContext.route], the Route object allows to handle the route.

Fields§

§inner: Weak<Route>

Implementations§

Source§

impl Route

Source

fn new(inner: Weak<Impl>) -> Self

Source

pub fn request(&self) -> Request

A request to be routed.

Source

pub async fn abort(&self, err_code: Option<&str>) -> Result<(), Arc<Error>>

Aborts the route’s request. Optional error code. Defaults to failed, could be one of the following:

  • 'aborted' - An operation was aborted (due to user action)
  • 'accessdenied' - Permission to access a resource, other than the network, was denied
  • 'addressunreachable' - The IP address is unreachable. This usually means that there is no route to the specified host or network.
  • 'blockedbyclient' - The client chose to block the request.
  • 'blockedbyresponse' - The request failed because the response was delivered along with requirements which are not met (‘X-Frame-Options’ and ‘Content-Security-Policy’ ancestor checks, for instance).
  • 'connectionaborted' - A connection timed out as a result of not receiving an ACK for data sent.
  • 'connectionclosed' - A connection was closed (corresponding to a TCP FIN).
  • 'connectionfailed' - A connection attempt failed.
  • 'connectionrefused' - A connection attempt was refused.
  • 'connectionreset' - A connection was reset (corresponding to a TCP RST).
  • 'internetdisconnected' - The Internet connection has been lost.
  • 'namenotresolved' - The host name could not be resolved.
  • 'timedout' - An operation timed out.
  • 'failed' - A generic failure occurred.
Source

pub async fn fulfill_builder<'a>( &self, body: &'a str, is_base64: bool, ) -> FulfillBuilder<'a, '_>

Fulfills route’s request with given response.

An example of fulfilling all requests with 404 responses:

await page.route('**/*', route => {
 route.fulfill({
   status: 404,
   contentType: 'text/plain',
   body: 'Not Found!'
 });
});
Source

pub async fn continue_builder(&self) -> ContinueBuilder<'_, '_, '_>

Continues route’s request with optional overrides.

await page.route('**/*', (route, request) => {
 // Override headers
 const headers = {
   ...request.headers(),
   foo: 'bar', // set "foo" header
   origin: undefined, // remove "origin" header
 };
 route.continue({headers});
});

Trait Implementations§

Source§

impl PartialEq for Route

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

impl Freeze for Route

§

impl RefUnwindSafe for Route

§

impl Send for Route

§

impl Sync for Route

§

impl Unpin 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.