puppeteer-ruby 0.0.8 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -0
  3. data/docs/Puppeteer.html +415 -97
  4. data/docs/Puppeteer/AsyncAwaitBehavior.html +1 -1
  5. data/docs/Puppeteer/Browser.html +261 -153
  6. data/docs/Puppeteer/BrowserContext.html +2 -2
  7. data/docs/Puppeteer/BrowserFetcher.html +1 -1
  8. data/docs/Puppeteer/BrowserRunner.html +1 -1
  9. data/docs/Puppeteer/BrowserRunner/BrowserProcess.html +1 -1
  10. data/docs/Puppeteer/CDPSession.html +2 -2
  11. data/docs/Puppeteer/CDPSession/Error.html +1 -1
  12. data/docs/Puppeteer/ConcurrentRubyUtils.html +14 -6
  13. data/docs/Puppeteer/Connection.html +66 -62
  14. data/docs/Puppeteer/Connection/MessageCallback.html +1 -1
  15. data/docs/Puppeteer/Connection/ProtocolError.html +1 -1
  16. data/docs/Puppeteer/Connection/RequestDebugPrinter.html +5 -5
  17. data/docs/Puppeteer/Connection/ResponseDebugPrinter.html +12 -12
  18. data/docs/Puppeteer/ConsoleMessage.html +1 -1
  19. data/docs/Puppeteer/ConsoleMessage/Location.html +1 -1
  20. data/docs/Puppeteer/DOMWorld.html +106 -32
  21. data/docs/Puppeteer/DOMWorld/DetachedError.html +1 -1
  22. data/docs/Puppeteer/DOMWorld/DocumentEvaluationError.html +1 -1
  23. data/docs/Puppeteer/DebugPrint.html +1 -1
  24. data/docs/Puppeteer/Device.html +1 -1
  25. data/docs/Puppeteer/Devices.html +1 -1
  26. data/docs/Puppeteer/ElementHandle.html +525 -207
  27. data/docs/Puppeteer/ElementHandle/BoundingBox.html +507 -0
  28. data/docs/Puppeteer/ElementHandle/BoxModel.html +404 -0
  29. data/docs/Puppeteer/ElementHandle/ElementNotFoundError.html +5 -5
  30. data/docs/Puppeteer/ElementHandle/ElementNotVisibleError.html +5 -5
  31. data/docs/Puppeteer/ElementHandle/Point.html +40 -29
  32. data/docs/Puppeteer/ElementHandle/ScrollIntoViewError.html +1 -1
  33. data/docs/Puppeteer/EmulationManager.html +1 -1
  34. data/docs/Puppeteer/EventCallbackable.html +83 -17
  35. data/docs/Puppeteer/EventCallbackable/EventListeners.html +1 -1
  36. data/docs/Puppeteer/ExecutionContext.html +1 -1
  37. data/docs/Puppeteer/ExecutionContext/EvaluationError.html +1 -1
  38. data/docs/Puppeteer/ExecutionContext/JavaScriptExpression.html +1 -1
  39. data/docs/Puppeteer/ExecutionContext/JavaScriptFunction.html +1 -1
  40. data/docs/Puppeteer/FileChooser.html +1 -1
  41. data/docs/Puppeteer/Frame.html +450 -292
  42. data/docs/Puppeteer/FrameManager.html +23 -27
  43. data/docs/Puppeteer/FrameManager/NavigationError.html +1 -1
  44. data/docs/Puppeteer/IfPresent.html +1 -1
  45. data/docs/Puppeteer/JSHandle.html +1 -1
  46. data/docs/Puppeteer/Keyboard.html +1 -1
  47. data/docs/Puppeteer/Keyboard/KeyDefinition.html +1 -1
  48. data/docs/Puppeteer/Keyboard/KeyDescription.html +1 -1
  49. data/docs/Puppeteer/Launcher.html +1 -1
  50. data/docs/Puppeteer/Launcher/Base.html +1 -1
  51. data/docs/Puppeteer/Launcher/Base/ExecutablePathNotFound.html +1 -1
  52. data/docs/Puppeteer/Launcher/BrowserOptions.html +1 -1
  53. data/docs/Puppeteer/Launcher/Chrome.html +36 -31
  54. data/docs/Puppeteer/Launcher/Chrome/DefaultArgs.html +1 -1
  55. data/docs/Puppeteer/Launcher/ChromeArgOptions.html +1 -1
  56. data/docs/Puppeteer/Launcher/LaunchOptions.html +1 -1
  57. data/docs/Puppeteer/LifecycleWatcher.html +1 -1
  58. data/docs/Puppeteer/LifecycleWatcher/ExpectedLifecycle.html +1 -1
  59. data/docs/Puppeteer/LifecycleWatcher/FrameDetachedError.html +1 -1
  60. data/docs/Puppeteer/LifecycleWatcher/TerminatedError.html +1 -1
  61. data/docs/Puppeteer/Mouse.html +31 -41
  62. data/docs/Puppeteer/Mouse/Button.html +1 -1
  63. data/docs/Puppeteer/NetworkManager.html +2 -2
  64. data/docs/Puppeteer/NetworkManager/Credentials.html +1 -1
  65. data/docs/Puppeteer/Page.html +502 -299
  66. data/docs/Puppeteer/Page/FileChooserTimeoutError.html +5 -5
  67. data/docs/Puppeteer/Page/ScreenshotOptions.html +1 -1
  68. data/docs/Puppeteer/Page/ScriptTag.html +24 -24
  69. data/docs/Puppeteer/Page/StyleTag.html +19 -19
  70. data/docs/Puppeteer/Page/TargetCrashedError.html +1 -1
  71. data/docs/Puppeteer/RemoteObject.html +110 -39
  72. data/docs/Puppeteer/Target.html +150 -198
  73. data/docs/Puppeteer/Target/InitializeFailure.html +1 -1
  74. data/docs/Puppeteer/Target/TargetInfo.html +1 -1
  75. data/docs/Puppeteer/TimeoutError.html +2 -2
  76. data/docs/Puppeteer/TimeoutSettings.html +1 -1
  77. data/docs/Puppeteer/TouchScreen.html +1 -1
  78. data/docs/Puppeteer/Viewport.html +81 -1
  79. data/docs/Puppeteer/WaitTask.html +1 -1
  80. data/docs/Puppeteer/WaitTask/TerminatedError.html +1 -1
  81. data/docs/Puppeteer/WaitTask/TimeoutError.html +1 -1
  82. data/docs/Puppeteer/WebSocket.html +26 -26
  83. data/docs/Puppeteer/WebSocket/DriverImpl.html +1 -1
  84. data/docs/Puppeteer/WebSocket/TransportError.html +124 -0
  85. data/docs/Puppeteer/WebSocketTransport.html +9 -9
  86. data/docs/Puppeteer/WebSocktTransportError.html +1 -1
  87. data/docs/_index.html +28 -21
  88. data/docs/class_list.html +1 -1
  89. data/docs/file.README.html +3 -1
  90. data/docs/index.html +3 -1
  91. data/docs/method_list.html +659 -515
  92. data/docs/top-level-namespace.html +1 -1
  93. data/lib/puppeteer.rb +36 -12
  94. data/lib/puppeteer/browser.rb +26 -6
  95. data/lib/puppeteer/concurrent_ruby_utils.rb +6 -2
  96. data/lib/puppeteer/connection.rb +13 -1
  97. data/lib/puppeteer/dom_world.rb +11 -12
  98. data/lib/puppeteer/element_handle.rb +66 -108
  99. data/lib/puppeteer/element_handle/bounding_box.rb +12 -0
  100. data/lib/puppeteer/element_handle/box_model.rb +19 -0
  101. data/lib/puppeteer/element_handle/point.rb +26 -0
  102. data/lib/puppeteer/errors.rb +1 -3
  103. data/lib/puppeteer/event_callbackable.rb +11 -0
  104. data/lib/puppeteer/frame.rb +20 -1
  105. data/lib/puppeteer/launcher.rb +6 -6
  106. data/lib/puppeteer/launcher/chrome.rb +10 -8
  107. data/lib/puppeteer/mouse.rb +3 -8
  108. data/lib/puppeteer/page.rb +43 -4
  109. data/lib/puppeteer/remote_object.rb +9 -0
  110. data/lib/puppeteer/target.rb +25 -25
  111. data/lib/puppeteer/version.rb +1 -1
  112. data/lib/puppeteer/viewport.rb +18 -0
  113. data/lib/puppeteer/web_socket.rb +3 -1
  114. data/lib/puppeteer/web_socket_transport.rb +8 -8
  115. data/puppeteer-ruby.png +0 -0
  116. metadata +9 -4
  117. data/Dockerfile +0 -6
  118. data/docker-compose.yml +0 -15
