autogen
autogen copied to clipboard
Fix: Catch TargetClosedError in PlaywrightController.sleep() to avoid crashes on download-triggered page closes
Why are these changes needed?
This PR fixes a crash that occurs when using MultimodalWebSurfer in scenarios where a click triggers a file download.
After the download is initiated, Playwright may close the page or context, leading to a TargetClosedError during sleep() in PlaywrightController.
The previous implementation of sleep() did not handle these closures, causing the agent to crash unexpectedly.
This PR adds safe exception handling for TargetClosedError and PlaywrightError during sleep(), ensuring that the agent can continue operating gracefully even if the page closes.
Related issue number
Closes #6413
Checks
- [ ] I've included any doc changes needed for https://microsoft.github.io/autogen/. See https://github.com/microsoft/autogen/blob/main/CONTRIBUTING.md to build and test documentation locally.
- [ ] I've added tests (if relevant) corresponding to the changes introduced in this PR.
- [x] I've made sure all auto checks have passed.