microsoft / microsoft/playwright
[Feature]: Allow Chrome to launch in the background during headful mode
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 96.3k
- Forks
- 6.5k
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 180
Description
### 🚀 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 https://github.com/microsoft/playwright/issues/4822 which had 36+ people support this motive: https://github.com/microsoft/playwright/issues/4822#issuecomment-971881082 but the issue was already closed
There is an open PR for this https://github.com/microsoft/playwright/pull/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 https://github.com/microsoft/playwright/issues/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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the open PR #41282 and the browserType.launch option described in this issue. Trace headed Chromium page creation through Target.createTarget, then check the existing handling of defaultArgs and ignoreDefaultArgs. Done means the background-launch option works for headed Chromium without stealing focus while preserving normal page visibility and bringToFront behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, testing-qa
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100