Skip to content

[Feature]: Allow Chrome to launch in the background during headful mode #41306

Closed as not planned

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 #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.

Activity

  1. dgozman commented on Jun 16, 2026

    @dgozman
    Collaborator

    Andrew Chen Wang (@Andrew-Chen-Wang) Thank you for explaining your usecase. It sounds very niche, so it's probably not worth a separate API. I'd recommend employing some workaround, for example ctrl-click a link instead of calling newPage() - this should open a background tab instead.

  2. injust commented on Aug 29, 2026

    @injust

    ctrl-click a link instead of calling newPage() - this should open a background tab instead.

    Dmitry Gozman (@dgozman) How do you ctrl-click a link without a page open?

  3. Andrew-Chen-Wang commented on Aug 31, 2026

    @Andrew-Chen-Wang
    Author

    Running into this issue again; we have tons of coding agents running browser instances to verify their code is correct, but it steals away input focus.

  4. fluidsonic commented on Oct 1, 2026

    @fluidsonic

    Same for us. We run plenty of coding agents that keep testing stuff in Playwright, and the autofocus keeps disrupting the user's work.

    We don't use headless, as we want to (a) monitor what the agent is doing and (b) frequently interact with the test website in Playwright.

  5. Andrew-Chen-Wang commented on Oct 1, 2026

    @Andrew-Chen-Wang
    Author

    linking my temporary solution here: #4822 (comment)

  6. hazeliscoding commented on Oct 25, 2026

    @hazeliscoding

    Until Chrome can open pages in the background, here's a workaround on Windows: Staypaw (https://github.com/hazeliscoding/staypaw; I'm its author) notices when headed Chrome takes focus while you're typing elsewhere, and puts focus straight back, along with the keys you typed meanwhile. It can also keep one app you pick, such as your editor, in front even while you're idle. It doesn't touch the browser or Playwright.

  7. pavelfeldman commented on Oct 31, 2026

    @pavelfeldman
    Member

    We're closing all P3-collecting-feedback issues and retiring the label. #43813 explains why. This doesn't mean the request is wrong. If it still matters to you, please open a new issue against the latest Playwright version with your concrete use case and link back here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions