puppeteer-ruby 0.31.0 → 0.31.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: 0d7c0b6410629e9119a7f298cc3cecdd6e5640a18fdb944dc53e1b47b4c940b0
4
- data.tar.gz: 4f9bf8f3e4a21a22cb89fcff1927e420bff86cbdec4a3084dbec32669530f03e
3
+ metadata.gz: 4c703eeb4952a1a5102ce3616daee3333747f37d790ad65efb8c1f95ac603f8b
4
+ data.tar.gz: 355cf71106ffce2576aea66680ff5fbb7f35b263da8abce5dd7056ff8fdca019
5
5
  SHA512:
6
- metadata.gz: a13874bd8b09ea00a33516f1237e3a91fcfa6b18795af251f3568dc421f026821325c2e89d2e2ee8e8211b03ed1700d8ba15c3a2d01e733ffaa378a1f97b02bc
7
- data.tar.gz: 3920af1f121788b36e68ee85194da1fe92335abed949610f726d90bd368d492502da10d935087bbadb386eab13f41f259263dd7777eb42d8988fecc3e1fa83da
6
+ metadata.gz: bb2f9d778d6f99c510d78025dba4f39a22ce2cdc8bdb278b6a8911e3498ee94268237fe929a6a0473a7d94a6f8f3839ad43e76a2c2825a54eb9cbc824078a980
7
+ data.tar.gz: 4d40e88f6ec1476854673a3a49c8598e24c5a0bd1de65c4ee09e87ef85773d96b12b415e1f28352b096d3e0fa95ae1267c81fa8ca34f30deaa3fe4308bbd45e0
data/CHANGELOG.md CHANGED
@@ -1,7 +1,13 @@
1
- ### master [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.31.0...master)]
1
+ ### master [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.31.1...master)]
2
2
 
3
3
  * xxx
4
4
 
5
+ ### 0.31.1 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.31.0...0.31.1)]
6
+
7
+ Bugfix:
8
+
9
+ * Fix `Page#pdf` to work on Windows.
10
+
5
11
  ### 0.31.0 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.30.0...0.31.0)]
6
12
 
7
13
  New features:
data/README.md CHANGED
@@ -6,7 +6,7 @@ A Ruby port of [puppeteer](https://pptr.dev/).
6
6
 
7
7
  ![logo](puppeteer-ruby.png)
8
8
 
9
- REMARK: This Gem covers just a part of Puppeteer APIs. Feedbacks and feature requests are welcome :)
9
+ REMARK: This Gem covers just a part of Puppeteer APIs. See [API Coverage list](./docs/api_coverage.md) for detail. Feedbacks and feature requests are welcome :)
10
10
 
11
11
  ## Getting Started
12
12
 
@@ -29,6 +29,8 @@ Or install it yourself as:
29
29
  ### Capture a site
30
30
 
31
31
  ```ruby
32
+ require 'puppeteer'
33
+
32
34
  Puppeteer.launch(headless: false) do |browser|
33
35
  page = browser.pages.first || browser.new_page
34
36
  page.goto("https://github.com/YusukeIwaki")
@@ -66,6 +68,8 @@ end
66
68
  ### Evaluate JavaScript
67
69
 
68
70
  ```ruby
71
+ require 'puppeteer'
72
+
69
73
  Puppeteer.launch do |browser|
70
74
  page = browser.pages.last || browser.new_page
71
75
  page.goto 'https://github.com/YusukeIwaki'
