Add selector parameter for element screenshots
Some checks failed
Build & Deploy to Staging / Build & Deploy to Staging (push) Has been cancelled

- New optional selector parameter to capture specific DOM elements
- Works with all existing parameters (format, quality, darkMode, etc.)
- Validates selector for length (max 200 chars) and dangerous content
- Mutual exclusivity with fullPage parameter
- Returns 400 error if selector not found
- Updates OpenAPI spec for both GET and POST endpoints
- Full test coverage including edge cases
This commit is contained in:
SnapAPI Developer 2026-03-05 12:07:55 +01:00
parent 91a08bab70
commit f1d63cdc66

View file

@ -117,6 +117,9 @@ export const screenshotRouter = Router();
* mobile: * mobile:
* summary: Mobile viewport * summary: Mobile viewport
* value: { "url": "https://example.com", "width": 375, "height": 812, "deviceScale": 2 } * value: { "url": "https://example.com", "width": 375, "height": 812, "deviceScale": 2 }
* element:
* summary: Element screenshot
* value: { "url": "https://github.com", "selector": "#readme" }
* responses: * responses:
* 200: * 200:
* description: Screenshot image binary * description: Screenshot image binary
@ -263,6 +266,13 @@ export const screenshotRouter = Router();
* maxLength: 5000 * maxLength: 5000
* description: Custom JavaScript code to execute on the page before capture (max 5000 chars, 5-second timeout) * description: Custom JavaScript code to execute on the page before capture (max 5000 chars, 5-second timeout)
* example: "document.querySelector('.modal').remove();" * example: "document.querySelector('.modal').remove();"
* - name: selector
* in: query
* schema:
* type: string
* maxLength: 200
* description: CSS selector for element to capture instead of full page/viewport (max 200 chars)
* example: "#main-content"
* - name: darkMode * - name: darkMode
* in: query * in: query
* schema: * schema: