puppeteer-ruby 0.0.22 → 0.28.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 627b2272803511db582250101edac0b5f1f0191abdf86255c6f16d0f088cc82e
4
- data.tar.gz: 70458a316f8ecce1b784bd84595c3f0fa248c77e671e4458384c494a1471c196
3
+ metadata.gz: 61aae6f779d8c0b4566cb9fd8966ba7d5941bda2b0c43754d61616dab29ca555
4
+ data.tar.gz: f5394e8ac944d188795e8a4eff87a60b2b226b659d8183ac1003d2d9f1c9c27b
5
5
  SHA512:
6
- metadata.gz: 2baf0cb4769fc7100495b3dc590293085e3219c661bd164cdb28f0aad1975f18cba17890029156a08873f879ef370c196c3d995bfd040d073d42d0b49acbeef3
7
- data.tar.gz: 67a23e46e7d439b76f438c59d062fe5daea0d216469e79ea1b4af2b8d60c4f9070455de22e51b9523fde2a67692919420bce2b05becf948120b71d426c4c560f
6
+ metadata.gz: e51fc1ffce61bf542d4057803ae3f2ac811285b54a221d4bc2ce6cfccc18e9de2828ba98de82d246efa7b1fdf58c44cce8e9205ac1343889f173462b8dd8f546
7
+ data.tar.gz: 4b5706d9f926372415acafa3c0d9339d653dd35542642a48593d400fd929ec03f1f32cd5624d99b0c1e870471f591c385b18b02b742d8b83d501fef599f64ffc
@@ -1,30 +1,41 @@
1
1
  version: 2.1
2
- orbs:
3
- ruby: circleci/ruby@0.1.2
2
+
3
+ rspec_chrome_job: &rspec_chrome_job
4
+ steps:
5
+ - checkout
6
+ - run:
7
+ command: gem install bundler:2.2.3 && bundle install
8
+ - run:
9
+ name: rspec
10
+ command: |
11
+ DEBUG=1 bundle exec rspec --profile 10 \
12
+ --format RspecJunitFormatter \
13
+ --out test_results/rspec.xml \
14
+ --format documentation
4
15
 
5
16
  jobs:
6
- rspec:
17
+ rspec_chrome_ruby2_6:
7
18
  docker:
8
19
  - image: circleci/ruby:2.6.6-buster-node-browsers
9
- executor: ruby/default
10
- steps:
11
- - checkout
12
- - ruby/bundle-install
13
- - run:
14
- name: rspec
15
- command: |
16
- DEBUG=1 bundle exec rspec --profile 10 \
17
- --format RspecJunitFormatter \
18
- --out test_results/rspec.xml \
19
- --format documentation
20
+ <<: *rspec_chrome_job
21
+
22
+ rspec_chrome_ruby2_7:
23
+ docker:
24
+ - image: circleci/ruby:2.7.2-buster-node-browsers
25
+ <<: *rspec_chrome_job
26
+
27
+ rspec_chrome_ruby3_0:
28
+ docker:
29
+ - image: circleci/ruby:3.0.0-rc1-buster-node-browsers
30
+ <<: *rspec_chrome_job
20
31
 
21
32
  rspec_firefox:
22
33
  docker:
23
- - image: circleci/ruby:2.6.6-buster-node-browsers
24
- executor: ruby/default
34
+ - image: circleci/ruby:2.7.2-buster-node-browsers
25
35
  steps:
26
36
  - checkout
27
- - ruby/bundle-install
37
+ - run:
38
+ command: gem install bundler:2.2.3 && bundle install
28
39
  - run:
29
40
  name: install firefox-nightly
30
41
  command: |
@@ -43,13 +54,10 @@ jobs:
43
54
  deploy:
44
55
  docker:
45
56
  - image: circleci/ruby:2.6.3-stretch-node
46
- executor: ruby/default
47
57
  steps:
48
58
  - checkout
49
59
  - run:
50
- name: Which bundler?
51
- command: bundle -v
52
- - ruby/bundle-install
60
+ command: gem install bundler:2.2.3 && bundle install
53
61
  - run:
54
62
  name: rake build
55
63
  command: rake build
@@ -70,7 +78,9 @@ jobs:
70
78
  workflows:
71
79
  ci:
72
80
  jobs:
73
- - rspec
81
+ - rspec_chrome_ruby2_6
82
+ - rspec_chrome_ruby2_7
83
+ - rspec_chrome_ruby3_0
74
84
  - rspec_firefox
75
85
  rubygems-deploy:
76
86
  jobs:
@@ -0,0 +1,17 @@
1
+ ---
2
+ name: Bug report
3
+ about: Create a report to help us improve
4
+ title: ''
5
+ labels: ''
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ ### Step To Reproduce / Observed behavior
11
+
12
+
13
+ ### Expected behavior
14
+
15
+ ### Environment
16
+
17
+ Paste the output of `ruby --version`
@@ -16,12 +16,12 @@ jobs:
16
16
  - name: Set up Ruby
17
17
  uses: ruby/setup-ruby@v1
18
18
  with:
19
- ruby-version: 2.6
19
+ ruby-version: 2.7
20
20
 
21
21
  - name: Install dependencies
22
22
  run: |
23
23
  gem uninstall bundler
24
- gem install bundler -v 1.17
24
+ gem install bundler -v 2.2.3
25
25
  bundle install
26
26
 
27
27
  - name: Deploy Configuration
@@ -12,4 +12,4 @@ jobs:
12
12
  with:
13
13
  github_token: ${{ secrets.github_token }}
14
14
  reporter: github-pr-review
15
- rubocop_version: 0.90.0
15
+ rubocop_version: 1.8.0
@@ -116,6 +116,43 @@ Style/DefWithParentheses:
116
116
  Style/MethodDefParentheses:
117
117
  Enabled: true
118
118
 
119
+ Style/MethodCallWithArgsParentheses:
120
+ Enabled: true
121
+ IgnoredMethods:
122
+ # Gemfile, gemspec
123
+ - source
124
+ - add_dependency
125
+ - add_development_dependency
126
+
127
+ # include/require
128
+ - require
129
+ - require_relative
130
+ - include
131
+
132
+ # fundamental methods
133
+ - raise
134
+ - sleep
135
+
136
+ # RSpec
137
+ - describe
138
+ - it
139
+ - to
140
+ - not_to
141
+ - be
142
+ - eq
143
+
144
+ # async/await
145
+ - define_async_method
146
+ - await
147
+ - future
148
+
149
+ # utils
150
+ - debug_print
151
+ - debug_puts
152
+
153
+ Style/MethodCallWithoutArgsParentheses:
154
+ Enabled: true
155
+
119
156
  Style/RedundantFreeze:
120
157
  Enabled: true
121
158
 
