Maximizing Browser Windows in Playwright Test (C#) for Firefox

How can I start the Browser Windows from a PlayWright test (Using C#) in a Maximized state on Firefox?

1 Like

Hey Ian,

To start the Browser Window in a maximized state on Firefox using Playwright in C#, you can utilize the following code snippet:

using var browser = await BrowserType.Firefox.LaunchAsync();
var context = await browser.NewContextAsync();
var page = await context.NewPageAsync();

await page.GoToAsync("https://www.example.com");

// Maximize the browser window
await page.RunAndWaitForActionAsync(async () =>
{
    await page.EvaluateAsync("() => window.innerWidth = screen.width");
    await page.EvaluateAsync("() => window.innerHeight = screen.height");
});

// Your test logic goes here...

// Close the browser when done
await browser.CloseAsync();

This code launches a Firefox browser, creates a new page, navigates to a specified URL (in this case, “https://www.example.com”), and then maximizes the browser window by setting the innerWidth and innerHeight properties to match the screen width and height.

Additionally, you can find more detailed information and examples on maximizing the browser window in Playwright by referring to the following article: Maximize Browser Window in Playwright.

We’re grateful for your interest! If you have more questions, we’re just a message away.