@@ -0,0 +1,12 @@
1
+ class Puppeteer::ElementHandle < Puppeteer::JSHandle
2
+ class BoundingBox
3
+ def initialize(x:, y:, width:, height:)
4
+ @x = x
5
+ @y = y
6
+ @width = width
7
+ @height = height
8
+ end
9
+
10
+ attr_reader :x, :y, :width, :height
11
+ end
12
+ end
@@ -0,0 +1,19 @@
1
+ class Puppeteer::ElementHandle < Puppeteer::JSHandle
2
+ class BoxModel
3
+ QUAD_ATTRIBUTE_NAMES = %i(content padding border margin)
4
+ # @param result [Hash]
5
+ def initialize(result_model)
6
+ QUAD_ATTRIBUTE_NAMES.each do |attr_name|
7
+ quad = result_model[attr_name.to_s]
8
+ instance_variable_set(
9
+ :"@#{attr_name}",
10
+ quad.each_slice(2).map { |x, y| Point.new(x: x, y: y) },
11
+ )
12
+ end
13
+ @width = result_model['width']
14
+ @height = result_model['height']
15
+ end
16
+ attr_reader(*QUAD_ATTRIBUTE_NAMES)
17
+ attr_reader :width, :height
18
+ end
19
+ end
@@ -0,0 +1,26 @@
1
+ class Puppeteer::ElementHandle < Puppeteer::JSHandle
2
+ # A class to represent (x, y)-coordinates
3
+ # supporting + and / operators.
4
+ class Point
5
+ def initialize(x:, y:)
6
+ @x = x
7
+ @y = y
8
+ end
9
+
10
+ def +(other)
11
+ Point.new(
12
+ x: @x + other.x,
13
+ y: @y + other.y,
14
+ )
15
+ end
16
+
17
+ def /(num)
18
+ Point.new(
19
+ x: @x / num,
20
+ y: @y / num,
21
+ )
22
+ end
23
+
24
+ attr_reader :x, :y
25
+ end
26
+ end
@@ -1,4 +1,2 @@
1
- # ref: https://github.com/puppeteer/puppeteer/blob/master/lib/Errors.js
1
+ # ref: https://github.com/puppeteer/puppeteer/blob/master/src/Errors.ts
2
2
  class Puppeteer::TimeoutError < StandardError; end
