fix(playwright): Fix tiled screenshot clip bounds validation#35806
fix(playwright): Fix tiled screenshot clip bounds validation#35806
Conversation
Fixes issue where Playwright tiled screenshots fail with "Clipped area is either empty or outside the resulting image" error on large dashboards (50+ charts). The problem occurred when: - Dashboard elements scroll above viewport (negative Y coordinates) - Clip regions extend beyond viewport boundaries - Element dimensions result in invalid clip calculations Changes: - Add viewport dimension tracking to clip calculations - Clamp coordinates to viewport bounds (prevent negative x/y) - Calculate visible portions for partially scrolled elements - Validate clip dimensions before screenshot (skip invalid tiles) - Add comprehensive test coverage for edge cases Tested with 21 unit tests including: - Negative element positions - Elements beyond viewport bounds - Invalid clip dimensions - Zero-width elements - Elements completely scrolled out of view 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Code Review Agent Run #b6d49eActionable Suggestions - 0Additional Suggestions - 4
Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
There was a problem hiding this comment.
I've completed my review and didn't find any issues.
Files scanned
| File Path | Reviewed |
|---|---|
| superset/utils/screenshot_utils.py | ✅ |
Explore our documentation to understand the languages and file types we support and the files we ignore.
Check out our docs on how you can make Korbit work best for you and your team.
Interaction Diagram by BitosequenceDiagram
participant REP as Report Execute Command
participant SCR as Screenshot Service<br/>🔄 Updated | ●●○ Medium
participant WEB as WebDriver Playwright
participant TSS as take_tiled_screenshot<br/>🔄 Updated | ●●● High
participant PAGE as Playwright Page
participant CMB as combine_screenshot_tiles
Note over TSS: Enhanced viewport bounds<br/>validation & clipping logic
REP->>SCR: get_screenshot(user)
SCR->>WEB: get_screenshot(url, element, user)
WEB->>TSS: take_tiled_screenshot(page, element_name)
TSS->>PAGE: evaluate() - get viewport info
PAGE-->>TSS: viewport dimensions & element bounds
TSS->>PAGE: screenshot(clip) - with validated bounds
PAGE-->>TSS: tile screenshot bytes
TSS->>CMB: combine_screenshot_tiles(tiles)
CMB-->>TSS: combined screenshot
TSS-->>WEB: screenshot bytes
WEB-->>SCR: screenshot data
SCR-->>REP: final screenshot
Critical path: Report Execute Command->Screenshot Service->WebDriver Playwright->take_tiled_screenshot->combine_screenshot_tiles
|
…lti-tile captures Fixes issue where Playwright tiled screenshots only captured the first frame and failed to capture subsequent tiles on large dashboards (50+ charts). **Problem:** The previous fix prevented errors but used overly complex tile_content_height calculations that caused incorrect clip dimensions for tiles after the first one. Customer testing revealed screenshots would not capture content past the first tile. **Solution:** Simplified the clip height calculation by: - Removing tile_content_height from the clip height logic - Directly calculating visible portion of element in viewport - Maintaining proper handling for elements scrolled above viewport After scrolling to position each tile, we now simply capture what's visible of the element rather than trying to match a calculated content height. **Testing:** - All 21 unit tests pass including edge cases - Negative element positions (scrolled above viewport) - Elements extending beyond viewport boundaries - Elements completely out of view Based on customer feedback from Brandon Sovran who confirmed this approach successfully captures massive pages. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
|
From codex, we should see if the test will catch the regression or not.
|
…ll calculations The configured SCREENSHOT_TILED_VIEWPORT_HEIGHT (default 2000px) was larger than Playwright's actual browser viewport (~768-1200px), causing scroll increments to skip content between tiles. Now we fetch the actual viewport height and use min(configured, actual) for scroll calculations to ensure complete content coverage. Added regression test to verify tiles properly cover all content when configured viewport exceeds actual viewport size. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
|
I'm handing this off to @kgabryje |
SUMMARY
Fixes the "Clipped area is either empty or outside the resulting image" error that occurs when generating tiled screenshots for large dashboards (50+ charts).
Root Cause:
When scrolling through tall dashboards to capture tiles,
getBoundingClientRect()returns negative Y coordinates for elements scrolled above the viewport. Playwright rejects these invalid clip coordinates, causing the screenshot to fail.Solution:
page.screenshot()Changes:
superset/utils/screenshot_utils.py: Enhanced clip validation logic (lines 142-205)tests/unit_tests/utils/test_screenshot_utils.py: Added 6 new edge case testsTest Coverage:
All 21 unit tests passing, including new tests for:
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
BEFORE:
Tiled screenshot fails → Falls back to single screenshot → Empty PDF for large dashboards
AFTER:
TESTING INSTRUCTIONS
Unit Tests:
All 21 tests should pass
Manual Testing (requires large dashboard):
Verify Logs:
ADDITIONAL INFORMATION
SCREENSHOT_TILED_ENABLED=True(optional, for testing)🤖 Generated with Claude Code