File tree Expand file tree Collapse file tree
main/java/com/microsoft/playwright
test/java/com/microsoft/playwright
tools/api-generator/src/main/java/com/microsoft/playwright/tools Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ Playwright is a Java library to automate [Chromium](https://www.chromium.org/Hom
1212| :--- | :---: | :---: | :---: |
1313| Chromium <!-- GEN:chromium-version --> 148.0.7778.96<!-- GEN:stop --> | :white_check_mark : | :white_check_mark : | :white_check_mark : |
1414| WebKit <!-- GEN:webkit-version --> 26.4<!-- GEN:stop --> | ✅ | ✅ | ✅ |
15- | Firefox <!-- GEN:firefox-version --> 150.0.1 <!-- GEN:stop --> | :white_check_mark : | :white_check_mark : | :white_check_mark : |
15+ | Firefox <!-- GEN:firefox-version --> 150.0.2 <!-- GEN:stop --> | :white_check_mark : | :white_check_mark : | :white_check_mark : |
1616
1717## Documentation
1818
Original file line number Diff line number Diff line change 2727public interface Screencast {
2828 class StartOptions {
2929 /**
30- * Callback that receives JPEG-encoded frame data.
30+ * Callback that receives JPEG-encoded frame data along with the page viewport size at the time of capture .
3131 */
3232 public Consumer <ScreencastFrame > onFrame ;
3333 /**
@@ -40,7 +40,7 @@ class StartOptions {
4040 public Integer quality ;
4141
4242 /**
43- * Callback that receives JPEG-encoded frame data.
43+ * Callback that receives JPEG-encoded frame data along with the page viewport size at the time of capture .
4444 */
4545 public StartOptions setOnFrame (Consumer <ScreencastFrame > onFrame ) {
4646 this .onFrame = onFrame ;
Original file line number Diff line number Diff line change @@ -44,7 +44,9 @@ void handleScreencastFrame(JsonObject params) {
4444 }
4545 String dataBase64 = params .get ("data" ).getAsString ();
4646 byte [] data = java .util .Base64 .getDecoder ().decode (dataBase64 );
47- onFrame .accept (new ScreencastFrame (data ));
47+ int viewportWidth = params .get ("viewportWidth" ).getAsInt ();
48+ int viewportHeight = params .get ("viewportHeight" ).getAsInt ();
49+ onFrame .accept (new ScreencastFrame (data , viewportWidth , viewportHeight ));
4850 }
4951
5052 @ Override
Original file line number Diff line number Diff line change 1616
1717package com .microsoft .playwright .options ;
1818
19- /**
20- * A single screencast frame delivered to {@link com.microsoft.playwright.Screencast#start Screencast.start()}'s
21- * {@code onFrame} callback.
22- */
2319public class ScreencastFrame {
2420 /**
2521 * JPEG-encoded frame data.
2622 */
2723 public byte [] data ;
24+ /**
25+ * Width of the page viewport at the time the frame was captured.
26+ */
27+ public int viewportWidth ;
28+ /**
29+ * Height of the page viewport at the time the frame was captured.
30+ */
31+ public int viewportHeight ;
2832
29- public ScreencastFrame (byte [] data ) {
33+ public ScreencastFrame (byte [] data , int viewportWidth , int viewportHeight ) {
3034 this .data = data ;
35+ this .viewportWidth = viewportWidth ;
36+ this .viewportHeight = viewportHeight ;
3137 }
32- }
38+ }
Original file line number Diff line number Diff line change @@ -122,6 +122,27 @@ void screencastStartShouldDeliverFramesViaOnFrame() throws Exception {
122122 }
123123 }
124124
125+ @ Test
126+ void onFrameShouldReceiveViewportSize () {
127+ BrowserContext context = browser .newContext (new Browser .NewContextOptions ().setViewportSize (1000 , 400 ));
128+ Page page = context .newPage ();
129+ try {
130+ List <ScreencastFrame > frames = new ArrayList <>();
131+ page .screencast ().start (new Screencast .StartOptions ().setOnFrame (frames ::add ));
132+ page .navigate (server .EMPTY_PAGE );
133+ page .evaluate ("() => document.body.style.backgroundColor = 'red'" );
134+ page .waitForTimeout (500 );
135+ page .screencast ().stop ();
136+ assertFalse (frames .isEmpty (), "expected at least one frame" );
137+ for (ScreencastFrame frame : frames ) {
138+ assertEquals (1000 , frame .viewportWidth );
139+ assertEquals (400 , frame .viewportHeight );
140+ }
141+ } finally {
142+ context .close ();
143+ }
144+ }
145+
125146 @ Test
126147 void screencastStartShouldThrowIfAlreadyStarted () {
127148 BrowserContext context = browser .newContext ();
Original file line number Diff line number Diff line change 1- 1.60.0-alpha-1778025033000
1+ 1.60.0-beta-1778180503000
Original file line number Diff line number Diff line change @@ -326,6 +326,14 @@ private void createClassesAndEnums(JsonObject jsonObject) {
326326 }
327327 return ;
328328 }
329+ if ("function" .equals (jsonObject .get ("name" ).getAsString ()) && jsonObject .has ("args" )) {
330+ for (JsonElement item : jsonObject .getAsJsonArray ("args" )) {
331+ if (item .isJsonObject () && javaAlias (item .getAsJsonObject ()) != null ) {
332+ createClassesAndEnums (item .getAsJsonObject ());
333+ }
334+ }
335+ return ;
336+ }
329337 if ("Object" .equals (jsonObject .get ("name" ).getAsString ())) {
330338 if (customType != null ) {
331339 // Same type maybe referenced as 'Object' in several union values, e.g. Object|Array<Object>
@@ -506,8 +514,8 @@ private String convertBuiltinType(JsonObject jsonType) {
506514 if (customType != null ) {
507515 return customType ;
508516 }
509- // Inner Objects (e.g. function arguments) are not visited by createClassesAndEnums,
510- // so resolve their Java type name from langAliases here.
517+ // Inner Objects without langAliases (e.g. unaliased function arguments) are not visited
518+ // by createClassesAndEnums, so resolve their Java type name from langAliases here.
511519 String alias = javaAlias (jsonType );
512520 if (alias != null ) {
513521 return alias ;
You can’t perform that action at this time.
0 commit comments