puppeteer-ruby 0.0.2 → 0.0.3

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: 4f42c72b65d27578da2dbdbbc4dac1544bb0a0038ba3c35ffd8f298dafc47f14
4
- data.tar.gz: c1fe854ee2566bb9c8993e42cf71b881ff9c87a709150bb7cddd09a6d952901d
3
+ metadata.gz: 499744d122eeb8736a1466f17cf9ee09235f488fb19a95d3902da5529406dab0
4
+ data.tar.gz: f6b27f599887d385c46914e1b255f9738fd7f946a0ff0a4f83a04075e50e092c
5
5
  SHA512:
6
- metadata.gz: ef51d01afe77f2c1bf31ed70a7bfe3a629377b32b69ceb265413876802639ef5c44de08856b0bfaa69bbddf7bf41a6aaef01bd7e4a2c4a516ec21b645b7caede
7
- data.tar.gz: 7a876a89710c9fd956377b01ce41d463a6fd547805991f8778bd89086182a4800459bb6cf5d6009ea8a363629993f4bdd333263475c1e24cfb3a99f9b886e53e
6
+ metadata.gz: 54ece5985462bc3f4f30c1a803fd43a5975845911657431aa33d78d70fba6e242d447869a03b3ad6cf925e0e94315db2df62b4d9d74d8b00e381b8d95326e311
7
+ data.tar.gz: d7d3ab0af4b1bd69588b3998d0a47031d04d80fe3d0b7b55ec1f4b1a9b3ccd683c857faf06e103b972b9b59d63bda6fdc3e984f410720eeae17922176d518561
@@ -0,0 +1,41 @@
1
+ version: 2.1
2
+ orbs:
3
+ ruby: circleci/ruby@0.1.2
4
+
5
+ jobs:
6
+ deploy:
7
+ docker:
8
+ - image: circleci/ruby:2.6.3-stretch-node
9
+ executor: ruby/default
10
+ steps:
11
+ - checkout
12
+ - run:
13
+ name: Which bundler?
14
+ command: bundle -v
15
+ - ruby/bundle-install
16
+ - run:
17
+ name: rake build
18
+ command: rake build
19
+ - run:
20
+ name: setup API key
21
+ command: |
22
+ mkdir -p ~/.gem/
23
+ echo "---" > ~/.gem/credentials
24
+ echo ":rubygems_api_key: $RUBYGEMS_API_KEY" >> ~/.gem/credentials
25
+ chmod 600 ~/.gem/credentials
26
+ - run:
27
+ name: Check Puppeteer::version
28
+ command: bundle exec ruby -e 'raise "invalid Puppeteer::VERSION" unless Puppeteer::VERSION == ENV["CIRCLE_TAG"]'
29
+ - run:
30
+ name: gem push
31
+ command: gem push pkg/puppeteer-ruby-$CIRCLE_TAG.gem
32
+
33
+ workflows:
34
+ rubygems-deploy:
35
+ jobs:
36
+ - deploy:
37
+ filters:
38
+ tags:
39
+ only: /^[0-9]\.[0-9]+\.[0-9].*/
40
+ branches:
41
+ ignore: /.*/
data/.rubocop.yml CHANGED
@@ -1,11 +1,175 @@
1
- Layout/LineLength:
2
- Max: 120
1
+ require:
2
+ - rubocop-rspec
3
3
 
4
- Style/AccessModifierDeclarations:
5
- EnforcedStyle: inline
4
+ AllCops:
5
+ TargetRubyVersion: 2.7
6
+ # RuboCop has a bunch of cops enabled by default. This setting tells RuboCop
7
+ # to ignore them, so only the ones explicitly set in this file are enabled.
8
+ DisabledByDefault: true
6
9
 
7
- Style/ClassAndModuleChildren:
8
- EnforcedStyle: compact
10
+ # Prefer &&/|| over and/or.
11
+ Style/AndOr:
12
+ Enabled: true
13
+
14
+ # Align `when` with `case`.
15
+ Layout/CaseIndentation:
16
+ Enabled: true
17
+
18
+ Layout/ClosingHeredocIndentation:
19
+ Enabled: true
20
+
21
+ # Align comments with method definitions.
22
+ Layout/CommentIndentation:
23
+ Enabled: true
24
+
25
+ Layout/ElseAlignment:
26
+ Enabled: true
27
+
28
+ # Align `end` with the matching keyword or starting expression except for
29
+ # assignments, where it should be aligned with the LHS.
30
+ Layout/EndAlignment:
31
+ Enabled: true
32
+ EnforcedStyleAlignWith: variable
33
+ AutoCorrect: true
34
+
35
+ Layout/EmptyLineAfterMagicComment:
36
+ Enabled: true
37
+
38
+ Layout/EmptyLinesAroundAccessModifier:
39
+ Enabled: true
40
+ EnforcedStyle: only_before
41
+
42
+ Layout/EmptyLinesAroundBlockBody:
43
+ Enabled: true
44
+
45
+ # In a regular class definition, no empty lines around the body.
46
+ Layout/EmptyLinesAroundClassBody:
47
+ Enabled: true
48
+
49
+ # In a regular method definition, no empty lines around the body.
50
+ Layout/EmptyLinesAroundMethodBody:
51
+ Enabled: true
52
+
53
+ # In a regular module definition, no empty lines around the body.
54
+ Layout/EmptyLinesAroundModuleBody:
55
+ Enabled: true
56
+
57
+ # Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }.
58
+ Style/HashSyntax:
59
+ Enabled: true
60
+
61
+ Layout/FirstArgumentIndentation:
62
+ Enabled: true
63
+
64
+ # Method definitions after `private` or `protected` isolated calls need one
65
+ # extra level of indentation.
66
+ Layout/IndentationConsistency:
67
+ Enabled: true
68
+ EnforcedStyle: indented_internal_methods
69
+
70
+ # Two spaces, no tabs (for indentation).
71
+ Layout/IndentationWidth:
72
+ Enabled: true
73
+
74
+ Layout/LeadingCommentSpace:
75
+ Enabled: true
76
+
77
+ Layout/SpaceAfterColon:
78
+ Enabled: true
79
+
80
+ Layout/SpaceAfterComma:
81
+ Enabled: true
82
+
83
+ Layout/SpaceAfterSemicolon:
84
+ Enabled: true
85
+
86
+ Layout/SpaceAroundEqualsInParameterDefault:
87
+ Enabled: true
88
+
89
+ Layout/SpaceAroundKeyword:
90
+ Enabled: true
91
+
92
+ Layout/SpaceBeforeComma:
93
+ Enabled: true
94
+
95
+ Layout/SpaceBeforeComment:
96
+ Enabled: true
97
+
98
+ Layout/SpaceBeforeFirstArg:
99
+ Enabled: true
100
+
101
+ Style/DefWithParentheses:
102
+ Enabled: true
103
+
104
+ # Defining a method with parameters needs parentheses.
105
+ Style/MethodDefParentheses:
106
+ Enabled: true
107
+
108
+ Style/RedundantFreeze:
109
+ Enabled: true
110
+
111
+ # Use `foo {}` not `foo{}`.
112
+ Layout/SpaceBeforeBlockBraces:
113
+ Enabled: true
114
+
115
+ # Use `foo { bar }` not `foo {bar}`.
116
+ Layout/SpaceInsideBlockBraces:
117
+ Enabled: true
118
+ EnforcedStyleForEmptyBraces: space
119
+
120
+ # Use `{ a: 1 }` not `{a:1}`.
121
+ Layout/SpaceInsideHashLiteralBraces:
122
+ Enabled: true
123
+
124
+ Layout/SpaceInsideParens:
125
+ Enabled: true
126
+
127
+ # Detect hard tabs, no hard tabs.
128
+ Layout/Tab:
129
+ Enabled: true
130
+
131
+ # Empty lines should not have any spaces.
132
+ Layout/TrailingEmptyLines:
133
+ Enabled: true
134
+
135
+ # No trailing whitespace.
136
+ Layout/TrailingWhitespace:
137
+ Enabled: true
138
+
139
+ # Use quotes for string literals when they are enough.
140
+ Style/RedundantPercentQ:
141
+ Enabled: true
142
+
143
+ Lint/AmbiguousOperator:
144
+ Enabled: true
145
+
146
+ Lint/AmbiguousRegexpLiteral:
147
+ Enabled: true
148
+
149
+ Lint/ErbNewArguments:
150
+ Enabled: true
151
+
152
+ # Use my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
153
+ Lint/RequireParentheses:
154
+ Enabled: true
155
+
156
+ Lint/ShadowingOuterLocalVariable:
157
+ Enabled: true
158
+
159
+ Lint/RedundantStringCoercion:
160
+ Enabled: true
161
+
162
+ Lint/UriEscapeUnescape:
163
+ Enabled: true
164
+
165
+ Lint/UselessAssignment:
166
+ Enabled: true
167
+
168
+ Lint/DeprecatedClassMethods:
169
+ Enabled: true
170
+
171
+ Style/ParenthesesAroundCondition:
172
+ Enabled: true
9
173
 
10
174
  Style/FrozenStringLiteralComment:
11
175
  Enabled: false
@@ -23,6 +187,31 @@ Style/RaiseArgs:
23
187
  Enabled: true
24
188
  EnforcedStyle: compact
25
189
 
190
+ Style/RedundantBegin:
191
+ Enabled: true
192
+
193
+ Style/RedundantReturn:
194
+ Enabled: true
195
+ AllowMultipleReturnValues: true
196
+
197
+ Style/Semicolon:
198
+ Enabled: true
199
+ AllowAsExpressionSeparator: true
200
+
201
+ # Prefer Foo.method over Foo::method
202
+ Style/ColonMethodCall:
203
+ Enabled: true
204
+
205
+ Style/TrivialAccessors:
206
+ Enabled: false
207
+
208
+ Style/AccessModifierDeclarations:
209
+ Enabled: true
210
+ EnforcedStyle: inline
211
+
212
+ Style/ClassAndModuleChildren:
213
+ EnforcedStyle: compact
214
+
26
215
  Style/TrailingCommaInArguments:
27
216
  Enabled: true
28
217
  EnforcedStyleForMultiline: comma
@@ -34,3 +223,81 @@ Style/TrailingCommaInArrayLiteral:
34
223
  Style/TrailingCommaInHashLiteral:
35
224
  Enabled: true
36
225
  EnforcedStyleForMultiline: comma
226
+
227
+
228
+ # rubocop-rspec
229
+
230
+ RSpec/EmptyLineAfterExampleGroup:
231
+ Enabled: true
232
+
233
+ RSpec/EmptyLineAfterHook:
234
+ Enabled: true
235
+
236
+ # bad: expect("success").to eq(result)
237
+ # good: expect(result).to eq("success")
238
+ RSpec/ExpectActual:
239
+ Enabled: true
240
+
241
+ # bad: expect{ subject }.to change(Hoge, :count).by(1)
242
+ # good: expect{ subject }.to change{ Hoge.count }.by(1)
243
+ RSpec/ExpectChange:
244
+ Enabled: true
245
+ EnforcedStyle: block
246
+
247
+ RSpec/ExpectInHook:
248
+ Enabled: true
249
+
250
+ RSpec/ImplicitBlockExpectation:
251
+ Enabled: true
252
+
253
+ RSpec/InstanceVariable:
254
+ Enabled: true
255
+
256
+ # bad: it_should_behave_like
257
+ # good: it_behaves_like
258
+ RSpec/ItBehavesLike:
259
+ Enabled: true
260
+
261
+ RSpec/LeakyConstantDeclaration:
262
+ Enabled: false
263
+
264
+ RSpec/LetSetup:
265
+ Enabled: true
266
+
267
+ RSpec/MultipleSubjects:
268
+ Enabled: true
269
+
270
+ RSpec/NestedGroups:
271
+ Enabled: true
272
+ Max: 4
273
+
274
+ RSpec/NotToNot:
275
+ Enabled: true
276
+
277
+ RSpec/PredicateMatcher:
278
+ Enabled: true
279
+
280
+ RSpec/ReceiveCounts:
281
+ Enabled: true
282
+
283
+ RSpec/ReceiveNever:
284
+ Enabled: true
285
+
286
+ RSpec/ReturnFromStub:
287
+ Enabled: true
288
+ EnforcedStyle: and_return
289
+
290
+ RSpec/SharedContext:
291
+ Enabled: true
292
+
293
+ RSpec/SharedExamples:
294
+ Enabled: true
295
+
296
+ RSpec/SingleArgumentMessageChain:
297
+ Enabled: true
298
+
299
+ RSpec/VoidExpect:
300
+ Enabled: true
301
+
302
+ RSpec/Yield:
303
+ Enabled: true
data/README.md CHANGED
@@ -6,7 +6,17 @@ REMARK: This Gem is NOT production-ready!!
6
6
 
7
7
  ## Getting Started
8
8
 
9
- Simple usage:
9
+ ### Capture a site
10
+
11
+ ```ruby
12
+ Puppeteer.launch(headless: false) do |browser|
13
+ page = browser.pages.first || browser.new_page
14
+ page.goto("https://github.com/YusukeIwaki")
15
+ page.screenshot(path: "YusukeIwaki.png")
16
+ end
17
+ ```
18
+
19
+ ### Simple scraping
10
20
 
