File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change 8
8
- ` Ferrum::Mouse#scroll_by ` to be able to scroll by, as alternative to ` scroll_to ` [ #514 ]
9
9
- ` Ferrum::Network::Exchange#unknown ` determines if the exchange is in an unknown state, meaning that browser might not return info about it [ #426 ]
10
10
- ` Ferrum::Network::Exchange#loader_id ` returns loader id [ #426 ]
11
+ - ` Ferrum::Browser#debug ` opens headless session in the browser devtools frontend [ #519 ]
11
12
12
13
### Changed
13
14
Original file line number Diff line number Diff line change @@ -245,6 +245,24 @@ def version
245
245
VersionInfo . new ( command ( "Browser.getVersion" ) )
246
246
end
247
247
248
+ #
249
+ # Opens headless session in the browser devtools frontend.
250
+ #
251
+ # @return [void]
252
+ #
253
+ # @since 0.16
254
+ #
255
+ def debug ( bind = nil )
256
+ ::Process . spawn ( process . path , debug_url )
257
+
258
+ bind ||= binding
259
+ if bind . respond_to? ( :pry )
260
+ Pry . start ( bind )
261
+ else
262
+ bind . irb
263
+ end
264
+ end
265
+
248
266
private
249
267
250
268
def start
@@ -262,5 +280,18 @@ def start
262
280
raise
263
281
end
264
282
end
283
+
284
+ def debug_url
285
+ response = JSON . parse ( Net ::HTTP . get ( URI ( build_remote_debug_url ( path : "/json" ) ) ) )
286
+
287
+ devtools_frontend_path = response [ 0 ] &.[]( "devtoolsFrontendUrl" )
288
+ raise "Could not generate debug url for remote debugging session" unless devtools_frontend_path
289
+
290
+ build_remote_debug_url ( path : devtools_frontend_path )
291
+ end
292
+
293
+ def build_remote_debug_url ( path :)
294
+ "http://#{ process . host } :#{ process . port } #{ path } "
295
+ end
265
296
end
266
297
end
You can’t perform that action at this time.
0 commit comments