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
{{ message }}
Repository navigation
[Question] How to disable bringing page to front during launching. #4822
Currently I am doing web chat tests where I would like to test multiple context.
If I spawn new context it brings that page to front loosing the focus.
letbrowser=awaitfirefox.launch()// Every 1 minute open new context and open page just to test if chat shows history or not.while(true){letcontext=awaitbrowser.newContext()letpage=awaitcontext.newPage();// delay code is there not shown here.}
The issue is that newContext spawns a new window which has focus or something is in page that is calling page.bringToFront() when its launched.
Questions:
I would like to disable these behavior. If possible please let me know.
Is there anyway to minimize the context window after launch. If I need to bring page to front I think i can call page.bringToFront() at the moment.
Well, we have a plenty of chat testing, and we have no issues running multiple browser instances. We have tests up to 4 users chatting at the same time, with no issues.
Aziz Gazanchiian (@creage) the issue is focus stealing. For 2-3 edge case we tests manually and we spawn like new window after 5 sec interval. When testing manually we are typing and the browser come in front of face which is abit annoying.
Pavel Feldman (@pavelfeldman) Yea its like when we are doing some work on one window and if another window is spawned focus is stolen from the person doing manual steps. Sometime we need to do it for accessibility check in headful mode and is mostly from devops team.
I also experience this; its pretty annoying to have jest running with --watch while developing and have focus stolen away constantly by the playwright. It seems like it has to be possible to have an option to instruct playwright to open Chromium in the background, rather than foreground.
Reacted by Aleksandr Popov, JJetmar, nakamura, Patrick Borowy, Joan Vicens, fternell, Alain Scialoja, John Hatton, dkocich, Loic Teixeira and 27 more
I was also surprised there is no way to prevent bringing it to front and loosing focus.
My workaround is to have "reusable pages" (1 if your program is simple, or X if you have a X as concurrency). You wait for a created page instance to be marked as available (with a mutex or so) to reuse it.
Make sure to clear all listeners if you added some, or the storage if you don't want it to be shared. It's a bit more at risk... but for now that's the only viable solution when headless: true does not fit the use case.
Reacted by Pablo LION, Stan Stanislaus, Troy Shu and 熊瘪三
The @* entries in pnpm-workspace.yaml reapply the patches across versions,
including the installed Playwright alpha. Keep patch failures fatal: if an upgrade
changes the surrounding code, regenerate the affected patch with pnpm patch
and pnpm patch-commit, then restore the wildcard entry. Check headed page creation,
navigation, input, and macOS focus behavior after browser upgrades.
Activity
creage commentedon Dec 28, 2020
Well, we have a plenty of chat testing, and we have no issues running multiple browser instances. We have tests up to 4 users chatting at the same time, with no issues.
What exact problem do you have?
shirshak55 commentedon Dec 28, 2020
Aziz Gazanchiian (@creage) the issue is focus stealing. For 2-3 edge case we tests manually and we spawn like new window after 5 sec interval. When testing manually we are typing and the browser come in front of face which is abit annoying.
pavelfeldman commentedon Jan 16, 2021
Playwright emulates all pages as focused, what exactly do you mean by focus stealing?
pavelfeldman commentedon Jan 16, 2021
Ah, you mean your scenarios are hybrid and the focus is stolen from the person performing the manual steps? Can I ask why you are typing manually?
shirshak55 commentedon Jan 16, 2021
Pavel Feldman (@pavelfeldman) Yea its like when we are doing some work on one window and if another window is spawned focus is stolen from the person doing manual steps. Sometime we need to do it for accessibility check in headful mode and is mostly from devops team.
pavelfeldman commentedon Jan 16, 2021
I don't think we can do anything about it (focusing), but we could try helping automating those a11y checks!
shirshak55 commentedon Jan 16, 2021
alright then I shall close this issue :) I also think its probably firefox or chrome issue
Thanks.
bstro commentedon Nov 17, 2021
I also experience this; its pretty annoying to have jest running with
--watchwhile developing and have focus stolen away constantly by the playwright. It seems like it has to be possible to have an option to instruct playwright to open Chromium in the background, rather than foreground.ThatGuySam commentedon Aug 7, 2024
There's a command I figured out on macOS to start iOS Simulator in the background which reliably disables it from taking focus.
However, I'm unsure how to launch Playwright's Chromium with this option
sneko commentedon May 18, 2025
I was also surprised there is no way to prevent bringing it to front and loosing focus.
My workaround is to have "reusable pages" (1 if your program is simple, or X if you have a X as concurrency). You wait for a created page instance to be marked as available (with a mutex or so) to reuse it.
Make sure to clear all listeners if you added some, or the storage if you don't want it to be shared. It's a bit more at risk... but for now that's the only viable solution when
headless: truedoes not fit the use case.Andrew-Chen-Wang commentedon Jun 12, 2026
This apparently really only affects chromium and only when launching a new page or launchPersistentContext. Added a PR: #41282
johnlshankman-privy commentedon Sep 14, 2026
bringing this back from the dead because this still affects me daily. is there no workaround anyone has found?
Andrew Chen Wang (@Andrew-Chen-Wang) still has an open PR #41306
Andrew-Chen-Wang commentedon Sep 14, 2026
Johnny Shankman (@johnlshankman-privy) Create a patches folder, and make a file. I use both playwright and patchright so:
patches/patchright-core-no-focus.patch:one more:
patches/playwright-core-no-focus.patchin pnpm-workspace.yaml:
The
@*entries inpnpm-workspace.yamlreapply the patches across versions,including the installed Playwright alpha. Keep patch failures fatal: if an upgrade
changes the surrounding code, regenerate the affected patch with
pnpm patchand
pnpm patch-commit, then restore the wildcard entry. Check headed page creation,navigation, input, and macOS focus behavior after browser upgrades.