Skip to content

[codex] Add browser humanization controls#41

Merged
michaelmwu merged 1 commit into
mainfrom
michaelmwu/botasaurus-mouse-windows
May 21, 2026
Merged

[codex] Add browser humanization controls#41
michaelmwu merged 1 commit into
mainfrom
michaelmwu/botasaurus-mouse-windows

Conversation

@michaelmwu
Copy link
Copy Markdown
Member

@michaelmwu michaelmwu commented May 21, 2026

Summary

  • Add weighted random desktop window sizing for browser sessions, with stable sizing for persistent profile directories.
  • Add opt-in CloakBrowser humanized input via BrowserSessionConfig(human_mouse=True) and the --human-mouse CLI flag.
  • Add --disable-random-window-size for callers that need CloakBrowser's default viewport, and carry session options into parallel worker sessions.
  • Update usage docs and focused coverage for launch arguments, CLI forwarding, and worker session propagation.

Validation

  • uv run python -m unittest tests.test_scraper tests.test_cli tests.test_place_scraper
  • uv run python -m unittest discover -s tests
  • ./scripts/lint.sh
  • ./scripts/typecheck.sh
  • Pre-commit hooks on commit: ruff, mypy
  • git diff --check

Summary by CodeRabbit

  • New Features

    • Added --disable-random-window-size and --human-mouse CLI flags to control browser behavior
    • Added browser session configuration options for window sizing and mouse humanization
  • Documentation

    • Updated library examples and usage documentation with new browser configuration options
  • Tests

    • Added comprehensive test coverage for new CLI flags and browser configuration propagation

Review Change Stack

Copilot AI review requested due to automatic review settings May 21, 2026 06:59
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 21, 2026

📝 Walkthrough

Walkthrough

This PR introduces browser window size humanization with user-facing CLI control. A new browser_humanization module provides weighted random or stable per-profile viewport selection; BrowserSessionConfig gains window_size and human_mouse fields; browser launch logic applies these settings; and CLI flags --disable-random-window-size and --human-mouse expose the behavior to users.

Changes

Browser Humanization and Window Sizing

Layer / File(s) Summary
Browser window size humanization foundation
src/gmaps_scraper/browser_humanization.py
New module defines BrowserWindowSize type and resolve_browser_window_size() function supporting random weighted selection, stable per-profile selection, or explicit positive dimensions.
Session configuration extension
src/gmaps_scraper/scraper.py
BrowserSessionConfig extends with window_size (default "random") and human_mouse (default False); imports new types and resolver.
Browser context launch integration
src/gmaps_scraper/scraper.py
_launch_browser_context applies humanize from session, resolves and applies window sizing via command-line args and viewport, and uses session configuration consistently.
CLI interface and configuration wiring
src/gmaps_scraper/cli.py
Adds --disable-random-window-size and --human-mouse flags; main() constructs BrowserSessionConfig with resolved window sizing and humanization options.
Parallel worker configuration propagation
src/gmaps_scraper/place_scraper.py
_browser_session_for_parallel_worker propagates window_size and human_mouse into per-worker session instances.
Test coverage for humanization and sizing
tests/test_cli.py, tests/test_place_scraper.py, tests/test_scraper.py
CLI test verifies flag forwarding; place scraper test tracks worker settings; scraper tests patch window resolution and assert viewport and args application.
Documentation and usage examples
README.md, docs/USAGE.md
README example adds human_mouse=True; USAGE.md documents viewport defaults and CLI flag behavior.

🎯 3 (Moderate) | ⏱️ ~25 minutes

🐰 A rabbit hops through windows new—
Some sized by weight, some picked per crew,
Mouse clicks humanized, CLI flags true,
Workers echo config through and through!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title '[codex] Add browser humanization controls' directly and accurately summarizes the main changes: adding browser window sizing and humanized input controls via new CLI flags and configuration options.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch michaelmwu/botasaurus-mouse-windows

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces configurable “humanization” controls for browser-based scraping sessions, including weighted random desktop window sizing (with stable sizing for persistent profile directories) and an opt-in toggle for CloakBrowser’s humanized input behaviors. It threads these options through the CLI and parallel place-scraping workers, and updates documentation plus targeted tests to validate the new forwarding/launch behavior.

