playwright
playwright copied to clipboard
[Feature] create context in fullscreen mode
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'm not sure what you mean. Currently the default is:
browser.newConext({
viewport: {
width: 800, // 1280 in commit 1ee6578
height: 600, // 720 in commit 1ee6578
}
})
If I understood correctly, you were expecting that viewport width and height will automatically be set to your current desktop/laptop's viewport?

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.
Could you share more about your use case?
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 ?
My point is user maximize browser window
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?
Before the viewport: null
I'm getting:
width: 800 height: 600
which is expected of course, since that is the default. I tried the browser.newContext({ viewport: null })
and now I'm getting:
width: 1200 height: 610
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:
{width: 1280, height: 721}
Side Note: not sure why there is an extra 1 pixel height, I used this method on an about:blank
page:
{
width: document.documentElement.clientWidth,
height: document.documentElement.clientHeight
}
@arjun27 What do you think here ?
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.
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!
Reopening as a feature request.
+1 for this.
interested also
Browser maximize issue is resolved for me with below lines of code. Depending on your screen resolution, you may adjust your window position and view port width and height values:
browser = playwright.chromium.launch(args=['--window-position=-5,-5'],headless=False) context = browser.new_context(viewport={'width':1600,'height':900})
interested also, especially in Firefox.
+1
+1
+1
+1
In Python, you can do:
from playwright.sync_api import sync_playwright
import tkinter
root = tkinter.Tk()
root_ndim_x = root.winfo_screenwidth()
root_ndim_y = root.winfo_screenheight()
with sync_playwright() as p:
browser = p.firefox.launch(headless=True)
context = browser.new_context()
page = browser.new_page()
page.goto('http://example.com')
page.set_viewport_size({'width':root_ndim_x/1,'height':root_ndim_y/1})
This worked for me:
from playwright.sync_api import sync_playwright
import time
p = sync_playwright().start()
browser = p.chromium.launch(args=['--start-maximized'], headless=False)
page = browser.new_page(no_viewport=True)
page.goto('https://www.google.com')
time.sleep(3600)
Upvoted this issue aswell 👍
Credits/thanks to @pavelfeldman (https://giters.com/microsoft/playwright-python/issues/585)
It is necessary, up
Hi All,
I am using playwright with nunit version 1.22 for dotnet 6, Trying to maximize chromium browsers (chromium, chrome,edge) by these approach BrowserTypeLaunchOptions args: --start-maximized,--window-position=-5,-5
& BrowserNewContextOptions: ViewportSize = null, ViewportSize = new ViewportSize() { Width = 1920, Height = 1080 }
but cannot able to maximize browser to fullscreen, can anyone share how to maximize browser.
@pavelfeldman Trying the code below I get the next browser picture on the Mac Code:
from playwright.sync_api import sync_playwright
import time
p = sync_playwright().start()
browser = p.chromium.launch(args=['--start-maximized'], headless=False)
page = browser.new_page(no_viewport=True)
page.goto('https://www.google.com')
time.sleep(3600)
Browser displaying:
Do you see the same picture after running this code?
from playwright.sync_api import sync_playwright import tkinter
root= tkinter.Tk() root_ndim_x = root.winfo_screenwidth() root_ndim_y = root.winfo_screenheight()
browser = sync_playwright().start().chromium.launch(headless=False, args=["--window-position=-5,-5"]) context = browser.new_context(viewport={'width': root_ndim_x/1, 'height': root_ndim_y/1}) page = context.new_page() page.goto("https://google.com")
+1 => needed
Hi, I couldn't launch ms-edge browser in full screen mode, tried setting the viewport height and width & null along with --start-maximized in launch options in playwright config file, but still launches the browser in half sized.
I see quite a lot of solutions to open the browser in maximized mode but no working solution to put the chrome browser in fullscreen mode (F11). How can this be achieved?
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.
from playwright.sync_api import sync_playwright as spl
pwt = 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 playwright
ignore_default_args=["--enable-automation", "--no-startup-window"],
# Also possible: --start-fullscreen
args=["--kiosk"],
no_viewport=True
)
page = browser.new_page()
page.goto("https://google.com/")
# Check that JavaScript can be evaluated despite removing --enable-automation
print(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.
+1, I find this feature very useful.
+1 => absolutely required