From f22ea7f1c29b1da50a0175ef0afd7a47b4ab67ff Mon Sep 17 00:00:00 2001 From: Dmitry Gozman Date: Wed, 4 Nov 2026 15:55:18 +0000 Subject: [PATCH 1/2] fix(chromium): account for tabs and toolbar in the new headless mode The new headless mode lays out tabs and toolbar like the headed mode does, but the window insets were only applied for headed browsers. The page area was smaller than the viewport, and screencast captured that smaller area, so videos and trace screenshots lost the bottom of the page on the chrome and msedge channels. --- .../src/server/chromium/crBrowser.ts | 14 ++++++++++++++ .../playwright-core/src/server/chromium/crPage.ts | 8 +++++++- tests/library/screencast.spec.ts | 9 +++++---- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/packages/playwright-core/src/server/chromium/crBrowser.ts b/packages/playwright-core/src/server/chromium/crBrowser.ts index e63331c201717..605accdef3e3e 100644 --- a/packages/playwright-core/src/server/chromium/crBrowser.ts +++ b/packages/playwright-core/src/server/chromium/crBrowser.ts @@ -57,6 +57,8 @@ export class CRBrowser extends Browser { private _tracingRecording = false; private _tracingClient: CRSession | undefined; private _userAgent: string = ''; + private _isHeadlessShell = false; + private _isEdge = false; static async connect(parent: SdkObject, transport: ConnectionTransport, options: BrowserOptions, devtools?: CRDevTools): Promise { // Make a copy in case we need to update `headful` property below. @@ -81,6 +83,10 @@ export class CRBrowser extends Browser { // We don't trust the option as it may lie in case of connectOverCDP where remote browser // may have been launched with different options. browser.options.headful = !version.userAgent.includes('Headless'); + // The headless shell reports itself as HeadlessChrome, while the new headless mode + // of the full browser reports the regular product name. + browser._isHeadlessShell = version.product.startsWith('HeadlessChrome/'); + browser._isEdge = version.product.startsWith('Edg/'); if (!options.persistent) { await session.send('Target.setAutoAttach', { autoAttach: true, waitForDebuggerOnStart: true, flatten: true }); return browser; @@ -160,6 +166,14 @@ export class CRBrowser extends Browser { return 'linux'; } + isHeadlessShell(): boolean { + return this._isHeadlessShell; + } + + isEdge(): boolean { + return this._isEdge; + } + isClank(): boolean { return this.options.name === 'clank'; } diff --git a/packages/playwright-core/src/server/chromium/crPage.ts b/packages/playwright-core/src/server/chromium/crPage.ts index 18a459b8a4066..f9e5d00e4a9dc 100644 --- a/packages/playwright-core/src/server/chromium/crPage.ts +++ b/packages/playwright-core/src/server/chromium/crPage.ts @@ -1036,7 +1036,8 @@ class FrameSession { const promises = []; if (!preserveWindowBoundaries && this._windowId) { let insets = { width: 0, height: 0 }; - if (this._crPage._browserContext._browser.options.headful) { + const browser = this._crPage._browserContext._browser; + if (browser.options.headful) { // TODO: popup windows have their own insets. insets = { width: 24, height: 88 }; if (process.platform === 'win32') @@ -1051,6 +1052,11 @@ class FrameSession { // Account for the infobar here to work around the bug. insets.height += 46; } + } else if (!browser.isHeadlessShell()) { + // The new headless mode lays out tabs and toolbar like the headed mode does. + insets = { width: 0, height: 87 }; + if (browser.isEdge()) + insets = process.platform === 'darwin' ? { width: 8, height: 84 } : { width: 0, height: 84 }; } promises.push(this.setWindowBounds({ width: viewportSize.width + insets.width, diff --git a/tests/library/screencast.spec.ts b/tests/library/screencast.spec.ts index 40f8dadac4277..8aed7e72f0a17 100644 --- a/tests/library/screencast.spec.ts +++ b/tests/library/screencast.spec.ts @@ -45,11 +45,12 @@ test('SC-001 screencast.start delivers frames via onFrame callback', async ({ br // Each frame must be a valid JPEG (starts with FF D8) expect(frame[0]).toBe(0xff); expect(frame[1]).toBe(0xd8); - const { width, height } = jpegDimensions(frame); - // Frame should be scaled down to fit the maximum size. - expect(width).toBe(500); - expect(height).toBe(200); } + // Chromium scales the first frame against the window size it had before the viewport + // was applied, so only the last frame is reliably scaled down to fit the maximum size. + const { width, height } = jpegDimensions(frames[frames.length - 1]); + expect(width).toBe(500); + expect(height).toBe(200); await context.close(); }); From aa72a755ef6f0cd6d1413b8ef84c412bb7420245 Mon Sep 17 00:00:00 2001 From: Dmitry Gozman Date: Thu, 5 Nov 2026 14:24:12 +0000 Subject: [PATCH 2/2] fix(chromium): use the browser platform for window insets Window insets depend on the platform the browser runs on, not the platform of the driver. Also use 90 for the tabs and toolbar height of Chrome in the new headless mode on Windows. --- .../playwright-core/src/server/chromium/crPage.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/playwright-core/src/server/chromium/crPage.ts b/packages/playwright-core/src/server/chromium/crPage.ts index f9e5d00e4a9dc..0090708b76b97 100644 --- a/packages/playwright-core/src/server/chromium/crPage.ts +++ b/packages/playwright-core/src/server/chromium/crPage.ts @@ -1037,14 +1037,14 @@ class FrameSession { if (!preserveWindowBoundaries && this._windowId) { let insets = { width: 0, height: 0 }; const browser = this._crPage._browserContext._browser; + const platform = browser._platform(); if (browser.options.headful) { // TODO: popup windows have their own insets. - insets = { width: 24, height: 88 }; - if (process.platform === 'win32') + if (platform === 'win') insets = { width: 16, height: 88 }; - else if (process.platform === 'linux') + else if (platform === 'linux') insets = { width: 8, height: 85 }; - else if (process.platform === 'darwin') + else insets = { width: 2, height: 80 }; if (this._crPage._browserContext.isPersistentContext()) { // FIXME: Chrome bug: OOPIF router is confused when hit target is @@ -1054,9 +1054,9 @@ class FrameSession { } } else if (!browser.isHeadlessShell()) { // The new headless mode lays out tabs and toolbar like the headed mode does. - insets = { width: 0, height: 87 }; + insets = { width: 0, height: platform === 'win' ? 90 : 87 }; if (browser.isEdge()) - insets = process.platform === 'darwin' ? { width: 8, height: 84 } : { width: 0, height: 84 }; + insets = platform === 'mac' ? { width: 8, height: 84 } : { width: 0, height: 84 }; } promises.push(this.setWindowBounds({ width: viewportSize.width + insets.width,