Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 7 additions & 1 deletion packages/playwright-core/src/server/chromium/crPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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 };

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this (and the above) be browser._platform() === 'mac' instead? that way we are actually checking the OS the browser is running on instead of where the driver is?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's a good idea.

}
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