Class: Playwright::Request

Inherits:
PlaywrightApi show all
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

Methods inherited from PlaywrightApi

from_channel_owner

Instance Method Details

#failureObject

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);

); “‘

Raises:

  • (NotImplementedError)


27
28
29
# File 'lib/playwright_api/request.rb', line 27

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

#frameObject

Returns the ‘Frame` that initiated this request.

Raises:

  • (NotImplementedError)


32
33
34
# File 'lib/playwright_api/request.rb', line 32

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

#headersObject

An object with HTTP headers associated with the request. All header names are lower-case.

Raises:

  • (NotImplementedError)


37
38
39
# File 'lib/playwright_api/request.rb', line 37

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

#methodObject

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

Whether this request is driving frame’s navigation.

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


42
43
44
# File 'lib/playwright_api/request.rb', line 42

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

#post_dataObject

Request’s post body, if any.

Raises:

  • (NotImplementedError)


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_bufferObject

Request’s post body in a binary form, if any.

Raises:

  • (NotImplementedError)


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_jsonObject

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.

Raises:

  • (NotImplementedError)


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_fromObject

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 “‘

Raises:

  • (NotImplementedError)


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_toObject

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 “`

Raises:

  • (NotImplementedError)


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_typeObject

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`.

Raises:

  • (NotImplementedError)


109
110
111
# File 'lib/playwright_api/request.rb', line 109

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

#responseObject

Returns the matching ‘Response` object, or `null` if the response was not received due to error.

Raises:

  • (NotImplementedError)


114
115
116
# File 'lib/playwright_api/request.rb', line 114

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

#timingObject

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()); “‘

Raises:

  • (NotImplementedError)


130
131
132
# File 'lib/playwright_api/request.rb', line 130

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

#urlObject

URL of the request.

Raises:

  • (NotImplementedError)


135
136
137
# File 'lib/playwright_api/request.rb', line 135

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