@@ -34,6 +34,7 @@ based on Ferrum and Mechanize.
34
34
* [ Navigation] ( https://github.com/rubycdp/ferrum#navigation )
35
35
* [ Finders] ( https://github.com/rubycdp/ferrum#finders )
36
36
* [ Screenshots] ( https://github.com/rubycdp/ferrum#screenshots )
37
+ * [ Screencast] ( https://github.com/rubycdp/ferrum#screencast )
37
38
* [ Network] ( https://github.com/rubycdp/ferrum#network )
38
39
* [ Downloads] ( https://github.com/rubycdp/ferrum#downloads )
39
40
* [ Proxy] ( https://github.com/rubycdp/ferrum#proxy )
@@ -136,7 +137,7 @@ browser.quit
136
137
In docker as root you must pass the no-sandbox browser option:
137
138
138
139
``` ruby
139
- Ferrum ::Browser .new (browser_options: { ' no-sandbox' : nil })
140
+ Ferrum ::Browser .new (browser_options: { " no-sandbox" : nil })
140
141
```
141
142
142
143
It has also been reported that the Chrome process repeatedly crashes when running inside a Docker container on an M1 Mac preventing Ferrum from working. Ferrum should work as expected when deployed to a Docker container on a non-M1 Mac.
@@ -415,7 +416,7 @@ page.screenshot(path: "google.jpg") # => 30902
415
416
# Save to Base64 the whole page not only viewport and reduce quality
416
417
page.screenshot(full: true , quality: 60 , encoding: :base64 ) # "iVBORw0KGgoAAAANSUhEUgAABAAAAAMACAYAAAC6uhUNAAAAAXNSR0IArs4c6Q...
417
418
# Save on the disk with the selected element in PNG
418
- page.screenshot(path: " google.png" , selector: ' textarea' ) # => 11340
419
+ page.screenshot(path: " google.png" , selector: " textarea" ) # => 11340
419
420
# Save to Base64 with an area of the page in PNG
420
421
page.screenshot(path: " google.png" , area: { x: 0 , y: 0 , width: 400 , height: 300 }) # => 54239
421
422
# Save with specific background color
@@ -459,9 +460,9 @@ page.mhtml(path: "google.mhtml") # => 87742
459
460
460
461
## Screencast
461
462
462
- #### start_screencast(\*\* options) {|data, metadata, session_id| block }
463
+ #### start_screencast(\*\* options) { |data, metadata, session_id| ... }
463
464
464
- Starts sending each frame to the given block.
465
+ Starts sending frames to record screencast to the given block.
465
466
466
467
* options ` Hash `
467
468
* : format ` Symbol ` ` :jpeg ` | ` :png ` The format the image should be returned in.
@@ -473,23 +474,23 @@ Starts sending each frame to the given block.
473
474
* Block inputs:
474
475
* data ` String ` Base64-encoded compressed image.
475
476
* metadata ` Hash ` Screencast frame metadata.
476
- * ' offsetTop' ` Integer ` Top offset in DIP.
477
- * ' pageScaleFactor' ` Integer ` Page scale factor.
478
- * ' deviceWidth' ` Integer ` Device screen width in DIP.
479
- * ' deviceHeight' ` Integer ` Device screen height in DIP.
480
- * ' scrollOffsetX' ` Integer ` Position of horizontal scroll in CSS pixels.
481
- * ' scrollOffsetY' ` Integer ` Position of vertical scroll in CSS pixels.
482
- * ' timestamp' ` Float ` (optional) Frame swap timestamp in seconds since Unix epoch.
477
+ * " offsetTop" ` Integer ` Top offset in DIP.
478
+ * " pageScaleFactor" ` Integer ` Page scale factor.
479
+ * " deviceWidth" ` Integer ` Device screen width in DIP.
480
+ * " deviceHeight" ` Integer ` Device screen height in DIP.
481
+ * " scrollOffsetX" ` Integer ` Position of horizontal scroll in CSS pixels.
482
+ * " scrollOffsetY" ` Integer ` Position of vertical scroll in CSS pixels.
483
+ * " timestamp" ` Float ` (optional) Frame swap timestamp in seconds since Unix epoch.
483
484
* session_id ` Integer ` Frame number.
484
485
485
486
``` ruby
486
- require ' base64'
487
+ require " base64"
487
488
488
489
page.go_to(" https://apple.com/ipad" )
489
490
490
491
page.start_screencast(format: :jpeg , quality: 75 ) do |data , metadata |
491
- timestamp_ms = metadata[' timestamp' ] * 1000
492
- File .binwrite(" image_#{ timestamp_ms.to_i } .jpg" , Base64 .decode64(data))
492
+ timestamp = ( metadata[" timestamp" ] * 1000 ).to_i
493
+ File .binwrite(" image_#{ timestamp } .jpg" , Base64 .decode64(data))
493
494
end
494
495
495
496
sleep 10
@@ -498,14 +499,18 @@ page.stop_screencast
498
499
```
499
500
500
501
> ### 📝 NOTE
501
- >
502
+ >
502
503
> Chrome only sends new frames while page content is changing. For example, if
503
504
> there is an animation or a video on the page, Chrome sends frames at the rate
504
505
> requested. On the other hand, if the page is nothing but a wall of static text,
505
506
> Chrome sends frames while the page renders. Once Chrome has finished rendering
506
507
> the page, it sends no more frames until something changes (e.g., navigating to
507
508
> another location).
508
509
510
+ #### stop_screencast
511
+
512
+ Stops sending frames.
513
+
509
514
## Network
510
515
511
516
` page.network `
@@ -1142,7 +1147,7 @@ Returns the element in which the window is embedded.
1142
1147
1143
1148
#### execution_id : ` Integer `
1144
1149
1145
- Execution context id which is used by JS, each frame has it's own context in
1150
+ Execution context id which is used by JS, each frame has its own context in
1146
1151
which JS evaluates.
1147
1152
1148
1153
#### name : ` String | nil `
@@ -1377,7 +1382,7 @@ Closes browser tabs opened by the `Browser` instance.
1377
1382
1378
1383
``` ruby
1379
1384
# connect to a long-running Chrome process
1380
- browser = Ferrum ::Browser .new (url: ' http://localhost:9222' )
1385
+ browser = Ferrum ::Browser .new (url: " http://localhost:9222" )
1381
1386
1382
1387
browser.go_to(" https://github.com/" )
1383
1388
0 commit comments