ferrum 0.19.0 → 0.19.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4a719b34dd1893e7c0ba2b71e121e1a2b7cc7950b96a1e462ac6a3a9f36c04e0
4
- data.tar.gz: 4c96a549ff3aa00d76420b43c2f7b4870cacb712d390efe7394ad2a8245f6825
3
+ metadata.gz: 07c9e2d0d81f6b0919d937f91e2432ce2a64890b78981d2088d606f8ce088d8f
4
+ data.tar.gz: 595a3850a55afed99b8a537b9c544fc706c8ca66f6531b4233b0f5adfa637500
5
5
  SHA512:
6
- metadata.gz: 1a4e9981f2e6334b2862a073eb645b893bbebd42399f0e4b3090d98ea3d69ab0d3104bebe34f86e66b3ec2ea01b827efa28b75c2be55482de6f89a8b082b2113
7
- data.tar.gz: acab89439a3655e51c3173bc30199bbccb6511567803fa16f066b26fbd6e5934f75492b6ed6383c8c59a27e397e23c781226abd439c551bc6be63c001868bc3a
6
+ metadata.gz: 2c8f277c645602793e5c9f63e89f12c810668ba9fd8d45585c090a220343abb4ea40769e5c03baa4c59d1aed530282db5bcaa30d151a7662f85142556dcfdd49
7
+ data.tar.gz: a4113a1261c436899348992e3514796c3dccffd425003e2d10da7d398bd743f6b864cbc85d8fd48efc33d42f8ce5e4c3546fcc209b813c5417982c4f8dca893e
@@ -48,7 +48,6 @@ module Ferrum
48
48
  "disable-smooth-scrolling" => nil,
49
49
  "disable-sync" => nil,
50
50
  "disable-translate" => nil,
51
- "disable-web-security" => nil,
52
51
  "enable-automation" => nil,
53
52
  "enable-features" => %w[
54
53
  NetworkService
@@ -16,6 +16,7 @@ module Ferrum
16
16
  WEBSOCKET_BUG_SLEEP = 0.05
17
17
  DEFAULT_PORTS = { "ws" => 80, "wss" => 443 }.freeze
18
18
  SKIP_LOGGING_SCREENSHOTS = !ENV["FERRUM_LOGGING_SCREENSHOTS"]
19
+ ESCAPE_OR_LONE_SURROGATE = /\\u[dD][89abAB]\h{2}\\u[dD][c-fC-F]\h{2}|\\u([dD][89a-fA-F]\h{2})|\\./
19
20
 
20
21
  attr_reader :url, :messages
21
22
 
@@ -223,14 +224,12 @@ module Ferrum
223
224
  rescue JSON::NestingError
224
225
  # nop
225
226
  rescue JSON::ParserError
226
- safely_parse_escaped_json(data)
227
+ safely_parse_lone_surrogates(data)
227
228
  end
228
229
 
229
- def safely_parse_escaped_json(data)
230
- unescaped_unicode =
231
- data.gsub(/\\u([\da-fA-F]{4})/) { |_| [::Regexp.last_match(1)].pack("H*").unpack("n*").pack("U*") }
232
- escaped_data = unescaped_unicode.encode("UTF-8", "UTF-8", undef: :replace, invalid: :replace, replace: "?")
233
- JSON.parse(escaped_data, max_nesting: false)
230
+ def safely_parse_lone_surrogates(data)
231
+ replaced = data.gsub(ESCAPE_OR_LONE_SURROGATE) { |escape| ::Regexp.last_match(1) ? "\\ufffd" : escape }
232
+ JSON.parse(replaced, max_nesting: false)
234
233
  rescue JSON::ParserError
235
234
  # nop
236
235
  end
data/lib/ferrum/client.rb CHANGED
@@ -376,7 +376,8 @@ module Ferrum
376
376
  # Node has disappeared while we were trying to get it
377
377
  when "No node with given id found",
378
378
  "Could not find node with given id",
379
- "Inspected target navigated or closed"
379
+ "Inspected target navigated or closed",
380
+ "Argument should belong to the same JavaScript world as target object"
380
381
  raise NodeNotFoundError, error
381
382
  # Context is lost, page is reloading
382
383
  when "Cannot find context with specified id"
@@ -116,7 +116,8 @@ module Ferrum
116
116
  # Returns the element in which the window is embedded.
117
117
  #
118
118
  # @return [Node, nil]
119
- # The element in which the window is embedded.
119
+ # The element in which the window is embedded, `nil` for the main frame
120
+ # and for a frame from a different origin than its parent.
120
121
  #
121
122
  # @example
122
123
  # browser.go_to("https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe")
data/lib/ferrum/mouse.rb CHANGED
@@ -152,6 +152,7 @@ module Ferrum
152
152
  from_y = @y
153
153
  @x = x
154
154
  @y = y
155
+ button = pressed_button
155
156
 
156
157
  steps.times do |i|
157
158
  new_x = from_x + ((@x - from_x) * ((i + 1) / steps.to_f))
@@ -162,6 +163,7 @@ module Ferrum
162
163
  type: "mouseMoved",
163
164
  x: new_x,
164
165
  y: new_y,
166
+ button: button,
165
167
  buttons: @buttons)
166
168
  end
167
169
 
@@ -185,6 +187,10 @@ module Ferrum
185
187
  button
186
188
  end
187
189
 
190
+ def pressed_button
191
+ BUTTON_MASKS.find { |_name, mask| mask.positive? && @buttons.anybits?(mask) }&.first || "none"
192
+ end
193
+
188
194
  def register_event_button(type, button)
189
195
  case type
190
196
  when "mousePressed"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ferrum
4
- VERSION = "0.19.0"
4
+ VERSION = "0.19.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ferrum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.19.0
4
+ version: 0.19.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Vorotilin