11
21
  ```ruby
12
22
  require 'puppeteer'
data/Rakefile CHANGED
@@ -1 +1 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
data/bin/console CHANGED
@@ -7,5 +7,5 @@ require 'puppeteer'
7
7
  # with your gem easier. You can also use a different console, if you like.
8
8
 
9
9
  # (If you use this, don't forget to add pry to your Gemfile!)
10
- require "pry"
10
+ require 'pry'
11
11
  Pry.start
data/lib/puppeteer.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'concurrent'
2
2
 
3
- class Puppeteer ; end
3
+ class Puppeteer; end
4
4
 
5
5
  # Custom data types.
6
6
  require 'puppeteer/device'
@@ -56,7 +56,7 @@ class Puppeteer
56
56
  def instance
57
57
  @instance ||= Puppeteer.new(
58
58
  project_root: __dir__,
59
- preferred_revision: "706915",
59
+ preferred_revision: '706915',
60
60
  is_puppeteer_core: true)
61
61
  end
62
62
  end
@@ -2,30 +2,28 @@ module Puppeteer::AsyncAwaitBehavior
2
2
  refine Class do
3
3
  # wrap with Concurrent::Promises.future
4
4
  def async(method_name)
5
- begin
6
- original_method = instance_method(method_name)
5
+ original_method = instance_method(method_name)
7
6
 
8
- unless method_name.to_s.start_with?("async_")
9
- puts "async method should start with 'async_': #{self.name}##{method_name}"
10
- end
7
+ unless method_name.to_s.start_with?('async_')
8
+ puts "async method should start with 'async_': #{self.name}##{method_name}"
9
+ end
11
10
 
12
- define_method(method_name) do |*args|
13
- Concurrent::Promises.future {
14
- original_method.bind(self).call(*args)
15
- }
11
+ define_method(method_name) do |*args|
12
+ Concurrent::Promises.future do
13
+ original_method.bind(self).call(*args)
16
14
  end
17
- rescue NameError
18
- if respond_to?(method_name)
19
- original_method = singleton_method(method_name)
15
+ end
16
+ rescue NameError
17
+ if respond_to?(method_name)
18
+ original_method = singleton_method(method_name)
20
19
 
21
- unless method_name.to_s.start_with?("async_")
22
- puts "async method should start with 'async_': #{method_name}"
23
- end
20
+ unless method_name.to_s.start_with?('async_')
21
+ puts "async method should start with 'async_': #{method_name}"
22
+ end
24
23
 
25
- define_singleton_method(method_name) do |*args|
26
- Concurrent::Promises.future {
27
- original_method.call(*args)
28
- }
24
+ define_singleton_method(method_name) do |*args|
25
+ Concurrent::Promises.future do
26
+ original_method.call(*args)
29
27
  end
30
28
  end
31
29
  end
@@ -94,7 +94,7 @@ class Puppeteer::Browser
94
94
  target = Puppeteer::Target.new(
95
95
  target_info: target_info,
96
96
  browser_context: context,
97
- session_factory: ->{ @connection.create_session(target_info) },
97
+ session_factory: -> { @connection.create_session(target_info) },
98
98
  ignore_https_errors: @ignore_https_errors,
99
99
  default_viewport: @default_viewport,
100
100
  screenshot_task_queue: @screenshot_task_queue,
@@ -158,18 +158,18 @@ class Puppeteer::Browser
158
158
  target_id = result['targetId']
159
159
  target = @targets[target_id]
160
160
  await target.initialized_promise
161
- await target.page;
161
+ await target.page
162
162
  end
163
163
 
164
164
  # @return {!Array<!Target>}
165
165
  def targets
166
- @targets.values.select{ |target| target.initialized? }
166
+ @targets.values.select { |target| target.initialized? }
167
167
  end
168
168
 
169
169
 
170
170
  # @return {!Target}
171
171
  def target
172
- targets.first{ |target| target.type == 'browser' }
172
+ targets.first { |target| target.type == 'browser' }
173
173
  end
174
174
 
175
175
  # @param {function(!Target):boolean} predicate
@@ -177,7 +177,7 @@ class Puppeteer::Browser
177
177
  # @return {!Promise<!Target>}
178
178
  def wait_for_target(predicate:, timeout: nil)
179
179
  timeout_in_sec = (timeout || 30000).to_i / 1000.0
180
- existing_target = targets.first{ |target| predicate.call(target) }
180
+ existing_target = targets.first { |target| predicate.call(target) }
181
181
  return existing_target if existing_target
182
182
 
183
183
  event_listening_ids = []