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

#initialize, unwrap, wrap

Constructor Details

This class inherits a constructor from Playwright::PlaywrightApi

Instance Method Details

#abort(errorCode: nil) ⇒ Object

Aborts the route’s request.



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

def abort(errorCode: nil)
  wrap_impl(@impl.abort(errorCode: unwrap_impl(errorCode)))
end

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

Continues route’s request with optional overrides.

“‘python sync def handle(route, request):

# override headers
headers = {
    **request.headers,
    "foo": "bar" # set "foo" header
    "origin": None # remove "origin" header
}
route.continue_(headers=headers)

} page.route(“*/”, handle) “‘



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

def continue(headers: nil, method: nil, postData: nil, url: nil)
  wrap_impl(@impl.continue(headers: unwrap_impl(headers), method: unwrap_impl(method), postData: unwrap_impl(postData), url: unwrap_impl(url)))
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:

“‘python sync page.route(“*/”, lambda route: route.fulfill(

status=404,
content_type="text/plain",
body="not found!"))

“‘

An example of serving static file:

“‘python sync page.route(“**/xhr_endpoint”, lambda route: route.fulfill(path=“mock_data.json”)) “`



45
46
47
48
49
50
51
52
# File 'lib/playwright_api/route.rb', line 45

def fulfill(
      body: nil,
      contentType: nil,
      headers: nil,
      path: nil,
      status: nil)
  wrap_impl(@impl.fulfill(body: unwrap_impl(body), contentType: unwrap_impl(contentType), headers: unwrap_impl(headers), path: unwrap_impl(path), status: unwrap_impl(status)))
end

#off(event, callback) ⇒ Object

– inherited from EventEmitter –



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

def off(event, callback)
  event_emitter_proxy.off(event, callback)
end

#on(event, callback) ⇒ Object

– inherited from EventEmitter –



73
74
75
# File 'lib/playwright_api/route.rb', line 73

def on(event, callback)
  event_emitter_proxy.on(event, callback)
end

#once(event, callback) ⇒ Object

– inherited from EventEmitter –



67
68
69
# File 'lib/playwright_api/route.rb', line 67

def once(event, callback)
  event_emitter_proxy.once(event, callback)
end

#requestObject

A request to be routed.



55
56
57
# File 'lib/playwright_api/route.rb', line 55

def request
  wrap_impl(@impl.request)
end