puppeteer-ruby 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +36 -0
  5. data/.travis.yml +7 -0
  6. data/Dockerfile +6 -0
  7. data/Gemfile +6 -0
  8. data/README.md +41 -0
  9. data/Rakefile +1 -0
  10. data/bin/console +11 -0
  11. data/bin/setup +8 -0
  12. data/docker-compose.yml +15 -0
  13. data/example.rb +7 -0
  14. data/lib/puppeteer.rb +192 -0
  15. data/lib/puppeteer/async_await_behavior.rb +34 -0
  16. data/lib/puppeteer/browser.rb +240 -0
  17. data/lib/puppeteer/browser_context.rb +90 -0
  18. data/lib/puppeteer/browser_fetcher.rb +6 -0
  19. data/lib/puppeteer/browser_runner.rb +142 -0
  20. data/lib/puppeteer/cdp_session.rb +78 -0
  21. data/lib/puppeteer/concurrent_ruby_utils.rb +37 -0
  22. data/lib/puppeteer/connection.rb +254 -0
  23. data/lib/puppeteer/console_message.rb +24 -0
  24. data/lib/puppeteer/debug_print.rb +20 -0
  25. data/lib/puppeteer/device.rb +12 -0
  26. data/lib/puppeteer/devices.rb +885 -0
  27. data/lib/puppeteer/dom_world.rb +447 -0
  28. data/lib/puppeteer/element_handle.rb +433 -0
  29. data/lib/puppeteer/emulation_manager.rb +46 -0
  30. data/lib/puppeteer/errors.rb +4 -0
  31. data/lib/puppeteer/event_callbackable.rb +88 -0
  32. data/lib/puppeteer/execution_context.rb +230 -0
  33. data/lib/puppeteer/frame.rb +278 -0
  34. data/lib/puppeteer/frame_manager.rb +380 -0
  35. data/lib/puppeteer/if_present.rb +18 -0
  36. data/lib/puppeteer/js_handle.rb +142 -0
  37. data/lib/puppeteer/keyboard.rb +183 -0
  38. data/lib/puppeteer/keyboard/key_description.rb +19 -0
  39. data/lib/puppeteer/keyboard/us_keyboard_layout.rb +283 -0
  40. data/lib/puppeteer/launcher.rb +26 -0
  41. data/lib/puppeteer/launcher/base.rb +48 -0
  42. data/lib/puppeteer/launcher/browser_options.rb +41 -0
  43. data/lib/puppeteer/launcher/chrome.rb +165 -0
  44. data/lib/puppeteer/launcher/chrome_arg_options.rb +49 -0
  45. data/lib/puppeteer/launcher/launch_options.rb +68 -0
  46. data/lib/puppeteer/lifecycle_watcher.rb +168 -0
  47. data/lib/puppeteer/mouse.rb +120 -0
  48. data/lib/puppeteer/network_manager.rb +122 -0
  49. data/lib/puppeteer/page.rb +1001 -0
  50. data/lib/puppeteer/page/screenshot_options.rb +78 -0
  51. data/lib/puppeteer/remote_object.rb +124 -0
  52. data/lib/puppeteer/target.rb +150 -0
  53. data/lib/puppeteer/timeout_settings.rb +15 -0
  54. data/lib/puppeteer/touch_screen.rb +43 -0
  55. data/lib/puppeteer/version.rb +3 -0
  56. data/lib/puppeteer/viewport.rb +36 -0
  57. data/lib/puppeteer/wait_task.rb +6 -0
  58. data/lib/puppeteer/web_socket.rb +117 -0
  59. data/lib/puppeteer/web_socket_transport.rb +49 -0
  60. data/puppeteer-ruby.gemspec +29 -0
  61. metadata +213 -0
