You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How to launch browser.newContext() or browser.newPage() in fullscreen ? There is no way to pass full-screen via options while calling browser.newContext(options).
I am talking about this new cognito window size, which I am launching by context.newPage(). Viewport is visible area which is visible on device, however browser window size is different. Opening new browser window in full screen size is my concern. How to launch it in full screen. Passing viewport do not help.
I know that the user can maximize the browser window and I know that the page can request full screen mode via the web api. But I'm not sure user can create a new full screen page.
Sorry, my bad. My point is user maximize browser window. How can we get it done ? Before context.newPage(), I am getting context by browser.newContext(). Can we get new context in fullscreen mode ?
changed the title [-][Question] How to launch newContext() or newPage() in fullscreen ?[/-][+][Question] How to launch newContext() in fullscreen ?[/+]on Feb 25, 2020
If you call browser.newContext({ viewport: null }), it would tell Playwright to not emulate certain device size and will follow the browser size when maximized. Is that what you are looking for?
Synced offline with star-kashyap to understand this better. Due to DRM constraints, the tests are executed in headful mode. A small browser window impacts verifiability of execution, and looks suboptimal to an observer.
While it is possible to use something like --start-fullscreen or --window-size as args to launch a browser, it is not possible to enlarge the size of a new window launched with newContext. Combination of enlarged window size and viewport: null would fix this.
Reacted by star-kashyap, VyacheslavDE, Vladislav Treshcheyko, Andrii Oriekhov and CodeStrikerr
I think launching with args: ['--window-size=1280,720'] and using viewport: null should bring you close to where you want to be. But that would be Chromium-specific solution. Non-chromium you should run with viewport: { width: 1280, height: 720 }.
Please feel free to reopen if there is something else we can do for you here!
Reacted by star-kashyap, honsa.ch, Andrii Oriekhov and QA BOX LETS TEST
I've solved this problem (in Python) by using launch_persistent_context() instead of launch() and tweaking the arguments a little but. This change prevents opening pages in new windows.
fromplaywright.sync_apiimportsync_playwrightassplpwt=spl().start()
browser=pwt.chromium.launch_persistent_context(
# Required (emtpy string means a temporary profile)user_data_dir="",
headless=False,
# This hides the annoying infobar "Chrome is being controlled by automated test software",# but it may break some functionality of playwrightignore_default_args=["--enable-automation", "--no-startup-window"],
# Also possible: --start-fullscreenargs=["--kiosk"],
no_viewport=True
)
page=browser.new_page()
page.goto("https://google.com/")
# Check that JavaScript can be evaluated despite removing --enable-automationprint(page.evaluate("location.href"))
print(page.evaluate("document.body.textContent = 'Hello world!'"))
dimensions=page.evaluate('''() => { return { width: document.documentElement.clientWidth, height: document.documentElement.clientHeight, deviceScaleFactor: window.devicePixelRatio, } }''')
print(dimensions)
I've removed the default flag --enable-automation in order to hide the annoying infobar "Chrome is being controlled by automated test software". This is likely to break some features of playwright, but for me all that is important is to communicate with the page using JavaScript, which seems fine.
Cons:
I don't know if this code works with other browsers as well.
You cannot change the context in which pages are opened.
For some tests we needed fullscreen mode but I was not able to get it working.
After embarrasing count of hours I figured out that Playwright exposes the underlying CDP Session and we can use it to make the window fullscreen.
This works in chromium
constclient=awaitpage.context().newCDPSession(page);// get window id from CDP sessionconst{ windowId }=awaitclient.send("Browser.getWindowForTarget");awaitclient.send("Browser.setWindowBounds",{windowId: windowId,bounds: {windowState: "fullscreen"},});
I don't know of any side effects this might cause, will update here if found any.
Reacted by Maciej Szwarc, jaktestowac.pl, Ivan Lagunovsky, Ruslan Sovinskyy, Vasek Codey Vlcek, craitose, Peter Hevesi, Karol Wozniak, Phê, Emil Sosa and 3 more
Reacted by Meby, Emil Sosa, Davis Weimer and Damir Zagidullin
For some tests we needed fullscreen mode but I was not able to get it working. After embarrasing count of hours I figured out that Playwright exposes the underlying CDP Session and we can use it to make the window fullscreen. This works in chromium
constclient=awaitpage.context().newCDPSession(page);// get window id from CDP sessionconst{ windowId }=awaitclient.send("Browser.getWindowForTarget");awaitclient.send("Browser.setWindowBounds",{windowId: windowId,bounds: {windowState: "fullscreen"},});
I don't know of any side effects this might cause, will update here if found any.
Yeah, I needed to test the full screen button on a web app but apparently playwright does not allow full screen to be triggered through events as it might interfere with accessibility of elements while the browser is full screen. You code snippet was the only way that allowed me to force full screen after the button was clicked.
For some tests we needed fullscreen mode but I was not able to get it working. After embarrasing count of hours I figured out that Playwright exposes the underlying CDP Session and we can use it to make the window fullscreen. This works in chromium
constclient=awaitpage.context().newCDPSession(page);// get window id from CDP sessionconst{ windowId }=awaitclient.send("Browser.getWindowForTarget");awaitclient.send("Browser.setWindowBounds",{windowId: windowId,bounds: {windowState: "fullscreen"},});
I don't know of any side effects this might cause, will update here if found any.
I just made a little change to this configuration and this may help you get what you want to achieve. Try it out.
bounds: { windowState: 'maximized' },
Also, this is my playwright.config.ts
projects: [
{
name: 'chromium',
use: { // ...devices['Desktop Chrome'],
headless: false,
launchOptions: {
args: ['--auth-server-allowlist="*"']
}, viewport: null,
}
},
For some tests we needed fullscreen mode but I was not able to get it working. After embarrasing count of hours I figured out that Playwright exposes the underlying CDP Session and we can use it to make the window fullscreen. This works in chromium
const client = await page.context().newCDPSession(page);
// get window id from CDP session
const { windowId } = await client.send("Browser.getWindowForTarget");
await client.send("Browser.setWindowBounds", {
windowId: windowId,
bounds: { windowState: "fullscreen" },
});
I don't know of any side effects this might cause, will update here if found any.
This is EXACTLY what I was looking for, converted to .NET in a LINQPad script for anyone looking to maximize the browser
classProgram{staticasyncTaskMain(string[]args){usingvarplaywright=awaitPlaywright.CreateAsync();awaitusingvarbrowser=awaitplaywright.Chromium.LaunchAsync(newBrowserTypeLaunchOptions{Headless=false});varcontext=awaitbrowser.NewContextAsync();varpage=awaitcontext.NewPageAsync();varclient=awaitcontext.NewCDPSessionAsync(page);vargetWindowResult=awaitclient.SendAsync("Browser.getWindowForTarget");varwindowId=getWindowResult.Value.GetProperty("windowId").GetInt32();// Initial max to grab width and heightawaitclient.SendAsync("Browser.setWindowBounds",newDictionary<string,object>{{"windowId",windowId},{"bounds",newDictionary<string,object>{{"windowState","maximized"}}}});varwidth=awaitpage.EvaluateAsync<int>(@"() => window.innerWidth");varheight=awaitpage.EvaluateAsync<int>(@"() => window.innerHeight");awaitpage.SetViewportSizeAsync(width,height);// Remaximize based on screen dimensionsawaitclient.SendAsync("Browser.setWindowBounds",newDictionary<string,object>{{"windowId",windowId},{"bounds",newDictionary<string,object>{{"windowState","maximized"}}}});awaitpage.GotoAsync("https://example.com");awaitTask.Delay(5000);}}
Here's a link to the other options for windowState as well
Activity
aesyondu commentedon Feb 25, 2020
I'm not sure what you mean. Currently the default is:
If I understood correctly, you were expecting that viewport width and height will automatically be set to your current desktop/laptop's viewport?
star-kashyap commentedon Feb 25, 2020
I am talking about this new cognito window size, which I am launching by context.newPage(). Viewport is visible area which is visible on device, however browser window size is different. Opening new browser window in full screen size is my concern. How to launch it in full screen. Passing viewport do not help.
pavelfeldman commentedon Feb 25, 2020
I know that the user can maximize the browser window and I know that the page can request full screen mode via the web api. But I'm not sure user can create a new full screen page.
Could you share more about your use case?
star-kashyap commentedon Feb 25, 2020
Sorry, my bad. My point is user maximize browser window. How can we get it done ? Before context.newPage(), I am getting context by browser.newContext(). Can we get new context in fullscreen mode ?
[-][Question] How to launch newContext() or newPage() in fullscreen ?[/-][+][Question] How to launch newContext() in fullscreen ?[/+]pavelfeldman commentedon Feb 25, 2020
If you call
browser.newContext({ viewport: null }), it would tell Playwright to not emulate certain device size and will follow the browser size when maximized. Is that what you are looking for?aesyondu commentedon Feb 26, 2020
Before the
viewport: nullI'm getting:which is expected of course, since that is the default. I tried the
browser.newContext({ viewport: null })and now I'm getting:Which does take the whole size of the browser, but the browser itself is not full screen. For reference, my full screen browser should measure:
Side Note: not sure why there is an extra 1 pixel height, I used this method on an
about:blankpage:star-kashyap commentedon Feb 27, 2020
arjun27 What do you think here ?
arjunattam commentedon Feb 27, 2020
Synced offline with star-kashyap to understand this better. Due to DRM constraints, the tests are executed in headful mode. A small browser window impacts verifiability of execution, and looks suboptimal to an observer.
While it is possible to use something like
--start-fullscreenor--window-sizeas args to launch a browser, it is not possible to enlarge the size of a new window launched withnewContext. Combination of enlarged window size andviewport: nullwould fix this.pavelfeldman commentedon Feb 27, 2020
I think launching with
args: ['--window-size=1280,720']and usingviewport: nullshould bring you close to where you want to be. But that would be Chromium-specific solution. Non-chromium you should run withviewport: { width: 1280, height: 720 }.Please feel free to reopen if there is something else we can do for you here!
pavelfeldman commentedon Oct 23, 2020
Reopening as a feature request.
[-][Question] How to launch newContext() in fullscreen ?[/-][+][Feature] create context in fullscreen mode[/+]17 remaining items
kputyra commentedon Jan 25, 2023
I've solved this problem (in Python) by using
launch_persistent_context()instead oflaunch()and tweaking the arguments a little but. This change prevents opening pages in new windows.I've removed the default flag
--enable-automationin order to hide the annoying infobar "Chrome is being controlled by automated test software". This is likely to break some features of playwright, but for me all that is important is to communicate with the page using JavaScript, which seems fine.Cons:
ssv-w32 commentedon Jan 30, 2023
+1, I find this feature very useful.
gs-vchauhan commentedon May 17, 2023
+1 => absolutely required
ManiMozaffar commentedon Jun 1, 2023
do we have some solution for firefox apart from hardcoding the size? willing to see one!
dron4ik86 commentedon Aug 12, 2023
This solution in working good for me, thanks!
imbdb commentedon Nov 25, 2023
For some tests we needed fullscreen mode but I was not able to get it working.
After embarrasing count of hours I figured out that Playwright exposes the underlying CDP Session and we can use it to make the window fullscreen.
This works in chromium
I don't know of any side effects this might cause, will update here if found any.
cybairfly commentedon Feb 21, 2024
Bharat D Bhadresha (@imbdb) You know your way around! Nice of you to share.
craitose commentedon Feb 28, 2024
Yeah, I needed to test the full screen button on a web app but apparently playwright does not allow full screen to be triggered through events as it might interfere with accessibility of elements while the browser is full screen. You code snippet was the only way that allowed me to force full screen after the button was clicked.
AbhineetSharmax commentedon Mar 4, 2024
I just made a little change to this configuration and this may help you get what you want to achieve. Try it out.
bounds: { windowState: 'maximized' },
Also, this is my playwright.config.ts
projects: [
{
name: 'chromium',
use: {
// ...devices['Desktop Chrome'],
headless: false,
launchOptions: {
args: ['--auth-server-allowlist="*"']
},
viewport: null,
}
},
nir-tal-talkspace commentedon Mar 28, 2024
wrote a blog post on how to resolve this issue when using playwright + python + pytest fixtures:
https://www.linkedin.com/pulse/test-automation-maximizing-browser-window-playwright-nir-tal-c24hf/
ilorwork commentedon Aug 1, 2024
My answer here might help:
https://stackoverflow.com/a/77713226/19574650
Dav1s-Ops commentedon Apr 24, 2025
This is EXACTLY what I was looking for, converted to .NET in a LINQPad script for anyone looking to maximize the browser
Here's a link to the other options for
windowStateas wellfeat(roll): roll to ToT Playwright (24-06-23) (microsoft#1086)
display-mode: fullscreenunder new Chromium headless #34687 as a duplicate of this issue