Skip to content

Fix: Catch TargetClosedError in PlaywrightController.sleep() to avoid crashes on download-triggered page closes #6415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

oscarvdl
Copy link

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

@oscarvdl oscarvdl changed the title Fix: Catch TargetClosedError in PlaywrightController.sleep() to avoid crashes on download-triggered page closes. Fix: Catch TargetClosedError in PlaywrightController.sleep() to avoid crashes on download-triggered page closes Apr 27, 2025
@ekzhu ekzhu requested a review from husseinmozannar April 29, 2025 20:47
Copy link

codecov bot commented May 6, 2025

Codecov Report

Attention: Patch coverage is 60.00000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 78.55%. Comparing base (bacfa98) to head (0342085).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...gen_ext/agents/web_surfer/playwright_controller.py 60.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6415      +/-   ##
==========================================
- Coverage   78.56%   78.55%   -0.01%     
==========================================
  Files         225      225              
  Lines       16549    16552       +3     
==========================================
+ Hits        13001    13002       +1     
- Misses       3548     3550       +2     
Flag Coverage Δ
unittests 78.55% <60.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

TargetClosedError during sleep after click-triggered download in PlaywrightController
2 participants