Changes:

  • Add BrowserSessionConfig.window_size (default "random") and BrowserSessionConfig.human_mouse (default False), and apply them when launching CloakBrowser contexts.
  • Add CLI flags --human-mouse and --disable-random-window-size, forwarding them into BrowserSessionConfig.
  • Propagate browser session options into parallel worker sessions and add focused unit coverage + docs updates.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/gmaps_scraper/browser_humanization.py New helper module to resolve weighted-random vs stable window sizes (and validate explicit sizes).
src/gmaps_scraper/scraper.py Extends BrowserSessionConfig and applies resolved window sizing + humanization when launching CloakBrowser contexts.
src/gmaps_scraper/cli.py Adds/forwards --human-mouse and --disable-random-window-size into BrowserSessionConfig.
src/gmaps_scraper/place_scraper.py Ensures parallel worker sessions inherit window_size and human_mouse.
tests/test_scraper.py Updates launch-context expectations and stabilizes window-size behavior via patching.
tests/test_place_scraper.py Verifies worker session propagation of human_mouse and window_size.
tests/test_cli.py Adds coverage ensuring CLI flags are forwarded into BrowserSessionConfig.
README.md Updates example to demonstrate human_mouse=True.
docs/USAGE.md Documents default random sizing behavior and the new CLI flags.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
tests/test_cli.py (1)

213-247: 🏗️ Heavy lift

Strengthen test by covering individual flag behavior and defaults.

The test verifies that both flags together produce the expected session configuration, but doesn't test individual flags or default behavior. This test would pass even if individual flags were broken, as long as the combination worked.

Consider adding test cases for:

  • --human-mouse alone (should yield human_mouse=True, window_size="random")
  • --disable-random-window-size alone (should yield window_size=None, human_mouse=False)
  • Neither flag present (should yield default window_size="random", human_mouse=False)

As per coding guidelines, tests should encode intent and would be stronger if they caught single-flag regressions independently.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/test_cli.py` around lines 213 - 247, Add separate unit cases alongside
test_forwards_browser_humanization_flags to verify each flag and the default:
call main() with only "--human-mouse" and assert collect_saved_list_result was
called with BrowserSessionConfig(window_size="random", human_mouse=True); call
main() with only "--disable-random-window-size" and assert
BrowserSessionConfig(window_size=None, human_mouse=False); and call main() with
neither flag and assert BrowserSessionConfig(window_size="random",
human_mouse=False). Use the same pattern of patching sys.argv,
gmaps_scraper.cli.collect_saved_list_result, and redirect_stdout as in the
existing test to assert exit_code, payload output, and the
collect_saved_list_result call arguments.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@tests/test_cli.py`:
- Around line 213-247: Add separate unit cases alongside
test_forwards_browser_humanization_flags to verify each flag and the default:
call main() with only "--human-mouse" and assert collect_saved_list_result was
called with BrowserSessionConfig(window_size="random", human_mouse=True); call
main() with only "--disable-random-window-size" and assert
BrowserSessionConfig(window_size=None, human_mouse=False); and call main() with
neither flag and assert BrowserSessionConfig(window_size="random",
human_mouse=False). Use the same pattern of patching sys.argv,
gmaps_scraper.cli.collect_saved_list_result, and redirect_stdout as in the
existing test to assert exit_code, payload output, and the
collect_saved_list_result call arguments.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2b9c10e7-1714-47b4-abb7-61b6d2afa79b

📥 Commits

Reviewing files that changed from the base of the PR and between 8a94e9c and f21c4f0.

📒 Files selected for processing (9)
  • README.md
  • docs/USAGE.md
  • src/gmaps_scraper/browser_humanization.py
  • src/gmaps_scraper/cli.py
  • src/gmaps_scraper/place_scraper.py
  • src/gmaps_scraper/scraper.py
  • tests/test_cli.py
  • tests/test_place_scraper.py
  • tests/test_scraper.py

@michaelmwu michaelmwu merged commit 9338823 into main May 21, 2026
5 checks passed
@michaelmwu michaelmwu deleted the michaelmwu/botasaurus-mouse-windows branch May 21, 2026 07:05
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.

2 participants