Skip to content

fix: parse PLAYWRIGHT_HEADLESS as case-insensitive boolean (fixes #119) - #123

Open
VG31OP wants to merge 3 commits into
google-gemini:mainfrom
VG31OP:fix/playwright-headless-env-bool
Open

VG31OP wants to merge 3 commits into
google-gemini:mainfrom
VG31OP:fix/playwright-headless-env-bool

Conversation

@VG31OP

@VG31OP VG31OP commented Oct 14, 2026 •

Copy link
Copy Markdown

Description

Fixes #119.

In computers/playwright/playwright.py, PLAYWRIGHT_HEADLESS was parsed using:

headless=bool(os.environ.get("PLAYWRIGHT_HEADLESS", False)),

Because os.environ.get() returns a string when set, bool("false") evaluates to True in Python (any non-empty string is truthy). Consequently, setting PLAYWRIGHT_HEADLESS=false in .env (which is the default in .env.example) caused the browser to always run in headless mode.

Solution

  1. Align the boolean parsing with the existing pattern in agent.py line 109:
    headless=os.environ.get("PLAYWRIGHT_HEADLESS", "false").lower() in ["true", "1"],
    This properly treats "false", "0", and unset as False while respecting "true" and "1" as True.
  2. Add unit tests in test_playwright.py covering "false", "true", and unset default cases.

Verification

Ran all tests with pytest:

  • test_agent.py (11 passed)
  • test_main.py (2 passed)
  • test_playwright.py (3 passed)
  • 16 passed in 8.80s

…mini#119)

Fixes google-gemini#119

Previously, bool(os.environ.get('PLAYWRIGHT_HEADLESS', False)) evaluated any non-empty string as True because bool('false') is True in Python. Consequently, setting PLAYWRIGHT_HEADLESS=false (as shown in .env.example) caused Playwright to always run in headless mode.

This aligns the boolean parsing with the existing pattern used in agent.py (os.environ.get(...).lower() in ['true', '1']), properly respecting false/0 values while maintaining default non-headless behavior when unset.
@google-cla

google-cla Bot commented Oct 14, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the evaluation of the 'PLAYWRIGHT_HEADLESS' environment variable to correctly parse string values like 'true' or '1' as booleans, and introduces unit tests to verify this behavior. The feedback recommends avoiding the use of 'clear=True' when patching 'os.environ' in tests, as clearing all environment variables can lead to unexpected side effects, and suggests specifically removing the target key instead.

Comment thread test_playwright.py Resolved
@VG31OP

VG31OP commented Oct 18, 2026 •

Copy link
Copy Markdown
Author

Thanks @gemini-code-assist for the review! Addressed in commit 0944952.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Thank you for the update. The changes look correct and the added unit tests provide good coverage for the environment variable parsing logic. The fix correctly addresses the issue where bool("false") was evaluating to True.

@VG31OP

VG31OP commented Oct 18, 2026

Copy link
Copy Markdown
Author

Commit reference: 0944952. Ready for maintainer merge.

@VG31OP

VG31OP commented Nov 18, 2026

Copy link
Copy Markdown
Author

Update: Expanded Test Coverage & Clean Documentation

In commit 7e4cdc5, I have added explicit test coverage in test_playwright.py to verify:

  • Numeric environment variable values: "1" (evaluates to True) and "0" (evaluates to False).
  • Case-insensitivity: "TRUE" (evaluates to True).
  • Cleaned up the PR description formatting.

All unit tests and repository status checks pass cleanly. Ready for maintainer review and merge.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PLAYWRIGHT_HEADLESS=false has no effect, browser always run headless

1 participant