Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix(screencast): remove white padding in headless chromium (#3746)

Yury Semikhatsky0976732ec6a3
diff --git a/src/server/chromium/crPage.ts b/src/server/chromium/crPage.ts
index cb130c4419..46b3cbc5ac 100644
--- a/src/server/chromium/crPage.ts
+++ b/src/server/chromium/crPage.ts
@@ -827,15 +827,17 @@ class FrameSession {
}),
];
if (this._windowId) {
- // TODO: popup windows have their own insets.
- let insets = { width: 24, height: 88 };
- if (process.platform === 'win32')
- insets = { width: 16, height: 88 };
- else if (process.platform === 'linux')
- insets = { width: 8, height: 85 };
- else if (process.platform === 'darwin')
- insets = { width: 2, height: 80 };
-
+ let insets = { width: 0, height: 0 };
+ if (this._crPage._browserContext._browser._options.headful) {
+ // TODO: popup windows have their own insets.
+ insets = { width: 24, height: 88 };
+ if (process.platform === 'win32')
+ insets = { width: 16, height: 88 };
+ else if (process.platform === 'linux')
+ insets = { width: 8, height: 85 };
+ else if (process.platform === 'darwin')
+ insets = { width: 2, height: 80 };
+ }
promises.push(this._client.send('Browser.setWindowBounds', {
windowId: this._windowId,
bounds: { width: viewportSize.width + insets.width, height: viewportSize.height + insets.height }
diff --git a/src/server/chromium/videoRecorder.ts b/src/server/chromium/videoRecorder.ts
index 9c4fd1a2e5..3651ede0db 100644
--- a/src/server/chromium/videoRecorder.ts
+++ b/src/server/chromium/videoRecorder.ts
@@ -51,7 +51,7 @@ export class VideoRecorder {
assert(!this._isRunning());
const w = options.width;
const h = options.height;
- const args = `-f image2pipe -c:v mjpeg -i - -y -an -r ${fps} -c:v vp8 -vf pad=${w}:${h}:0:0:gray,crop=${w}:${h}:0:0`.split(' ');
+ const args = `-loglevel error -f image2pipe -c:v mjpeg -i - -y -an -r ${fps} -c:v vp8 -vf pad=${w}:${h}:0:0:gray,crop=${w}:${h}:0:0`.split(' ');
args.push(options.outputFile);
const progress = this._progress;
// Use ffmpeg provided by the host system.
diff --git a/test/screencast.spec.ts b/test/screencast.spec.ts
index 5800330092..2457cdd03e 100644
--- a/test/screencast.spec.ts
+++ b/test/screencast.spec.ts
@@ -318,9 +318,7 @@ describe('screencast', suite => {
await context.close();
});
- it('should scale frames down to the requested size ', test => {
- test.fixme(options.CHROMIUM && options.HEADLESS, 'Window is not resized when changing viewport');
- }, async ({page, videoPlayer, tmpDir, server, toImpl}) => {
+ it('should scale frames down to the requested size ', async ({page, videoPlayer, tmpDir, server, toImpl}) => {
await page.setViewportSize({width: 640, height: 480});
const videoFile = path.join(tmpDir, 'v.webm');
await page.goto(server.PREFIX + '/checkerboard.html');