Add js parameter for custom JavaScript injection

- Add js parameter to ScreenshotOptions interface (max 5000 chars)
- Execute JavaScript via page.evaluate() after delay, before CSS/hideSelectors
- 5-second timeout with JS_TIMEOUT error handling
- JS_EXECUTION_ERROR for script failures with sanitized error messages
- Support in both GET and POST endpoints with validation
- Updated OpenAPI spec for both GET and POST routes
- Added comprehensive test coverage (service + route layers)
- Updated SDK documentation (Node.js and Python) with examples

Test results: 414 tests passing (includes new JS injection tests)
This commit is contained in:
SnapAPI Developer 2026-03-05 12:07:54 +01:00
parent ba888bb580
commit 91a08bab70
6 changed files with 572 additions and 3 deletions

View file

@ -125,6 +125,37 @@ combined = snap.capture(
)
```
### JavaScript Injection
```python
# Execute custom JavaScript before capture
interactive_screenshot = snap.capture(
"https://example.com",
js="""
// Dismiss modal popup
document.querySelector('.modal-overlay')?.remove();
// Scroll to specific content
window.scrollTo(0, 500);
// Click button to reveal content
document.querySelector('#show-more-btn')?.click();
// Wait for animation to complete
await new Promise(resolve => setTimeout(resolve, 1000));
""",
)
# Combine with other options for complex scenarios
complex_capture = snap.capture(
"https://example.com/app",
js='document.querySelector(".sidebar").style.display = "none";',
css="body { zoom: 0.8 }",
wait_for_selector="#content-loaded",
hide_selectors=[".ad-banner", ".cookie-notice"],
)
```
### Error Handling
```python