Skip to content

Commit

Permalink
Merge pull request #275 from YusukeIwaki/driver/1.40.0
Browse files Browse the repository at this point in the history
Update playwright driver to 1.40.0
  • Loading branch information
YusukeIwaki authored Dec 10, 2023
2 parents 159bd7c + cc5905f commit 7da38ff
Show file tree
Hide file tree
Showing 34 changed files with 741 additions and 276 deletions.
2 changes: 1 addition & 1 deletion development/CLI_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.39.0
1.40.0
421 changes: 350 additions & 71 deletions development/api.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions development/generate_api/example_codes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def example_de61e349d06a98a38ba9bfccc5708125cd263b7d3a31b9a837eda3db0baac288(bro
end

# BrowserContext#expose_binding
def example_a450852d36dda88564582371af8d87bb58b1a517aac4fa60b7a58a0e41c5ceff(browser_context:)
def example_ba61d7312419a50eab8b67fd47e467e3b53590e7fd2ee55055fb6d12c94a61e4(browser_context:)
browser_context.expose_binding("pageURL", ->(source) { source[:page].url })
page = browser_context.new_page

Expand Down Expand Up @@ -1447,7 +1447,7 @@ def example_fd8ed14043be0b21635ea7b0c55b59c55991a6a686904fcb82f2eee7671f9d55(pag
end

# Page#expose_binding
def example_4f7d99a72aaea957cc5678ed8728965338d78598d7772f47fbf23c28f0eba52d(page:)
def example_f32bc2194cbfc7c632c148ab34523bc5a4e3fdbdc66d7dfcf85304977a1adcbf(page:)
page.expose_binding("pageURL", ->(source) { source[:page].url })
page.content = <<~HTML
<script>
Expand All @@ -1458,7 +1458,7 @@ def example_4f7d99a72aaea957cc5678ed8728965338d78598d7772f47fbf23c28f0eba52d(pag
<button onclick="onClick()">Click me</button>
<div></div>
HTML
page.locator("button").click
page.click("button")
end

# Page#expose_binding
Expand Down
3 changes: 1 addition & 2 deletions documentation/docs/api/api_request_context.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ def dispose
```


All responses returned by [APIRequestContext#get](./api_request_context#get) and similar methods are stored in the memory, so that you can later call [APIResponse#body](./api_response#body). This method
discards all stored responses, and makes [APIResponse#body](./api_response#body) throw "Response disposed" error.
All responses returned by [APIRequestContext#get](./api_request_context#get) and similar methods are stored in the memory, so that you can later call [APIResponse#body](./api_response#body).This method discards all its resources, calling any method on disposed [APIRequestContext](./api_request_context) will throw an exception.

## fetch

Expand Down
2 changes: 1 addition & 1 deletion documentation/docs/api/browser.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Get the browser type (chromium, firefox or webkit) that the browser belongs to.
## close

```
def close
def close(reason: nil)
```


Expand Down
2 changes: 1 addition & 1 deletion documentation/docs/api/browser_context.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ context.clear_permissions
## close

```
def close
def close(reason: nil)
```


Expand Down
1 change: 1 addition & 0 deletions documentation/docs/api/browser_type.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ def launch_persistent_context(
env: nil,
executablePath: nil,
extraHTTPHeaders: nil,
firefoxUserPrefs: nil,
forcedColors: nil,
geolocation: nil,
handleSIGHUP: nil,
Expand Down
3 changes: 1 addition & 2 deletions documentation/docs/api/download.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ def path
```


Returns path to the downloaded file in case of successful download. The method will
wait for the download to finish if necessary. The method throws when connected remotely.
Returns path to the downloaded file for a successful download, or throws for a failed/canceled download. The method will wait for the download to finish if necessary. The method throws when connected remotely.

Note that the download's file name is a random GUID, use [Download#suggested_filename](./download#suggested_filename)
to get suggested file name.
Expand Down
5 changes: 4 additions & 1 deletion documentation/docs/api/element_handle.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,16 @@ default.

Since `eventInit` is event-specific, please refer to the events documentation for the lists of initial
properties:
- [DeviceMotionEvent](https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent/DeviceMotionEvent)
- [DeviceOrientationEvent](https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent/DeviceOrientationEvent)
- [DragEvent](https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent)
- [Event](https://developer.mozilla.org/en-US/docs/Web/API/Event/Event)
- [FocusEvent](https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent)
- [KeyboardEvent](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent)
- [MouseEvent](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent)
- [PointerEvent](https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent)
- [TouchEvent](https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent)
- [Event](https://developer.mozilla.org/en-US/docs/Web/API/Event/Event)
- [WheelEvent](https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/WheelEvent)

You can also specify [JSHandle](./js_handle) as the property value if you want live objects to be passed into the event:

Expand Down
5 changes: 4 additions & 1 deletion documentation/docs/api/frame.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,16 @@ default.

Since `eventInit` is event-specific, please refer to the events documentation for the lists of initial
properties:
- [DeviceMotionEvent](https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent/DeviceMotionEvent)
- [DeviceOrientationEvent](https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent/DeviceOrientationEvent)
- [DragEvent](https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent)
- [Event](https://developer.mozilla.org/en-US/docs/Web/API/Event/Event)
- [FocusEvent](https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent)
- [KeyboardEvent](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent)
- [MouseEvent](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent)
- [PointerEvent](https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent)
- [TouchEvent](https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent)
- [Event](https://developer.mozilla.org/en-US/docs/Web/API/Event/Event)
- [WheelEvent](https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/WheelEvent)

You can also specify [JSHandle](./js_handle) as the property value if you want live objects to be passed into the event:

Expand Down
5 changes: 4 additions & 1 deletion documentation/docs/api/locator.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,16 @@ default.

Since `eventInit` is event-specific, please refer to the events documentation for the lists of initial
properties:
- [DeviceMotionEvent](https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent/DeviceMotionEvent)
- [DeviceOrientationEvent](https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent/DeviceOrientationEvent)
- [DragEvent](https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent)
- [Event](https://developer.mozilla.org/en-US/docs/Web/API/Event/Event)
- [FocusEvent](https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent)
- [KeyboardEvent](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent)
- [MouseEvent](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent)
- [PointerEvent](https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent)
- [TouchEvent](https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent)
- [Event](https://developer.mozilla.org/en-US/docs/Web/API/Event/Event)
- [WheelEvent](https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/WheelEvent)

You can also specify [JSHandle](./js_handle) as the property value if you want live objects to be passed into the event:

Expand Down
12 changes: 11 additions & 1 deletion documentation/docs/api/locator_assertions.md
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,11 @@ expect(locator).to contain_text(expected, ignoreCase: nil, timeout: nil, useInne

Ensures the [Locator](./locator) points to an element that contains the given text. You can use regular expressions for the value as well.

**Details**

When `expected` parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual text and
in the expected string before matching. When regular expression is used, the actual text is matched as is.

**Usage**

```ruby
Expand Down Expand Up @@ -443,7 +448,7 @@ expect(page.locator("ul")).to contain_text(["Text 3"])
## to_have_attribute

```ruby
expect(locator).to have_attribute(name, value, timeout: nil)
expect(locator).to have_attribute(name, value, ignoreCase: nil, timeout: nil)
```


Expand Down Expand Up @@ -559,6 +564,11 @@ expect(locator).to have_text(expected, ignoreCase: nil, timeout: nil, useInnerTe

Ensures the [Locator](./locator) points to an element with the given text. You can use regular expressions for the value as well.

**Details**

When `expected` parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual text and
in the expected string before matching. When regular expression is used, the actual text is matched as is.

**Usage**

```ruby
Expand Down
9 changes: 6 additions & 3 deletions documentation/docs/api/page.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ When all steps combined have not finished during the specified `timeout`, this m
## close

```
def close(runBeforeUnload: nil)
def close(reason: nil, runBeforeUnload: nil)
```


Expand Down Expand Up @@ -240,13 +240,16 @@ default.

Since `eventInit` is event-specific, please refer to the events documentation for the lists of initial
properties:
- [DeviceMotionEvent](https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent/DeviceMotionEvent)
- [DeviceOrientationEvent](https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent/DeviceOrientationEvent)
- [DragEvent](https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent)
- [Event](https://developer.mozilla.org/en-US/docs/Web/API/Event/Event)
- [FocusEvent](https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent)
- [KeyboardEvent](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent)
- [MouseEvent](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent)
- [PointerEvent](https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent)
- [TouchEvent](https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent)
- [Event](https://developer.mozilla.org/en-US/docs/Web/API/Event/Event)
- [WheelEvent](https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/WheelEvent)

You can also specify [JSHandle](./js_handle) as the property value if you want live objects to be passed into the event:

Expand Down Expand Up @@ -473,7 +476,7 @@ page.content = <<~HTML
<button onclick="onClick()">Click me</button>
<div></div>
HTML
page.locator("button").click
page.click("button")
```

An example of passing an element handle:
Expand Down
2 changes: 1 addition & 1 deletion lib/playwright.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module Playwright; end
require 'playwright/url_matcher'
require 'playwright/version'
require 'playwright/video'
require 'playwright/wait_helper'
require 'playwright/waiter'

require 'playwright/playwright_api'
# load generated files
Expand Down
4 changes: 2 additions & 2 deletions lib/playwright/api_response_impl.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Playwright
define_api_implementation :APIResponseImpl do
include Utils::Errors::SafeCloseError
include Utils::Errors::TargetClosedErrorMethods

# @params context [APIRequestContext]
# @params initializer [Hash]
Expand Down Expand Up @@ -50,7 +50,7 @@ def body
raise AlreadyDisposedError.new unless binary
Base64.strict_decode64(binary)
rescue => err
if safe_close_error?(err)
if target_closed_error?(err)
raise AlreadyDisposedError.new
else
raise
Expand Down
15 changes: 12 additions & 3 deletions lib/playwright/channel_owners/api_request_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@ def fetch(
case data
when String
if headers_obj&.any? { |key, value| key.downcase == 'content-type' && value == 'application/json' }
json_data = data
json_data = json_parsable?(data) ? data : data.to_json
else
post_data_buffer = data
end
when Hash, Array, Numeric, true, false
json_data = data
json_data = data.to_json
else
raise ArgumentError.new("Unsupported 'data' type: #{data.class}")
end
Expand All @@ -142,7 +142,6 @@ def fetch(
if post_data_buffer
fetch_params[:postData] = Base64.strict_encode64(post_data_buffer)
end

fetch_params[:jsonData] = json_data
fetch_params[:formData] = form_data
fetch_params[:multipartData] = multipart_data
Expand Down Expand Up @@ -174,5 +173,15 @@ def fetch(
{ name: key, value: value.to_s }
end
end

private def json_parsable?(data)
return false unless data.is_a?(String)
begin
JSON.parse(data)
true
rescue JSON::ParserError
false
end
end
end
end
18 changes: 11 additions & 7 deletions lib/playwright/channel_owners/browser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@
module Playwright
# @ref https://github.com/microsoft/playwright-python/blob/master/playwright/_impl/_browser.py
define_channel_owner :Browser do
include Utils::Errors::SafeCloseError
include Utils::Errors::TargetClosedErrorMethods
include Utils::PrepareBrowserContextOptions

private def after_initialize
@browser_type = @parent
@connected = true
@closed_or_closing = false
@should_close_connection_on_close = false

@contexts = Set.new
@channel.on('close', method(:on_close))
@close_reason = nil
end

private def close_reason
@close_reason
end

def contexts
Expand Down Expand Up @@ -63,16 +67,16 @@ def new_page(**options, &block)
@browser_type = browser_type
end

def close
return if @closed_or_closing
@closed_or_closing = true
@channel.send_message_to_server('close')
def close(reason: nil)
@close_reason = reason
if @should_close_connection_on_close
@connection.stop
else
@channel.send_message_to_server('close', { reason: reason }.compact)
end
nil
rescue => err
raise unless safe_close_error?(err)
raise unless target_closed_error?(err)
end

def version
Expand Down
Loading

1 comment on commit 7da38ff

@vercel
Copy link

@vercel vercel bot commented on 7da38ff Dec 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.