@@ -0,0 +1,24 @@
1
+ class Puppeteer::ConsoleMessage
2
+ class Location
3
+ def initialize(url:, line_number:, column_number: nil)
4
+ @url = url
5
+ @line_number = line_number
6
+ @column_number = column_number
7
+ end
8
+
9
+ attr_reader :url, :line_number, :column_number
10
+ end
11
+
12
+ # @param log_type [String]
13
+ # @param text [String]
14
+ # @param args [Array<Puppeteer::JSHandle>]
15
+ # @param location [Location]
16
+ def initialize(log_type, text, args, location)
17
+ @log_type = log_type
18
+ @text = text
19
+ @args = args
20
+ @location = location
21
+ end
22
+
23
+ attr_reader :log_type, :text, :args, :location
24
+ end
@@ -0,0 +1,20 @@
1
+ require 'logger'
2
+
3
+ module Puppeteer::DebugPrint
4
+ if ["1", "true"].include?(ENV["DEBUG"])
5
+ def debug_puts(*args, **kwargs)
6
+ @__debug_logger ||= Logger.new(STDOUT)
7
+ @__debug_logger.debug(*args, **kwargs)
8
+ end
9
+
10
+ def debug_print(*args)
11
+ print(*args)
12
+ end
13
+ else
14
+ def debug_puts(*args, **kwargs)
15
+ end
16
+
17
+ def debug_print(*args)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,12 @@
1
+ class Puppeteer::Device
2
+ # @param name [String]
3
+ # @param user_agent [String]
4
+ # @param viewport [Viewport]
5
+ def initialize(name:, user_agent:, viewport:)
6
+ @name = name
7
+ @user_agent = user_agent
8
+ @viewport = viewport
9
+ end
10
+
11
+ attr_reader :name, :user_agent, :viewport
12
+ end
@@ -0,0 +1,885 @@
1
+ Puppeteer::DEVICES = Hash[
2
+ [
3
+ {
4
+ 'name': 'Blackberry PlayBook',
5
+ 'userAgent': 'Mozilla/5.0 (PlayBook; U; RIM Tablet OS 2.1.0; en-US) AppleWebKit/536.2+ (KHTML like Gecko) Version/7.2.1.0 Safari/536.2+',
6
+ 'viewport': {
7
+ 'width': 600,
8
+ 'height': 1024,
9
+ 'deviceScaleFactor': 1,
10
+ 'isMobile': true,
11
+ 'hasTouch': true,
12
+ 'isLandscape': false,
13
+ },
14
+ },
15
+ {
16
+ 'name': 'Blackberry PlayBook landscape',
17
+ 'userAgent': 'Mozilla/5.0 (PlayBook; U; RIM Tablet OS 2.1.0; en-US) AppleWebKit/536.2+ (KHTML like Gecko) Version/7.2.1.0 Safari/536.2+',
18
+ 'viewport': {
19
+ 'width': 1024,
20
+ 'height': 600,
21
+ 'deviceScaleFactor': 1,
22
+ 'isMobile': true,
23
+ 'hasTouch': true,
24
+ 'isLandscape': true,
25
+ },
26
+ },
27
+ {
28
+ 'name': 'BlackBerry Z30',
29
+ 'userAgent': 'Mozilla/5.0 (BB10; Touch) AppleWebKit/537.10+ (KHTML, like Gecko) Version/10.0.9.2372 Mobile Safari/537.10+',
30
+ 'viewport': {
31
+ 'width': 360,
32
+ 'height': 640,
33
+ 'deviceScaleFactor': 2,
34
+ 'isMobile': true,
35
+ 'hasTouch': true,
36
+ 'isLandscape': false,
37
+ },
38
+ },
39
+ {
40
+ 'name': 'BlackBerry Z30 landscape',
41
+ 'userAgent': 'Mozilla/5.0 (BB10; Touch) AppleWebKit/537.10+ (KHTML, like Gecko) Version/10.0.9.2372 Mobile Safari/537.10+',
42
+ 'viewport': {
43
+ 'width': 640,
44
+ 'height': 360,
45
+ 'deviceScaleFactor': 2,
46
+ 'isMobile': true,
47
+ 'hasTouch': true,
48
+ 'isLandscape': true,
49
+ },
50
+ },
51
+ {
52
+ 'name': 'Galaxy Note 3',
53
+ 'userAgent': 'Mozilla/5.0 (Linux; U; Android 4.3; en-us; SM-N900T Build/JSS15J) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30',
54
+ 'viewport': {
55
+ 'width': 360,
56
+ 'height': 640,
57
+ 'deviceScaleFactor': 3,
58
+ 'isMobile': true,
59
+ 'hasTouch': true,
60
+ 'isLandscape': false,
61
+ },
62
+ },
63
+ {
64
+ 'name': 'Galaxy Note 3 landscape',
65
+ 'userAgent': 'Mozilla/5.0 (Linux; U; Android 4.3; en-us; SM-N900T Build/JSS15J) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30',
66
+ 'viewport': {
67
+ 'width': 640,
68
+ 'height': 360,
69
+ 'deviceScaleFactor': 3,
70
+ 'isMobile': true,
71
+ 'hasTouch': true,
72
+ 'isLandscape': true,
73
+ },
74
+ },
75
+ {
76
+ 'name': 'Galaxy Note II',
77
+ 'userAgent': 'Mozilla/5.0 (Linux; U; Android 4.1; en-us; GT-N7100 Build/JRO03C) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30',
78
+ 'viewport': {
79
+ 'width': 360,
80
+ 'height': 640,
81
+ 'deviceScaleFactor': 2,
82
+ 'isMobile': true,
83
+ 'hasTouch': true,
84
+ 'isLandscape': false,
85
+ },
86
+ },
87
+ {
88
+ 'name': 'Galaxy Note II landscape',
89
+ 'userAgent': 'Mozilla/5.0 (Linux; U; Android 4.1; en-us; GT-N7100 Build/JRO03C) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30',
90
+ 'viewport': {
91
+ 'width': 640,
92
+ 'height': 360,
93
+ 'deviceScaleFactor': 2,
94
+ 'isMobile': true,
95
+ 'hasTouch': true,
96
+ 'isLandscape': true,
97
+ },
98
+ },
99
+ {
100
+ 'name': 'Galaxy S III',
101
+ 'userAgent': 'Mozilla/5.0 (Linux; U; Android 4.0; en-us; GT-I9300 Build/IMM76D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30',
102
+ 'viewport': {
103
+ 'width': 360,
104
+ 'height': 640,
105
+ 'deviceScaleFactor': 2,
106
+ 'isMobile': true,
107
+ 'hasTouch': true,
108
+ 'isLandscape': false,
109
+ },
110
+ },
111
+ {
112
+ 'name': 'Galaxy S III landscape',
113
+ 'userAgent': 'Mozilla/5.0 (Linux; U; Android 4.0; en-us; GT-I9300 Build/IMM76D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30',
114
+ 'viewport': {
115
+ 'width': 640,
116
+ 'height': 360,
117
+ 'deviceScaleFactor': 2,
118
+ 'isMobile': true,
119
+ 'hasTouch': true,
120
+ 'isLandscape': true,
121
+ },
122
+ },
123
+ {
124
+ 'name': 'Galaxy S5',
125
+ 'userAgent': 'Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3765.0 Mobile Safari/537.36',
126
+ 'viewport': {
127
+ 'width': 360,
128
+ 'height': 640,
129
+ 'deviceScaleFactor': 3,
130
+ 'isMobile': true,
131
+ 'hasTouch': true,
132
+ 'isLandscape': false,
133
+ },
134
+ },
135
+ {
136
+ 'name': 'Galaxy S5 landscape',
137
+ 'userAgent': 'Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3765.0 Mobile Safari/537.36',
138
+ 'viewport': {
139
+ 'width': 640,
140
+ 'height': 360,
141
+ 'deviceScaleFactor': 3,
142
+ 'isMobile': true,
143
+ 'hasTouch': true,
144
+ 'isLandscape': true,
145
+ },
146
+ },
147
+ {
148
+ 'name': 'iPad',
149
+ 'userAgent': 'Mozilla/5.0 (iPad; CPU OS 11_0 like Mac OS X) AppleWebKit/604.1.34 (KHTML, like Gecko) Version/11.0 Mobile/15A5341f Safari/604.1',
150
+ 'viewport': {
151
+ 'width': 768,
152
+ 'height': 1024,
153
+ 'deviceScaleFactor': 2,
154
+ 'isMobile': true,
155
+ 'hasTouch': true,
156
+ 'isLandscape': false,
157
+ },
158
+ },
159
+ {
160
+ 'name': 'iPad landscape',
161
+ 'userAgent': 'Mozilla/5.0 (iPad; CPU OS 11_0 like Mac OS X) AppleWebKit/604.1.34 (KHTML, like Gecko) Version/11.0 Mobile/15A5341f Safari/604.1',
162
+ 'viewport': {
163
+ 'width': 1024,
164
+ 'height': 768,
165
+ 'deviceScaleFactor': 2,
166
+ 'isMobile': true,
167
+ 'hasTouch': true,
168
+ 'isLandscape': true,
169
+ },
170
+ },
171
+ {
172
+ 'name': 'iPad Mini',
173
+ 'userAgent': 'Mozilla/5.0 (iPad; CPU OS 11_0 like Mac OS X) AppleWebKit/604.1.34 (KHTML, like Gecko) Version/11.0 Mobile/15A5341f Safari/604.1',
174
+ 'viewport': {
175
+ 'width': 768,
176
+ 'height': 1024,
177
+ 'deviceScaleFactor': 2,
178
+ 'isMobile': true,
179
+ 'hasTouch': true,
180
+ 'isLandscape': false,
181
+ },
182
+ },
183
+ {
184
+ 'name': 'iPad Mini landscape',
185
+ 'userAgent': 'Mozilla/5.0 (iPad; CPU OS 11_0 like Mac OS X) AppleWebKit/604.1.34 (KHTML, like Gecko) Version/11.0 Mobile/15A5341f Safari/604.1',
186
+ 'viewport': {
187
+ 'width': 1024,
188
+ 'height': 768,
189
+ 'deviceScaleFactor': 2,
190
+ 'isMobile': true,
191
+ 'hasTouch': true,
192
+ 'isLandscape': true,
193
+ },
194
+ },
195
+ {
196
+ 'name': 'iPad Pro',
197
+ 'userAgent': 'Mozilla/5.0 (iPad; CPU OS 11_0 like Mac OS X) AppleWebKit/604.1.34 (KHTML, like Gecko) Version/11.0 Mobile/15A5341f Safari/604.1',
198
+ 'viewport': {
199
+ 'width': 1024,
200
+ 'height': 1366,
201
+ 'deviceScaleFactor': 2,
202
+ 'isMobile': true,
203
+ 'hasTouch': true,
204
+ 'isLandscape': false,
205
+ },
206
+ },
207
+ {
208
+ 'name': 'iPad Pro landscape',
209
+ 'userAgent': 'Mozilla/5.0 (iPad; CPU OS 11_0 like Mac OS X) AppleWebKit/604.1.34 (KHTML, like Gecko) Version/11.0 Mobile/15A5341f Safari/604.1',
210
+ 'viewport': {
211
+ 'width': 1366,
212
+ 'height': 1024,
213
+ 'deviceScaleFactor': 2,
214
+ 'isMobile': true,
215
+ 'hasTouch': true,
216
+ 'isLandscape': true,
217
+ },
218
+ },
219
+ {
220
+ 'name': 'iPhone 4',
221
+ 'userAgent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 7_1_2 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Version/7.0 Mobile/11D257 Safari/9537.53',
222
+ 'viewport': {
223
+ 'width': 320,
224
+ 'height': 480,
225
+ 'deviceScaleFactor': 2,
226
+ 'isMobile': true,
227
+ 'hasTouch': true,
228
+ 'isLandscape': false,
229
+ },
230
+ },
231
+ {
232
+ 'name': 'iPhone 4 landscape',
233
+ 'userAgent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 7_1_2 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Version/7.0 Mobile/11D257 Safari/9537.53',
234
+ 'viewport': {
235
+ 'width': 480,
236
+ 'height': 320,
237
+ 'deviceScaleFactor': 2,
238
+ 'isMobile': true,
239
+ 'hasTouch': true,
240
+ 'isLandscape': true,
241
+ },
242
+ },
243
+ {
244
+ 'name': 'iPhone 5',
245
+ 'userAgent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1',
246
+ 'viewport': {
247
+ 'width': 320,
248
+ 'height': 568,
249
+ 'deviceScaleFactor': 2,
250
+ 'isMobile': true,
251
+ 'hasTouch': true,
252
+ 'isLandscape': false,
253
+ },
254
+ },
255
+ {
256
+ 'name': 'iPhone 5 landscape',
257
+ 'userAgent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1',
258
+ 'viewport': {
259
+ 'width': 568,
260
+ 'height': 320,
261
+ 'deviceScaleFactor': 2,
262
+ 'isMobile': true,
263
+ 'hasTouch': true,
264
+ 'isLandscape': true,
265
+ },
266
+ },
267
+ {
268
+ 'name': 'iPhone 6',
269
+ 'userAgent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1',
270
+ 'viewport': {
271
+ 'width': 375,
272
+ 'height': 667,
273
+ 'deviceScaleFactor': 2,
274
+ 'isMobile': true,
275
+ 'hasTouch': true,
276
+ 'isLandscape': false,
277
+ },
278
+ },
279
+ {
280
+ 'name': 'iPhone 6 landscape',
281
+ 'userAgent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1',
282
+ 'viewport': {
283
+ 'width': 667,
284
+ 'height': 375,
285
+ 'deviceScaleFactor': 2,
286
+ 'isMobile': true,
287
+ 'hasTouch': true,
288
+ 'isLandscape': true,
289
+ },
290
+ },
291
+ {
292
+ 'name': 'iPhone 6 Plus',
293
+ 'userAgent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1',
294
+ 'viewport': {
295
+ 'width': 414,
296
+ 'height': 736,
297
+ 'deviceScaleFactor': 3,
298
+ 'isMobile': true,
299
+ 'hasTouch': true,
300
+ 'isLandscape': false,
301
+ },
302
+ },
303
+ {
304
+ 'name': 'iPhone 6 Plus landscape',
305
+ 'userAgent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1',
306
+ 'viewport': {
307
+ 'width': 736,
308
+ 'height': 414,
309
+ 'deviceScaleFactor': 3,
310
+ 'isMobile': true,
311
+ 'hasTouch': true,
312
+ 'isLandscape': true,
313
+ },
314
+ },
315
+ {
316
+ 'name': 'iPhone 7',
317
+ 'userAgent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1',
318
+ 'viewport': {
319
+ 'width': 375,
320
+ 'height': 667,
321
+ 'deviceScaleFactor': 2,
322
+ 'isMobile': true,
323
+ 'hasTouch': true,
324
+ 'isLandscape': false,
325
+ },
326
+ },
327
+ {
328
+ 'name': 'iPhone 7 landscape',
329
+ 'userAgent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1',
330
+ 'viewport': {
331
+ 'width': 667,
332
+ 'height': 375,
333
+ 'deviceScaleFactor': 2,
334
+ 'isMobile': true,
335
+ 'hasTouch': true,
336
+ 'isLandscape': true,
337
+ },
338
+ },
339
+ {
340
+ 'name': 'iPhone 7 Plus',
341
+ 'userAgent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1',
342
+ 'viewport': {
343
+ 'width': 414,
344
+ 'height': 736,
345
+ 'deviceScaleFactor': 3,
346
+ 'isMobile': true,
347
+ 'hasTouch': true,
348
+ 'isLandscape': false,
349
+ },
350
+ },
351
+ {
352
+ 'name': 'iPhone 7 Plus landscape',
353
+ 'userAgent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1',
354
+ 'viewport': {
355
+ 'width': 736,
356
+ 'height': 414,
357
+ 'deviceScaleFactor': 3,
358
+ 'isMobile': true,
359
+ 'hasTouch': true,
360
+ 'isLandscape': true,
361
+ },
362
+ },
363
+ {
364
+ 'name': 'iPhone 8',
365
+ 'userAgent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1',
366
+ 'viewport': {
367
+ 'width': 375,
368
+ 'height': 667,
369
+ 'deviceScaleFactor': 2,
370
+ 'isMobile': true,
371
+ 'hasTouch': true,
372
+ 'isLandscape': false,
373
+ },
374
+ },
375
+ {
376
+ 'name': 'iPhone 8 landscape',
377
+ 'userAgent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1',
378
+ 'viewport': {
379
+ 'width': 667,
380
+ 'height': 375,
381
+ 'deviceScaleFactor': 2,
382
+ 'isMobile': true,
383
+ 'hasTouch': true,
384
+ 'isLandscape': true,
385
+ },
386
+ },
387
+ {
388
+ 'name': 'iPhone 8 Plus',
389
+ 'userAgent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1',
390
+ 'viewport': {
391
+ 'width': 414,
392
+ 'height': 736,
393
+ 'deviceScaleFactor': 3,
394
+ 'isMobile': true,
395
+ 'hasTouch': true,
396
+ 'isLandscape': false,
397
+ },
398
+ },
399
+ {
400
+ 'name': 'iPhone 8 Plus landscape',
401
+ 'userAgent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1',
402
+ 'viewport': {
403
+ 'width': 736,
404
+ 'height': 414,
405
+ 'deviceScaleFactor': 3,
406
+ 'isMobile': true,
407
+ 'hasTouch': true,
408
+ 'isLandscape': true,
409
+ },
410
+ },
411
+ {
412
+ 'name': 'iPhone SE',
413
+ 'userAgent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1',
414
+ 'viewport': {
415
+ 'width': 320,
416
+ 'height': 568,
417
+ 'deviceScaleFactor': 2,
418
+ 'isMobile': true,
419
+ 'hasTouch': true,
420
+ 'isLandscape': false,
421
+ },
422
+ },
423
+ {
424
+ 'name': 'iPhone SE landscape',
425
+ 'userAgent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1',
426
+ 'viewport': {
427
+ 'width': 568,
428
+ 'height': 320,
429
+ 'deviceScaleFactor': 2,
430
+ 'isMobile': true,
431
+ 'hasTouch': true,
432
+ 'isLandscape': true,
433
+ },
434
+ },
435
+ {
436
+ 'name': 'iPhone X',
437
+ 'userAgent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1',
438
+ 'viewport': {
439
+ 'width': 375,
440
+ 'height': 812,
441
+ 'deviceScaleFactor': 3,
442
+ 'isMobile': true,
443
+ 'hasTouch': true,
444
+ 'isLandscape': false,
445
+ },
446
+ },
447
+ {
448
+ 'name': 'iPhone X landscape',
449
+ 'userAgent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1',
450
+ 'viewport': {
451
+ 'width': 812,
452
+ 'height': 375,
453
+ 'deviceScaleFactor': 3,
454
+ 'isMobile': true,
455
+ 'hasTouch': true,
456
+ 'isLandscape': true,
457
+ },
458
+ },
459
+ {
460
+ 'name': 'iPhone XR',
461
+ 'userAgent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 12_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Mobile/15E148 Safari/604.1',
462
+ 'viewport': {
463
+ 'width': 414,
464
+ 'height': 896,
465
+ 'deviceScaleFactor': 3,
466
+ 'isMobile': true,
467
+ 'hasTouch': true,
468
+ 'isLandscape': false,
469
+ },
470
+ },
471
+ {
472
+ 'name': 'iPhone XR landscape',
473
+ 'userAgent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 12_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Mobile/15E148 Safari/604.1',
474
+ 'viewport': {
475
+ 'width': 896,
476
+ 'height': 414,
477
+ 'deviceScaleFactor': 3,
478
+ 'isMobile': true,
479
+ 'hasTouch': true,
480
+ 'isLandscape': true,
481
+ },
482
+ },
483
+ {
484
+ 'name': 'JioPhone 2',
485
+ 'userAgent': 'Mozilla/5.0 (Mobile; LYF/F300B/LYF-F300B-001-01-15-130718-i;Android; rv:48.0) Gecko/48.0 Firefox/48.0 KAIOS/2.5',
486
+ 'viewport': {
487
+ 'width': 240,
488
+ 'height': 320,
489
+ 'deviceScaleFactor': 1,
490
+ 'isMobile': true,
491
+ 'hasTouch': true,
492
+ 'isLandscape': false,
493
+ },
494
+ },
495
+ {
496
+ 'name': 'JioPhone 2 landscape',
497
+ 'userAgent': 'Mozilla/5.0 (Mobile; LYF/F300B/LYF-F300B-001-01-15-130718-i;Android; rv:48.0) Gecko/48.0 Firefox/48.0 KAIOS/2.5',
498
+ 'viewport': {
499
+ 'width': 320,
500
+ 'height': 240,
501
+ 'deviceScaleFactor': 1,
502
+ 'isMobile': true,
503
+ 'hasTouch': true,
504
+ 'isLandscape': true,
505
+ },
506
+ },
507
+ {
508
+ 'name': 'Kindle Fire HDX',
509
+ 'userAgent': 'Mozilla/5.0 (Linux; U; en-us; KFAPWI Build/JDQ39) AppleWebKit/535.19 (KHTML, like Gecko) Silk/3.13 Safari/535.19 Silk-Accelerated=true',
510
+ 'viewport': {
511
+ 'width': 800,
512
+ 'height': 1280,
513
+ 'deviceScaleFactor': 2,
514
+ 'isMobile': true,
515
+ 'hasTouch': true,
516
+ 'isLandscape': false,
517
+ },
518
+ },
519
+ {
520
+ 'name': 'Kindle Fire HDX landscape',
521
+ 'userAgent': 'Mozilla/5.0 (Linux; U; en-us; KFAPWI Build/JDQ39) AppleWebKit/535.19 (KHTML, like Gecko) Silk/3.13 Safari/535.19 Silk-Accelerated=true',
522
+ 'viewport': {
523
+ 'width': 1280,
524
+ 'height': 800,
525
+ 'deviceScaleFactor': 2,
526
+ 'isMobile': true,
527
+ 'hasTouch': true,
528
+ 'isLandscape': true,
529
+ },
530
+ },
531
+ {
532
+ 'name': 'LG Optimus L70',
533
+ 'userAgent': 'Mozilla/5.0 (Linux; U; Android 4.4.2; en-us; LGMS323 Build/KOT49I.MS32310c) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/75.0.3765.0 Mobile Safari/537.36',
534
+ 'viewport': {
535
+ 'width': 384,
536
+ 'height': 640,
537
+ 'deviceScaleFactor': 1.25,
538
+ 'isMobile': true,
539
+ 'hasTouch': true,
540
+ 'isLandscape': false,
541
+ },
542
+ },
543
+ {
544
+ 'name': 'LG Optimus L70 landscape',
545
+ 'userAgent': 'Mozilla/5.0 (Linux; U; Android 4.4.2; en-us; LGMS323 Build/KOT49I.MS32310c) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/75.0.3765.0 Mobile Safari/537.36',
546
+ 'viewport': {
547
+ 'width': 640,
548
+ 'height': 384,
549
+ 'deviceScaleFactor': 1.25,
550
+ 'isMobile': true,
551
+ 'hasTouch': true,
552
+ 'isLandscape': true,
553
+ },
554
+ },
555
+ {
556
+ 'name': 'Microsoft Lumia 550',
557
+ 'userAgent': 'Mozilla/5.0 (Windows Phone 10.0; Android 4.2.1; Microsoft; Lumia 550) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Mobile Safari/537.36 Edge/14.14263',
558
+ 'viewport': {
559
+ 'width': 640,
560
+ 'height': 360,
561
+ 'deviceScaleFactor': 2,
562
+ 'isMobile': true,
563
+ 'hasTouch': true,
564
+ 'isLandscape': false,
565
+ },
566
+ },
567
+ {
568
+ 'name': 'Microsoft Lumia 950',
569
+ 'userAgent': 'Mozilla/5.0 (Windows Phone 10.0; Android 4.2.1; Microsoft; Lumia 950) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Mobile Safari/537.36 Edge/14.14263',
570
+ 'viewport': {
571
+ 'width': 360,
572
+ 'height': 640,
573
+ 'deviceScaleFactor': 4,
574
+ 'isMobile': true,
575
+ 'hasTouch': true,
576
+ 'isLandscape': false,
577
+ },
578
+ },
579
+ {
580
+ 'name': 'Microsoft Lumia 950 landscape',
581
+ 'userAgent': 'Mozilla/5.0 (Windows Phone 10.0; Android 4.2.1; Microsoft; Lumia 950) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Mobile Safari/537.36 Edge/14.14263',
582
+ 'viewport': {
583
+ 'width': 640,
584
+ 'height': 360,
585
+ 'deviceScaleFactor': 4,
586
+ 'isMobile': true,
587
+ 'hasTouch': true,
588
+ 'isLandscape': true,
589
+ },
590
+ },
591
+ {
592
+ 'name': 'Nexus 10',
593
+ 'userAgent': 'Mozilla/5.0 (Linux; Android 6.0.1; Nexus 10 Build/MOB31T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3765.0 Safari/537.36',
594
+ 'viewport': {
595
+ 'width': 800,
596
+ 'height': 1280,
597
+ 'deviceScaleFactor': 2,
598
+ 'isMobile': true,
599
+ 'hasTouch': true,
600
+ 'isLandscape': false,
601
+ },
602
+ },
603
+ {
604
+ 'name': 'Nexus 10 landscape',
605
+ 'userAgent': 'Mozilla/5.0 (Linux; Android 6.0.1; Nexus 10 Build/MOB31T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3765.0 Safari/537.36',
606
+ 'viewport': {
607
+ 'width': 1280,
608
+ 'height': 800,
609
+ 'deviceScaleFactor': 2,
610
+ 'isMobile': true,
611
+ 'hasTouch': true,
612
+ 'isLandscape': true,
613
+ },
614
+ },
615
+ {
616
+ 'name': 'Nexus 4',
617
+ 'userAgent': 'Mozilla/5.0 (Linux; Android 4.4.2; Nexus 4 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3765.0 Mobile Safari/537.36',
618
+ 'viewport': {
619
+ 'width': 384,
620
+ 'height': 640,
621
+ 'deviceScaleFactor': 2,
622
+ 'isMobile': true,
623
+ 'hasTouch': true,
624
+ 'isLandscape': false,
625
+ },
626
+ },
627
+ {
628
+ 'name': 'Nexus 4 landscape',
629
+ 'userAgent': 'Mozilla/5.0 (Linux; Android 4.4.2; Nexus 4 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3765.0 Mobile Safari/537.36',
630
+ 'viewport': {
631
+ 'width': 640,
632
+ 'height': 384,
633
+ 'deviceScaleFactor': 2,
634
+ 'isMobile': true,
635
+ 'hasTouch': true,
636
+ 'isLandscape': true,
637
+ },
638
+ },
639
+ {
640
+ 'name': 'Nexus 5',
641
+ 'userAgent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3765.0 Mobile Safari/537.36',
642
+ 'viewport': {
643
+ 'width': 360,
644
+ 'height': 640,
645
+ 'deviceScaleFactor': 3,
646
+ 'isMobile': true,
647
+ 'hasTouch': true,
648
+ 'isLandscape': false,
649
+ },
650
+ },
651
+ {
652
+ 'name': 'Nexus 5 landscape',
653
+ 'userAgent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3765.0 Mobile Safari/537.36',
654
+ 'viewport': {
655
+ 'width': 640,
656
+ 'height': 360,
657
+ 'deviceScaleFactor': 3,
658
+ 'isMobile': true,
659
+ 'hasTouch': true,
660
+ 'isLandscape': true,
661
+ },
662
+ },
663
+ {
664
+ 'name': 'Nexus 5X',
665
+ 'userAgent': 'Mozilla/5.0 (Linux; Android 8.0.0; Nexus 5X Build/OPR4.170623.006) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3765.0 Mobile Safari/537.36',
666
+ 'viewport': {
667
+ 'width': 412,
668
+ 'height': 732,
669
+ 'deviceScaleFactor': 2.625,
670
+ 'isMobile': true,
671
+ 'hasTouch': true,
672
+ 'isLandscape': false,
673
+ },
674
+ },
675
+ {
676
+ 'name': 'Nexus 5X landscape',
677
+ 'userAgent': 'Mozilla/5.0 (Linux; Android 8.0.0; Nexus 5X Build/OPR4.170623.006) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3765.0 Mobile Safari/537.36',
678
+ 'viewport': {
679
+ 'width': 732,
680
+ 'height': 412,
681
+ 'deviceScaleFactor': 2.625,
682
+ 'isMobile': true,
683
+ 'hasTouch': true,
684
+ 'isLandscape': true,
685
+ },
686
+ },
687
+ {
688
+ 'name': 'Nexus 6',
689
+ 'userAgent': 'Mozilla/5.0 (Linux; Android 7.1.1; Nexus 6 Build/N6F26U) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3765.0 Mobile Safari/537.36',
690
+ 'viewport': {
691
+ 'width': 412,
692
+ 'height': 732,
693
+ 'deviceScaleFactor': 3.5,
694
+ 'isMobile': true,
695
+ 'hasTouch': true,
696
+ 'isLandscape': false,
697
+ },
698
+ },
699
+ {
700
+ 'name': 'Nexus 6 landscape',
701
+ 'userAgent': 'Mozilla/5.0 (Linux; Android 7.1.1; Nexus 6 Build/N6F26U) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3765.0 Mobile Safari/537.36',
702
+ 'viewport': {
703
+ 'width': 732,
704
+ 'height': 412,
705
+ 'deviceScaleFactor': 3.5,
706
+ 'isMobile': true,
707
+ 'hasTouch': true,
708
+ 'isLandscape': true,
709
+ },
710
+ },
711
+ {
712
+ 'name': 'Nexus 6P',
713
+ 'userAgent': 'Mozilla/5.0 (Linux; Android 8.0.0; Nexus 6P Build/OPP3.170518.006) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3765.0 Mobile Safari/537.36',
714
+ 'viewport': {
715
+ 'width': 412,
716
+ 'height': 732,
717
+ 'deviceScaleFactor': 3.5,
718
+ 'isMobile': true,
719
+ 'hasTouch': true,
720
+ 'isLandscape': false,
721
+ },
722
+ },
723
+ {
724
+ 'name': 'Nexus 6P landscape',
725
+ 'userAgent': 'Mozilla/5.0 (Linux; Android 8.0.0; Nexus 6P Build/OPP3.170518.006) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3765.0 Mobile Safari/537.36',
726
+ 'viewport': {
727
+ 'width': 732,
728
+ 'height': 412,
729
+ 'deviceScaleFactor': 3.5,
730
+ 'isMobile': true,
731
+ 'hasTouch': true,
732
+ 'isLandscape': true,
733
+ },
734
+ },
735
+ {
736
+ 'name': 'Nexus 7',
737
+ 'userAgent': 'Mozilla/5.0 (Linux; Android 6.0.1; Nexus 7 Build/MOB30X) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3765.0 Safari/537.36',
738
+ 'viewport': {
739
+ 'width': 600,
740
+ 'height': 960,
741
+ 'deviceScaleFactor': 2,
742
+ 'isMobile': true,
743
+ 'hasTouch': true,
744
+ 'isLandscape': false,
745
+ },
746
+ },
747
+ {
748
+ 'name': 'Nexus 7 landscape',
749
+ 'userAgent': 'Mozilla/5.0 (Linux; Android 6.0.1; Nexus 7 Build/MOB30X) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3765.0 Safari/537.36',
750
+ 'viewport': {
751
+ 'width': 960,
752
+ 'height': 600,
753
+ 'deviceScaleFactor': 2,
754
+ 'isMobile': true,
755
+ 'hasTouch': true,
756
+ 'isLandscape': true,
757
+ },
758
+ },
759
+ {
760
+ 'name': 'Nokia Lumia 520',
761
+ 'userAgent': 'Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; Lumia 520)',
762
+ 'viewport': {
763
+ 'width': 320,
764
+ 'height': 533,
765
+ 'deviceScaleFactor': 1.5,
766
+ 'isMobile': true,
767
+ 'hasTouch': true,
768
+ 'isLandscape': false,
769
+ },
770
+ },
771
+ {
772
+ 'name': 'Nokia Lumia 520 landscape',
773
+ 'userAgent': 'Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; Lumia 520)',
774
+ 'viewport': {
775
+ 'width': 533,
776
+ 'height': 320,
777
+ 'deviceScaleFactor': 1.5,
778
+ 'isMobile': true,
779
+ 'hasTouch': true,
780
+ 'isLandscape': true,
781
+ },
782
+ },
783
+ {
784
+ 'name': 'Nokia N9',
785
+ 'userAgent': 'Mozilla/5.0 (MeeGo; NokiaN9) AppleWebKit/534.13 (KHTML, like Gecko) NokiaBrowser/8.5.0 Mobile Safari/534.13',
786
+ 'viewport': {
787
+ 'width': 480,
788
+ 'height': 854,
789
+ 'deviceScaleFactor': 1,
790
+ 'isMobile': true,
791
+ 'hasTouch': true,
792
+ 'isLandscape': false,
793
+ },
794
+ },
795
+ {
796
+ 'name': 'Nokia N9 landscape',
797
+ 'userAgent': 'Mozilla/5.0 (MeeGo; NokiaN9) AppleWebKit/534.13 (KHTML, like Gecko) NokiaBrowser/8.5.0 Mobile Safari/534.13',
798
+ 'viewport': {
799
+ 'width': 854,
800
+ 'height': 480,
801
+ 'deviceScaleFactor': 1,
802
+ 'isMobile': true,
803
+ 'hasTouch': true,
804
+ 'isLandscape': true,
805
+ },
806
+ },
807
+ {
808
+ 'name': 'Pixel 2',
809
+ 'userAgent': 'Mozilla/5.0 (Linux; Android 8.0; Pixel 2 Build/OPD3.170816.012) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3765.0 Mobile Safari/537.36',
810
+ 'viewport': {
811
+ 'width': 411,
812
+ 'height': 731,
813
+ 'deviceScaleFactor': 2.625,
814
+ 'isMobile': true,
815
+ 'hasTouch': true,
816
+ 'isLandscape': false,
817
+ },
818
+ },
819
+ {
820
+ 'name': 'Pixel 2 landscape',
821
+ 'userAgent': 'Mozilla/5.0 (Linux; Android 8.0; Pixel 2 Build/OPD3.170816.012) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3765.0 Mobile Safari/537.36',
822
+ 'viewport': {
823
+ 'width': 731,
824
+ 'height': 411,
825
+ 'deviceScaleFactor': 2.625,
826
+ 'isMobile': true,
827
+ 'hasTouch': true,
828
+ 'isLandscape': true,
829
+ },
830
+ },
831
+ {
832
+ 'name': 'Pixel 2 XL',
833
+ 'userAgent': 'Mozilla/5.0 (Linux; Android 8.0.0; Pixel 2 XL Build/OPD1.170816.004) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3765.0 Mobile Safari/537.36',
834
+ 'viewport': {
835
+ 'width': 411,
836
+ 'height': 823,
837
+ 'deviceScaleFactor': 3.5,
838
+ 'isMobile': true,
839
+ 'hasTouch': true,
840
+ 'isLandscape': false,
841
+ },
842
+ },
843
+ {
844
+ 'name': 'Pixel 2 XL landscape',
845
+ 'userAgent': 'Mozilla/5.0 (Linux; Android 8.0.0; Pixel 2 XL Build/OPD1.170816.004) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3765.0 Mobile Safari/537.36',
846
+ 'viewport': {
847
+ 'width': 823,
848
+ 'height': 411,
849
+ 'deviceScaleFactor': 3.5,
850
+ 'isMobile': true,
851
+ 'hasTouch': true,
852
+ 'isLandscape': true,
853
+ },
854
+ },
855
+ ].map do |json|
856
+ [
857
+ json[:name],
858
+ Puppeteer::Device.new(
859
+ name: json[:name],
860
+ user_agent: json[:userAgent],
861
+ viewport: Puppeteer::Viewport.new(
862
+ width: json[:viewport][:width],
863
+ height: json[:viewport][:height],
864
+ device_scale_factor: json[:viewport][:deviceScaleFactor],
865
+ is_mobile: json[:viewport][:isMobile],
866
+ has_touch: json[:viewport][:hasTouch],
867
+ is_landscape: json[:viewport][:isLandscape],
868
+ ),
869
+ ),
870
+ ]
871
+ end
872
+ ]
873
+
874
+ # Instead of Puppeteer::DEVICES["iPhone X"], Puppeteer::DEVICES["iPad Pro"],
875
+ # - Puppeteer::Devices.iPhone_X
876
+ # - Puppeteer::Devices.iPad_Pro
877
+ # etc...
878
+ class Puppeteer::Devices
879
+ Puppeteer::DEVICES.each do |name, device|
880
+ method_name = name.gsub(/\W/, '_').to_sym
881
+ define_singleton_method(method_name) do
882
+ device
883
+ end
884
+ end
885
+ end