3
-
4
- class Puppeteer::WebSocktTransportError < StandardError; end
@@ -39,6 +39,17 @@ module Puppeteer::EventCallbackable
39
39
  end
40
40
  end
41
41
 
42
+ def observe_first(event_name, &block)
43
+ listener_id = add_event_listener(event_name) do |*args, **kwargs|
44
+ if kwargs.empty?
45
+ block.call(*args)
46
+ else
47
+ block.call(*args, **kwargs)
48
+ end
49
+ remove_event_listener(listener_id)
50
+ end
51
+ end
52
+
42
53
  def on_event(event_name, &block)
43
54
  @event_callbackable_handlers ||= {}
44
55
  @event_callbackable_handlers[event_name] = block
@@ -1,4 +1,6 @@
1
1
  class Puppeteer::Frame
2
+ using Puppeteer::AsyncAwaitBehavior
3
+
2
4
  # @param {!FrameManager} frameManager
3
5
  # @param {!Puppeteer.CDPSession} client
4
6
  # @param {?Frame} parentFrame
@@ -33,10 +35,17 @@ class Puppeteer::Frame
33
35
 
34
36
  # @param timeout [number|nil]
35
37
  # @param wait_until [string|nil] 'load' | 'domcontentloaded' | 'networkidle0' | 'networkidle2'
