feat(browserContext): support maximized viewport by dcrousso · Pull Request #43363 · microsoft/playwright · GitHub
Skip to content

feat(browserContext): support maximized viewport - #43363

Open
Devin Rousso (dcrousso) wants to merge 2 commits into
microsoft:mainfrom
dcrousso:fix-1086
Open

Devin Rousso (dcrousso) wants to merge 2 commits into
microsoft:mainfrom
dcrousso:fix-1086

Conversation

@dcrousso

Copy link
Copy Markdown
Contributor

allow viewport: 'maximized' to maximize native browser windows without a default emulated viewport

keep native maximization independent of browser fullscreen and the web Fullscreen API

preserve the maximized outer window when Page.setViewportSize() enables viewport emulation

fixes #1086

@github-actions

Copy link
Copy Markdown
Contributor

@github-actions

Copy link
Copy Markdown
Contributor

Test results for "MCP"

2 failed
❌ [firefox] › mcp/cli-core.spec.ts:97 › fill @mcp-windows-latest-firefox
❌ [firefox] › mcp/idle-timeout.spec.ts:19 › closes the browser after the idle timeout and relaunches it on the next call @mcp-windows-latest-firefox

9202 passed, 1495 skipped


Merge workflow run.

@github-actions

Copy link
Copy Markdown
Contributor

Hi, I'm the Playwright bot and I took a first look at the CI failures.

🟢 Both failures are confirmed pre-existing flakes

The same tests have failed on Windows/Firefox on revisions unrelated to this PR. This PR only activates its new window behavior when viewport: 'maximized' is requested; neither failing MCP test uses that option.

Details

Overall assessment

The two MCP failures are not likely caused by this PR. The other four reported tests passed on retry, so they do not require failure triage.

Pre-existing flakes

  • [firefox] › mcp/cli-core.spec.ts:97 › fill — failed with the same missing snapshot on an unrelated run for #43321. On the Windows/Firefox bot, it passed 77 of the 79 recent runs and failed twice, including this PR.
  • [firefox] › mcp/idle-timeout.spec.ts:19 › closes the browser after the idle timeout and relaunches it on the next call — failed with the same missing snapshot after the browser closed on an unrelated push run. On the Windows/Firefox bot, it passed 67 of the 79 recent runs and failed 12 times; 11 failures were outside this PR.

Triaged by the Playwright bot - agent run

Comment thread docs/src/api/params.md Outdated
Use `null` to disable the consistent viewport emulation. Learn more about [viewport emulation](../emulation#viewport).
Use `"maximized"` to disable viewport emulation and maximize each native browser window. This is only supported in headed mode and does not enter fullscreen mode or trigger the web Fullscreen API.

Calling [`method: Page.setViewportSize`] overrides `"maximized"` for that page and resizes its native window.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think this sentence is confusing rather than helping.

if (options.userAgent)
lines.push(` .setUserAgent(${quote(options.userAgent)})`);
if (options.viewport)
if (options.viewport && options.viewport !== 'maximized')

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why suddenly a java-only change? I'd expect either all languages or none.

Comment thread docs/src/api/params.md
tests non-deterministic.
:::

## java-context-option-viewport

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Let's sketch out how this API looks for other languages right away.

Comment thread packages/protocol/spec/mixins.yml Outdated
properties:
width: int
height: int
viewportMaximized: boolean?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'd recommend an enum viewportMode instead of noDefaultViewport+viewportMaximized. Otherwise it's unclear what noDefaultViewport: true, viewportMaximized: true means.

Comment thread tests/library/headful.spec.ts Outdated
it('should create context in maximized window without entering fullscreen', async ({ browser, browserName }) => {
const context = await browser.newContext({ viewport: 'maximized' });
const page = await context.newPage();
await expect.poll(() => windowIsMaximized(context, page, browserName)).toBe(true);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why do we have to poll here? Shouldn't the newPage already be maximized right away? I'd expect that from the API.

startAutomaticVideoRecording(this._page);
await Promise.all(promises);
if (contextOptions.viewportMaximized) {
await this._browserContext._browser._browserSession.send('Playwright.maximizeWindow', {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

  • Why is this not a part of _updateViewport() method? It seems to be either viewport or maximized, but not both.
  • Similarly, does setting viewport undo Playwright.maximizeWindow? If so, perhaps it should be the same webkit protocol method as well?

await context.close();
});

it('should override maximized viewport when resizing a page', async ({ browser, browserName }) => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'd expect a symmetric test as well: create a context with viewport=567x345, then call page.setViewportSize('maximized') after.

},
}));
}
if (this._options.viewportMaximized) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It feels like this should be a part of doUpdateDefaultViewport().


async _initialize(hasUIWindow: boolean) {
const browserOptions = this._crPage._browserContext._browser.options;
const options = this._crPage._browserContext._options;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: contextOptions

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'd expect the new "maximized" option to affect metricsOverride somehow...

allow `viewport: 'maximized'` to maximize native browser windows without a default emulated viewport

keep native maximization independent of browser fullscreen and the web Fullscreen API

preserve the maximized outer window when `Page.setViewportSize()` enables viewport emulation
`noDefaultViewport` duplicates `viewportMode`

use `viewportMode` as the only viewport mode setting

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] create context in fullscreen mode

2 participants