@@ -0,0 +1,81 @@
1
+ ### master [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.28.1...master)]
2
+
3
+ * xxx
4
+
5
+ ### 0.28.1 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.0.27...0.28.1)]
6
+
7
+ New features:
8
+
9
+ * Add `Page#emulate_idle_state`
10
+ * Change versioning rule.
11
+
12
+ ### 0.0.27 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.0.26...0.0.27)]
13
+
14
+ New features:
15
+
16
+ * Now puppeteer-ruby is Ruby 3.0 compatible!
17
+
18
+ ### 0.0.26 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.0.25...0.0.26)]
19
+
20
+ Bugfix:
21
+
22
+ * Fix `Page#screenshot` working correctly with `quality` parameter.
23
+
24
+ ### 0.0.25 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.0.23...0.0.25)]
25
+
26
+ New feature:
27
+
28
+ * **Cookie** feature: `Page#set_cookie`, `Page#cookies`
29
+
30
+ ### 0.0.23 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.0.22...0.0.23)]
31
+
32
+ New feature:
33
+
34
+ * **GeoLocation** feature
35
+ * grant/clear permission
36
+
37
+ Bugfix/Improvement:
38
+
39
+ * Refactoring for events ([#31](https://github.com/YusukeIwaki/puppeteer-ruby/pull/31))
40
+ * Improve SEND/RECV handling in CDPSession ([#34](https://github.com/YusukeIwaki/puppeteer-ruby/pull/34))
41
+
42
+ ### 0.0.22 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.0.21...0.0.22)]
43
+
44
+ Bugfix
45
+
46
+ * Make `Puppeteer#default_args` to work
47
+ * Respect Firefox launch options
48
+ * Respect `default_viewport: nil`
49
+
50
+ ### 0.0.21 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.0.20...0.0.21)]
51
+
52
+ Bugfix/Improvement:
53
+
54
+ * Update DeviceDescriptors (list of emulatable devices)
55
+ * Fix bug on inputing "(" ([#25](https://github.com/YusukeIwaki/puppeteer-ruby/pull/25))
56
+
57
+ ### 0.0.20 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.0.19...0.0.20)]
58
+
59
+ New feature
60
+
61
+ * Dialog-handling feature
62
+
63
+ ### 0.0.19 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.0.18...0.0.19)]
64
+
65
+ New feature
66
+
67
+ * **Firefox support**
68
+
69
+ Bugfix/Improvement
70
+
71
+ * Allow `Page#keyboard` with block ([#18](https://github.com/YusukeIwaki/puppeteer-ruby/pull/18))
72
+
73
+ ### 0.0.18 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.0.17...0.0.18)]
74
+
75
+ New feature
76
+
77
+ * **Firefox support**
78
+
79
+ Bugfix/Improvement
80
+
81
+ * Allow `Page#keyboard` with block ([#18](https://github.com/YusukeIwaki/puppeteer-ruby/pull/18))
data/Dockerfile CHANGED
@@ -1,4 +1,4 @@
1
- FROM circleci/ruby:2.6.6-buster-node-browsers
1
+ FROM circleci/ruby:3.0.0-rc1-buster-node-browsers
2
2
 
3
3
  USER root
4
4
 
data/README.md CHANGED
@@ -72,6 +72,21 @@ end
72
72
 
73
73
  More usage examples can be found [here](https://github.com/YusukeIwaki/puppeteer-ruby-example)
74
74
 
75
+ ## :whale: Running in Docker
76
+
77
+ Following packages are required.
78
+
79
+ * Google Chrome or Chromium
80
+ * In Debian-based images, `google-chrome-stable`
81
+ * In Alpine-based images, `chromium`
82
+
83
+ Also, CJK font will be required for Chinese, Japanese, Korean sites.
84
+
85
+ ### References
86
+
87
+ * Puppeteer official README: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#running-puppeteer-in-docker
88
+ * puppeteer-ruby example: https://github.com/YusukeIwaki/puppeteer-ruby-example/tree/master/docker_chromium
89
+
75
90
  ## :bulb: Collaboration with Selenium or Capybara
76
91
 
77
92
  It is really remarkable that we can use puppeteer functions in existing Selenium or Capybara codes, with a few configuration in advance.
@@ -6,7 +6,9 @@ require 'puppeteer/env'
6
6
 
7
7
  # Custom data types.
8
8
  require 'puppeteer/device'
9
+ require 'puppeteer/events'
9
10
  require 'puppeteer/errors'
11
+ require 'puppeteer/geolocation'
10
12
  require 'puppeteer/viewport'
11
13
 
12
14
  # Modules
@@ -27,6 +29,7 @@ require 'puppeteer/devices'
27
29
  require 'puppeteer/dialog'
28
30
  require 'puppeteer/dom_world'
29
31
  require 'puppeteer/emulation_manager'
32
+ require 'puppeteer/exception_details'
30
33
  require 'puppeteer/execution_context'
31
34
  require 'puppeteer/file_chooser'
32
35
  require 'puppeteer/frame'
@@ -36,7 +36,6 @@ class Puppeteer::Browser
36
36
  @ignore_https_errors = ignore_https_errors
37
37
  @default_viewport = default_viewport
38
38
  @process = process
39
- # @screenshot_task_queue = TaskQueue.new
40
39
  @connection = connection
41
40
  @close_callback = close_callback
42
41
 
@@ -46,37 +45,30 @@ class Puppeteer::Browser
46
45
  @contexts[context_id] = Puppeteer::BrowserContext.new(@connection, self, context_id)
47
46
  end
48
47
  @targets = {}
49
- @connection.on_event 'Events.Connection.Disconnected' do
50
- emit_event 'Events.Browser.Disconnected'
48
+ @connection.on_event(ConnectionEmittedEvents::Disconnected) do
49
+ emit_event(BrowserEmittedEvents::Disconnected)
51
50
  end
52
- @connection.on_event 'Target.targetCreated', &method(:handle_target_created)
53
- @connection.on_event 'Target.targetDestroyed', &method(:handle_target_destroyed)
54
- @connection.on_event 'Target.targetInfoChanged', &method(:handle_target_info_changed)
51
+ @connection.on_event('Target.targetCreated', &method(:handle_target_created))
52
+ @connection.on_event('Target.targetDestroyed', &method(:handle_target_destroyed))
53
+ @connection.on_event('Target.targetInfoChanged', &method(:handle_target_info_changed))
55
54
  end
56
55
 
57
- EVENT_MAPPINGS = {
58
- disconnected: 'Events.Browser.Disconnected',
59
- targetcreated: 'Events.Browser.TargetCreated',
60
- targetchanged: 'Events.Browser.TargetChanged',
61
- targetdestroyed: 'Events.Browser.TargetDestroyed',
62
- }
63
-
64
56
  # @param event_name [Symbol] either of :disconnected, :targetcreated, :targetchanged, :targetdestroyed
65
57
  def on(event_name, &block)
66
- unless EVENT_MAPPINGS.has_key?(event_name.to_sym)
67
- raise ArgumentError.new("Unknown event name: #{event_name}. Known events are #{EVENT_MAPPINGS.keys.join(", ")}")
58
+ unless BrowserEmittedEvents.values.include?(event_name.to_s)
59
+ raise ArgumentError.new("Unknown event name: #{event_name}. Known events are #{BrowserEmittedEvents.values.to_a.join(", ")}")
68
60
  end
69
61
 
70
- add_event_listener(EVENT_MAPPINGS[event_name.to_sym], &block)
62
+ super(event_name.to_s, &block)
71
63
  end
72
64
 
73
65
  # @param event_name [Symbol]
74
66
  def once(event_name, &block)
75
- unless EVENT_MAPPINGS.has_key?(event_name.to_sym)
76
- raise ArgumentError.new("Unknown event name: #{event_name}. Known events are #{EVENT_MAPPINGS.keys.join(", ")}")
67
+ unless BrowserEmittedEvents.values.include?(event_name.to_s)
68
+ raise ArgumentError.new("Unknown event name: #{event_name}. Known events are #{BrowserEmittedEvents.values.to_a.join(", ")}")
77
69
  end
78
70
 
79
- observe_first(EVENT_MAPPINGS[event_name.to_sym], &block)
71
+ super(event_name.to_s, &block)
80
72
  end
81
73
 
82
74
  # @return [Puppeteer::BrowserRunner::BrowserProcess]
@@ -132,13 +124,12 @@ class Puppeteer::Browser
132
124
  session_factory: -> { @connection.create_session(target_info) },
133
125
  ignore_https_errors: @ignore_https_errors,
134
126
  default_viewport: @default_viewport,
135
- screenshot_task_queue: @screenshot_task_queue,
136
127
  )
137
128
  # assert(!this._targets.has(event.targetInfo.targetId), 'Target should not exist before targetCreated');
138
129
  @targets[target_info.target_id] = target
139
130
  if await target.initialized_promise
140
- emit_event 'Events.Browser.TargetCreated', target
141
- context.emit_event 'Events.BrowserContext.TargetCreated', target
131
+ emit_event(BrowserEmittedEvents::TargetCreated, target)
132
+ context.emit_event(BrowserContextEmittedEvents::TargetCreated, target)
142
133
  end
143
134
  end
144
135
 
@@ -150,8 +141,8 @@ class Puppeteer::Browser
150
141
  @targets.delete(target_id)
151
142
  target.closed_callback
152
143
  if await target.initialized_promise
153
- emit_event 'Events.Browser.TargetDestroyed', target
154
- target.browser_context.emit_event 'Events.BrowserContext.TargetDestroyed', target
144
+ emit_event(BrowserEmittedEvents::TargetDestroyed, target)
145
+ target.browser_context.emit_event(BrowserContextEmittedEvents::TargetDestroyed, target)
155
146
  end
156
147
  end
157
148
 
@@ -169,8 +160,8 @@ class Puppeteer::Browser
169
160
  was_initialized = target.initialized?
170
161
  target.handle_target_info_changed(target_info)
171
162
  if was_initialized && previous_url != target.url
172
- emit_event 'Events.Browser.TargetChanged', target
173
- target.browser_context.emit_event 'Events.BrowserContext.TargetChanged', target
163
+ emit_event(BrowserEmittedEvents::TargetChanged, target)
164
+ target.browser_context.emit_event(BrowserContextEmittedEvents::TargetChanged, target)
174
165
  end
175
166
  end
176
167
 
@@ -222,12 +213,12 @@ class Puppeteer::Browser
222
213
 
223
214
  event_listening_ids = []
224
215
  target_promise = resolvable_future
225
- event_listening_ids << add_event_listener('Events.Browser.TargetCreated') do |target|
216
+ event_listening_ids << add_event_listener(BrowserEmittedEvents::TargetCreated) do |target|
226
217
  if predicate.call(target)
227
218
  target_promise.fulfill(target)
228
219
  end
229
220
  end
230
- event_listening_ids << add_event_listener('Events.Browser.TargetChanged') do |target|
221
+ event_listening_ids << add_event_listener(BrowserEmittedEvents::TargetChanged) do |target|
231
222
  if predicate.call(target)
232
223
  target_promise.fulfill(target)
233
224
  end
@@ -11,29 +11,22 @@ class Puppeteer::BrowserContext
11
11
  @id = context_id
12
12
  end
13
13
 
14
- EVENT_MAPPINGS = {
15
- disconnected: 'Events.BrowserContext.Disconnected',
16
- targetcreated: 'Events.BrowserContext.TargetCreated',
17
- targetchanged: 'Events.BrowserContext.TargetChanged',
18
- targetdestroyed: 'Events.BrowserContext.TargetDestroyed',
19
- }
20
-
21
14
  # @param event_name [Symbol] either of :disconnected, :targetcreated, :targetchanged, :targetdestroyed
22
15
  def on(event_name, &block)
23
- unless EVENT_MAPPINGS.has_key?(event_name.to_sym)
24
- raise ArgumentError.new("Unknown event name: #{event_name}. Known events are #{EVENT_MAPPINGS.keys.join(", ")}")
16
+ unless BrowserContextEmittedEvents.values.include?(event_name.to_s)
17
+ raise ArgumentError.new("Unknown event name: #{event_name}. Known events are #{BrowserContextEmittedEvents.values.to_a.join(", ")}")
25
18
  end
26
19
 
27
- add_event_listener(EVENT_MAPPINGS[event_name.to_sym], &block)
20
+ super(event_name.to_s, &block)
28
21
  end
29
22
 
30
23
  # @param event_name [Symbol]
31
24
  def once(event_name, &block)
32
- unless EVENT_MAPPINGS.has_key?(event_name.to_sym)
33
- raise ArgumentError.new("Unknown event name: #{event_name}. Known events are #{EVENT_MAPPINGS.keys.join(", ")}")
25
+ unless BrowserContextEmittedEvents.values.include?(event_name.to_s)
26
+ raise ArgumentError.new("Unknown event name: #{event_name}. Known events are #{BrowserContextEmittedEvents.values.to_a.join(", ")}")
34
27
  end
35
28
 
36
- observe_first(EVENT_MAPPINGS[event_name.to_sym], &block)
29
+ super(event_name.to_s, &block)
37
30
  end
38
31
 
39
32
  # @return {!Array<!Target>} target
@@ -64,42 +57,48 @@ class Puppeteer::BrowserContext
64
57
  !!@id
65
58
  end
66
59
 
67
- # /**
68
- # * @param {string} origin
69
- # * @param {!Array<string>} permissions
70
- # */
71
- # async overridePermissions(origin, permissions) {
72
- # const webPermissionToProtocol = new Map([
73
- # ['geolocation', 'geolocation'],
74
- # ['midi', 'midi'],
75
- # ['notifications', 'notifications'],
76
- # ['push', 'push'],
77
- # ['camera', 'videoCapture'],
78
- # ['microphone', 'audioCapture'],
79
- # ['background-sync', 'backgroundSync'],
80
- # ['ambient-light-sensor', 'sensors'],
81
- # ['accelerometer', 'sensors'],
82
- # ['gyroscope', 'sensors'],
83
- # ['magnetometer', 'sensors'],
84
- # ['accessibility-events', 'accessibilityEvents'],
85
- # ['clipboard-read', 'clipboardRead'],
86
- # ['clipboard-write', 'clipboardWrite'],
87
- # ['payment-handler', 'paymentHandler'],
88
- # // chrome-specific permissions we have.
89
- # ['midi-sysex', 'midiSysex'],
90
- # ]);
91
- # permissions = permissions.map(permission => {
92
- # const protocolPermission = webPermissionToProtocol.get(permission);
93
- # if (!protocolPermission)
94
- # throw new Error('Unknown permission: ' + permission);
95
- # return protocolPermission;
96
- # });
97
- # await this._connection.send('Browser.grantPermissions', {origin, browserContextId: this._id || undefined, permissions});
98
- # }
99
-
100
- # async clearPermissionOverrides() {
101
- # await this._connection.send('Browser.resetPermissions', {browserContextId: this._id || undefined});
102
- # }
60
+ WEB_PERMISSION_TO_PROTOCOL = {
61
+ 'geolocation' => 'geolocation',
62
+ 'midi' => 'midi',
63
+ 'notifications' => 'notifications',
64
+ # TODO: push isn't a valid type?
65
+ # 'push' => 'push',
66
+ 'camera' => 'videoCapture',
67
+ 'microphone' => 'audioCapture',
68
+ 'background-sync' => 'backgroundSync',
69
+ 'ambient-light-sensor' => 'sensors',
70
+ 'accelerometer' => 'sensors',
71
+ 'gyroscope' => 'sensors',
72
+ 'magnetometer' => 'sensors',
73
+ 'accessibility-events' => 'accessibilityEvents',
74
+ 'clipboard-read' => 'clipboardReadWrite',
75
+ 'clipboard-write' => 'clipboardReadWrite',
76
+ 'payment-handler' => 'paymentHandler',
77
+ 'idle-detection' => 'idleDetection',
78
+ # chrome-specific permissions we have.
79
+ 'midi-sysex' => 'midiSysex',
80
+ }.freeze
81
+
82
+ # @param origin [String]
83
+ # @param permissions [Array<String>]
84
+ def override_permissions(origin, permissions)
85
+ protocol_permissions = permissions.map do |permission|
86
+ WEB_PERMISSION_TO_PROTOCOL[permission] or raise ArgumentError.new("Unknown permission: #{permission}")
87
+ end
88
+ @connection.send_message('Browser.grantPermissions', {
89
+ origin: origin,
90
+ browserContextId: @id,
91
+ permissions: protocol_permissions,
92
+ }.compact)
93
+ end
94
+
95
+ def clear_permission_overrides
96
+ if @id
97
+ @connection.send_message('Browser.resetPermissions', browserContextId: @id)
98
+ else
99
+ @connection.send_message('Browser.resetPermissions')
100
+ end
101
+ end
103
102
 
104
103
  # @return [Future<Puppeteer::Page>]
105
104
  def new_page