36
- def wait_for_navigation(timeout: nil, wait_until: nil)
38
+ private def wait_for_navigation(timeout: nil, wait_until: nil)
37
39
  @frame_manager.wait_for_frame_navigation(self, timeout: timeout, wait_until: wait_until)
38
40
  end
39
41
 
42
+ # @param timeout [number|nil]
43
+ # @param wait_until [string|nil] 'load' | 'domcontentloaded' | 'networkidle0' | 'networkidle2'
44
+ # @return [Future]
45
+ async def async_wait_for_navigation(timeout: nil, wait_until: nil)
46
+ wait_for_navigation(timeout: timeout, wait_until: wait_until)
47
+ end
48
+
40
49
  def execution_context
41
50
  @main_world.execution_context
42
51
  end
@@ -143,6 +152,15 @@ class Puppeteer::Frame
143
152
  @main_world.add_style_tag(style_tag)
144
153
  end
145
154
 
155
+ # @param selector [String]
156
+ # @param delay [Number]
157
+ # @param button [String] "left"|"right"|"middle"
158
+ # @param click_count [Number]
159
+ # @return [Future]
160
+ async def async_click(selector, delay: nil, button: nil, click_count: nil)
161
+ click(selector, delay: delay, button: button, click_count: click_count)
162
+ end
163
+
146
164
  # @param selector [String]
147
165
  # @param delay [Number]
148
166
  # @param button [String] "left"|"right"|"middle"
@@ -240,6 +258,7 @@ class Puppeteer::Frame
240
258
  @main_world.wait_for_function(page_function, options, *args)
241
259
  end
242
260
 
261
+ # @return [String]
243
262
  def title
244
263
  @secondary_world.title
245
264
  end
@@ -4,13 +4,13 @@ require_relative './launcher/chrome'
4
4
  require_relative './launcher/chrome_arg_options'
5
5
  require_relative './launcher/launch_options'
6
6
 
7
- # https://github.com/puppeteer/puppeteer/blob/master/lib/Launcher.js
7
+ # https://github.com/puppeteer/puppeteer/blob/main/src/node/Launcher.ts
8
8
  module Puppeteer::Launcher
9
- # @param {string} projectRoot
10
- # @param {string} preferredRevision
11
- # @param {boolean} isPuppeteerCore
12
- # @param {string=} product
13
- # @return {!Puppeteer.ProductLauncher}
9
+ # @param project_root [String]
10
+ # @param prefereed_revision [String]
11
+ # @param is_puppeteer_core [String]
12
+ # @param product [String] 'chrome' or 'firefox' (not implemented yet)
13
+ # @return [Puppeteer::Launcher::Chrome]
14
14
  module_function def new(project_root:, preferred_revision:, is_puppeteer_core:, product:)
15
15
  if product == 'firefox'
16
16
  raise NotImplementedError.new('FirefoxLauncher is not implemented yet.')
@@ -1,6 +1,6 @@
1
1
  require 'tmpdir'
2
2
 
3
- # https://github.com/puppeteer/puppeteer/blob/master/lib/Launcher.js
3
+ # https://github.com/puppeteer/puppeteer/blob/main/src/node/Launcher.ts
4
4
  module Puppeteer::Launcher
5
5
  class Chrome < Base
6
6
  # @param {!(Launcher.LaunchOptions & Launcher.ChromeArgOptions & Launcher.BrowserOptions)=} options
@@ -139,6 +139,7 @@ module Puppeteer::Launcher
139
139
  end
140
140
  end
141
141
 
142
+ # @return [DefaultArgs]
142
143
  def default_args(options = nil)
143
144
  if options.nil?
144
145
  @default_args ||= DefaultArgs.new(@chrome_arg_options)
@@ -147,8 +148,7 @@ module Puppeteer::Launcher
147
148
  end
148
149
  end
149
150
 
150
- # @param {!(Launcher.BrowserOptions & {browserWSEndpoint?: string, browserURL?: string, transport?: !Puppeteer.ConnectionTransport})} options
151
- # @return {!Promise<!Browser>}
151
+ # @return [Puppeteer::Browser]
152
152
  def connect(options = {})
153
153
  @browser_options = BrowserOptions.new(options)
154
154
  browser_ws_endpoint = options[:browser_ws_endpoint]
@@ -187,11 +187,13 @@ module Puppeteer::Launcher
187
187
 
188
188
  # @return [Puppeteer::Connection]
189
189
  private def connect_with_browser_url(browser_url)
190
- raise NotImplementedError.new('Puppeteer#connect with browserUrl is not implemented yet.')
191
- # const connectionURL = await getWSEndpoint(browserURL);
192
- # const connectionTransport = await WebSocketTransport.create(
193
- # connectionURL
194
- # );
190
+ require 'net/http'
191
+ uri = URI(browser_url)
192
+ uri.path = '/json/version'
193
+ response_body = Net::HTTP.get(uri)
194
+ json = JSON.parse(response_body)
195
+ connection_url = json['webSocketDebuggerUrl']
196
+ connect_with_browser_ws_endpoint(connection_url)
195
197
  end
196
198
 
197
199
  # @return [Puppeteer::Connection]
@@ -61,18 +61,13 @@ class Puppeteer::Mouse
61
61
  # D, [2020-04-15T17:09:47.898422 #88683] DEBUG -- : SEND >> {"sessionId":"0B09EA5E18DEE403E525B3E7FCD7E225","method":"Input.dispatchMouseEvent","params":{"type":"mouseReleased","button":"left","x":0,"y":0,"modifiers":0,"clickCount":1},"id":24}
62
62
  # D, [2020-04-15T17:09:47.899711 #88683] DEBUG -- : SEND >> {"sessionId":"0B09EA5E18DEE403E525B3E7FCD7E225","method":"Input.dispatchMouseEvent","params":{"type":"mousePressed","button":"left","x":0,"y":0,"modifiers":0,"clickCount":1},"id":25}
63
63
  # D, [2020-04-15T17:09:47.900237 #88683] DEBUG -- : SEND >> {"sessionId":"0B09EA5E18DEE403E525B3E7FCD7E225","method":"Input.dispatchMouseEvent","params":{"type":"mouseMoved","button":"left","x":187,"y":283,"modifiers":0},"id":26}
64
- # So we execute move in advance.
64
+ # So we execute them sequential
65
65
  move(x, y)
66
+ down(button: button, click_count: click_count)
66
67
  if delay
67
- down(button: button, click_count: click_count)
68
68
  sleep(delay / 1000.0)
69
- up(button: button, click_count: click_count)
70
- else
71
- await_all(
72
- async_down(button: button, click_count: click_count),
73
- async_up(button: button, click_count: click_count),
74
- )
75
69
  end
70
+ up(button: button, click_count: click_count)
76
71
  end
77
72
 
78
73
  # @param x [number]
@@ -109,7 +109,7 @@ class Puppeteer::Page
109
109
  @client.on_event 'Page.fileChooserOpened' do |event|
110
110
  handle_file_chooser(event)
111
111
  end
112
- @target.on_close do
112
+ @target.is_closed_promise.then do
113
113
  emit_event 'Events.Page.Close'
114
114
  @closed = true
115
115
  end
@@ -124,6 +124,45 @@ class Puppeteer::Page
124
124
  )
125
125
  end
126
126
 
127
+ EVENT_MAPPINGS = {
128
+ close: 'Events.Page.Close',
129
+ # console: 'Events.Page.Console',
130
+ # dialog: 'Events.Page.Dialog',
131
+ domcontentloaded: 'Events.Page.DOMContentLoaded',
132
+ # error:
133
+ frameattached: 'Events.Page.FrameAttached',
134
+ framedetached: 'Events.Page.FrameDetached',
135
+ framenavigated: 'Events.Page.FrameNavigated',
136
+ load: 'Events.Page.Load',
137
+ # metrics: 'Events.Page.Metrics',
138
+ # pageerror: 'Events.Page.PageError',
139
+ popup: 'Events.Page.Popup',
140
+ request: 'Events.Page.Request',
141
+ requestfailed: 'Events.Page.RequestFailed',
142
+ requestfinished: 'Events.Page.RequestFinished',
143
+ response: 'Events.Page.Response',
144
+ # workercreated: 'Events.Page.WorkerCreated',
145
+ # workerdestroyed: 'Events.Page.WorkerDestroyed',
146
+ }
147
+
148
+ # @param event_name [Symbol]
149
+ def on(event_name, &block)
150
+ unless EVENT_MAPPINGS.has_key?(event_name.to_sym)
151
+ raise ArgumentError.new("Unknown event name: #{event_name}. Known events are #{EVENT_MAPPINGS.keys.join(", ")}")
152
+ end
153
+
154
+ add_event_listener(EVENT_MAPPINGS[event_name.to_sym], &block)
155
+ end
156
+
157
+ # @param event_name [Symbol]
158
+ def once(event_name, &block)
159
+ unless EVENT_MAPPINGS.has_key?(event_name.to_sym)
160
+ raise ArgumentError.new("Unknown event name: #{event_name}. Known events are #{EVENT_MAPPINGS.keys.join(", ")}")
161
+ end
162
+
163
+ observe_first(EVENT_MAPPINGS[event_name.to_sym], &block)
164
+ end
165
+
127
166
  def handle_file_chooser(event)
128
167
  return if @file_chooser_interceptors.empty?
129
168
 
@@ -651,7 +690,7 @@ class Puppeteer::Page
651
690
  # @param timeout [number|nil]
652
691
  # @param wait_until [string|nil] 'load' | 'domcontentloaded' | 'networkidle0' | 'networkidle2'
653
692
  private def wait_for_navigation(timeout: nil, wait_until: nil)
654
- main_frame.wait_for_navigation(timeout: timeout, wait_until: wait_until)
693
+ main_frame.send(:wait_for_navigation, timeout: timeout, wait_until: wait_until)
655
694
  end
656
695
 
657
696
  # @param timeout [number|nil]
@@ -806,9 +845,9 @@ class Puppeteer::Page
806
845
  @frame_manager.network_manager.cache_enabled = enabled
807
846
  end
808
847
 
809
- # @return {!Promise<string>}
848
+ # @return [String]
810
849
  def title
811
- @title
850
+ main_frame.title
812
851
  end
813
852
 
814
853
  # /**
@@ -62,6 +62,15 @@ class Puppeteer::RemoteObject
62
62
  client.send_message('DOM.getContentQuads', objectId: @object_id)
63
63
  end
64
64
 
65
+ # used in ElementHandle#_box_model
66
+ def box_model(client)
67
+ client.send_message('DOM.getBoxModel', objectId: @object_id)
68
+ rescue => err
69
+ debug_puts(err)
70
+ nil
71
+ end
72
+
73
+
65
74
  # helper#valueFromRemoteObject
66
75
  def value
67
76
  if @unserializable_value
@@ -33,47 +33,47 @@ class Puppeteer::Target
33
33
  # this._pagePromise = null;
34
34
  # /** @type {?Promise<!Worker>} */
35
35
  # this._workerPromise = null;
36
- @initialized_promise = resolvable_future
37
- # this._isClosedPromise = new Promise(fulfill => this._closedCallback = fulfill);
36
+ @initialize_callback_promise = resolvable_future
37
+ @initialized_promise = @initialize_callback_promise.then do |success|
38
+ handle_initialized(success)
39
+ end
40
+ @is_closed_promise = resolvable_future
38
41
 
39
42
  @is_initialized = @target_info.type != 'page' || !@target_info.url.empty?
40
43
 
41
44
  if @is_initialized
42
- handle_initialized(true)
45
+ @initialize_callback_promise.fulfill(true)
43
46
  end
44
47
  end
45
48
 
46
- attr_reader :target_id, :initialized_promise
49
+ attr_reader :target_id, :initialized_promise, :is_closed_promise
50
+
51
+ def closed_callback
52
+ @is_closed_promise.fulfill(true)
53
+ end
47
54
 
48
55
  class InitializeFailure < StandardError; end
49
56
 
50
- def handle_initialized(success)
57
+ def ignore_initialize_callback_promise
58
+ unless @initialize_callback_promise.fulfilled?
59
+ @initialize_callback_promise.fulfill(false)
60
+ end
61
+ end
62
+
63
+ private def handle_initialized(success)
51
64
  unless success
52
- @initialized_promise.reject(InitializeFailure.new('Failed to create target for page'))
65
+ raise InitializeFailure.new('Failed to create target for page')
53
66
  end
54
- @on_initialize_succeeded&.call
55
- @initialized_promise.fulfill(true)
56
67
  opener_page = opener&.page
57
68
  if opener_page.nil? || type != 'page'
58
- return
69
+ return true
59
70
  end
60
71
  # if (!openerPage.listenerCount(Events.Page.Popup))
61
72
  # return true;
62
73
  popup_page = page
63
74
  opener_page.emit_event('Events.Page.Popup', popup_page)
64
- end
65
-
66
- def on_initialize_succeeded(&block)
67
- @on_initialize_succeeded = block
68
- end
69
-
70
- def handle_closed
71
- @closed = true
72
- @on_close&.call
73
- end
74
75
 
75
- def on_close(&block)
76
- @on_close = block
76
+ true
77
77
  end
78
78
 
79
79
  def initialized?
@@ -85,7 +85,7 @@ class Puppeteer::Target
85
85
  end
86
86
 
87
87
  def page
88
- if ['page', 'background_page'].include?(@target_info.type) && @page.nil?
88
+ if ['page', 'background_page', 'webview'].include?(@target_info.type) && @page.nil?
89
89
  client = @session_factory.call
90
90
  @page = Puppeteer::Page.create(client, self, @ignore_https_errors, @default_viewport, @screenshot_task_queue)
91
91
  end
@@ -135,16 +135,16 @@ class Puppeteer::Target
135
135
  def opener
136
136
  opener_id = @target_info.opener_id
137
137
  return nil if opener_id.nil?
138
- browser.targets[opener_id]
138
+ browser.send(:find_target_by_id, opener_id)
139
139
  end
140
140
 
141
141
  # @param {!Protocol.Target.TargetInfo} targetInfo
142
142
  def handle_target_info_changed(target_info)
143
143
  @target_info = target_info
144
144
 
145
- if !@is_initialized && (@target_info.type != 'page' || !target_info.url.empty?)
145
+ if !@is_initialized && (@target_info.type != 'page' || !@target_info.url.empty?)
146
146
  @is_initialized = true
147
- handle_initialized(true)
147
+ @initialize_callback_promise.fulfill(true)
148
148
  end
149
149
  end
150
150
  end
@@ -1,3 +1,3 @@
1
1
  class Puppeteer
2
- VERSION = '0.0.8'
2
+ VERSION = '0.0.13'
3
3
  end
@@ -33,4 +33,22 @@ class Puppeteer::Viewport
33
33
  def landscape?
34
34
  @is_landscape
35
35
  end
36
+
37
+ def merge(
38
+ width: nil,
39
+ height: nil,
40
+ device_scale_factor: nil,
41
+ is_mobile: nil,
42
+ has_touch: nil,
43
+ is_landscape: nil)
44
+
45
+ Puppeteer::Viewport.new(
46
+ width: width || @width,
47
+ height: height || @height,
48
+ device_scale_factor: device_scale_factor || @device_scale_factor,
49
+ is_mobile: is_mobile.nil? ? @is_mobile : is_mobile,
50
+ has_touch: has_touch.nil? ? @has_touch : has_touch,
51
+ is_landscape: is_landscape.nil? ? @is_landscape : is_landscape,
52
+ )
53
+ end
36
54
  end
@@ -43,6 +43,8 @@ class Puppeteer::WebSocket
43
43
  end
44
44
  end
45
45
 
46
+ class TransportError < StandardError; end
47
+
46
48
  private def setup
47
49
  @ready_state = STATE_CONNECTING
48
50
  @driver.on(:open) do
@@ -55,7 +57,7 @@ class Puppeteer::WebSocket
55
57
  end
56
58
  @driver.on(:error) do |event|
57
59
  if !handle_on_error(error_message: event.message)
58
- raise Puppeteer::WebSocktTransportError.new(event.message)
60
+ raise TransportError.new(event.message)
59
61
  end
60
62
  end
61
63
  @driver.on(:message) do |event|