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
-
#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.
-
#headers ⇒ Object
An object with HTTP headers associated with the request.
-
#method ⇒ Object
Request’s method (GET, POST, etc.).
-
#navigation_request? ⇒ Boolean
Whether this request is driving frame’s navigation.
-
#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.
-
#timing ⇒ Object
Returns resource timing information for given request.
-
#url ⇒ Object
URL of the request.
Methods inherited from PlaywrightApi
Instance Method Details
#failure ⇒ Object
The method returns ‘null` unless this request has failed, as reported by `requestfailed` event.
Example of logging of all the failed requests:
“‘js page.on(’requestfailed’, request =>
console.log(request.url() + ' ' + request.failure().errorText);
); “‘
27 28 29 |
# File 'lib/playwright_api/request.rb', line 27 def failure raise NotImplementedError.new('failure is not implemented yet.') end |
#frame ⇒ Object
Returns the ‘Frame` that initiated this request.
32 33 34 |
# File 'lib/playwright_api/request.rb', line 32 def frame raise NotImplementedError.new('frame is not implemented yet.') end |
#headers ⇒ Object
An object with HTTP headers associated with the request. All header names are lower-case.
37 38 39 |
# File 'lib/playwright_api/request.rb', line 37 def headers raise NotImplementedError.new('headers is not implemented yet.') end |
#method ⇒ Object
Request’s method (GET, POST, etc.)
47 48 49 |
# File 'lib/playwright_api/request.rb', line 47 def method wrap_channel_owner(@channel_owner.method) end |
#navigation_request? ⇒ Boolean
Whether this request is driving frame’s navigation.
42 43 44 |
# File 'lib/playwright_api/request.rb', line 42 def raise NotImplementedError.new('navigation_request? is not implemented yet.') end |
#post_data ⇒ Object
Request’s post body, if any.
52 53 54 |
# File 'lib/playwright_api/request.rb', line 52 def post_data raise NotImplementedError.new('post_data is not implemented yet.') end |
#post_data_buffer ⇒ Object
Request’s post body in a binary form, if any.
57 58 59 |
# File 'lib/playwright_api/request.rb', line 57 def post_data_buffer raise NotImplementedError.new('post_data_buffer is not implemented yet.') 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.
65 66 67 |
# File 'lib/playwright_api/request.rb', line 65 def post_data_json raise NotImplementedError.new('post_data_json is not implemented yet.') 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`:
“‘js const response = await page.goto(’example.com’); console.log(response.request().redirectedFrom().url()); // ‘example.com’ “‘
If the website ‘google.com` has no redirects:
“‘js const response = await page.goto(’google.com’); console.log(response.request().redirectedFrom()); // null “‘
90 91 92 |
# File 'lib/playwright_api/request.rb', line 90 def redirected_from raise NotImplementedError.new('redirected_from is not implemented yet.') 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`]:
“‘js console.log(request.redirectedFrom().redirectedTo() === request); // true “`
102 103 104 |
# File 'lib/playwright_api/request.rb', line 102 def redirected_to raise NotImplementedError.new('redirected_to is not implemented yet.') 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`.
109 110 111 |
# File 'lib/playwright_api/request.rb', line 109 def resource_type raise NotImplementedError.new('resource_type is not implemented yet.') end |
#response ⇒ Object
Returns the matching ‘Response` object, or `null` if the response was not received due to error.
114 115 116 |
# File 'lib/playwright_api/request.rb', line 114 def response raise NotImplementedError.new('response is not implemented yet.') 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).
“‘js const [request] = await Promise.all([
page.waitForEvent('requestfinished'),
page.goto(httpsServer.EMPTY_PAGE)
]); console.log(request.timing()); “‘
130 131 132 |
# File 'lib/playwright_api/request.rb', line 130 def timing raise NotImplementedError.new('timing is not implemented yet.') end |
#url ⇒ Object
URL of the request.
135 136 137 |
# File 'lib/playwright_api/request.rb', line 135 def url raise NotImplementedError.new('url is not implemented yet.') end |