Class: Playwright::Request
- Inherits:
-
PlaywrightApi
- Object
- PlaywrightApi
- Playwright::Request
- Defined in:
- lib/playwright_api/request.rb
Overview
Whenever the page sends a request for a network resource the following sequence of events are emitted by `Page`:
- `event: Page.request`
-
emitted when the request is issued by the page.
- `event: Page.response`
-
emitted when/if the response status and headers are received for the request.
- `event: Page.requestFinished`
-
emitted when the response body is downloaded and the request is complete.
If request fails at some point, then instead of `'requestfinished'` event (and possibly instead of 'response' event), the [`event: Page.requestFailed`] event is emitted.
> NOTE: HTTP Error responses, such as 404 or 503, are still successful responses from HTTP standpoint, so request will complete with `'requestfinished'` event.
If request gets a 'redirect' response, the request is successfully finished with the 'requestfinished' event, and a new request is issued to a redirected url.
Instance Method Summary collapse
-
#all_headers ⇒ Object
An object with all the request HTTP headers associated with this request.
-
#failure ⇒ Object
The method returns `null` unless this request has failed, as reported by `requestfailed` event.
-
#frame ⇒ Object
Returns the `Frame` that initiated this request.
-
#header_value(name) ⇒ Object
Returns the value of the header matching the name.
- #header_values(name) ⇒ Object
-
#headers ⇒ Object
*DEPRECATED* Incomplete list of headers as seen by the rendering engine.
-
#headers_array ⇒ Object
An array with all the request HTTP headers associated with this request.
-
#method ⇒ Object
Request's method (GET, POST, etc.).
-
#navigation_request? ⇒ Boolean
Whether this request is driving frame's navigation.
-
#off(event, callback) ⇒ Object
– inherited from EventEmitter –.
-
#on(event, callback) ⇒ Object
– inherited from EventEmitter –.
-
#once(event, callback) ⇒ Object
– inherited from EventEmitter –.
-
#post_data ⇒ Object
Request's post body, if any.
-
#post_data_buffer ⇒ Object
Request's post body in a binary form, if any.
-
#post_data_json ⇒ Object
Returns parsed request's body for `form-urlencoded` and JSON as a fallback if any.
-
#redirected_from ⇒ Object
Request that was redirected by the server to this one, if any.
-
#redirected_to ⇒ Object
New request issued by the browser if the server responded with redirect.
-
#resource_type ⇒ Object
Contains the request's resource type as it was perceived by the rendering engine.
-
#response ⇒ Object
Returns the matching `Response` object, or `null` if the response was not received due to error.
-
#sizes ⇒ Object
Returns resource size information for given request.
-
#timing ⇒ Object
Returns resource timing information for given request.
-
#url ⇒ Object
URL of the request.
Methods inherited from PlaywrightApi
Constructor Details
This class inherits a constructor from Playwright::PlaywrightApi
Instance Method Details
#all_headers ⇒ Object
An object with all the request HTTP headers associated with this request. The header names are lower-cased.
18 19 20 |
# File 'lib/playwright_api/request.rb', line 18 def all_headers wrap_impl(@impl.all_headers) end |
#failure ⇒ Object
The method returns `null` unless this request has failed, as reported by `requestfailed` event.
Example of logging of all the failed requests:
“`py page.on(“requestfailed”, lambda request: print(request.url + “ ” + request.failure)) “`
29 30 31 |
# File 'lib/playwright_api/request.rb', line 29 def failure wrap_impl(@impl.failure) end |
#frame ⇒ Object
Returns the `Frame` that initiated this request.
34 35 36 |
# File 'lib/playwright_api/request.rb', line 34 def frame wrap_impl(@impl.frame) end |
#header_value(name) ⇒ Object
Returns the value of the header matching the name. The name is case insensitive.
50 51 52 |
# File 'lib/playwright_api/request.rb', line 50 def header_value(name) wrap_impl(@impl.header_value(unwrap_impl(name))) end |
#header_values(name) ⇒ Object
153 154 155 |
# File 'lib/playwright_api/request.rb', line 153 def header_values(name) wrap_impl(@impl.header_values(unwrap_impl(name))) end |
#headers ⇒ Object
*DEPRECATED* Incomplete list of headers as seen by the rendering engine. Use [`method: Request.allHeaders`] instead.
39 40 41 |
# File 'lib/playwright_api/request.rb', line 39 def headers wrap_impl(@impl.headers) end |
#headers_array ⇒ Object
An array with all the request HTTP headers associated with this request. Unlike [`method: Request.allHeaders`], header names are NOT lower-cased. Headers with multiple entries, such as `Set-Cookie`, appear in the array multiple times.
45 46 47 |
# File 'lib/playwright_api/request.rb', line 45 def headers_array wrap_impl(@impl.headers_array) end |
#method ⇒ Object
Request's method (GET, POST, etc.)
60 61 62 |
# File 'lib/playwright_api/request.rb', line 60 def method wrap_impl(@impl.method) end |
#navigation_request? ⇒ Boolean
Whether this request is driving frame's navigation.
55 56 57 |
# File 'lib/playwright_api/request.rb', line 55 def wrap_impl(@impl.) end |
#off(event, callback) ⇒ Object
– inherited from EventEmitter –
171 172 173 |
# File 'lib/playwright_api/request.rb', line 171 def off(event, callback) event_emitter_proxy.off(event, callback) end |
#on(event, callback) ⇒ Object
– inherited from EventEmitter –
165 166 167 |
# File 'lib/playwright_api/request.rb', line 165 def on(event, callback) event_emitter_proxy.on(event, callback) end |
#once(event, callback) ⇒ Object
– inherited from EventEmitter –
159 160 161 |
# File 'lib/playwright_api/request.rb', line 159 def once(event, callback) event_emitter_proxy.once(event, callback) end |
#post_data ⇒ Object
Request's post body, if any.
65 66 67 |
# File 'lib/playwright_api/request.rb', line 65 def post_data wrap_impl(@impl.post_data) end |
#post_data_buffer ⇒ Object
Request's post body in a binary form, if any.
70 71 72 |
# File 'lib/playwright_api/request.rb', line 70 def post_data_buffer wrap_impl(@impl.post_data_buffer) end |
#post_data_json ⇒ Object
Returns parsed request's body for `form-urlencoded` and JSON as a fallback if any.
When the response is `application/x-www-form-urlencoded` then a key/value object of the values will be returned. Otherwise it will be parsed as JSON.
78 79 80 |
# File 'lib/playwright_api/request.rb', line 78 def post_data_json wrap_impl(@impl.post_data_json) end |
#redirected_from ⇒ Object
Request that was redirected by the server to this one, if any.
When the server responds with a redirect, Playwright creates a new `Request` object. The two requests are connected by `redirectedFrom()` and `redirectedTo()` methods. When multiple server redirects has happened, it is possible to construct the whole redirect chain by repeatedly calling `redirectedFrom()`.
For example, if the website `example.com` redirects to `example.com`:
“`python sync response = page.goto(“example.com”) print(response.request.redirected_from.url) # “example.com” “`
If the website `google.com` has no redirects:
“`python sync response = page.goto(“google.com”) print(response.request.redirected_from) # None “`
101 102 103 |
# File 'lib/playwright_api/request.rb', line 101 def redirected_from wrap_impl(@impl.redirected_from) end |
#redirected_to ⇒ Object
New request issued by the browser if the server responded with redirect.
This method is the opposite of [`method: Request.redirectedFrom`]:
“`py assert request.redirected_from.redirected_to == request “`
112 113 114 |
# File 'lib/playwright_api/request.rb', line 112 def redirected_to wrap_impl(@impl.redirected_to) end |
#resource_type ⇒ Object
Contains the request's resource type as it was perceived by the rendering engine. ResourceType will be one of the following: `document`, `stylesheet`, `image`, `media`, `font`, `script`, `texttrack`, `xhr`, `fetch`, `eventsource`, `websocket`, `manifest`, `other`.
119 120 121 |
# File 'lib/playwright_api/request.rb', line 119 def resource_type wrap_impl(@impl.resource_type) end |
#response ⇒ Object
Returns the matching `Response` object, or `null` if the response was not received due to error.
124 125 126 |
# File 'lib/playwright_api/request.rb', line 124 def response wrap_impl(@impl.response) end |
#sizes ⇒ Object
Returns resource size information for given request.
129 130 131 |
# File 'lib/playwright_api/request.rb', line 129 def sizes wrap_impl(@impl.sizes) end |
#timing ⇒ Object
Returns resource timing information for given request. Most of the timing values become available upon the response, `responseEnd` becomes available when request finishes. Find more information at [Resource Timing API](developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming).
“`python sync with page.expect_event(“requestfinished”) as request_info:
page.goto("http://example.com")
request = request_info.value print(request.timing) “`
143 144 145 |
# File 'lib/playwright_api/request.rb', line 143 def timing wrap_impl(@impl.timing) end |
#url ⇒ Object
URL of the request.
148 149 150 |
# File 'lib/playwright_api/request.rb', line 148 def url wrap_impl(@impl.url) end |