Fix cdp setting with managed browser #1572
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes a concurrency bug in AsyncWebCrawler.arun_many() when using managed browsers. The issue was that all concurrent crawl tasks were fighting over one shared tab, causing failures. The fix modifies the get_page() method in browser_manager.py to always create new pages instead of reusing context.pages[0] for managed browsers.
Fixes #1563
List of files changed and why
crawl4ai/browser_manager.py - Modified the get_page() method to create new pages for managed browsers instead of reusing the first page, which was causing tab contention in concurrent scenarios.
tests/test_cdp_concurrency_compact.py - Created a comprehensive test suite that verifies the concurrency fix works correctly across multiple scenarios including basic arun_many functionality, managed CDP browsers, and various concurrency patterns.
How Has This Been Tested?
Created and ran a comprehensive test suite with 6 different test scenarios:
All tests pass successfully, demonstrating that:
Manual verification of the fix with both basic and managed browser configurations.
Checklist: