class Playwright::Route
Whenever a network route is set up with [`method: Page.route
`] or [`method: BrowserContext.route
`], the `Route` object allows to handle the route.
Public Instance Methods
abort(errorCode: nil)
click to toggle source
Aborts the route's request.
# 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)
click to toggle source
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) “`
# 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)
click to toggle source
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”)) “`
# 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)
click to toggle source
– inherited from EventEmitter
– @nodoc
# File lib/playwright_api/route.rb, line 73 def off(event, callback) event_emitter_proxy.off(event, callback) end
on(event, callback)
click to toggle source
– inherited from EventEmitter
– @nodoc
# File lib/playwright_api/route.rb, line 67 def on(event, callback) event_emitter_proxy.on(event, callback) end
once(event, callback)
click to toggle source
– inherited from EventEmitter
– @nodoc
# File lib/playwright_api/route.rb, line 61 def once(event, callback) event_emitter_proxy.once(event, callback) end
request()
click to toggle source
A request to be routed.
# File lib/playwright_api/route.rb, line 55 def request wrap_impl(@impl.request) end
Private Instance Methods
event_emitter_proxy()
click to toggle source
# File lib/playwright_api/route.rb, line 77 def event_emitter_proxy @event_emitter_proxy ||= EventEmitterProxy.new(self, @impl) end