@@ -0,0 +1,359 @@
1
+ # API coverages
2
+ - Puppeteer version: v8.0.0
3
+ - puppeteer-ruby version: 0.31.1
4
+
5
+ ## Puppeteer
6
+
7
+ * ~~clearCustomQueryHandlers~~
8
+ * connect
9
+ * ~~createBrowserFetcher~~
10
+ * ~~customQueryHandlerNames~~
11
+ * defaultArgs => `#default_args`
12
+ * devices
13
+ * ~~errors~~
14
+ * executablePath => `#executable_path`
15
+ * launch
16
+ * ~~networkConditions~~
17
+ * product
18
+ * ~~registerCustomQueryHandler~~
19
+ * ~~unregisterCustomQueryHandler~~
20
+
21
+ ## ~~BrowserFetcher~~
22
+
23
+ * ~~canDownload~~
24
+ * ~~download~~
25
+ * ~~host~~
26
+ * ~~localRevisions~~
27
+ * ~~platform~~
28
+ * ~~product~~
29
+ * ~~remove~~
30
+ * ~~revisionInfo~~
31
+
32
+ ## Browser
33
+
34
+ * browserContexts => `#browser_contexts`
35
+ * close
36
+ * createIncognitoBrowserContext => `#create_incognito_browser_context`
37
+ * defaultBrowserContext => `#default_browser_context`
38
+ * disconnect
39
+ * isConnected => `#connected?`
40
+ * newPage => `#new_page`
41
+ * pages
42
+ * process
43
+ * target
44
+ * targets
45
+ * userAgent => `#user_agent`
46
+ * version
47
+ * waitForTarget => `#wait_for_target`
48
+ * wsEndpoint => `#ws_endpoint`
49
+
50
+ ## BrowserContext
51
+
52
+ * browser
53
+ * clearPermissionOverrides => `#clear_permission_overrides`
54
+ * close
55
+ * isIncognito => `#incognito?`
56
+ * newPage => `#new_page`
57
+ * overridePermissions => `#override_permissions`
58
+ * pages
59
+ * targets
60
+ * waitForTarget => `#wait_for_target`
61
+
62
+ ## Page
63
+
64
+ * $ => `#query_selector`
65
+ * $$ => `#query_selector_all`
66
+ * $$eval => `#eval_on_selector_all`
67
+ * $eval => `#eval_on_selector`
68
+ * $x => `#Sx`
69
+ * accessibility
70
+ * addScriptTag => `#add_script_tag`
71
+ * addStyleTag => `#add_style_tag`
72
+ * authenticate
73
+ * ~~bringToFront~~
74
+ * browser
75
+ * browserContext => `#browser_context`
76
+ * click
77
+ * close
78
+ * content
79
+ * cookies
80
+ * coverage
81
+ * deleteCookie => `#delete_cookie`
82
+ * emulate
83
+ * emulateIdleState => `#emulate_idle_state`
84
+ * ~~emulateMediaFeatures~~
85
+ * emulateMediaType => `#emulate_media_type`
86
+ * ~~emulateNetworkConditions~~
87
+ * emulateTimezone => `#emulate_timezone`
88
+ * ~~emulateVisionDeficiency~~
89
+ * evaluate
90
+ * evaluateHandle => `#evaluate_handle`
91
+ * evaluateOnNewDocument => `#evaluate_on_new_document`
92
+ * ~~exposeFunction~~
93
+ * focus
94
+ * frames
95
+ * goBack => `#go_back`
96
+ * goForward => `#go_forward`
97
+ * goto
98
+ * hover
99
+ * isClosed => `#closed?`
100
+ * isJavaScriptEnabled => `#javascript_enabled?`
101
+ * keyboard
102
+ * mainFrame => `#main_frame`
103
+ * ~~metrics~~
104
+ * mouse
105
+ * pdf
106
+ * queryObjects => `#query_objects`
107
+ * reload
108
+ * screenshot
109
+ * select
110
+ * setBypassCSP => `#bypass_csp=`
111
+ * setCacheEnabled => `#cache_enabled=`
112
+ * setContent => `#content=`
113
+ * setCookie => `#set_cookie`
114
+ * setDefaultNavigationTimeout => `#default_navigation_timeout=`
115
+ * setDefaultTimeout => `#default_timeout=`
116
+ * setExtraHTTPHeaders => `#extra_http_headers=`
117
+ * setGeolocation => `#geolocation=`
118
+ * setJavaScriptEnabled => `#javascript_enabled=`
119
+ * setOfflineMode => `#offline_mode=`
120
+ * setRequestInterception => `#request_interception=`
121
+ * setUserAgent => `#user_agent=`
122
+ * setViewport => `#viewport=`
123
+ * tap
124
+ * target
125
+ * title
126
+ * ~~touchscreen~~
127
+ * ~~tracing~~
128
+ * type => `#type_text`
129
+ * url
130
+ * viewport
131
+ * ~~waitFor~~
132
+ * waitForFileChooser => `#wait_for_file_chooser`
133
+ * waitForFunction => `#wait_for_function`
134
+ * waitForNavigation => `#async_wait_for_navigation`
135
+ * waitForRequest => `#async_wait_for_request`
136
+ * waitForResponse => `#async_wait_for_response`
137
+ * waitForSelector => `#wait_for_selector`
138
+ * waitForTimeout => `#wait_for_timeout`
139
+ * waitForXPath => `#wait_for_xpath`
140
+ * workers
141
+
142
+ ## ~~WebWorker~~
143
+
144
+ * ~~evaluate~~
145
+ * ~~evaluateHandle~~
146
+ * ~~executionContext~~
147
+ * ~~url~~
148
+
149
+ ## ~~Accessibility~~
150
+
151
+ * ~~snapshot~~
152
+
153
+ ## Keyboard
154
+
155
+ * down
156
+ * press
157
+ * sendCharacter => `#send_character`
158
+ * type => `#type_text`
159
+ * up
160
+
161
+ ## Mouse
162
+
163
+ * click
164
+ * down
165
+ * move
166
+ * up
167
+ * wheel
168
+
169
+ ## ~~Touchscreen~~
170
+
171
+ * ~~tap~~
172
+
173
+ ## ~~Tracing~~
174
+
175
+ * ~~start~~
176
+ * ~~stop~~
177
+
178
+ ## FileChooser
179
+
180
+ * accept
181
+ * cancel
182
+ * isMultiple => `#multiple?`
183
+
184
+ ## Dialog
185
+
186
+ * accept
187
+ * defaultValue => `#default_value`
188
+ * dismiss
189
+ * message
190
+ * type
191
+
192
+ ## ConsoleMessage
193
+
194
+ * args
195
+ * location
196
+ * ~~stackTrace~~
197
+ * text
198
+ * ~~type~~
199
+
200
+ ## Frame
201
+
202
+ * $ => `#query_selector`
203
+ * $$ => `#query_selector_all`
204
+ * $$eval => `#eval_on_selector_all`
205
+ * $eval => `#eval_on_selector`
206
+ * $x => `#Sx`
207
+ * addScriptTag => `#add_script_tag`
208
+ * addStyleTag => `#add_style_tag`
209
+ * childFrames => `#child_frames`
210
+ * click
211
+ * content
212
+ * evaluate
213
+ * evaluateHandle => `#evaluate_handle`
214
+ * executionContext => `#execution_context`
215
+ * focus
216
+ * goto
217
+ * hover
218
+ * isDetached => `#detached?`
219
+ * name
220
+ * parentFrame => `#parent_frame`
221
+ * select
222
+ * setContent => `#set_content`
223
+ * tap
224
+ * title
225
+ * type => `#type_text`
226
+ * url
227
+ * ~~waitFor~~
228
+ * waitForFunction => `#wait_for_function`
229
+ * waitForNavigation => `#async_wait_for_navigation`
230
+ * waitForSelector => `#wait_for_selector`
231
+ * waitForTimeout => `#wait_for_timeout`
232
+ * waitForXPath => `#wait_for_xpath`
233
+
234
+ ## ExecutionContext
235
+
236
+ * evaluate
237
+ * evaluateHandle => `#evaluate_handle`
238
+ * frame
239
+ * ~~queryObjects~~
240
+
241
+ ## JSHandle
242
+
243
+ * asElement => `#as_element`
244
+ * dispose
245
+ * evaluate
246
+ * evaluateHandle => `#evaluate_handle`
247
+ * executionContext => `#execution_context`
248
+ * getProperties => `#properties`
249
+ * getProperty => `#[]`
250
+ * jsonValue => `#json_value`
251
+
252
+ ## ElementHandle
253
+
254
+ * $ => `#query_selector`
255
+ * $$ => `#query_selector_all`
256
+ * $$eval => `#eval_on_selector_all`
257
+ * $eval => `#eval_on_selector`
258
+ * $x => `#Sx`
259
+ * asElement => `#as_element`
260
+ * boundingBox => `#bounding_box`
261
+ * boxModel => `#box_model`
262
+ * click
263
+ * contentFrame => `#content_frame`
264
+ * dispose
265
+ * evaluate
266
+ * evaluateHandle => `#evaluate_handle`
267
+ * executionContext => `#execution_context`
268
+ * focus
269
+ * getProperties => `#properties`
270
+ * getProperty => `#[]`
271
+ * hover
272
+ * isIntersectingViewport => `#intersecting_viewport?`
273
+ * jsonValue => `#json_value`
274
+ * press
275
+ * screenshot
276
+ * select
277
+ * tap
278
+ * ~~toString~~
279
+ * type => `#type_text`
280
+ * uploadFile => `#upload_file`
281
+
282
+ ## ~~HTTPRequest~~
283
+
284
+ * ~~abort~~
285
+ * ~~continue~~
286
+ * ~~failure~~
287
+ * ~~frame~~
288
+ * ~~headers~~
289
+ * ~~isNavigationRequest~~
290
+ * ~~method~~
291
+ * ~~postData~~
292
+ * ~~redirectChain~~
293
+ * ~~resourceType~~
294
+ * ~~respond~~
295
+ * ~~response~~
296
+ * ~~url~~
297
+
298
+ ## ~~HTTPResponse~~
299
+
300
+ * ~~buffer~~
301
+ * ~~frame~~
302
+ * ~~fromCache~~
303
+ * ~~fromServiceWorker~~
304
+ * ~~headers~~
305
+ * ~~json~~
306
+ * ~~ok~~
307
+ * ~~remoteAddress~~
308
+ * ~~request~~
309
+ * ~~securityDetails~~
310
+ * ~~status~~
311
+ * ~~statusText~~
312
+ * ~~text~~
313
+ * ~~url~~
314
+
315
+ ## ~~SecurityDetails~~
316
+
317
+ * ~~issuer~~
318
+ * ~~protocol~~
319
+ * ~~subjectAlternativeNames~~
320
+ * ~~subjectName~~
321
+ * ~~validFrom~~
322
+ * ~~validTo~~
323
+
324
+ ## Target
325
+
326
+ * browser
327
+ * browserContext => `#browser_context`
328
+ * createCDPSession => `#create_cdp_session`
329
+ * opener
330
+ * page
331
+ * type
332
+ * url
333
+ * ~~worker~~
334
+
335
+ ## CDPSession
336
+
337
+ * detach
338
+ * send
339
+
340
+ ## ~~Coverage~~
341
+
342
+ * ~~startCSSCoverage~~
343
+ * ~~startJSCoverage~~
344
+ * ~~stopCSSCoverage~~
345
+ * ~~stopJSCoverage~~
346
+
347
+ ## TimeoutError
348
+
349
+
350
+ ## ~~EventEmitter~~
351
+
352
+ * ~~addListener~~
353
+ * ~~emit~~
354
+ * ~~listenerCount~~
355
+ * ~~off~~
356
+ * ~~on~~
357
+ * ~~once~~
358
+ * ~~removeAllListeners~~
359
+ * ~~removeListener~~
data/lib/puppeteer.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'concurrent'
2
2
 
