🚀 Feature Request
Allow chrome to open in headful mode but in the background without removing focus from an active window. Firefox already supports this via Playwright flags, but Chrome does not have a flag.
This is a reincarnation of #4822 which had 36+ people support this motive: #4822 (comment) but the issue was already closed
There is an open PR for this #41282 description:
Summary
- New
browserType.launch({ createPagesInBackground: true }) option (default false, no behavior change otherwise).
- When enabled, headed Chromium passes
background: true to Target.createTarget, so newPage() no longer activates the browser app and steals OS focus from the user (verified on macOS).
- Pages remain normal visible windows:
document.hasFocus() / visibilityState are unaffected thanks to focus emulation, and page.bringToFront() still raises the window. Skipped for headless (headless shell does not support the parameter) and Android.
Why Chromium-only
- Firefox and WebKit do not reproduce the problem on current builds: headed Firefox never stole focus in testing even though
-foreground is passed (older builds did), and WebKit never steals.
- Firefox's (historical) steal was a one-time app activation at launch caused by the
-foreground CLI arg — a different mechanism than Chromium's per-newPage() foreground target creation, and there is no juggler equivalent of background: true. Affected Firefox users can already opt out via ignoreDefaultArgs: ['-foreground'].
- Extending the option to Firefox would mean skipping
-foreground in defaultArgs() when the option is set; left out for now since it is untestable against current builds and changes launch activation rather than page creation. Happy to generalize if preferred.
fixes #4822
Example
I have a script launches Okta and automatically re-authenticates for me. If the script runs while I'm typing in a different browser, Chrome focuses and my typing is interrupted.
Motivation
There is currently no way to activate Chrome in the background during headful mode without stealing focus from active tasks. This is particularly annoying when trying to work in multiple contexts.
🚀 Feature Request
Allow chrome to open in headful mode but in the background without removing focus from an active window. Firefox already supports this via Playwright flags, but Chrome does not have a flag.
This is a reincarnation of #4822 which had 36+ people support this motive: #4822 (comment) but the issue was already closed
There is an open PR for this #41282 description:
Summary
browserType.launch({ createPagesInBackground: true })option (defaultfalse, no behavior change otherwise).background: truetoTarget.createTarget, sonewPage()no longer activates the browser app and steals OS focus from the user (verified on macOS).document.hasFocus()/visibilityStateare unaffected thanks to focus emulation, andpage.bringToFront()still raises the window. Skipped for headless (headless shell does not support the parameter) and Android.Why Chromium-only
-foregroundis passed (older builds did), and WebKit never steals.-foregroundCLI arg — a different mechanism than Chromium's per-newPage()foreground target creation, and there is no juggler equivalent ofbackground: true. Affected Firefox users can already opt out viaignoreDefaultArgs: ['-foreground'].-foregroundindefaultArgs()when the option is set; left out for now since it is untestable against current builds and changes launch activation rather than page creation. Happy to generalize if preferred.fixes #4822
Example
I have a script launches Okta and automatically re-authenticates for me. If the script runs while I'm typing in a different browser, Chrome focuses and my typing is interrupted.
Motivation
There is currently no way to activate Chrome in the background during headful mode without stealing focus from active tasks. This is particularly annoying when trying to work in multiple contexts.