Skip to content

Commit f73e488

Browse files
author
Nutchanon Ninyawee
committed
Add RENDER_COMPLETE signal for precise screenshot timing
- Updated README with new feature for controlling screenshot timing - Added documentation for `render_timeout` parameter - Explained use cases for custom rendering signal - Provided example of how to use RENDER_COMPLETE in HTML/JavaScript - Updated CLI options to include render timeout parameter
1 parent e5efa4b commit f73e488

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Built on top of `playwright` for reliability and speed.
3333
- 🖼️ **Flexible Display**: Multiple object-fit options (contain, cover, fill)
3434
- 🖨️ **Print-Ready**: Combined PrintMediaResolution for precise document sizing
3535
- 💪 **Developer Friendly**: Sensible defaults with optional fine-tuning
36+
- ⏱️ **Precise Timing**: Custom `RENDER_COMPLETE` signal for perfect screenshot timing
3637

3738
## 🧑‍💻 Development
3839

@@ -266,6 +267,42 @@ screenshot = generate_image_sync(
266267
)
267268
```
268269

270+
### Render Complete Signal
271+
272+
For pages with dynamic content or JavaScript animations, you can control exactly when the screenshot is taken using the `RENDER_COMPLETE` signal:
273+
274+
```python
275+
from snap_html import generate_image_sync
276+
277+
# Specify a longer timeout for waiting for the RENDER_COMPLETE signal
278+
screenshot = generate_image_sync(
279+
"https://www.example.com",
280+
render_timeout=15.0 # Wait up to 15 seconds for RENDER_COMPLETE signal
281+
)
282+
```
283+
284+
In your HTML/JavaScript, add a console log message to signal when rendering is complete:
285+
286+
```html
287+
<script>
288+
// After your page is fully rendered and ready for screenshot
289+
window.addEventListener('load', function() {
290+
// Do any final rendering tasks
291+
setTimeout(function() {
292+
console.log('RENDER_COMPLETE');
293+
}, 500); // Add a small delay if needed
294+
});
295+
</script>
296+
```
297+
298+
This is particularly useful for:
299+
- Pages with dynamic content loading
300+
- JavaScript animations or transitions
301+
- Asynchronous data fetching
302+
- Custom rendering logic
303+
304+
If the `RENDER_COMPLETE` signal is not received within the specified timeout, snap-html will fall back to using the "networkidle" state to determine when to take the screenshot.
305+
269306
## 🖥️ CLI Usage
270307

271308
**Basic commands**:
@@ -282,6 +319,9 @@ snap-html capture https://example.com -o screenshot.png --width 1024 --height 76
282319

283320
# Using both pixel and physical dimensions with object-fit
284321
snap-html capture https://example.com -o screenshot.png --width 1920 --height 1080 --cm-width 21.0 --cm-height 29.7 --object-fit cover
322+
323+
# Wait for RENDER_COMPLETE signal with custom timeout
324+
snap-html capture https://example.com -o screenshot.png --render-timeout 15.0
285325
```
286326

287327
**Available Options**:
@@ -294,6 +334,7 @@ snap-html capture https://example.com -o screenshot.png --width 1920 --height 10
294334
--dpi INTEGER DPI for cm-based resolution [default: 300]
295335
--scale FLOAT Browser scale factor (zoom level) [default: 1.5]
296336
--object-fit TEXT How content fits viewport: contain, cover, fill, none [default: contain]
337+
--render-timeout FLOAT Time to wait for RENDER_COMPLETE signal (in seconds) [default: 10.0]
297338
--help Show this message and exit.
298339
```
299340

0 commit comments

Comments
 (0)