Fix cdp setting with managed browser #1572
Open
Ahmed-Tawfik94 wants to merge 2 commits intodevelopfrom
Open
Conversation
…rency - Modify get_page() to always create new pages instead of reusing existing ones - Add page lock to serialize new page creation in managed browser context - Improve subprocess argument formatting and cleanup logging - Delegate profile-related static methods to BrowserProfiler class - Enhance startup checks for managed browser processes - Add comprehensive test suite validating concurrency fix for arun_many with CDP browsers - Fix proxy flag formatting and deduplicate browser launch args - Refactor imports and code formatting for clarity and consistency
… concurrency - Modify get_page() to always create new pages instead of reusing existing ones - Add page lock to serialize new page creation in managed browser context - Improve subprocess argument formatting and cleanup logging - Delegate profile-related static methods to BrowserProfiler class - Enhance startup checks for managed browser processes - Add comprehensive test suite validating concurrency fix for arun_many with CDP browsers - Fix proxy flag formatting and deduplicate browser launch args - Refactor imports and code formatting for clarity and consistency
Contributor
|
I was eagerly anticipating this pull request to land. Great job guys |
|
Hi team, thank you for all the hard work! any way we can help here to move this PR forward? This solves a bug that we have been encountering using cdp. |
Collaborator
|
Hi there! We will include this in our next release in two weeks. Stay tuned! 💜 |
|
Hi @ntohidi , thank you for all the hard work! I was wondering if a realease it planned soon for this PR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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: