Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/playwright-core/src/server/chromium/crBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<CRBrowser> {
// Make a copy in case we need to update `headful` property below.
Expand All @@ -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;
Expand Down Expand Up @@ -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';
}
Expand Down
16 changes: 11 additions & 5 deletions packages/playwright-core/src/server/chromium/crPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1036,21 +1036,27 @@ 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;
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
// outside browser window.
// 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: platform === 'win' ? 90 : 87 };
if (browser.isEdge())
insets = platform === 'mac' ? { width: 8, height: 84 } : { width: 0, height: 84 };
}
promises.push(this.setWindowBounds({
width: viewportSize.width + insets.width,
Expand Down
9 changes: 5 additions & 4 deletions tests/library/screencast.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
Loading