puppeteer-ruby 0.0.19 → 0.0.20
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +23 -0
- data/lib/puppeteer.rb +1 -0
- data/lib/puppeteer/cdp_session.rb +10 -0
- data/lib/puppeteer/connection.rb +2 -2
- data/lib/puppeteer/dialog.rb +34 -0
- data/lib/puppeteer/frame.rb +1 -3
- data/lib/puppeteer/page.rb +15 -16
- data/lib/puppeteer/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a0821b740ece89c3194c7b9fc7778b18528d38becf524e7a1c50ceffd37ab3c
|
4
|
+
data.tar.gz: 86a3e592c61b4f0095ca3fad2ab0ecb1b031c4dbe4f9607caa52b2b82cf225bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e73f8a9f380aadb2e4dd4164be571ee22b688b48b1999720d0ecefb39b62f79a071a709134b00f701b04a1d179bba3efe742d3307fca9bc2d2f56cb305b7bb53
|
7
|
+
data.tar.gz: f03efa136e60899f4eb0e0bd671e60c86b52efb13a59d62754b88961188d1495e7e85e012bb93a11d118e2f5a93375de07c453ef5a5eff7375325c2ec9b2b5ae
|
data/README.md
CHANGED
@@ -47,6 +47,29 @@ Puppeteer.launch(headless: false, slow_mo: 50, args: ['--guest', '--window-size=
|
|
47
47
|
end
|
48
48
|
```
|
49
49
|
|
50
|
+
### Evaluate JavaScript
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
Puppeteer.launch do |browser|
|
54
|
+
page = browser.pages.last || browser.new_page
|
55
|
+
page.goto 'https://github.com/YusukeIwaki'
|
56
|
+
|
57
|
+
# Get the "viewport" of the page, as reported by the page.
|
58
|
+
dimensions = page.evaluate(<<~JAVASCRIPT)
|
59
|
+
() => {
|
60
|
+
return {
|
61
|
+
width: document.documentElement.clientWidth,
|
62
|
+
height: document.documentElement.clientHeight,
|
63
|
+
deviceScaleFactor: window.devicePixelRatio
|
64
|
+
};
|
65
|
+
}
|
66
|
+
JAVASCRIPT
|
67
|
+
|
68
|
+
puts "dimensions: #{dimensions}"
|
69
|
+
# => dimensions: {"width"=>800, "height"=>600, "deviceScaleFactor"=>1}
|
70
|
+
end
|
71
|
+
```
|
72
|
+
|
50
73
|
More usage examples can be found [here](https://github.com/YusukeIwaki/puppeteer-ruby-example)
|
51
74
|
|
52
75
|
## :bulb: Collaboration with Selenium or Capybara
|
data/lib/puppeteer.rb
CHANGED
@@ -24,6 +24,7 @@ require 'puppeteer/cdp_session'
|
|
24
24
|
require 'puppeteer/connection'
|
25
25
|
require 'puppeteer/console_message'
|
26
26
|
require 'puppeteer/devices'
|
27
|
+
require 'puppeteer/dialog'
|
27
28
|
require 'puppeteer/dom_world'
|
28
29
|
require 'puppeteer/emulation_manager'
|
29
30
|
require 'puppeteer/execution_context'
|
@@ -81,4 +81,14 @@ class Puppeteer::CDPSession
|
|
81
81
|
@connection = nil
|
82
82
|
emit_event 'Events.CDPSession.Disconnected'
|
83
83
|
end
|
84
|
+
|
85
|
+
# @param event_name [String]
|
86
|
+
def on(event_name, &block)
|
87
|
+
add_event_listener(event_name, &block)
|
88
|
+
end
|
89
|
+
|
90
|
+
# @param event_name [String]
|
91
|
+
def once(event_name, &block)
|
92
|
+
observe_first(event_name, &block)
|
93
|
+
end
|
84
94
|
end
|
data/lib/puppeteer/connection.rb
CHANGED
@@ -204,8 +204,8 @@ class Puppeteer::Connection
|
|
204
204
|
callback.reject(
|
205
205
|
ProtocolError.new(
|
206
206
|
method: callback.method,
|
207
|
-
error_message:
|
208
|
-
error_data:
|
207
|
+
error_message: message['error']['message'],
|
208
|
+
error_data: message['error']['data']))
|
209
209
|
else
|
210
210
|
callback.resolve(message['result'])
|
211
211
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class Puppeteer::Dialog
|
2
|
+
def initialize(client, type:, message:, default_value:)
|
3
|
+
@client = client
|
4
|
+
@type = type
|
5
|
+
@message = message
|
6
|
+
@default_value = default_value || ''
|
7
|
+
end
|
8
|
+
|
9
|
+
attr_reader :type, :message, :default_value
|
10
|
+
|
11
|
+
# @param prompt_text - optional text that will be entered in the dialog
|
12
|
+
# prompt. Has no effect if the dialog's type is not `prompt`.
|
13
|
+
#
|
14
|
+
# @returns A promise that resolves when the dialog has been accepted.
|
15
|
+
def accept(prompt_text = nil)
|
16
|
+
if @handled
|
17
|
+
raise 'Cannot accept dialog which is already handled!'
|
18
|
+
end
|
19
|
+
@handled = true
|
20
|
+
@client.send_message('Page.handleJavaScriptDialog', {
|
21
|
+
accept: true,
|
22
|
+
promptText: prompt_text,
|
23
|
+
}.compact)
|
24
|
+
end
|
25
|
+
|
26
|
+
# @returns A promise which will resolve once the dialog has been dismissed
|
27
|
+
def dismiss
|
28
|
+
if @handled
|
29
|
+
raise 'Cannot accept dialog which is already handled!'
|
30
|
+
end
|
31
|
+
@handled = true
|
32
|
+
@client.send_message('Page.handleJavaScriptDialog', accept: false)
|
33
|
+
end
|
34
|
+
end
|
data/lib/puppeteer/frame.rb
CHANGED
@@ -266,9 +266,7 @@ class Puppeteer::Frame
|
|
266
266
|
# @param frame_payload [Hash]
|
267
267
|
def navigated(frame_payload)
|
268
268
|
@name = frame_payload['name']
|
269
|
-
|
270
|
-
@navigation_url = frame_payload['url']
|
271
|
-
@url = frame_payload['url']
|
269
|
+
@url = "#{frame_payload['url']}#{frame_payload['urlFragment']}"
|
272
270
|
|
273
271
|
# Ensure loaderId updated.
|
274
272
|
# The order of [Page.lifecycleEvent name="init"] and [Page.frameNavigated] is random... for some reason...
|
data/lib/puppeteer/page.rb
CHANGED
@@ -101,7 +101,9 @@ class Puppeteer::Page
|
|
101
101
|
end
|
102
102
|
# client.on('Runtime.consoleAPICalled', event => this._onConsoleAPI(event));
|
103
103
|
# client.on('Runtime.bindingCalled', event => this._onBindingCalled(event));
|
104
|
-
|
104
|
+
@client.on_event 'Page.javascriptDialogOpening' do |event|
|
105
|
+
handle_dialog_opening(event)
|
106
|
+
end
|
105
107
|
# client.on('Runtime.exceptionThrown', exception => this._handleException(exception.exceptionDetails));
|
106
108
|
# client.on('Inspector.targetCrashed', event => this._onTargetCrashed());
|
107
109
|
# client.on('Performance.metrics', event => this._emitMetrics(event));
|
@@ -129,7 +131,7 @@ class Puppeteer::Page
|
|
129
131
|
EVENT_MAPPINGS = {
|
130
132
|
close: 'Events.Page.Close',
|
131
133
|
# console: 'Events.Page.Console',
|
132
|
-
|
134
|
+
dialog: 'Events.Page.Dialog',
|
133
135
|
domcontentloaded: 'Events.Page.DOMContentLoaded',
|
134
136
|
# error:
|
135
137
|
frameattached: 'Events.Page.FrameAttached',
|
@@ -632,20 +634,17 @@ class Puppeteer::Page
|
|
632
634
|
# this.emit(Events.Page.Console, message);
|
633
635
|
# }
|
634
636
|
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
# const dialog = new Dialog(this._client, dialogType, event.message, event.defaultPrompt);
|
647
|
-
# this.emit(Events.Page.Dialog, dialog);
|
648
|
-
# }
|
637
|
+
private def handle_dialog_opening(event)
|
638
|
+
dialog_type = event['type']
|
639
|
+
unless %w(alert confirm prompt beforeunload).include?(dialog_type)
|
640
|
+
raise ArgumentError.new("Unknown javascript dialog type: #{dialog_type}")
|
641
|
+
end
|
642
|
+
dialog = Puppeteer::Dialog.new(@client,
|
643
|
+
type: dialog_type,
|
644
|
+
message: event['message'],
|
645
|
+
default_value: event['defaultPrompt'])
|
646
|
+
emit_event('Events.Page.Dialog', dialog)
|
647
|
+
end
|
649
648
|
|
650
649
|
# @return [String]
|
651
650
|
def url
|
data/lib/puppeteer/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppeteer-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.20
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- YusukeIwaki
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-09-
|
11
|
+
date: 2020-09-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -213,6 +213,7 @@ files:
|
|
213
213
|
- lib/puppeteer/define_async_method.rb
|
214
214
|
- lib/puppeteer/device.rb
|
215
215
|
- lib/puppeteer/devices.rb
|
216
|
+
- lib/puppeteer/dialog.rb
|
216
217
|
- lib/puppeteer/dom_world.rb
|
217
218
|
- lib/puppeteer/element_handle.rb
|
218
219
|
- lib/puppeteer/element_handle/bounding_box.rb
|