Class: Playwright::Route

Inherits:
PlaywrightApi show all
Defined in:
lib/playwright_api/route.rb

Overview

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

Instance Method Summary collapse

Methods inherited from PlaywrightApi

from_channel_owner

Instance Method Details

#abort(errorCode: nil) ⇒ Object

Aborts the route’s request.

Raises:

  • (NotImplementedError)


7
8
9
# File 'lib/playwright_api/route.rb', line 7

def abort(errorCode: nil)
  raise NotImplementedError.new('abort is not implemented yet.')
end

#continue_(headers: nil, method: nil, postData: nil, url: nil) ⇒ Object

Continues route’s request with optional overrides.

“‘js await page.route(’*/‘, (route, request) => {

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

}); “‘

Raises:

  • (NotImplementedError)


25
26
27
# File 'lib/playwright_api/route.rb', line 25

def continue_(headers: nil, method: nil, postData: nil, url: nil)
  raise NotImplementedError.new('continue_ is not implemented yet.')
end

#fulfill(body: nil, contentType: nil, headers: nil, path: nil, status: nil) ⇒ Object

Fulfills route’s request with given response.

An example of fulfilling all requests with 404 responses:

“‘js await page.route(’*/‘, route => {

route.fulfill({
  status: 404,
  contentType: 'text/plain',
  body: 'Not Found!'
});

}); “‘

An example of serving static file:

“‘js await page.route(’**/xhr_endpoint’, route => route.fulfill({ path: ‘mock_data.json’ })); “‘

Raises:

  • (NotImplementedError)


50
51
52
53
54
55
56
57
# File 'lib/playwright_api/route.rb', line 50

def fulfill(
      body: nil,
      contentType: nil,
      headers: nil,
      path: nil,
      status: nil)
  raise NotImplementedError.new('fulfill is not implemented yet.')
end

#requestObject

A request to be routed.

Raises:

  • (NotImplementedError)


60
61
62
# File 'lib/playwright_api/route.rb', line 60

def request
  raise NotImplementedError.new('request is not implemented yet.')
end