1
1
package com .github .kklisura .cdt .examples ;
2
2
3
3
import com .github .kklisura .cdt .launch .ChromeLauncher ;
4
+ import com .github .kklisura .cdt .protocol .commands .Emulation ;
4
5
import com .github .kklisura .cdt .protocol .commands .Page ;
5
6
import com .github .kklisura .cdt .protocol .types .page .CaptureScreenshotFormat ;
6
7
import com .github .kklisura .cdt .protocol .types .page .LayoutMetrics ;
7
8
import com .github .kklisura .cdt .protocol .types .page .Viewport ;
8
9
import com .github .kklisura .cdt .services .ChromeDevToolsService ;
9
10
import com .github .kklisura .cdt .services .ChromeService ;
10
11
import com .github .kklisura .cdt .services .types .ChromeTab ;
12
+
11
13
import java .io .File ;
12
14
import java .io .FileOutputStream ;
13
15
import java .io .IOException ;
21
23
*/
22
24
public class FullPageScreenshotExample {
23
25
24
- private static void captureFullPageScreenshot (Page page , String outputFilename ) {
26
+ private static void captureFullPageScreenshot (ChromeDevToolsService devToolsService , Page page , String outputFilename ) {
25
27
final LayoutMetrics layoutMetrics = page .getLayoutMetrics ();
26
28
29
+ final double width = layoutMetrics .getContentSize ().getWidth ();
30
+ final double height = layoutMetrics .getContentSize ().getHeight ();
31
+
32
+ final Emulation emulation = devToolsService .getEmulation ();
33
+ emulation .setDeviceMetricsOverride (Double .valueOf (width ).intValue (), Double .valueOf (height ).intValue (), 1.0d , Boolean .FALSE );
34
+
27
35
Viewport viewport = new Viewport ();
28
36
viewport .setScale (1d );
29
37
@@ -32,8 +40,8 @@ private static void captureFullPageScreenshot(Page page, String outputFilename)
32
40
viewport .setY (0d );
33
41
34
42
// Set a width, height of a page to take screenshot at
35
- viewport .setWidth (layoutMetrics . getContentSize (). getWidth () );
36
- viewport .setHeight (layoutMetrics . getContentSize (). getHeight () );
43
+ viewport .setWidth (width );
44
+ viewport .setHeight (height );
37
45
38
46
dump (
39
47
outputFilename ,
@@ -60,7 +68,7 @@ public static void main(String[] args) {
60
68
event -> {
61
69
System .out .println ("Taking screenshot..." );
62
70
63
- captureFullPageScreenshot (page , "screenshot.png" );
71
+ captureFullPageScreenshot (devToolsService , page , "screenshot.png" );
64
72
65
73
System .out .println ("Done!" );
66
74
0 commit comments