Skip to content

Fix compatibility with manual lifecycle management#27

Open
tobbber wants to merge 1 commit intoMattwmaster58:mainfrom
tobbber:main
Open

Fix compatibility with manual lifecycle management#27
tobbber wants to merge 1 commit intoMattwmaster58:mainfrom
tobbber:main

Conversation

@tobbber
Copy link

@tobbber tobbber commented Feb 6, 2026

The wrapping context managers currently behave slightly differently from the upstream async and sync Playwright context managers they are wrapping.

I ran into this when using playwright-stealth together with scrapy-playwright:

This change would make the stealth context-managers more consistent with interface of the original playwright context managers and improve compatibility with libraries such as scrapy-playwright.

Cheers!

Summary by CodeRabbit

  • New Features

    • Added new context manager initialization method for improved usability.
  • Chores

    • Enhanced context manager implementation with improved flexibility in lifecycle operations.

@coderabbitai
Copy link

coderabbitai bot commented Feb 6, 2026

Walkthrough

The pull request adds new start() methods to both async and sync context manager wrapper classes and refactors their exit methods to accept flexible arguments using *args for more generic exception handling forwarding.

Changes

Cohort / File(s) Summary
Context Manager Enhancements
playwright_stealth/context_managers.py
Added start() public methods to AsyncWrappingContextManager and SyncWrappingContextManager classes. Refactored __aexit__ and __exit__ method signatures to accept *args instead of explicit exception parameters, enabling flexible argument forwarding to underlying managers.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 Hop, hop, hooray! The context managers leap,
With start() methods now bright and neat,
Flexible *args flowing through and through,
Less rigid, more clever—our stealth friends anew! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding a start() method and refactoring aexit/exit signatures to fix compatibility issues with manual lifecycle management in libraries like scrapy-playwright.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

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.

1 participant