1
0
mirror of synced 2026-08-31 19:55:37 +00:00

chore: roll driver to 1.60.0-beta-1778180503000 (#1918)

This commit is contained in:
Yury Semikhatsky
2026-05-07 15:45:23 -07:00
committed by GitHub
parent f081667e44
commit d84a2db0b3
8 changed files with 166 additions and 28 deletions
@@ -27,7 +27,7 @@ import java.util.function.Consumer;
public interface Screencast {
class StartOptions {
/**
* Callback that receives JPEG-encoded frame data.
* Callback that receives JPEG-encoded frame data along with the page viewport size at the time of capture.
*/
public Consumer<ScreencastFrame> onFrame;
/**
@@ -40,7 +40,7 @@ public interface Screencast {
public Integer quality;
/**
* Callback that receives JPEG-encoded frame data.
* Callback that receives JPEG-encoded frame data along with the page viewport size at the time of capture.
*/
public StartOptions setOnFrame(Consumer<ScreencastFrame> onFrame) {
this.onFrame = onFrame;
@@ -14,19 +14,21 @@
* limitations under the License.
*/
package com.microsoft.playwright.options;
package com.microsoft.playwright;
/**
* A single screencast frame delivered to {@link com.microsoft.playwright.Screencast#start Screencast.start()}'s
* {@code onFrame} callback.
*/
public class ScreencastFrame {
public interface ScreencastFrame {
/**
* JPEG-encoded frame data.
*/
public byte[] data;
byte[] data();
public ScreencastFrame(byte[] data) {
this.data = data;
}
}
/**
* Width of the page viewport at the time the frame was captured.
*/
int viewportWidth();
/**
* Height of the page viewport at the time the frame was captured.
*/
int viewportHeight();
}
@@ -0,0 +1,46 @@
/*
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.microsoft.playwright.impl;
import com.microsoft.playwright.ScreencastFrame;
class ScreencastFrameImpl implements ScreencastFrame {
private final byte[] data;
private final int viewportWidth;
private final int viewportHeight;
ScreencastFrameImpl(byte[] data, int viewportWidth, int viewportHeight) {
this.data = data;
this.viewportWidth = viewportWidth;
this.viewportHeight = viewportHeight;
}
@Override
public byte[] data() {
return data;
}
@Override
public int viewportWidth() {
return viewportWidth;
}
@Override
public int viewportHeight() {
return viewportHeight;
}
}
@@ -19,7 +19,7 @@ package com.microsoft.playwright.impl;
import com.google.gson.JsonObject;
import com.microsoft.playwright.PlaywrightException;
import com.microsoft.playwright.Screencast;
import com.microsoft.playwright.options.ScreencastFrame;
import com.microsoft.playwright.ScreencastFrame;
import java.nio.file.Path;
import java.util.function.Consumer;
@@ -44,7 +44,9 @@ class ScreencastImpl implements Screencast {
}
String dataBase64 = params.get("data").getAsString();
byte[] data = java.util.Base64.getDecoder().decode(dataBase64);
onFrame.accept(new ScreencastFrame(data));
int viewportWidth = params.get("viewportWidth").getAsInt();
int viewportHeight = params.get("viewportHeight").getAsInt();
onFrame.accept(new ScreencastFrameImpl(data, viewportWidth, viewportHeight));
}
@Override
@@ -16,7 +16,6 @@
package com.microsoft.playwright;
import com.microsoft.playwright.options.ScreencastFrame;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
@@ -113,9 +112,30 @@ public class TestScreencast extends TestBase {
assertFalse(frames.isEmpty(), "expected at least one frame");
// JPEG-encoded frames start with FF D8.
for (ScreencastFrame frame : frames) {
assertNotNull(frame.data);
assertEquals((byte) 0xFF, frame.data[0]);
assertEquals((byte) 0xD8, frame.data[1]);
assertNotNull(frame.data());
assertEquals((byte) 0xFF, frame.data()[0]);
assertEquals((byte) 0xD8, frame.data()[1]);
}
} finally {
context.close();
}
}
@Test
void onFrameShouldReceiveViewportSize() {
BrowserContext context = browser.newContext(new Browser.NewContextOptions().setViewportSize(1000, 400));
Page page = context.newPage();
try {
List<ScreencastFrame> frames = new ArrayList<>();
page.screencast().start(new Screencast.StartOptions().setOnFrame(frames::add));
page.navigate(server.EMPTY_PAGE);
page.evaluate("() => document.body.style.backgroundColor = 'red'");
page.waitForTimeout(500);
page.screencast().stop();
assertFalse(frames.isEmpty(), "expected at least one frame");
for (ScreencastFrame frame : frames) {
assertEquals(1000, frame.viewportWidth());
assertEquals(400, frame.viewportHeight());
}
} finally {
context.close();