3
- class Puppeteer; end
3
+ module Puppeteer; end
4
4
 
5
5
  require 'puppeteer/env'
6
6
 
@@ -43,6 +43,7 @@ require 'puppeteer/lifecycle_watcher'
43
43
  require 'puppeteer/mouse'
44
44
  require 'puppeteer/network_manager'
45
45
  require 'puppeteer/page'
46
+ require 'puppeteer/puppeteer'
46
47
  require 'puppeteer/query_handler_manager'
47
48
  require 'puppeteer/remote_object'
48
49
  require 'puppeteer/request'
@@ -59,9 +60,9 @@ require 'puppeteer/web_socket_transport'
59
60
  require 'puppeteer/element_handle'
60
61
 
61
62
  # ref: https://github.com/puppeteer/puppeteer/blob/master/lib/Puppeteer.js
62
- class Puppeteer
63
- def self.method_missing(method, *args, **kwargs, &block)
64
- @puppeteer ||= Puppeteer.new(
63
+ module Puppeteer
64
+ module_function def method_missing(method, *args, **kwargs, &block)
65
+ @puppeteer ||= ::Puppeteer::Puppeteer.new(
65
66
  project_root: __dir__,
66
67
  preferred_revision: '706915',
67
68
  is_puppeteer_core: true,
@@ -73,167 +74,4 @@ class Puppeteer
73
74
  @puppeteer.public_send(method, *args, **kwargs, &block)
74
75
  end
75
76
  end
76
-
77
- # @param project_root [String]
78
- # @param prefereed_revision [String]
79
- # @param is_puppeteer_core [String]
80
- def initialize(project_root:, preferred_revision:, is_puppeteer_core:)
81
- @project_root = project_root
82
- @preferred_revision = preferred_revision
83
- @is_puppeteer_core = is_puppeteer_core
84
- end
85
-
86
- # @param product [String]
87
- # @param executable_path [String]
88
- # @param ignore_default_args [Array<String>|nil]
89
- # @param handle_SIGINT [Boolean]
90
- # @param handle_SIGTERM [Boolean]
91
- # @param handle_SIGHUP [Boolean]
92
- # @param timeout [Integer]
93
- # @param dumpio [Boolean]
94
- # @param env [Hash]
95
- # @param pipe [Boolean]
96
- # @param args [Array<String>]
97
- # @param user_data_dir [String]
98
- # @param devtools [Boolean]
99
- # @param headless [Boolean]
100
- # @param ignore_https_errors [Boolean]
101
- # @param default_viewport [Puppeteer::Viewport|nil]
102
- # @param slow_mo [Integer]
103
- # @return [Puppeteer::Browser]
104
- def launch(
105
- product: nil,
106
- executable_path: nil,
107
- ignore_default_args: nil,
108
- handle_SIGINT: nil,
109
- handle_SIGTERM: nil,
110
- handle_SIGHUP: nil,
111
- timeout: nil,
112
- dumpio: nil,
113
- env: nil,
114
- pipe: nil,
115
- args: nil,
116
- user_data_dir: nil,
117
- devtools: nil,
118
- headless: nil,
119
- ignore_https_errors: nil,
120
- default_viewport: nil,
121
- slow_mo: nil
122
- )
123
- options = {
124
- executable_path: executable_path,
125
- ignore_default_args: ignore_default_args,
126
- handle_SIGINT: handle_SIGINT,
127
- handle_SIGTERM: handle_SIGTERM,
128
- handle_SIGHUP: handle_SIGHUP,
129
- timeout: timeout,
130
- dumpio: dumpio,
131
- env: env,
132
- pipe: pipe,
133
- args: args,
134
- user_data_dir: user_data_dir,
135
- devtools: devtools,
136
- headless: headless,
137
- ignore_https_errors: ignore_https_errors,
138
- default_viewport: default_viewport,
139
- slow_mo: slow_mo,
140
- }
141
-
142
- @product_name ||= product
143
- browser = launcher.launch(options)
144
- if block_given?
145
- begin
146
- yield(browser)
147
- ensure
148
- browser.close
149
- end
150
- else
151
- browser
152
- end
153
- end
154
-
155
- # @param browser_ws_endpoint [String]
156
- # @param browser_url [String]
157
- # @param transport [Puppeteer::WebSocketTransport]
158
- # @param ignore_https_errors [Boolean]
159
- # @param default_viewport [Puppeteer::Viewport|nil]
160
- # @param slow_mo [Integer]
161
- # @return [Puppeteer::Browser]
162
- def connect(
163
- browser_ws_endpoint: nil,
164
- browser_url: nil,
165
- transport: nil,
166
- ignore_https_errors: nil,
167
- default_viewport: nil,
168
- slow_mo: nil
169
- )
170
- options = {
171
- browser_ws_endpoint: browser_ws_endpoint,
172
- browser_url: browser_url,
173
- transport: transport,
174
- ignore_https_errors: ignore_https_errors,
175
- default_viewport: default_viewport,
176
- slow_mo: slow_mo,
177
- }.compact
178
- browser = launcher.connect(options)
179
- if block_given?
180
- begin
181
- yield(browser)
182
- ensure
183
- browser.disconnect
184
- end
185
- else
186
- browser
187
- end
188
- end
189
-
190
- # @return [String]
191
- def executable_path
192
- launcher.executable_path
193
- end
194
-
195
- private def launcher
196
- @launcher ||= Puppeteer::Launcher.new(
197
- project_root: @project_root,
198
- preferred_revision: @preferred_revision,
199
- is_puppeteer_core: @is_puppeteer_core,
200
- product: @product_name,
201
- )
202
- end
203
-
204
- # @return [String]
205
- def product
206
- launcher.product
207
- end
208
-
209
- # @return [Puppeteer::Devices]
210
- def devices
211
- Puppeteer::Devices
212
- end
213
-
214
- # # @return {Object}
215
- # def errors
216
- # # ???
217
- # end
218
-
219
- # @param args [Array<String>]
220
- # @param user_data_dir [String]
221
- # @param devtools [Boolean]
222
- # @param headless [Boolean]
223
- # @return [Array<String>]
224
- def default_args(args: nil, user_data_dir: nil, devtools: nil, headless: nil)
225
- options = {
226
- args: args,
227
- user_data_dir: user_data_dir,
228
- devtools: devtools,
229
- headless: headless,
230
- }.compact
231
- launcher.default_args(options)
232
- end
233
-
234
- # @param {!BrowserFetcher.Options=} options
235
- # @return {!BrowserFetcher}
236
- def createBrowserFetcher(options = {})
237
- BrowserFetcher.new(@project_root, options)
238
- end
239
77
  end
@@ -273,6 +273,16 @@ class Puppeteer::Connection
273
273
  def create_session(target_info)
274
274
  result = send_message('Target.attachToTarget', targetId: target_info.target_id, flatten: true)
275
275
  session_id = result['sessionId']
276
- @sessions[session_id]
276
+
277
+ # Target.attachedToTarget is often notified after the result of Target.attachToTarget.
278
+ # D, [2020-04-04T23:04:30.736311 #91875] DEBUG -- : RECV << {"id"=>2, "result"=>{"sessionId"=>"DA002F8A95B04710502CB40D8430B95A"}}
279
+ # D, [2020-04-04T23:04:30.736649 #91875] DEBUG -- : RECV << {"method"=>"Target.attachedToTarget", "params"=>{"sessionId"=>"DA002F8A95B04710502CB40D8430B95A", "targetInfo"=>{"targetId"=>"EBAB949A7DE63F12CB94268AD3A9976B", "type"=>"page", "title"=>"about:blank", "url"=>"about:blank", "attached"=>true, "browserContextId"=>"46D23767E9B79DD9E589101121F6DADD"}, "waitingForDebugger"=>false}}
280
+ # So we have to wait for "Target.attachedToTarget" a bit.
281
+ 20.times do
282
+ if @sessions[session_id]
283
+ return @sessions[session_id]
284
+ end
285
+ sleep 0.1
286
+ end
277
287
  end
278
288
  end
data/lib/puppeteer/env.rb CHANGED
@@ -20,8 +20,8 @@ class Puppeteer::Env
20
20
  end
21
21
  end
22
22
 
23
- class Puppeteer
24
- def self.env
25
- Puppeteer::Env.new
23
+ module Puppeteer
24
+ module_function def env
25
+ ::Puppeteer::Env.new
26
26
  end
27
27
  end
@@ -202,6 +202,7 @@ class Puppeteer::Page
202
202
  end
203
203
 
204
204
  attr_reader :javascript_enabled, :target
205
+ alias_method :javascript_enabled?, :javascript_enabled
205
206
 
206
207
  def browser
207
208
  @target.browser
@@ -988,7 +989,7 @@ class Puppeteer::Page
988
989
 
989
990
  def read
990
991
  out = StringIO.new
991
- File.open(@path, 'w') do |file|
992
+ File.open(@path, 'wb') do |file|
992
993
  eof = false
993
994
  until eof
994
995
  response = @client.send_message('IO.read', handle: @handle)
@@ -0,0 +1,164 @@
1
+ class Puppeteer::Puppeteer
2
+ # @param project_root [String]
3
+ # @param prefereed_revision [String]
4
+ # @param is_puppeteer_core [String]
5
+ def initialize(project_root:, preferred_revision:, is_puppeteer_core:)
6
+ @project_root = project_root
7
+ @preferred_revision = preferred_revision
8
+ @is_puppeteer_core = is_puppeteer_core
9
+ end
10
+
11
+ # @param product [String]
12
+ # @param executable_path [String]
13
+ # @param ignore_default_args [Array<String>|nil]
14
+ # @param handle_SIGINT [Boolean]
15
+ # @param handle_SIGTERM [Boolean]
16
+ # @param handle_SIGHUP [Boolean]
17
+ # @param timeout [Integer]
18
+ # @param dumpio [Boolean]
19
+ # @param env [Hash]
20
+ # @param pipe [Boolean]
21
+ # @param args [Array<String>]
22
+ # @param user_data_dir [String]
23
+ # @param devtools [Boolean]
24
+ # @param headless [Boolean]
25
+ # @param ignore_https_errors [Boolean]
26
+ # @param default_viewport [Puppeteer::Viewport|nil]
27
+ # @param slow_mo [Integer]
28
+ # @return [Puppeteer::Browser]
29
+ def launch(
30
+ product: nil,
31
+ executable_path: nil,
32
+ ignore_default_args: nil,
33
+ handle_SIGINT: nil,
34
+ handle_SIGTERM: nil,
35
+ handle_SIGHUP: nil,
36
+ timeout: nil,
37
+ dumpio: nil,
38
+ env: nil,
39
+ pipe: nil,
40
+ args: nil,
41
+ user_data_dir: nil,
42
+ devtools: nil,
43
+ headless: nil,
44
+ ignore_https_errors: nil,
45
+ default_viewport: nil,
46
+ slow_mo: nil
47
+ )
48
+ options = {
49
+ executable_path: executable_path,
50
+ ignore_default_args: ignore_default_args,
51
+ handle_SIGINT: handle_SIGINT,
52
+ handle_SIGTERM: handle_SIGTERM,
53
+ handle_SIGHUP: handle_SIGHUP,
54
+ timeout: timeout,
55
+ dumpio: dumpio,
56
+ env: env,
57
+ pipe: pipe,
58
+ args: args,
59
+ user_data_dir: user_data_dir,
60
+ devtools: devtools,
61
+ headless: headless,
62
+ ignore_https_errors: ignore_https_errors,
63
+ default_viewport: default_viewport,
64
+ slow_mo: slow_mo,
65
+ }
66
+
67
+ @product_name ||= product
68
+ browser = launcher.launch(options)
69
+ if block_given?
70
+ begin
71
+ yield(browser)
72
+ ensure
73
+ browser.close
74
+ end
75
+ else
76
+ browser
77
+ end
78
+ end
79
+
80
+ # @param browser_ws_endpoint [String]
81
+ # @param browser_url [String]
82
+ # @param transport [Puppeteer::WebSocketTransport]
83
+ # @param ignore_https_errors [Boolean]
84
+ # @param default_viewport [Puppeteer::Viewport|nil]
85
+ # @param slow_mo [Integer]
86
+ # @return [Puppeteer::Browser]
87
+ def connect(
88
+ browser_ws_endpoint: nil,
89
+ browser_url: nil,
90
+ transport: nil,
91
+ ignore_https_errors: nil,
92
+ default_viewport: nil,
93
+ slow_mo: nil
94
+ )
95
+ options = {
96
+ browser_ws_endpoint: browser_ws_endpoint,
97
+ browser_url: browser_url,
98
+ transport: transport,
99
+ ignore_https_errors: ignore_https_errors,
100
+ default_viewport: default_viewport,
101
+ slow_mo: slow_mo,
102
+ }.compact
103
+ browser = launcher.connect(options)
104
+ if block_given?
105
+ begin
106
+ yield(browser)
107
+ ensure
108
+ browser.disconnect
109
+ end
110
+ else
111
+ browser
112
+ end
113
+ end
114
+
115
+ # @return [String]
116
+ def executable_path
117
+ launcher.executable_path
118
+ end
119
+
120
+ private def launcher
121
+ @launcher ||= Puppeteer::Launcher.new(
122
+ project_root: @project_root,
123
+ preferred_revision: @preferred_revision,
124
+ is_puppeteer_core: @is_puppeteer_core,
125
+ product: @product_name,
126
+ )
127
+ end
128
+
129
+ # @return [String]
130
+ def product
131
+ launcher.product
132
+ end
133
+
134
+ # @return [Puppeteer::Devices]
135
+ def devices
136
+ Puppeteer::Devices
137
+ end
138
+
139
+ # # @return {Object}
140
+ # def errors
141
+ # # ???
142
+ # end
143
+
144
+ # @param args [Array<String>]
145
+ # @param user_data_dir [String]
146
+ # @param devtools [Boolean]
147
+ # @param headless [Boolean]
148
+ # @return [Array<String>]
149
+ def default_args(args: nil, user_data_dir: nil, devtools: nil, headless: nil)
150
+ options = {
151
+ args: args,
152
+ user_data_dir: user_data_dir,
153
+ devtools: devtools,
154
+ headless: headless,
155
+ }.compact
156
+ launcher.default_args(options)
157
+ end
158
+
159
+ # @param {!BrowserFetcher.Options=} options
160
+ # @return {!BrowserFetcher}
161
+ def createBrowserFetcher(options = {})
162
+ BrowserFetcher.new(@project_root, options)
163
+ end
164
+ end
@@ -1,3 +1,3 @@
1
- class Puppeteer
2
- VERSION = '0.31.0'
1
+ module Puppeteer
2
+ VERSION = '0.31.1'
3
3
  end
@@ -12,7 +12,9 @@ Gem::Specification.new do |spec|
12
12
  spec.homepage = 'https://github.com/YusukeIwaki/puppeteer-ruby'
13
13
 
14
14
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
15
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
15
+ `git ls-files -z`.split("\x0").reject do |f|
16
+ f.match(%r{^(test|spec|features)/}) || f.include?(".git") || f.include?(".circleci") || f.start_with?("development/")
17
+ end
16
18
  end
17
19
  spec.bindir = 'exe'
18
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
@@ -23,6 +25,7 @@ Gem::Specification.new do |spec|
23
25
  spec.add_dependency 'mime-types', '>= 3.0'
24
26
  spec.add_development_dependency 'bundler', '~> 2.2.3'
25
27
  spec.add_development_dependency 'chunky_png'
28
+ spec.add_development_dependency 'dry-inflector'
26
29
  spec.add_development_dependency 'pry-byebug'
27
30
  spec.add_development_dependency 'rake', '~> 13.0.3'
28
31
  spec.add_development_dependency 'rspec', '~> 3.10.0 '
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.31.0
4
+ version: 0.31.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - YusukeIwaki
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-18 00:00:00.000000000 Z
11
+ date: 2021-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: dry-inflector
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: pry-byebug
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -213,17 +227,8 @@ executables: []
213
227
  extensions: []
214
228
  extra_rdoc_files: []
215
229
  files:
216
- - ".circleci/config.yml"
217
- - ".github/ISSUE_TEMPLATE/bug_report.md"
218
- - ".github/ISSUE_TEMPLATE/feature_request.md"
219
- - ".github/stale.yml"
220
- - ".github/workflows/docs.yml"
221
- - ".github/workflows/reviewdog.yml"
222
- - ".github/workflows/windows_check.yml"
223
- - ".gitignore"
224
230
  - ".rspec"
225
231
  - ".rubocop.yml"
226
- - ".travis.yml"
227
232
  - CHANGELOG.md
228
233
  - Dockerfile
229
234
  - Gemfile
@@ -232,6 +237,7 @@ files:
232
237
  - bin/console
233
238
  - bin/setup
234
239
  - docker-compose.yml
240
+ - docs/api_coverage.md
235
241
  - lib/puppeteer.rb
236
242
  - lib/puppeteer/aria_query_handler.rb
237
243
  - lib/puppeteer/browser.rb
@@ -283,6 +289,7 @@ files:
283
289
  - lib/puppeteer/page/pdf_options.rb
284
290
  - lib/puppeteer/page/screenshot_options.rb
285
291
  - lib/puppeteer/page/screenshot_task_queue.rb
292
+ - lib/puppeteer/puppeteer.rb
286
293
  - lib/puppeteer/query_handler_manager.rb
287
294
  - lib/puppeteer/remote_object.rb
288
295
  - lib/puppeteer/request.rb
data/.circleci/config.yml DELETED
@@ -1,92 +0,0 @@
1
- version: 2.1
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
15
-
16
- jobs:
17
- rspec_chrome_ruby2_6:
18
- docker:
19
- - image: circleci/ruby:2.6.6-buster-node-browsers
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-buster-node-browsers
30
- <<: *rspec_chrome_job
31
-
32
- rspec_firefox:
33
- docker:
34
- - image: circleci/ruby:2.7.2-buster-node-browsers
35
- steps:
36
- - checkout
37
- - run:
38
- command: gem install bundler:2.2.3 && bundle install
39
- - run:
40
- name: install firefox-nightly
41
- command: |
42
- wget -O nightly.tar.bz2 "https://download.mozilla.org/?product=firefox-nightly-latest-ssl&os=linux64&lang=en-US"
43
- tar xf nightly.tar.bz2
44
- - run:
45
- name: rspec
46
- command: |
47
- DEBUG=1 PUPPETEER_PRODUCT_RSPEC=firefox \
48
- PUPPETEER_EXECUTABLE_PATH_RSPEC=${CIRCLE_WORKING_DIRECTORY/#\~/$HOME}/firefox/firefox \
49
- bundle exec rspec --profile 10 \
50
- --format RspecJunitFormatter \
51
- --out test_results/rspec.xml \
52
- --format documentation spec/integration/
53
-
54
- deploy:
55
- docker:
56
- - image: circleci/ruby:2.6.3-stretch-node
57
- steps:
58
- - checkout
59
- - run:
60
- command: gem install bundler:2.2.3 && bundle install
61
- - run:
62
- name: rake build
63
- command: rake build
64
- - run:
65
- name: setup API key
66
- command: |
67
- mkdir -p ~/.gem/
68
- echo "---" > ~/.gem/credentials
69
- echo ":rubygems_api_key: $RUBYGEMS_API_KEY" >> ~/.gem/credentials
70
- chmod 600 ~/.gem/credentials
71
- - run:
72
- name: Check Puppeteer::version
73
- command: bundle exec ruby -e 'raise "invalid Puppeteer::VERSION" unless Puppeteer::VERSION == ENV["CIRCLE_TAG"]'
74
- - run:
75
- name: gem push
76
- command: gem push pkg/puppeteer-ruby-$CIRCLE_TAG.gem
77
-
78
- workflows:
79
- ci:
80
- jobs:
81
- - rspec_chrome_ruby2_6
82
- - rspec_chrome_ruby2_7
83
- - rspec_chrome_ruby3_0
84
- - rspec_firefox
85
- rubygems-deploy:
86
- jobs:
87
- - deploy:
88
- filters:
89
- tags:
90
- only: /^[0-9]\.[0-9]+\.[0-9].*/
91
- branches:
92
- ignore: /.*/
@@ -1,17 +0,0 @@
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`
@@ -1,15 +0,0 @@
1
- ---
2
- name: Feature request
3
- about: Request a new feature for playwright-ruby-client
4
- title: ''
5
- labels: ''
6
- assignees: ''
7
-
8
- ---
9
-
10
- ### Simple description about the feature
11
-
12
-
13
- ### Usecase / Motivation
14
-
15
- <!-- Describe why the feature helps. -->
data/.github/stale.yml DELETED
@@ -1,16 +0,0 @@
1
- # Number of days of inactivity before an issue becomes stale
2
- daysUntilStale: 14
3
- # Number of days of inactivity before a stale issue is closed
4
- daysUntilClose: 7
5
- # Issues with these labels will never be considered stale
6
- exemptLabels:
7
- - security
8
- # Label to use when marking an issue as stale
9
- staleLabel: inactive
10
- # Comment to post when marking an issue as stale. Set to `false` to disable
11
- markComment: >
12
- This issue has been automatically marked as stale because it has not had
13
- recent activity. It will be closed if no further activity occurs. Thank you
14
- for your contributions.
15
- # Comment to post when closing a stale issue. Set to `false` to disable
16
- closeComment: false
@@ -1,45 +0,0 @@
1
- name: update docs
2
- on:
3
- push:
4
- branches:
5
- - master
6
-
7
- jobs:
8
- update-docs:
9
- name: update docs
10
- runs-on: ubuntu-latest
11
-
12
- steps:
13
- - name: Checkout
14
- uses: actions/checkout@v2
15
-
16
- - name: Set up Ruby
17
- uses: ruby/setup-ruby@v1
18
- with:
19
- ruby-version: 2.7
20
-
21
- - name: Install dependencies
22
- run: |
23
- gem uninstall bundler
24
- gem install bundler -v 2.2.3
25
- bundle install
26
-
27
- - name: Deploy Configuration
28
- run: |
29
- mkdir ~/.ssh
30
- ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
31
- echo "${{ secrets.DOCS_DEPLOY_SSH_RSA }}" | base64 -d > ~/.ssh/id_rsa
32
- chmod 400 ~/.ssh/id_rsa
33
-
34
- - name: Build and Push
35
- run: |
36
- git clone git@github.com:YusukeIwaki/puppeteer-ruby-docs.git docs
37
- rm -rf docs/*
38
- bundle exec yardoc -o docs
39
- cp puppeteer-ruby.png docs/
40
- cd docs/
41
- git add -A
42
- git config user.name github
43
- git config user.email github@example.com
44
- git commit -m ${{ github.sha }}
45
- git push origin master
@@ -1,18 +0,0 @@
1
- name: reviewdog
2
- on: [pull_request]
3
- jobs:
4
- rubocop:
5
- name: runner / rubocop
6
- runs-on: ubuntu-latest
7
- steps:
8
- - name: Check out code
9
- uses: actions/checkout@v2
10
- - uses: ruby/setup-ruby@v1
11
- with:
12
- ruby-version: 3.0.0
13
- - name: rubocop
14
- uses: reviewdog/action-rubocop@v1
15
- with:
16
- github_token: ${{ secrets.github_token }}
17
- reporter: github-pr-review
18
- rubocop_version: 1.11.0
@@ -1,40 +0,0 @@
1
- name: Windows check
2
- on: [pull_request]
3
- jobs:
4
- windows_edge_rspec:
5
- name: RSpec on Windows / Edge
6
- runs-on: windows-latest
7
- steps:
8
- - name: Check out code
9
- uses: actions/checkout@v2
10
- - uses: ruby/setup-ruby@v1
11
- with:
12
- ruby-version: 3.0.0
13
- - name: Install dependencies
14
- run: |
15
- gem uninstall bundler
16
- gem install bundler -v 2.2.3
17
- bundle install
18
- - uses: browser-actions/setup-edge@latest
19
- - name: Check example
20
- run: bundle exec rspec spec/integration/example_spec.rb
21
- env:
22
- PUPPETEER_EXECUTABLE_PATH_RSPEC: 'C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe'
23
-
24
- windows_chrome_rspec:
25
- name: RSpec on Windows / Chrome
26
- runs-on: windows-latest
27
- steps:
28
- - name: Check out code
29
- uses: actions/checkout@v2
30
- - uses: ruby/setup-ruby@v1
31
- with:
32
- ruby-version: 3.0.0
33
- - name: Install dependencies
34
- run: |
35
- gem uninstall bundler
36
- gem install bundler -v 2.2.3
37
- bundle install
38
- - uses: browser-actions/setup-chrome@latest
39
- - name: Check example
40
- run: bundle exec rspec spec/integration/example_spec.rb
data/.gitignore DELETED
@@ -1,21 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
-
10
- /.vscode
11
- /Gemfile.lock
12
- /vendor/bundle
13
-
14
- # rspec failure tracking
15
- .rspec_status
16
-
17
- # RubyMine
18
- /.idea/
19
- /.rakeTasks
20
-
21
- diff-*.png
data/.travis.yml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- sudo: false
3
- language: ruby
4
- cache: bundler
5
- rvm:
6
- - 2.6.3
7
- before_install: gem install bundler -v 1.17.2